feat: avoid occasional delays in showing the switcher (closes #5109)

This commit is contained in:
lwouis committed 2026-01-03 17:36:23 +01:00
1 parent 2f875b3bcb
commit 3c04a4ce15
3 files changed
+26 -7

No files matched your search

-1
View File
@@ -220,7 +220,6 @@ class App: AppCenterApplication {
Logger.debug(shortcutIndex, self.shortcutIndex, isFirstSummon)
App.app.appIsBeingUsed = true
if isFirstSummon || shortcutIndex != self.shortcutIndex {
MainMenu.toggle(enabled: false)
NSScreen.updatePreferred()
if isVeryFirstSummon {
Windows.sortByLevel()
+17 -6
View File
@@ -1,5 +1,6 @@
class MainMenu {
private static var mainMenu: NSMenu!
private static var menuItemsWithShortcut = [NSMenuItem: String]()
/// classic keyboard shortcuts like copy-and-paste are missing without a MainMenu. We generated the default menu from XCode and load it
/// see https://stackoverflow.com/a/3746058/2249756
@@ -8,16 +9,26 @@ class MainMenu {
Bundle.main.loadNibNamed("MainMenu", owner: self, topLevelObjects: &menuObjects)
mainMenu = menuObjects?.first { $0 is NSMenu } as? NSMenu
App.shared.mainMenu = mainMenu
rememberMenuItemsWithShortcut()
}
/// we toggle the mainMenu off when showing the main window, and on when showing secondary windows
static func toggle(enabled: Bool) {
if enabled {
if App.shared.mainMenu == nil {
App.shared.mainMenu = mainMenu
for (item, keyEquivalent) in menuItemsWithShortcut {
item.keyEquivalent = enabled ? keyEquivalent : ""
}
}
private static func rememberMenuItemsWithShortcut() {
var stack: [NSMenu] = [mainMenu]
while let menu = stack.popLast() {
for item in menu.items {
if !item.keyEquivalent.isEmpty {
menuItemsWithShortcut[item] = item.keyEquivalent
}
if let submenu = item.submenu {
stack.append(submenu)
}
}
} else {
App.shared.mainMenu = nil
}
}
}
+9
View File
@@ -99,6 +99,15 @@ extension ThumbnailsPanel: NSWindowDelegate {
if App.app.appIsBeingUsed {
App.app.thumbnailsPanel.makeKeyAndOrderFront(nil)
}
MainMenu.toggle(enabled: true)
}
}
func windowDidBecomeKey(_ notification: Notification) {
// we toggle the mainMenu off when showing the main window
// this avoids command+q from quitting AltTab itself, or command+p from printing
DispatchQueue.main.async {
MainMenu.toggle(enabled: false)
}
}
}