mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-04-26 11:28:38 +03:00
macos: more robust cursor visibility handling
Fixes #519 The core issue here was that `mouseEntered` was called AFTER `cursorUpdate` (by Cocoa) so we were messing up our NSCursor state. To fix this more robustly, all cursor state should ONLY be handled by cursorUpdate and mouseEntered/Exit goes through that system now.
This commit is contained in:
@ -210,7 +210,7 @@ extension Ghostty {
|
|||||||
|
|
||||||
// State machine for mouse cursor visibility because every call to
|
// State machine for mouse cursor visibility because every call to
|
||||||
// NSCursor.hide/unhide must be balanced.
|
// NSCursor.hide/unhide must be balanced.
|
||||||
enum CursorVisibility {
|
enum CursorVisibility: String {
|
||||||
case visible
|
case visible
|
||||||
case hidden
|
case hidden
|
||||||
case pendingVisible
|
case pendingVisible
|
||||||
@ -519,11 +519,9 @@ extension Ghostty {
|
|||||||
|
|
||||||
mouseEntered = true
|
mouseEntered = true
|
||||||
|
|
||||||
// If our cursor is hidden, we hide it on upon entry and we unhide
|
// Update our cursor when we enter so we fully process our
|
||||||
// it on exit (mouseExited)
|
// cursorVisible state.
|
||||||
if (cursorVisible == .hidden) {
|
cursorUpdate(with: NSEvent())
|
||||||
NSCursor.hide()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func mouseExited(with event: NSEvent) {
|
override func mouseExited(with event: NSEvent) {
|
||||||
@ -532,8 +530,17 @@ extension Ghostty {
|
|||||||
|
|
||||||
mouseEntered = false
|
mouseEntered = false
|
||||||
|
|
||||||
|
// If the mouse is currently hidden, we want to show it when we exit
|
||||||
|
// this view. We go through the cursorVisible dance so that only
|
||||||
|
// cursorUpdate manages cursor state.
|
||||||
if (cursorVisible == .hidden) {
|
if (cursorVisible == .hidden) {
|
||||||
NSCursor.unhide()
|
cursorVisible = .pendingVisible
|
||||||
|
cursorUpdate(with: NSEvent())
|
||||||
|
assert(cursorVisible == .visible)
|
||||||
|
|
||||||
|
// We set the state to pending hidden again for the next time
|
||||||
|
// we enter.
|
||||||
|
cursorVisible = .pendingHidden
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user