forked from ghostty-org/ghostty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
macos: autohide dock if quick terminal would conflict with it (ghostt…
…y-org#5361) Fixes ghostty-org#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. ## Demo https://github.com/user-attachments/assets/1f5bb945-dca4-49e7-8bcb-95b55524cfb5
- Loading branch information
Showing
6 changed files
with
124 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Cocoa | ||
|
||
// Private API to get Dock location | ||
@_silgen_name("CoreDockGetOrientationAndPinning") | ||
func CoreDockGetOrientationAndPinning( | ||
_ outOrientation: UnsafeMutablePointer<Int32>, | ||
_ outPinning: UnsafeMutablePointer<Int32>) | ||
|
||
// Private API to get the current Dock auto-hide state | ||
@_silgen_name("CoreDockGetAutoHideEnabled") | ||
func CoreDockGetAutoHideEnabled() -> Bool | ||
|
||
enum DockOrientation: Int { | ||
case top = 1 | ||
case bottom = 2 | ||
case left = 3 | ||
case right = 4 | ||
} | ||
|
||
class Dock { | ||
/// Returns the orientation of the dock or nil if it can't be determined. | ||
static var orientation: DockOrientation? { | ||
var orientation: Int32 = 0 | ||
var pinning: Int32 = 0 | ||
CoreDockGetOrientationAndPinning(&orientation, &pinning) | ||
return .init(rawValue: Int(orientation)) ?? nil | ||
} | ||
|
||
/// Returns true if the dock has auto-hide enabled. | ||
static var autoHideEnabled: Bool { | ||
return CoreDockGetAutoHideEnabled() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Cocoa | ||
|
||
extension NSApplication { | ||
private static var presentationOptionCounts: [NSApplication.PresentationOptions.Element: UInt] = [:] | ||
|
||
/// Add a presentation option to the application and main a reference count so that and equal | ||
/// number of pops is required to disable it. This is useful so that multiple classes can affect global | ||
/// app state without overriding others. | ||
func acquirePresentationOption(_ option: NSApplication.PresentationOptions.Element) { | ||
Self.presentationOptionCounts[option, default: 0] += 1 | ||
presentationOptions.insert(option) | ||
} | ||
|
||
/// See acquirePresentationOption | ||
func releasePresentationOption(_ option: NSApplication.PresentationOptions.Element) { | ||
guard let value = Self.presentationOptionCounts[option] else { return } | ||
guard value > 0 else { return } | ||
if (value == 1) { | ||
presentationOptions.remove(option) | ||
Self.presentationOptionCounts.removeValue(forKey: option) | ||
} else { | ||
Self.presentationOptionCounts[option] = value - 1 | ||
} | ||
} | ||
} | ||
|
||
extension NSApplication.PresentationOptions.Element: @retroactive Hashable { | ||
public func hash(into hasher: inout Hasher) { | ||
hasher.combine(rawValue) | ||
} | ||
} |