diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-10-26 15:42:23 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-11-12 23:00:02 +0000 |
commit | cb9f861b2e3b521dad85d789f81b43083bec6213 (patch) | |
tree | 7d034b71f585e50777f0ea66cf7e63d01535ae17 | |
parent | eb937aa84f4e4c24a03ac5ba5228171f25f8defa (diff) |
macOS: Activate all windows on launch, not just key/main windows
The default macOS behavior when an application is activated is to
bring key and main windows to the front. Any window shown after
that is order to the front as normal.
For Qt apps we show windows in main() instead of waiting for the
application to become active first, and the request to show
the window may reach the window server before or after Finder
has made the application active. If it arrives first, the window
may end up behind the currently frontmost application.
This is particularly noticeable when the application is not
activated by Finder, and we do our own activation workaround.
In this case all our windows are hidden, except for the key
window.
To ensure a consistent behavior here, we explicitly activate
all windows of the application on launch.
Pick-to: 6.5
Change-Id: Ice55f7d03e077c5a5ca843f75f1a7296ebb47aa7
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit b49211c12543c3369b286b507c4277c66ef9fdef)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index b25e470399..581777f240 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -203,6 +203,14 @@ QT_USE_NAMESPACE << "as frontmost application. Activating" << currentApplication << "instead."; [NSApplication.sharedApplication activateIgnoringOtherApps:YES]; } + + // Qt windows are typically shown in main(), at which point the application + // is not active yet. When the application is activated, either externally + // or via the override above, it will only bring the main and key windows + // forward, which differs from the behavior if these windows had been shown + // once the application was already active. To work around this, we explicitly + // activate the current application again, bringing all windows to the front. + [currentApplication activateWithOptions:NSApplicationActivateAllWindows]; } QCocoaMenuBar::insertWindowMenu(); |