misc cleanups

This commit is contained in:
Mitchell Hashimoto
2025-01-08 11:28:02 -08:00
parent 37db4578c8
commit 6e54589db4
2 changed files with 34 additions and 18 deletions

View File

@ -90,9 +90,6 @@ class QuickTerminalController: BaseTerminalController {
delegate: self delegate: self
)) ))
// Change the collection behavior of the window depending on the configuration.
window.collectionBehavior = derivedConfig.quickTerminalSpaceBehavior.collectionBehavior
// Animate the window in // Animate the window in
animateIn() animateIn()
} }
@ -122,23 +119,24 @@ class QuickTerminalController: BaseTerminalController {
if derivedConfig.quickTerminalAutoHide { if derivedConfig.quickTerminalAutoHide {
switch derivedConfig.quickTerminalSpaceBehavior { switch derivedConfig.quickTerminalSpaceBehavior {
case .remain: case .remain:
if self.window?.isOnActiveSpace == true { // If we lose focus on the active space, then we can animate out
// If we lose focus on the active space, then we can animate out animateOut()
animateOut()
}
case .move: case .move:
// Check if the reason for losing focus is due to an active space change
let currentActiveSpace = CGSGetActiveSpace(CGSMainConnectionID()) let currentActiveSpace = CGSGetActiveSpace(CGSMainConnectionID())
if previousActiveSpace == currentActiveSpace { if previousActiveSpace == currentActiveSpace {
// If we lose focus on the active space, then we can animate out // We haven't moved spaces. We lost focus to another app on the
// current space. Animate out.
animateOut() animateOut()
} else { } else {
// If we're from different space, then we bring the window back // We've moved to a different space. Bring the quick terminal back
// into view.
DispatchQueue.main.async { DispatchQueue.main.async {
self.window?.makeKeyAndOrderFront(nil) self.window?.makeKeyAndOrderFront(nil)
} }
self.previousActiveSpace = currentActiveSpace
} }
self.previousActiveSpace = currentActiveSpace
} }
} }
} }
@ -320,6 +318,14 @@ class QuickTerminalController: BaseTerminalController {
} }
private func animateWindowOut(window: NSWindow, to position: QuickTerminalPosition) { private func animateWindowOut(window: NSWindow, to position: QuickTerminalPosition) {
// If the window isn't on our active space then we don't animate, we just
// hide it.
if !window.isOnActiveSpace {
self.previousApp = nil
window.orderOut(self)
return
}
// We always animate out to whatever screen the window is actually on. // We always animate out to whatever screen the window is actually on.
guard let screen = window.screen ?? NSScreen.main else { return } guard let screen = window.screen ?? NSScreen.main else { return }
@ -355,6 +361,9 @@ class QuickTerminalController: BaseTerminalController {
private func syncAppearance() { private func syncAppearance() {
guard let window else { return } guard let window else { return }
// Change the collection behavior of the window depending on the configuration.
window.collectionBehavior = derivedConfig.quickTerminalSpaceBehavior.collectionBehavior
// If our window is not visible, then no need to sync the appearance yet. // If our window is not visible, then no need to sync the appearance yet.
// Some APIs such as window blur have no effect unless the window is visible. // Some APIs such as window blur have no effect unless the window is visible.
guard window.isVisible else { return } guard window.isVisible else { return }
@ -433,9 +442,6 @@ class QuickTerminalController: BaseTerminalController {
// Update our derived config // Update our derived config
self.derivedConfig = DerivedConfig(config) self.derivedConfig = DerivedConfig(config)
// Update window.collectionBehavior
self.window?.collectionBehavior = derivedConfig.quickTerminalSpaceBehavior.collectionBehavior
syncAppearance() syncAppearance()
} }

View File

@ -1568,10 +1568,20 @@ keybind: Keybinds = .{},
@"quick-terminal-autohide": bool = true, @"quick-terminal-autohide": bool = true,
/// This configuration option determines the behavior of the quick terminal /// This configuration option determines the behavior of the quick terminal
/// when switching between spaces. If set to `move`, the quick terminal will /// when switching between macOS spaces. macOS spaces are virtual desktops
/// be moved to the space where the focused window is. If set to `remain`, /// that can be manually created or are automatically created when an
/// the quick terminal will stay only in the space where it was originally opened and /// application is in full-screen mode.
/// will not follow when switching to another space. ///
/// Valid values are:
///
/// * `move` - When switching to another space, the quick terminal will
/// also moved to the current space.
///
/// * `remain` - The quick terminal will stay only in the space where it
/// was originally opened and will not follow when switching to another
/// space.
///
/// The default value is `move`.
@"quick-terminal-space-behavior": QuickTerminalSpaceBehavior = .move, @"quick-terminal-space-behavior": QuickTerminalSpaceBehavior = .move,
/// Whether to enable shell integration auto-injection or not. Shell integration /// Whether to enable shell integration auto-injection or not. Shell integration