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 <gabriel.dedietrich@digia.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
This commit is contained in:
Andy Shaw 2013-10-15 20:11:37 +02:00 committed by The Qt Project
parent 66e3e1f75b
commit b271ddebfc
2 changed files with 14 additions and 4 deletions

View File

@ -204,6 +204,7 @@ public: // for QNSView
static const int NoAlertRequest;
NSInteger m_alertRequest;
id monitor;
};
QT_END_NAMESPACE

View File

@ -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 {
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) {