mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-21 17:21:52 +00:00
macos: autohide dock if quick terminal would conflict with it
Fixes #5328 The dock sits above the level of the quick terminal, and the quick terminal frame typical includes the dock. Hence, if the dock is visible and the quick terminal would conflict with it, then part of the terminal is obscured. This commit makes the dock autohide if the quick terminal would conflict with it. The autohide is disabled when the quick terminal is closed. We can't set our window level above the dock, as this would prevent things such as input methods from rendering properly in the quick terminal window. iTerm2 (the only other macOS terminal I know of that supports a dropdown mode) frames the terminal around the dock. I think this looks less aesthetically pleasing and I prefer autohiding the dock instead. We can introduce a setting to change this behavior if desired later. Additionally, this commit introduces a mechanism to safely set app-global presentation options from multiple sources without stepping on each other.
This commit is contained in:
@@ -27,6 +27,10 @@ class QuickTerminalController: BaseTerminalController {
|
||||
// The active space when the quick terminal was last shown.
|
||||
private var previousActiveSpace: size_t = 0
|
||||
|
||||
/// This is set to true of the dock was autohid when the terminal animated in. This lets us
|
||||
/// know if we have to unhide when the terminal is animated out.
|
||||
private var hidDock: Bool = false
|
||||
|
||||
/// The configuration derived from the Ghostty config so we don't need to rely on references.
|
||||
private var derivedConfig: DerivedConfig
|
||||
|
||||
@@ -224,6 +228,18 @@ class QuickTerminalController: BaseTerminalController {
|
||||
animateWindowOut(window: window, to: position)
|
||||
}
|
||||
|
||||
private func hideDock() {
|
||||
guard !hidDock else { return }
|
||||
NSApp.acquirePresentationOption(.autoHideDock)
|
||||
hidDock = true
|
||||
}
|
||||
|
||||
private func unhideDock() {
|
||||
guard hidDock else { return }
|
||||
NSApp.releasePresentationOption(.autoHideDock)
|
||||
hidDock = false
|
||||
}
|
||||
|
||||
private func animateWindowIn(window: NSWindow, from position: QuickTerminalPosition) {
|
||||
guard let screen = derivedConfig.quickTerminalScreen.screen else { return }
|
||||
|
||||
@@ -240,6 +256,12 @@ class QuickTerminalController: BaseTerminalController {
|
||||
window.makeKeyAndOrderFront(nil)
|
||||
}
|
||||
|
||||
// If our dock position would conflict with our target location then
|
||||
// we autohide the dock.
|
||||
if position.conflictsWithDock(on: screen) {
|
||||
hideDock()
|
||||
}
|
||||
|
||||
// Run the animation that moves our window into the proper place and makes
|
||||
// it visible.
|
||||
NSAnimationContext.runAnimationGroup({ context in
|
||||
@@ -250,8 +272,11 @@ class QuickTerminalController: BaseTerminalController {
|
||||
// There is a very minor delay here so waiting at least an event loop tick
|
||||
// keeps us safe from the view not being on the window.
|
||||
DispatchQueue.main.async {
|
||||
// If we canceled our animation in we do nothing
|
||||
guard self.visible else { return }
|
||||
// If we canceled our animation clean up some state.
|
||||
guard self.visible else {
|
||||
self.unhideDock()
|
||||
return
|
||||
}
|
||||
|
||||
// After animating in, we reset the window level to a value that
|
||||
// is above other windows but not as high as popUpMenu. This allows
|
||||
@@ -320,6 +345,9 @@ class QuickTerminalController: BaseTerminalController {
|
||||
}
|
||||
|
||||
private func animateWindowOut(window: NSWindow, to position: QuickTerminalPosition) {
|
||||
// If we hid the dock then we unhide it.
|
||||
unhideDock()
|
||||
|
||||
// If the window isn't on our active space then we don't animate, we just
|
||||
// hide it.
|
||||
if !window.isOnActiveSpace {
|
||||
|
Reference in New Issue
Block a user