mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
[macOS] feat: PR feedback
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 }
|
||||
}
|
||||
|
Reference in New Issue
Block a user