[macOS] feat: Add "quick-terminal" option to "macos-hidden" config

This commit is contained in:
McNight
2025-02-16 15:02:44 +01:00
parent 2e7ed98dfd
commit c5f0709e7e
6 changed files with 40 additions and 1 deletions

View File

@ -403,6 +403,12 @@ class AppDelegate: NSObject,
reloadDockMenu() reloadDockMenu()
} }
func applicationDidUpdate(_ notification: Notification) {
guard derivedConfig.shouldSwitchBetweenActivationPolicies else { return }
// 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
/// action string used for the Ghostty configuration. /// action string used for the Ghostty configuration.
private func syncMenuShortcut(_ config: Ghostty.Config, action: String, menuItem: NSMenuItem?) { private func syncMenuShortcut(_ config: Ghostty.Config, action: String, menuItem: NSMenuItem?) {
@ -540,6 +546,9 @@ class AppDelegate: NSObject,
case .always: case .always:
NSApp.setActivationPolicy(.accessory) 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.
@ -786,17 +795,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
init() { init() {
self.initialWindow = true self.initialWindow = true
self.shouldQuitAfterLastWindowClosed = false self.shouldQuitAfterLastWindowClosed = false
self.quickTerminalPosition = .top self.quickTerminalPosition = .top
self.shouldSwitchBetweenActivationPolicies = false
} }
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
} }
} }

View File

@ -17,7 +17,13 @@ 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.
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

@ -529,6 +529,7 @@ extension Ghostty.Config {
enum MacHidden : String { enum MacHidden : String {
case never case never
case always case always
case quick_terminal = "quick-terminal"
} }
enum ResizeOverlay : String { enum ResizeOverlay : String {

View File

@ -247,6 +247,10 @@ 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

@ -24,6 +24,21 @@ extension NSApplication {
} }
} }
extension NSApplication {
private static let nonRegularWindowsClassNames: [String] = [
"NSStatusBarWindow",
"_NSPopoverWindow",
"TUINSWindow"
]
/// Windows that are visible and regular (such as terminal & update windows)
var visibleRegularWindows: [NSWindow] {
NSApp.windows
.filter { !Self.nonRegularWindowsClassNames.contains($0.className) }
.filter { $0.isVisible }
}
}
extension NSApplication.PresentationOptions.Element: @retroactive Hashable { extension NSApplication.PresentationOptions.Element: @retroactive Hashable {
public func hash(into hasher: inout Hasher) { public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue) hasher.combine(rawValue)

View File

@ -5762,6 +5762,7 @@ pub const MacTitlebarProxyIcon = enum {
pub const MacHidden = enum { pub const MacHidden = enum {
never, never,
always, always,
@"quick-terminal",
}; };
/// See macos-icon /// See macos-icon