diff --git a/alt-tab-macos.xcodeproj/project.pbxproj b/alt-tab-macos.xcodeproj/project.pbxproj index 821e71bb..86c2b7d5 100644 --- a/alt-tab-macos.xcodeproj/project.pbxproj +++ b/alt-tab-macos.xcodeproj/project.pbxproj @@ -132,6 +132,7 @@ BF0C8846AFEE2FFF93FAB36F /* AppearanceTestable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C8D57C86AF492D43A576D /* AppearanceTestable.swift */; }; BF0C884D88B74F05B8BBF956 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C88A25E1ED37E5F80AC91 /* Localizable.strings */; }; BF0C8879F979414A87AB2958 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C89348E07FC05870FEE62 /* InfoPlist.strings */; }; + BF0C88A9AB286CB7CDC1019E /* MainMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C8468DF35990A7731D86C /* MainMenu.swift */; }; BF0C88ACA8CD6B68A0501F65 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8757A13FF9E54632146D /* Localizable.strings */; }; BF0C88C371B5550E7D23E4F1 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8BF5835F97923BF3E8DA /* InfoPlist.strings */; }; BF0C88D7E209C788558BD943 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8CC9692E6E4A32846D72 /* InfoPlist.strings */; }; @@ -400,6 +401,7 @@ BF0C843C2EDF4EF3A7A2C64A /* app.svg */ = {isa = PBXFileReference; lastKnownFileType = file.svg; path = app.svg; sourceTree = ""; }; BF0C8465A0A9EA2814A22C35 /* SF-Pro-Text-Regular-Full.otf */ = {isa = PBXFileReference; lastKnownFileType = file.otf; path = "SF-Pro-Text-Regular-Full.otf"; sourceTree = ""; }; BF0C84674BAE2B4D7871B86C /* et */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = et; path = Localizable.strings; sourceTree = ""; }; + BF0C8468DF35990A7731D86C /* MainMenu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainMenu.swift; sourceTree = ""; }; BF0C847A108ABC72723ABBA2 /* hi */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = hi; path = InfoPlist.strings; sourceTree = ""; }; BF0C848A4DDFF5D118CA9CAF /* ca */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = ca; path = Localizable.strings; sourceTree = ""; }; BF0C84933936C6FE676CD33C /* AppearanceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppearanceTests.swift; sourceTree = ""; }; @@ -1380,6 +1382,7 @@ D04BA1C271F0DA573345B860 /* permission-window */, D04BAAF79737A0673502FEB5 /* AppCenterApplication.h */, D04BA48BC82D3060C3A1AB11 /* AppCenterApplication.m */, + BF0C8468DF35990A7731D86C /* MainMenu.swift */, ); path = ui; sourceTree = ""; @@ -2438,6 +2441,7 @@ BF0C8521DA3078516615C414 /* HelperExtensionsTestable.swift in Sources */, BF0C8991399A3277A9A02FFA /* LightImageView.swift in Sources */, BF0C8F40C2D0FF7601D926D3 /* LightweightTimer.swift in Sources */, + BF0C88A9AB286CB7CDC1019E /* MainMenu.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/resources/MainMenu.xib b/resources/MainMenu.xib index 5c2e2380..a914814a 100644 --- a/resources/MainMenu.xib +++ b/resources/MainMenu.xib @@ -1,8 +1,7 @@ - + - - + @@ -11,17 +10,10 @@ - + - + - - - - - - - @@ -29,17 +21,6 @@ - - - - - - - - - - - @@ -47,7 +28,7 @@ - + @@ -59,50 +40,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -599,38 +541,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -660,7 +570,7 @@ - + diff --git a/src/ui/App.swift b/src/ui/App.swift index dcbec462..bfb315b0 100644 --- a/src/ui/App.swift +++ b/src/ui/App.swift @@ -48,14 +48,6 @@ class App: AppCenterApplication { thumbnailsPanel.orderOut(nil) } - /// keyboard shortcuts are broken without a menu. We generated the default menu from XCode and load it - /// see https://stackoverflow.com/a/3746058/2249756 - private func loadMainMenuXib() { - var menuObjects: NSArray? - Bundle.main.loadNibNamed("MainMenu", owner: self, topLevelObjects: &menuObjects) - menu = menuObjects?.first { $0 is NSMenu } as? NSMenu - } - /// we put application code here which should be executed on init() and Preferences change func resetPreferencesDependentComponents() { thumbnailsPanel.thumbnailsView.reset() @@ -81,6 +73,7 @@ class App: AppCenterApplication { previewPanel.orderOut(nil) } hideAllTooltips() + MainMenu.toggle(enabled: true) } /// some tooltips may not be hidden when the main window is hidden; we force it through a private API @@ -238,6 +231,7 @@ class App: AppCenterApplication { Logger.debug(shortcutIndex, self.shortcutIndex, isFirstSummon) App.app.appIsBeingUsed = true if isFirstSummon || shortcutIndex != self.shortcutIndex { + MainMenu.toggle(enabled: false) NSScreen.updatePreferred() Applications.manuallyRefreshAllWindows() if isVeryFirstSummon { @@ -317,7 +311,7 @@ extension App: NSApplicationDelegate { NSScreen.updatePreferred() Appearance.update() Menubar.initialize() - self.loadMainMenuXib() + MainMenu.loadFromXib() self.thumbnailsPanel = ThumbnailsPanel() self.previewPanel = PreviewPanel() Spaces.refresh() diff --git a/src/ui/MainMenu.swift b/src/ui/MainMenu.swift new file mode 100644 index 00000000..a80eebe1 --- /dev/null +++ b/src/ui/MainMenu.swift @@ -0,0 +1,23 @@ +class MainMenu { + private static var mainMenu: NSMenu! + + /// 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 + static func loadFromXib() { + var menuObjects: NSArray? + Bundle.main.loadNibNamed("MainMenu", owner: self, topLevelObjects: &menuObjects) + mainMenu = menuObjects?.first { $0 is NSMenu } as? NSMenu + App.shared.mainMenu = mainMenu + } + + /// 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 + } + } else { + App.shared.mainMenu = nil + } + } +}