Skip to content

Commit d7a7da6

Browse files
committed
[macOS] feat: PR feedback
1 parent c5f0709 commit d7a7da6

File tree

4 files changed

+23
-28
lines changed

4 files changed

+23
-28
lines changed

macos/Sources/App/macOS/AppDelegate.swift

+19-16
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,7 @@ class AppDelegate: NSObject,
404404
}
405405

406406
func applicationDidUpdate(_ notification: Notification) {
407-
guard derivedConfig.shouldSwitchBetweenActivationPolicies else { return }
408-
// Are we presenting any regular windows ?
409-
NSApp.setActivationPolicy(NSApp.visibleRegularWindows.isEmpty ? .accessory : .regular)
407+
syncActivationPolicy()
410408
}
411409

412410
/// Syncs a single menu shortcut for the given action. The action string is the same
@@ -540,16 +538,7 @@ class AppDelegate: NSObject,
540538
DispatchQueue.main.async { self.syncAppearance(config: config) }
541539

542540
// Decide whether to hide/unhide app from dock and app switcher
543-
switch (config.macosHidden) {
544-
case .never:
545-
NSApp.setActivationPolicy(.regular)
546-
547-
case .always:
548-
NSApp.setActivationPolicy(.accessory)
549-
550-
case .quick_terminal:
551-
NSApp.setActivationPolicy(NSApp.visibleRegularWindows.isEmpty ? .accessory : .regular)
552-
}
541+
syncActivationPolicy()
553542

554543
// If we have configuration errors, we need to show them.
555544
let c = ConfigurationErrorsController.sharedInstance
@@ -625,6 +614,20 @@ class AppDelegate: NSObject,
625614
NSApplication.shared.appearance = .init(ghosttyConfig: config)
626615
}
627616

617+
/// Sync the app activation policy based on the config `MacHidden` value.
618+
private func syncActivationPolicy() {
619+
switch (derivedConfig.macosHidden) {
620+
case .never:
621+
NSApp.setActivationPolicy(.regular)
622+
623+
case .always:
624+
NSApp.setActivationPolicy(.accessory)
625+
626+
case .quick_terminal:
627+
NSApp.setActivationPolicy(NSApp.visibleRegularWindows.isEmpty ? .accessory : .regular)
628+
}
629+
}
630+
628631
//MARK: - Restorable State
629632

630633
/// We support NSSecureCoding for restorable state. Required as of macOS Sonoma (14) but a good idea anyways.
@@ -795,20 +798,20 @@ class AppDelegate: NSObject,
795798
let initialWindow: Bool
796799
let shouldQuitAfterLastWindowClosed: Bool
797800
let quickTerminalPosition: QuickTerminalPosition
798-
let shouldSwitchBetweenActivationPolicies: Bool
801+
let macosHidden: Ghostty.Config.MacHidden
799802

800803
init() {
801804
self.initialWindow = true
802805
self.shouldQuitAfterLastWindowClosed = false
803806
self.quickTerminalPosition = .top
804-
self.shouldSwitchBetweenActivationPolicies = false
807+
self.macosHidden = .never
805808
}
806809

807810
init(_ config: Ghostty.Config) {
808811
self.initialWindow = config.initialWindow
809812
self.shouldQuitAfterLastWindowClosed = config.shouldQuitAfterLastWindowClosed
810813
self.quickTerminalPosition = config.quickTerminalPosition
811-
self.shouldSwitchBetweenActivationPolicies = config.macosHidden == .quick_terminal
814+
self.macosHidden = config.macosHidden
812815
}
813816
}
814817

macos/Sources/Features/Terminal/TerminalManager.swift

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ class TerminalManager {
1717
var focusedSurface: Ghostty.SurfaceView? { mainWindow?.controller.focusedSurface }
1818

1919
/// The set of windows we currently have.
20-
private(set) var windows: [Window] = [] {
21-
didSet {
22-
let userInfo = [Notification.Name.GhosttyWindowsChangedKey: windows.count]
23-
NotificationCenter.default
24-
.post(name: .ghosttyWindowsChanged, object: nil, userInfo: userInfo)
25-
}
26-
}
20+
private(set) var windows: [Window] = []
2721

2822
// Keep track of the last point that our window was launched at so that new
2923
// windows "cascade" over each other and don't just launch directly on top

macos/Sources/Ghostty/Package.swift

-4
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,6 @@ extension Notification.Name {
247247

248248
/// Close tab
249249
static let ghosttyCloseTab = Notification.Name("com.mitchellh.ghostty.closeTab")
250-
251-
/// Managed windows did change.
252-
static let ghosttyWindowsChanged = Notification.Name("com.mitchellh.ghostty.windowsChanged")
253-
static let GhosttyWindowsChangedKey = ghosttyWindowsChanged.rawValue
254250
}
255251

256252
// NOTE: I am moving all of these to Notification.Name extensions over time. This

macos/Sources/Helpers/NSApplication+Extension.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ extension NSApplication {
3131
"TUINSWindow"
3232
]
3333

34-
/// Windows that are visible and regular (such as terminal & update windows)
34+
/// Windows that are visible and regular (such as terminal & update windows).
35+
/// `QuickTerminalWindow` instances are omitted from this collection.
3536
var visibleRegularWindows: [NSWindow] {
3637
NSApp.windows
38+
.filter { !($0 is QuickTerminalWindow) }
3739
.filter { !Self.nonRegularWindowsClassNames.contains($0.className) }
3840
.filter { $0.isVisible }
3941
}

0 commit comments

Comments
 (0)