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
))
// Change the collection behavior of the window depending on the configuration.
window.collectionBehavior = derivedConfig.quickTerminalSpaceBehavior.collectionBehavior
// Animate the window in
animateIn()
}
@ -122,26 +119,27 @@ class QuickTerminalController: BaseTerminalController {
if derivedConfig.quickTerminalAutoHide {
switch derivedConfig.quickTerminalSpaceBehavior {
case .remain:
if self.window?.isOnActiveSpace == true {
// If we lose focus on the active space, then we can animate out
animateOut()
}
case .move:
// Check if the reason for losing focus is due to an active space change
let currentActiveSpace = CGSGetActiveSpace(CGSMainConnectionID())
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()
} 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 {
self.window?.makeKeyAndOrderFront(nil)
}
}
self.previousActiveSpace = currentActiveSpace
}
}
}
}
func windowWillResize(_ sender: NSWindow, to frameSize: NSSize) -> NSSize {
// We use the actual screen the window is on for this, since it should
@ -320,6 +318,14 @@ class QuickTerminalController: BaseTerminalController {
}
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.
guard let screen = window.screen ?? NSScreen.main else { return }
@ -355,6 +361,9 @@ class QuickTerminalController: BaseTerminalController {
private func syncAppearance() {
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.
// Some APIs such as window blur have no effect unless the window is visible.
guard window.isVisible else { return }
@ -433,9 +442,6 @@ class QuickTerminalController: BaseTerminalController {
// Update our derived config
self.derivedConfig = DerivedConfig(config)
// Update window.collectionBehavior
self.window?.collectionBehavior = derivedConfig.quickTerminalSpaceBehavior.collectionBehavior
syncAppearance()
}

View File

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