mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
[macOS] feat: Add "quick-terminal" option to "macos-hidden" config
This commit is contained in:
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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 {
|
||||||
|
@ -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
|
||||||
|
@ -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)
|
||||||
|
@ -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
|
||||||
|
Reference in New Issue
Block a user