From 2bb0e4e797fb9fa613c0c2fbbfec1ecd5c4d1d90 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 10 Apr 2021 14:30:06 -0700 Subject: [PATCH] macos: use alternative cursor hiding technique NSCursor hide/unhide must be perfectly balanced otherwise the cursor can vanish unexpectedly when the mouse leaves the window, and not come back. So, let's use NSCursor:setHiddenUntilMouseMoves instead; it's not 100% fulfilling the promise of the API, but it's close enough and should avoid the permanent invisibility issue. refs: https://github.com/wez/wezterm/issues/618 --- window/src/os/macos/window.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index 61e87a5b7..883ceb716 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -321,7 +321,6 @@ pub(crate) struct WindowInner { view: StrongPtr, window: StrongPtr, config: ConfigHandle, - cursor: Option, } fn function_key_to_keycode(function_key: char) -> KeyCode { @@ -457,7 +456,6 @@ impl Window { window, view, config: config.clone(), - cursor: Some(MouseCursor::Arrow), })); inner.borrow_mut().window.replace(weak_window); conn.windows @@ -802,18 +800,12 @@ impl WindowOpsMut for WindowInner { MouseCursor::SizeUpDown => msg_send![ns_cursor_cls, resizeUpDownCursor], MouseCursor::SizeLeftRight => msg_send![ns_cursor_cls, resizeLeftRightCursor], }; + let () = msg_send![ns_cursor_cls, setHiddenUntilMouseMoves: NO]; let () = msg_send![instance, set]; - if self.cursor.is_none() { - // If we believe that it was hidden previously, unhide it. - let () = msg_send![ns_cursor_cls, unhide]; - } - } else if self.cursor.is_some() { - // If we believe that it was shown previously, hide it. - let () = msg_send![ns_cursor_cls, hide]; + } else { + let () = msg_send![ns_cursor_cls, setHiddenUntilMouseMoves: YES]; } } - - self.cursor = cursor; } fn invalidate(&mut self) {