mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-06-04 02:44:50 +00:00
macOS: restore visiblity state when hiding quick terminal
This commit is contained in:
@@ -110,7 +110,7 @@ class AppDelegate: NSObject,
|
||||
}
|
||||
|
||||
/// Tracks the windows that we hid for toggleVisibility.
|
||||
private var hiddenState: ToggleVisibilityState? = nil
|
||||
private(set) var hiddenState: ToggleVisibilityState? = nil
|
||||
|
||||
/// The observer for the app appearance.
|
||||
private var appearanceObserver: NSKeyValueObservation? = nil
|
||||
@@ -280,6 +280,11 @@ class AppDelegate: NSObject,
|
||||
}
|
||||
}
|
||||
|
||||
func applicationDidHide(_ notification: Notification) {
|
||||
// Keep track of our hidden state to restore properly
|
||||
self.hiddenState = .init()
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(_ notification: Notification) {
|
||||
// If we're back manually then clear the hidden state because macOS handles it.
|
||||
self.hiddenState = nil
|
||||
@@ -1084,8 +1089,6 @@ class AppDelegate: NSObject,
|
||||
guard let keyWindow = NSApp.keyWindow,
|
||||
!keyWindow.styleMask.contains(.fullScreen) else { return }
|
||||
|
||||
// Keep track of our hidden state to restore properly
|
||||
self.hiddenState = .init()
|
||||
NSApp.hide(nil)
|
||||
return
|
||||
}
|
||||
@@ -1134,11 +1137,11 @@ class AppDelegate: NSObject,
|
||||
}
|
||||
}
|
||||
|
||||
private struct ToggleVisibilityState {
|
||||
struct ToggleVisibilityState {
|
||||
let hiddenWindows: [Weak<NSWindow>]
|
||||
let keyWindow: Weak<NSWindow>?
|
||||
|
||||
init() {
|
||||
fileprivate init() {
|
||||
// We need to know the key window so that we can bring focus back to the
|
||||
// right window if it was hidden.
|
||||
self.keyWindow = if let keyWindow = NSApp.keyWindow {
|
||||
|
||||
@@ -513,6 +513,10 @@ class QuickTerminalController: BaseTerminalController {
|
||||
if !window.isOnActiveSpace {
|
||||
self.previousApp = nil
|
||||
window.orderOut(self)
|
||||
// If our application is hidden previously, we hide it again
|
||||
if (NSApp.delegate as? AppDelegate)?.hiddenState != nil {
|
||||
NSApp.hide(nil)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -549,6 +553,10 @@ class QuickTerminalController: BaseTerminalController {
|
||||
// This causes the window to be removed from the screen list and macOS
|
||||
// handles what should be focused next.
|
||||
window.orderOut(self)
|
||||
// If our application is hidden previously, we hide it again
|
||||
if (NSApp.delegate as? AppDelegate)?.hiddenState != nil {
|
||||
NSApp.hide(nil)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user