From 0d7248345dfde075122b135370e77f76334bba38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 3 Sep 2020 16:29:23 +0200 Subject: [PATCH] macOS: Don't assume we will get didBecomeKey for non-Qt NSWindows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The optimization resulted in losing out on window focus changes when for example a native file dialog was shown, resulting in the cursor blinking both in the parent window, and in the native file dialog. Change-Id: I9c1f9df20fbc5c4b80f906ded70d9a2658b70438 Reviewed-by: Volker Hilsheimer Reviewed-by: Timur Pocheptsov (cherry picked from commit 5fbb17c39785ed2c80219c9c0ea97879e371d490) Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoawindow.mm | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index a3120f4cccd..23c5a2fddaa 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1197,15 +1197,17 @@ void QCocoaWindow::windowDidResignKey() if (isForeignWindow()) return; - // Key window will be non-nil if another window became key, so 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 || keyWindow == m_view.window) { - // No new key window, go ahead and set the active window to zero - if (!windowIsPopupType()) - QWindowSystemInterface::handleWindowActivated(0); - } + // The current key window will be non-nil if another window became key. If that + // window is a Qt window, we delay the window activation event until the didBecomeKey + // notification is delivered to the active window, to ensure an atomic update. + NSWindow *newKeyWindow = [NSApp keyWindow]; + if (newKeyWindow && newKeyWindow != m_view.window + && [newKeyWindow conformsToProtocol:@protocol(QNSWindowProtocol)]) + return; + + // Lost key window, go ahead and set the active window to zero + if (!windowIsPopupType()) + QWindowSystemInterface::handleWindowActivated(nullptr); } void QCocoaWindow::windowDidOrderOnScreen()