From af48c1af0c6555964b07de5e33445ff194a34549 Mon Sep 17 00:00:00 2001 From: Roland Peelen Date: Tue, 1 Oct 2024 09:52:14 +0200 Subject: [PATCH] Refactor to hide only BaseTerminalController windows This also slightly changes the code, as the duplication of the for loop was making it harder to read now. I think technically slightly less efficient, but this is hardly a hot code path, so should be fine imo. --- macos/Sources/App/macOS/AppDelegate.swift | 26 +++++++++-------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index 658f4ca83..c1f2615bf 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -570,26 +570,20 @@ class AppDelegate: NSObject, self.menuQuickTerminal?.state = if (quickController.visible) { .on } else { .off } } - /// Toggles the visibility of all Ghostty windows + /// Toggles visibility of all Ghosty Terminal windows. When hidden, activates Ghostty as the frontmost application @IBAction func toggleVisibility(_ sender: Any) { - let configurationErrorsWindow = ConfigurationErrorsController.sharedInstance.window - - if isVisible { - // Hide all windows - for window in NSApp.windows { - if window !== configurationErrorsWindow { - window.orderOut(nil) - } - } - } else { - // Show all windows - for window in NSApp.windows { - if window !== configurationErrorsWindow { - window.makeKeyAndOrderFront(nil) - } + for controller in NSApp.windows.compactMap({ $0.windowController as? BaseTerminalController }) { + if isVisible { + controller.window?.orderOut(nil) + } else { + controller.window?.makeKeyAndOrderFront(nil) } + } + + if !isVisible { NSApp.activate(ignoringOtherApps: true) } + isVisible.toggle() } }