From 42a9daec9db57e16541b6ef236b695b71bfb1199 Mon Sep 17 00:00:00 2001 From: yzy-1 <50034950+yzy-1@users.noreply.github.com> Date: Wed, 2 Oct 2024 08:22:50 +0800 Subject: Implement hide cursor on key press and on timeout --- src/niri.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/niri.rs') diff --git a/src/niri.rs b/src/niri.rs index 396852bf..6119c4d6 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -267,6 +267,7 @@ pub struct Niri { /// When this happens, the pointer also loses any focus. This is so that touch can prevent /// various tooltips from sticking around. pub pointer_hidden: bool, + pub last_cursor_movement: Instant, // FIXME: this should be able to be removed once PointerFocus takes grabs into account. pub pointer_grab_ongoing: bool, pub tablet_cursor_location: Option>, @@ -1860,6 +1861,7 @@ impl Niri { dnd_icon: None, pointer_focus: PointerFocus::default(), pointer_hidden: false, + last_cursor_movement: Instant::now(), pointer_grab_ongoing: false, tablet_cursor_location: None, gesture_swipe_3f_cumulative: None, @@ -2663,7 +2665,26 @@ impl Niri { pointer_elements } + fn hide_cursor_after_timeout_if_needed(&mut self) { + if self.pointer_hidden { + return; + } + + let config = self.config.borrow(); + let timeout = &config.cursor.hide_after_inactive_ms; + + if let Some(duration_ms) = timeout { + let timeout = Duration::from_millis(*duration_ms as u64); + + if self.last_cursor_movement.elapsed() >= timeout { + self.pointer_hidden = true; + } + } + } + pub fn refresh_pointer_outputs(&mut self) { + self.hide_cursor_after_timeout_if_needed(); + if self.pointer_hidden { return; } -- cgit