macOS: restore visiblity state when hiding quick terminal

pull/9576/head
Lukas 2025-11-13 11:30:43 +01:00
parent 0f64b9a8e8
commit bcb5112b24
No known key found for this signature in database
GPG Key ID: 845CB61BD38F4E49
2 changed files with 16 additions and 5 deletions

View File

@ -110,7 +110,7 @@ class AppDelegate: NSObject,
} }
/// Tracks the windows that we hid for toggleVisibility. /// 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. /// The observer for the app appearance.
private var appearanceObserver: NSKeyValueObservation? = nil 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) { func applicationDidBecomeActive(_ notification: Notification) {
// If we're back manually then clear the hidden state because macOS handles it. // If we're back manually then clear the hidden state because macOS handles it.
self.hiddenState = nil self.hiddenState = nil
@ -1084,8 +1089,6 @@ class AppDelegate: NSObject,
guard let keyWindow = NSApp.keyWindow, guard let keyWindow = NSApp.keyWindow,
!keyWindow.styleMask.contains(.fullScreen) else { return } !keyWindow.styleMask.contains(.fullScreen) else { return }
// Keep track of our hidden state to restore properly
self.hiddenState = .init()
NSApp.hide(nil) NSApp.hide(nil)
return return
} }
@ -1134,11 +1137,11 @@ class AppDelegate: NSObject,
} }
} }
private struct ToggleVisibilityState { struct ToggleVisibilityState {
let hiddenWindows: [Weak<NSWindow>] let hiddenWindows: [Weak<NSWindow>]
let keyWindow: 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 // We need to know the key window so that we can bring focus back to the
// right window if it was hidden. // right window if it was hidden.
self.keyWindow = if let keyWindow = NSApp.keyWindow { self.keyWindow = if let keyWindow = NSApp.keyWindow {

View File

@ -513,6 +513,10 @@ class QuickTerminalController: BaseTerminalController {
if !window.isOnActiveSpace { if !window.isOnActiveSpace {
self.previousApp = nil self.previousApp = nil
window.orderOut(self) window.orderOut(self)
// If our application is hidden previously, we hide it again
if (NSApp.delegate as? AppDelegate)?.hiddenState != nil {
NSApp.hide(nil)
}
return return
} }
@ -549,6 +553,10 @@ class QuickTerminalController: BaseTerminalController {
// This causes the window to be removed from the screen list and macOS // This causes the window to be removed from the screen list and macOS
// handles what should be focused next. // handles what should be focused next.
window.orderOut(self) window.orderOut(self)
// If our application is hidden previously, we hide it again
if (NSApp.delegate as? AppDelegate)?.hiddenState != nil {
NSApp.hide(nil)
}
}) })
} }