From e8cd9a617d85deebb6407973fd1fb11a6486ee99 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Wed, 6 Jun 2012 09:25:01 +0200 Subject: [PATCH] Cocoa: do not send multiple window activation events MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When switching the active window within the same application, Cocoa sends us an NSWindowDidResignKeyNotification for the old activated window, then an NSWindowDidBecomeKeyNotificationfor the newly activated window. Our handling of this would first set Qt's active window to zero, then immediately reset it afterwards. Avoid this by checking the key window when handling the deactivation event, and don't set the active window to zero if a new window has become active. Task-number: QTBUG-24322 Change-Id: I8719fc501049eeaaebb75e9ea03261b2209458b6 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qnsview.mm | 11 +++++++++-- tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp | 3 --- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index e0fc678..c94b8a5 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -154,8 +154,15 @@ static QTouchDevice *touchDevice = 0; if (!m_platformWindow->windowIsPopupType()) QWindowSystemInterface::handleWindowActivated(m_window); } else if (notificationName == NSWindowDidResignKeyNotification) { - if (!m_platformWindow->windowIsPopupType()) - QWindowSystemInterface::handleWindowActivated(0); + // key window will be non-nil if another window became key... do not + // set the active window to zero here, the new key window's + // NSWindowDidBecomeKeyNotification hander will change the active window + NSWindow *keyWindow = [NSApp keyWindow]; + if (!keyWindow) { + // no new key window, go ahead and set the active window to zero + if (!m_platformWindow->windowIsPopupType()) + QWindowSystemInterface::handleWindowActivated(0); + } } else if (notificationName == NSWindowDidMiniaturizeNotification) { QWindowSystemInterface::handleWindowStateChanged(m_window, Qt::WindowMinimized); } else if (notificationName == NSWindowDidDeminiaturizeNotification) { diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index c0242d9..578ea9f 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -81,9 +81,6 @@ public: void tst_QGuiApplication::focusObject() { -#ifdef Q_OS_MAC - QSKIP("This test fails intermittently, and at different locations. See QTBUG-24322"); -#endif int argc = 0; QGuiApplication app(argc, 0); -- 2.7.4