From b271ddebfcda26839a02705f17e287a4686f36fb Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 15 Oct 2013 20:11:37 +0200 Subject: [PATCH] Ensure that context menus show even if the window is not active on Mac When using the mouse to show a context menu on Mac then even if the window is not active then it will show the menu for native applications. So this ensures that this is respected for context menus in Qt too. Task-number: QTBUG-31497 Change-Id: Ibfcb4b893b0e31d4ce36926a83c9214d130d8fa2 Reviewed-by: Gabriel de Dietrich Reviewed-by: Shawn Rutledge --- src/plugins/platforms/cocoa/qcocoawindow.h | 1 + src/plugins/platforms/cocoa/qcocoawindow.mm | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index 05bf657c1fc..6598bf393ea 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -204,6 +204,7 @@ public: // for QNSView static const int NoAlertRequest; NSInteger m_alertRequest; + id monitor; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index bee6d635ece..522b48a61e2 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -213,6 +213,7 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw) , m_registerTouchCount(0) , m_resizableTransientParent(false) , m_alertRequest(NoAlertRequest) + , monitor(nil) { #ifdef QT_COCOA_ENABLE_WINDOW_DEBUG qDebug() << "QCocoaWindow::QCocoaWindow" << this; @@ -367,6 +368,11 @@ void QCocoaWindow::setVisible(bool visible) if ((window()->type() == Qt::Popup || window()->type() == Qt::Dialog || window()->type() == Qt::Tool) && [m_nsWindow isKindOfClass:[NSPanel class]]) { [(NSPanel *)m_nsWindow setWorksWhenModal:YES]; + if (!(parentCocoaWindow && window()->transientParent()->isActive()) && window()->type() == Qt::Popup) { + monitor = [NSEvent addGlobalMonitorForEventsMatchingMask:NSLeftMouseDownMask|NSRightMouseDownMask|NSOtherMouseDown handler:^(NSEvent *) { + QWindowSystemInterface::handleMouseEvent(window(), QPointF(-1, -1), QPointF(window()->framePosition() - QPointF(1, 1)), Qt::LeftButton); + }]; + } } } } @@ -403,6 +409,10 @@ void QCocoaWindow::setVisible(bool visible) } else { [m_contentView setHidden:YES]; } + if (monitor && window()->type() == Qt::Popup) { + [NSEvent removeMonitor:monitor]; + monitor = nil; + } if (parentCocoaWindow && window()->type() == Qt::Popup) { parentCocoaWindow->m_activePopupWindow = 0; if (m_resizableTransientParent @@ -849,10 +859,9 @@ NSWindow * QCocoaWindow::createNSWindow() // before the window is shown and needs a proper window.). if ((type & Qt::Popup) == Qt::Popup) [window setHasShadow:YES]; - else { - setWindowShadow(flags); - [window setHidesOnDeactivate: NO]; - } + else + setWindowShadow(flags); + [window setHidesOnDeactivate: NO]; #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {