From e6b97fd2c793ae702cf2102e43ce9efb4d27983a Mon Sep 17 00:00:00 2001 From: Christoph Schleifenbaum Date: Mon, 16 Mar 2015 15:51:53 +0100 Subject: [PATCH] Cocoa: Don't let key events triggering input method events close dialog. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added a flag to QCocoaWindow to ignore shouldCloseWindow. This is set from within QNSView when escape is pressed and the current focus widgets is processing input method events (like QTextEdit). This lead to unwanted dialog rejects. Task-number: QTBUG-44076 Change-Id: Ic90a8a6ba8c5cddbc0d486563acad57dd384d179 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoawindow.h | 1 + src/plugins/platforms/cocoa/qcocoawindow.mm | 4 ++++ src/plugins/platforms/cocoa/qnsview.mm | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index cc14cd75ba..4064f31cd7 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -265,6 +265,7 @@ public: // for QNSView QPointer m_enterLeaveTargetWindow; bool m_windowUnderMouse; + bool m_ignoreWindowShouldClose; bool m_inConstructor; bool m_inSetVisible; bool m_inSetGeometry; diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 5877885eee..f811bd630f 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -371,6 +371,7 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw) , m_synchedWindowState(Qt::WindowActive) , m_windowModality(Qt::NonModal) , m_windowUnderMouse(false) + , m_ignoreWindowShouldClose(false) , m_inConstructor(true) , m_inSetVisible(false) , m_inSetGeometry(false) @@ -1218,6 +1219,9 @@ void QCocoaWindow::windowDidEndLiveResize() bool QCocoaWindow::windowShouldClose() { + // might have been set from qnsview.mm + if (m_ignoreWindowShouldClose) + return false; bool accepted = false; QWindowSystemInterface::handleCloseEvent(window(), &accepted); QWindowSystemInterface::flushWindowSystemEvents(); diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index a969981400..0b0dcc4322 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -1437,6 +1437,10 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent) QObject *fo = QGuiApplication::focusObject(); if (m_sendKeyEvent && fo) { + // if escape is pressed we don't want interpretKeyEvents to close a dialog. This will be done via QWindowSystemInterface + if (keyCode == Qt::Key_Escape) + m_platformWindow->m_ignoreWindowShouldClose = true; + QInputMethodQueryEvent queryEvent(Qt::ImEnabled | Qt::ImHints); if (QCoreApplication::sendEvent(fo, &queryEvent)) { bool imEnabled = queryEvent.value(Qt::ImEnabled).toBool(); @@ -1446,6 +1450,8 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent) [self interpretKeyEvents:[NSArray arrayWithObject:nsevent]]; } } + + m_platformWindow->m_ignoreWindowShouldClose = false;; } if (m_resendKeyEvent) m_sendKeyEvent = true;