macos: quick terminal close focuses next window on same screen/space

Previously, we'd find the next Ghostty window anywhere. Now we find the
one on the same screen/space to avoid moving the focus to a different screen.
This commit is contained in:
Mitchell Hashimoto
2024-09-29 14:04:48 -07:00
parent 83505bb4c0
commit c8a40a7791

View File

@ -177,13 +177,24 @@ class QuickTerminalController: BaseTerminalController {
position.setInitial(in: window.animator(), on: screen)
}, completionHandler: {
guard wasKey else { return }
self.focusNextWindow()
self.focusNextWindow(on: screen)
})
}
private func focusNextWindow() {
// We only want to consider windows that are visible
let windows = NSApp.windows.filter { $0.isVisible }
private func focusNextWindow(on screen: NSScreen) {
let windows = NSApp.windows.filter {
// Visible, otherwise we'll make an invisible window visible.
guard $0.isVisible else { return false }
// Same screen, just a preference...
guard $0.screen == screen else { return false }
// Same space (virtual screen). Otherwise we'll force an animation to
// another space which is very jarring.
guard $0.isOnActiveSpace else { return false }
return true
}
// If we have no windows there is nothing to focus.
guard !windows.isEmpty else { return }