summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-10-28 16:38:15 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-10-29 04:17:33 +0000
commit12968a819ab27ec5fb21c32cbd0737164cb43711 (patch)
tree75457a090ad48e4a6e158d233a89b5b64a2290ab
parent1980923bd3fba57828d8566d47afd4de4b486539 (diff)
downloadqtbase-12968a819ab27ec5fb21c32cbd0737164cb43711.tar.gz
macOS: Don't include QSystemTrayIcon windows in Dock menu window list
As of 3fcdb6cb6e35a37f9b511ec2705336102c194d6b we now have a hidden Window menu, which results in macOS also populating the Dock menu with the application's windows. But since the AppKit logic for populating the window menu happens when the window is shown, and we create the menu after many windows have been already shown, we had a workaround to add the shown windows manually. Unfortunately this workaround didn't take into account the NSWindow excludedFromWindowsMenu property, nor did it include various other checks that AppKit itself uses to decide if a window should be included in the window list, resulting in adding the NSStatusBarWindow that AppKit uses to manage the status bar items. Instead of trying to replicate the AppKit logic, we toggle the excludedFromWindowsMenu property back and forth, which triggers AppKit to reevaluate the situation for each window, and add it to the window menu if necessary. Fixes: QTBUG-107008 Change-Id: I6c7f61c1f4610fec9ce1f814fcea2b6140230602 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> (cherry picked from commit 737011dd026018986c74e4155b2470777b676baa) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/plugins/platforms/cocoa/qcocoamenubar.mm12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm
index 62ceb86214..b0e8745171 100644
--- a/src/plugins/platforms/cocoa/qcocoamenubar.mm
+++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm
@@ -338,10 +338,16 @@ void QCocoaMenuBar::insertWindowMenu()
[mainMenu insertItem:winMenuItem atIndex:mainMenu.itemArray.count];
app.windowsMenu = winMenuItem.submenu;
- // Windows, created and 'ordered front' before, will not be in this menu:
+ // Windows that have already been ordered in at this point have already been
+ // evaluated by AppKit via _addToWindowsMenuIfNecessary and added to the menu,
+ // but since the menu didn't exist at that point the addition was a noop.
+ // Instead of trying to duplicate the logic AppKit uses for deciding if
+ // a window should be part of the Window menu we toggle one of the settings
+ // that definitely will affect this, which results in AppKit reevaluating the
+ // situation and adding the window to the menu if necessary.
for (NSWindow *win in app.windows) {
- if (win.title && ![win.title isEqualToString:@""])
- [app addWindowsItem:win title:win.title filename:NO];
+ win.excludedFromWindowsMenu = !win.excludedFromWindowsMenu;
+ win.excludedFromWindowsMenu = !win.excludedFromWindowsMenu;
}
}