diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index e27bf2f8e..fa5921628 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -404,9 +404,7 @@ class AppDelegate: NSObject, } func applicationDidUpdate(_ notification: Notification) { - guard derivedConfig.shouldSwitchBetweenActivationPolicies else { return } - // Are we presenting any regular windows ? - NSApp.setActivationPolicy(NSApp.visibleRegularWindows.isEmpty ? .accessory : .regular) + syncActivationPolicy() } /// Syncs a single menu shortcut for the given action. The action string is the same @@ -540,16 +538,7 @@ class AppDelegate: NSObject, DispatchQueue.main.async { self.syncAppearance(config: config) } // Decide whether to hide/unhide app from dock and app switcher - switch (config.macosHidden) { - case .never: - NSApp.setActivationPolicy(.regular) - - case .always: - NSApp.setActivationPolicy(.accessory) - - case .quick_terminal: - NSApp.setActivationPolicy(NSApp.visibleRegularWindows.isEmpty ? .accessory : .regular) - } + syncActivationPolicy() // If we have configuration errors, we need to show them. let c = ConfigurationErrorsController.sharedInstance @@ -625,6 +614,20 @@ class AppDelegate: NSObject, NSApplication.shared.appearance = .init(ghosttyConfig: config) } + /// Sync the app activation policy based on the config `MacHidden` value. + private func syncActivationPolicy() { + switch (derivedConfig.macosHidden) { + case .never: + NSApp.setActivationPolicy(.regular) + + case .always: + NSApp.setActivationPolicy(.accessory) + + case .quick_terminal: + NSApp.setActivationPolicy(NSApp.visibleRegularWindows.isEmpty ? .accessory : .regular) + } + } + //MARK: - Restorable State /// We support NSSecureCoding for restorable state. Required as of macOS Sonoma (14) but a good idea anyways. @@ -795,20 +798,20 @@ class AppDelegate: NSObject, let initialWindow: Bool let shouldQuitAfterLastWindowClosed: Bool let quickTerminalPosition: QuickTerminalPosition - let shouldSwitchBetweenActivationPolicies: Bool + let macosHidden: Ghostty.Config.MacHidden init() { self.initialWindow = true self.shouldQuitAfterLastWindowClosed = false self.quickTerminalPosition = .top - self.shouldSwitchBetweenActivationPolicies = false + self.macosHidden = .never } init(_ config: Ghostty.Config) { self.initialWindow = config.initialWindow self.shouldQuitAfterLastWindowClosed = config.shouldQuitAfterLastWindowClosed self.quickTerminalPosition = config.quickTerminalPosition - self.shouldSwitchBetweenActivationPolicies = config.macosHidden == .quick_terminal + self.macosHidden = config.macosHidden } } diff --git a/macos/Sources/Features/Terminal/TerminalManager.swift b/macos/Sources/Features/Terminal/TerminalManager.swift index ba7076fef..c0d78f023 100644 --- a/macos/Sources/Features/Terminal/TerminalManager.swift +++ b/macos/Sources/Features/Terminal/TerminalManager.swift @@ -17,13 +17,7 @@ class TerminalManager { var focusedSurface: Ghostty.SurfaceView? { mainWindow?.controller.focusedSurface } /// The set of windows we currently have. - private(set) var windows: [Window] = [] { - didSet { - let userInfo = [Notification.Name.GhosttyWindowsChangedKey: windows.count] - NotificationCenter.default - .post(name: .ghosttyWindowsChanged, object: nil, userInfo: userInfo) - } - } + private(set) var windows: [Window] = [] // Keep track of the last point that our window was launched at so that new // windows "cascade" over each other and don't just launch directly on top diff --git a/macos/Sources/Ghostty/Package.swift b/macos/Sources/Ghostty/Package.swift index 7071b8e09..18ef3f3a7 100644 --- a/macos/Sources/Ghostty/Package.swift +++ b/macos/Sources/Ghostty/Package.swift @@ -247,10 +247,6 @@ extension Notification.Name { /// Close tab static let ghosttyCloseTab = Notification.Name("com.mitchellh.ghostty.closeTab") - - /// Managed windows did change. - static let ghosttyWindowsChanged = Notification.Name("com.mitchellh.ghostty.windowsChanged") - static let GhosttyWindowsChangedKey = ghosttyWindowsChanged.rawValue } // NOTE: I am moving all of these to Notification.Name extensions over time. This diff --git a/macos/Sources/Helpers/NSApplication+Extension.swift b/macos/Sources/Helpers/NSApplication+Extension.swift index 67f6b2e64..0f8062470 100644 --- a/macos/Sources/Helpers/NSApplication+Extension.swift +++ b/macos/Sources/Helpers/NSApplication+Extension.swift @@ -31,9 +31,11 @@ extension NSApplication { "TUINSWindow" ] - /// Windows that are visible and regular (such as terminal & update windows) + /// Windows that are visible and regular (such as terminal & update windows). + /// `QuickTerminalWindow` instances are omitted from this collection. var visibleRegularWindows: [NSWindow] { NSApp.windows + .filter { !($0 is QuickTerminalWindow) } .filter { !Self.nonRegularWindowsClassNames.contains($0.className) } .filter { $0.isVisible } }