[macOS] feat: PR feedback

This commit is contained in:
McNight
2025-02-16 21:36:44 +01:00
parent c5f0709e7e
commit d7a7da6ea0
4 changed files with 23 additions and 28 deletions

View File

@ -404,9 +404,7 @@ class AppDelegate: NSObject,
} }
func applicationDidUpdate(_ notification: Notification) { func applicationDidUpdate(_ notification: Notification) {
guard derivedConfig.shouldSwitchBetweenActivationPolicies else { return } syncActivationPolicy()
// Are we presenting any regular windows ?
NSApp.setActivationPolicy(NSApp.visibleRegularWindows.isEmpty ? .accessory : .regular)
} }
/// Syncs a single menu shortcut for the given action. The action string is the same /// 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) } DispatchQueue.main.async { self.syncAppearance(config: config) }
// Decide whether to hide/unhide app from dock and app switcher // Decide whether to hide/unhide app from dock and app switcher
switch (config.macosHidden) { syncActivationPolicy()
case .never:
NSApp.setActivationPolicy(.regular)
case .always:
NSApp.setActivationPolicy(.accessory)
case .quick_terminal:
NSApp.setActivationPolicy(NSApp.visibleRegularWindows.isEmpty ? .accessory : .regular)
}
// If we have configuration errors, we need to show them. // If we have configuration errors, we need to show them.
let c = ConfigurationErrorsController.sharedInstance let c = ConfigurationErrorsController.sharedInstance
@ -625,6 +614,20 @@ class AppDelegate: NSObject,
NSApplication.shared.appearance = .init(ghosttyConfig: config) 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 //MARK: - Restorable State
/// We support NSSecureCoding for restorable state. Required as of macOS Sonoma (14) but a good idea anyways. /// 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 initialWindow: Bool
let shouldQuitAfterLastWindowClosed: Bool let shouldQuitAfterLastWindowClosed: Bool
let quickTerminalPosition: QuickTerminalPosition let quickTerminalPosition: QuickTerminalPosition
let shouldSwitchBetweenActivationPolicies: Bool let macosHidden: Ghostty.Config.MacHidden
init() { init() {
self.initialWindow = true self.initialWindow = true
self.shouldQuitAfterLastWindowClosed = false self.shouldQuitAfterLastWindowClosed = false
self.quickTerminalPosition = .top self.quickTerminalPosition = .top
self.shouldSwitchBetweenActivationPolicies = false self.macosHidden = .never
} }
init(_ config: Ghostty.Config) { init(_ config: Ghostty.Config) {
self.initialWindow = config.initialWindow self.initialWindow = config.initialWindow
self.shouldQuitAfterLastWindowClosed = config.shouldQuitAfterLastWindowClosed self.shouldQuitAfterLastWindowClosed = config.shouldQuitAfterLastWindowClosed
self.quickTerminalPosition = config.quickTerminalPosition self.quickTerminalPosition = config.quickTerminalPosition
self.shouldSwitchBetweenActivationPolicies = config.macosHidden == .quick_terminal self.macosHidden = config.macosHidden
} }
} }

View File

@ -17,13 +17,7 @@ class TerminalManager {
var focusedSurface: Ghostty.SurfaceView? { mainWindow?.controller.focusedSurface } var focusedSurface: Ghostty.SurfaceView? { mainWindow?.controller.focusedSurface }
/// The set of windows we currently have. /// The set of windows we currently have.
private(set) var windows: [Window] = [] { private(set) var windows: [Window] = []
didSet {
let userInfo = [Notification.Name.GhosttyWindowsChangedKey: windows.count]
NotificationCenter.default
.post(name: .ghosttyWindowsChanged, object: nil, userInfo: userInfo)
}
}
// Keep track of the last point that our window was launched at so that new // 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 // windows "cascade" over each other and don't just launch directly on top

View File

@ -247,10 +247,6 @@ extension Notification.Name {
/// Close tab /// Close tab
static let ghosttyCloseTab = Notification.Name("com.mitchellh.ghostty.closeTab") 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 // NOTE: I am moving all of these to Notification.Name extensions over time. This

View File

@ -31,9 +31,11 @@ extension NSApplication {
"TUINSWindow" "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] { var visibleRegularWindows: [NSWindow] {
NSApp.windows NSApp.windows
.filter { !($0 is QuickTerminalWindow) }
.filter { !Self.nonRegularWindowsClassNames.contains($0.className) } .filter { !Self.nonRegularWindowsClassNames.contains($0.className) }
.filter { $0.isVisible } .filter { $0.isVisible }
} }