From b5d6851c976ef87a9f662a8aaae3db45d6141cef Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 20 Aug 2020 17:57:42 +0400 Subject: [PATCH] Fix build with Qt 5.6.2. --- ui/platform/mac/ui_window_mac.h | 8 ++++++++ ui/platform/mac/ui_window_mac.mm | 30 ++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/ui/platform/mac/ui_window_mac.h b/ui/platform/mac/ui_window_mac.h index 6653079..717c5e3 100644 --- a/ui/platform/mac/ui_window_mac.h +++ b/ui/platform/mac/ui_window_mac.h @@ -39,6 +39,14 @@ private: const not_null _title; const not_null _body; +#ifdef OS_OSX + struct WindowDrag { + QPoint windowStartPosition; + QPoint dragStartPosition; + }; + std::optional _drag; +#endif // OS_OSX + }; } // namespace Platform diff --git a/ui/platform/mac/ui_window_mac.mm b/ui/platform/mac/ui_window_mac.mm index a67a1f2..550584e 100644 --- a/ui/platform/mac/ui_window_mac.mm +++ b/ui/platform/mac/ui_window_mac.mm @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -188,8 +189,10 @@ bool WindowHelper::Private::checkNativeMove(void *nswindow) const { || ([_nativeWindow styleMask] & NSFullScreenWindowMask) == NSFullScreenWindowMask) { return false; } - const auto real = QPointF::fromCGPoint([NSEvent mouseLocation]); - const auto frame = QRectF::fromCGRect([_nativeWindow frame]); + const auto cgReal = [NSEvent mouseLocation]; + const auto real = QPointF(cgReal.x, cgReal.y); + const auto cgFrame = [_nativeWindow frame]; + const auto frame = QRectF(cgFrame.origin.x, cgFrame.origin.y, cgFrame.size.width, cgFrame.size.height); const auto border = QMarginsF{ 3., 3., 3., 3. }; return frame.marginsRemoved(border).contains(real); } @@ -341,6 +344,7 @@ void WindowHelper::setGeometry(QRect rect) { } void WindowHelper::setupBodyTitleAreaEvents() { +#ifndef OS_OSX const auto controls = _private->controlsRect(); qApp->installNativeEventFilter(new EventFilter(window(), [=](void *nswindow) { const auto point = body()->mapFromGlobal(QCursor::pos()); @@ -353,6 +357,28 @@ void WindowHelper::setupBodyTitleAreaEvents() { } return false; })); +#else // OS_OSX + // OS X 10.10 doesn't have performWindowDragWithEvent yet. + body()->events() | rpl::start_with_next([=](not_null e) { + const auto hitTest = [&] { + return bodyTitleAreaHit( + static_cast(e.get())->pos()); + }; + if (e->type() == QEvent::MouseButtonRelease + && (static_cast(e.get())->button() + == Qt::LeftButton)) { + _drag = std::nullopt; + } else if (e->type() == QEvent::MouseButtonPress + && hitTest() + && (static_cast(e.get())->button() + == Qt::LeftButton)) { + _drag = { window()->pos(), static_cast(e.get())->globalPos() }; + } else if (e->type() == QEvent::MouseMove && _drag && !window()->isFullScreen()) { + const auto delta = static_cast(e.get())->globalPos() - _drag->dragStartPosition; + window()->move(_drag->windowStartPosition + delta); + } + }, body()->lifetime()); +#endif // OS_OSX } void WindowHelper::close() {