mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: swap out pointerVisible with NSCursor.setHiddenUntilMouseMoves
Fixes #2695 We had various issues with the pointerVisible property on macOS, including the pointer not being hidden when it should be. Our only use case today is mouse hide while typing so NSCursor.setHiddenUntilMouseMoves is a better fit!
This commit is contained in:
@ -59,23 +59,6 @@ extension Ghostty {
|
|||||||
|
|
||||||
@EnvironmentObject private var ghostty: Ghostty.App
|
@EnvironmentObject private var ghostty: Ghostty.App
|
||||||
|
|
||||||
#if canImport(AppKit)
|
|
||||||
// The visibility state of the mouse pointer
|
|
||||||
private var pointerVisibility: BackportVisibility {
|
|
||||||
// If our window or surface loses focus we always bring it back
|
|
||||||
if (!windowFocus || !surfaceFocus) {
|
|
||||||
return .visible
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we have window focus then it depends on surface state
|
|
||||||
if (surfaceView.pointerVisible) {
|
|
||||||
return .visible
|
|
||||||
} else {
|
|
||||||
return .hidden
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
let center = NotificationCenter.default
|
let center = NotificationCenter.default
|
||||||
|
|
||||||
@ -96,7 +79,6 @@ extension Ghostty {
|
|||||||
.focusedValue(\.ghosttySurfaceView, surfaceView)
|
.focusedValue(\.ghosttySurfaceView, surfaceView)
|
||||||
.focusedValue(\.ghosttySurfaceCellSize, surfaceView.cellSize)
|
.focusedValue(\.ghosttySurfaceCellSize, surfaceView.cellSize)
|
||||||
#if canImport(AppKit)
|
#if canImport(AppKit)
|
||||||
.backport.pointerVisibility(pointerVisibility)
|
|
||||||
.backport.pointerStyle(surfaceView.pointerStyle)
|
.backport.pointerStyle(surfaceView.pointerStyle)
|
||||||
.onReceive(pubBecomeKey) { notification in
|
.onReceive(pubBecomeKey) { notification in
|
||||||
guard let window = notification.object as? NSWindow else { return }
|
guard let window = notification.object as? NSWindow else { return }
|
||||||
|
@ -46,7 +46,6 @@ extension Ghostty {
|
|||||||
@Published var surfaceSize: ghostty_surface_size_s? = nil
|
@Published var surfaceSize: ghostty_surface_size_s? = nil
|
||||||
|
|
||||||
// Whether the pointer should be visible or not
|
// Whether the pointer should be visible or not
|
||||||
@Published private(set) var pointerVisible: Bool = true
|
|
||||||
@Published private(set) var pointerStyle: BackportPointerStyle = .default
|
@Published private(set) var pointerStyle: BackportPointerStyle = .default
|
||||||
|
|
||||||
// An initial size to request for a window. This will only affect
|
// An initial size to request for a window. This will only affect
|
||||||
@ -309,7 +308,11 @@ extension Ghostty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setCursorVisibility(_ visible: Bool) {
|
func setCursorVisibility(_ visible: Bool) {
|
||||||
pointerVisible = visible
|
// Technically this action could be called anytime we want to
|
||||||
|
// change the mouse visibility but at the time of writing this
|
||||||
|
// mouse-hide-while-typing is the only use case so this is the
|
||||||
|
// preferred method.
|
||||||
|
NSCursor.setHiddenUntilMouseMoves(!visible)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Notifications
|
// MARK: - Notifications
|
||||||
|
@ -449,11 +449,10 @@ palette: Palette = .{},
|
|||||||
/// way to implement it.
|
/// way to implement it.
|
||||||
@"cursor-click-to-move": bool = true,
|
@"cursor-click-to-move": bool = true,
|
||||||
|
|
||||||
/// Hide the mouse immediately when typing. The mouse becomes visible again when
|
/// Hide the mouse immediately when typing. The mouse becomes visible again
|
||||||
/// the mouse is used. The mouse is only hidden if the mouse cursor is over the
|
/// when the mouse is used (button, movement, etc.). Platform-specific behavior
|
||||||
/// active terminal surface.
|
/// may dictate other scenarios where the mouse is shown. For example on macOS,
|
||||||
///
|
/// the mouse is shown again when a new window, tab, or split is created.
|
||||||
/// macOS: This feature requires macOS 15.0 (Sequoia) or later.
|
|
||||||
@"mouse-hide-while-typing": bool = false,
|
@"mouse-hide-while-typing": bool = false,
|
||||||
|
|
||||||
/// Determines whether running programs can detect the shift key pressed with a
|
/// Determines whether running programs can detect the shift key pressed with a
|
||||||
|
Reference in New Issue
Block a user