Fix pointer hiding so that it is no longer annoying (#1426)
Browse files at this commit3 changed files +49 -27
- src/handlers/mod.rs +2 -2
- src/input/mod.rs +12 -12
- src/niri.rs +35 -13
src/handlers/mod.rsmodified+2 -2
| @@ -211,7 +211,7 @@ impl PointerConstraintsHandler for State { | |||
| 211 | pointer.set_location(target); | 211 | pointer.set_location(target); |
| 212 | 212 | ||
| 213 | // Redraw to update the cursor position if it's visible. | 213 | // Redraw to update the cursor position if it's visible. |
| 214 | - if !self.niri.pointer_hidden { | 214 | + if self.niri.pointer_visibility.is_visible() { |
| 215 | // FIXME: redraw only outputs overlapping the cursor. | 215 | // FIXME: redraw only outputs overlapping the cursor. |
| 216 | self.niri.queue_redraw_all(); | 216 | self.niri.queue_redraw_all(); |
| 217 | } | 217 | } |
| @@ -369,7 +369,7 @@ impl ClientDndGrabHandler for State { | |||
| 369 | // parameters from Smithay I guess. | 369 | // parameters from Smithay I guess. |
| 370 | // | 370 | // |
| 371 | // Assume that hidden pointer means touch DnD. | 371 | // Assume that hidden pointer means touch DnD. |
| 372 | - if !self.niri.pointer_hidden { | 372 | + if self.niri.pointer_visibility.is_visible() { |
| 373 | // We can't even get the current pointer location because it's locked (we're deep | 373 | // We can't even get the current pointer location because it's locked (we're deep |
| 374 | // in the grab call stack here). So use the last known one. | 374 | // in the grab call stack here). So use the last known one. |
| 375 | if let Some(output) = &self.niri.pointer_contents.output { | 375 | if let Some(output) = &self.niri.pointer_contents.output { |
src/input/mod.rsmodified+12 -12
| @@ -42,7 +42,7 @@ use self::resize_grab::ResizeGrab; | |||
| 42 | use self::spatial_movement_grab::SpatialMovementGrab; | 42 | use self::spatial_movement_grab::SpatialMovementGrab; |
| 43 | use crate::layout::scrolling::ScrollDirection; | 43 | use crate::layout::scrolling::ScrollDirection; |
| 44 | use crate::layout::{ActivateWindow, LayoutElement as _}; | 44 | use crate::layout::{ActivateWindow, LayoutElement as _}; |
| 45 | -use crate::niri::{CastTarget, State}; | 45 | +use crate::niri::{CastTarget, PointerVisibility, State}; |
| 46 | use crate::ui::screenshot_ui::ScreenshotUi; | 46 | use crate::ui::screenshot_ui::ScreenshotUi; |
| 47 | use crate::utils::spawning::spawn; | 47 | use crate::utils::spawning::spawn; |
| 48 | use crate::utils::{center, get_monotonic_time, ResizeEdge}; | 48 | use crate::utils::{center, get_monotonic_time, ResizeEdge}; |
| @@ -477,13 +477,13 @@ impl State { | |||
| 477 | } | 477 | } |
| 478 | 478 | ||
| 479 | // niri keeps this set only while actively using a tablet, which means the cursor position | 479 | // niri keeps this set only while actively using a tablet, which means the cursor position |
| 480 | - // is likely to change almost immediately, causing pointer_hidden to just flicker back and | 480 | + // is likely to change almost immediately, causing pointer_visibility to just flicker back |
| 481 | - // forth. | 481 | + // and forth. |
| 482 | if self.niri.tablet_cursor_location.is_some() { | 482 | if self.niri.tablet_cursor_location.is_some() { |
| 483 | return; | 483 | return; |
| 484 | } | 484 | } |
| 485 | 485 | ||
| 486 | - self.niri.pointer_hidden = true; | 486 | + self.niri.pointer_visibility = PointerVisibility::Hidden; |
| 487 | self.niri.queue_redraw_all(); | 487 | self.niri.queue_redraw_all(); |
| 488 | } | 488 | } |
| 489 | 489 | ||
| @@ -2014,7 +2014,7 @@ impl State { | |||
| 2014 | let mut new_pos = pos + event.delta(); | 2014 | let mut new_pos = pos + event.delta(); |
| 2015 | 2015 | ||
| 2016 | // We received an event for the regular pointer, so show it now. | 2016 | // We received an event for the regular pointer, so show it now. |
| 2017 | - self.niri.pointer_hidden = false; | 2017 | + self.niri.pointer_visibility = PointerVisibility::Visible; |
| 2018 | self.niri.tablet_cursor_location = None; | 2018 | self.niri.tablet_cursor_location = None; |
| 2019 | 2019 | ||
| 2020 | // Check if we have an active pointer constraint. | 2020 | // Check if we have an active pointer constraint. |
| @@ -2283,7 +2283,7 @@ impl State { | |||
| 2283 | self.niri.maybe_activate_pointer_constraint(); | 2283 | self.niri.maybe_activate_pointer_constraint(); |
| 2284 | 2284 | ||
| 2285 | // We moved the pointer, show it. | 2285 | // We moved the pointer, show it. |
| 2286 | - self.niri.pointer_hidden = false; | 2286 | + self.niri.pointer_visibility = PointerVisibility::Visible; |
| 2287 | 2287 | ||
| 2288 | // We moved the regular pointer, so show it now. | 2288 | // We moved the regular pointer, so show it now. |
| 2289 | self.niri.tablet_cursor_location = None; | 2289 | self.niri.tablet_cursor_location = None; |
| @@ -2348,7 +2348,7 @@ impl State { | |||
| 2348 | } | 2348 | } |
| 2349 | 2349 | ||
| 2350 | // We received an event for the regular pointer, so show it now. | 2350 | // We received an event for the regular pointer, so show it now. |
| 2351 | - self.niri.pointer_hidden = false; | 2351 | + self.niri.pointer_visibility = PointerVisibility::Visible; |
| 2352 | self.niri.tablet_cursor_location = None; | 2352 | self.niri.tablet_cursor_location = None; |
| 2353 | 2353 | ||
| 2354 | let is_overview_open = self.niri.layout.is_overview_open(); | 2354 | let is_overview_open = self.niri.layout.is_overview_open(); |
| @@ -2608,7 +2608,7 @@ impl State { | |||
| 2608 | // We received an event for the regular pointer, so show it now. This is also needed for | 2608 | // We received an event for the regular pointer, so show it now. This is also needed for |
| 2609 | // update_pointer_contents() below to return the real contents, necessary for the pointer | 2609 | // update_pointer_contents() below to return the real contents, necessary for the pointer |
| 2610 | // axis event to reach the window. | 2610 | // axis event to reach the window. |
| 2611 | - self.niri.pointer_hidden = false; | 2611 | + self.niri.pointer_visibility = PointerVisibility::Visible; |
| 2612 | self.niri.tablet_cursor_location = None; | 2612 | self.niri.tablet_cursor_location = None; |
| 2613 | 2613 | ||
| 2614 | let timestamp = Duration::from_micros(event.time()); | 2614 | let timestamp = Duration::from_micros(event.time()); |
| @@ -3053,7 +3053,7 @@ impl State { | |||
| 3053 | event.time_msec(), | 3053 | event.time_msec(), |
| 3054 | ); | 3054 | ); |
| 3055 | 3055 | ||
| 3056 | - self.niri.pointer_hidden = false; | 3056 | + self.niri.pointer_visibility = PointerVisibility::Visible; |
| 3057 | self.niri.tablet_cursor_location = Some(pos); | 3057 | self.niri.tablet_cursor_location = Some(pos); |
| 3058 | } | 3058 | } |
| 3059 | 3059 | ||
| @@ -3145,7 +3145,7 @@ impl State { | |||
| 3145 | event.time_msec(), | 3145 | event.time_msec(), |
| 3146 | ); | 3146 | ); |
| 3147 | } | 3147 | } |
| 3148 | - self.niri.pointer_hidden = false; | 3148 | + self.niri.pointer_visibility = PointerVisibility::Visible; |
| 3149 | self.niri.tablet_cursor_location = Some(pos); | 3149 | self.niri.tablet_cursor_location = Some(pos); |
| 3150 | } | 3150 | } |
| 3151 | ProximityState::Out => { | 3151 | ProximityState::Out => { |
| @@ -3159,7 +3159,7 @@ impl State { | |||
| 3159 | self.move_cursor(pos); | 3159 | self.move_cursor(pos); |
| 3160 | } | 3160 | } |
| 3161 | 3161 | ||
| 3162 | - self.niri.pointer_hidden = false; | 3162 | + self.niri.pointer_visibility = PointerVisibility::Visible; |
| 3163 | self.niri.tablet_cursor_location = None; | 3163 | self.niri.tablet_cursor_location = None; |
| 3164 | } | 3164 | } |
| 3165 | } | 3165 | } |
| @@ -3591,7 +3591,7 @@ impl State { | |||
| 3591 | ); | 3591 | ); |
| 3592 | 3592 | ||
| 3593 | // We're using touch, hide the pointer. | 3593 | // We're using touch, hide the pointer. |
| 3594 | - self.niri.pointer_hidden = true; | 3594 | + self.niri.pointer_visibility = PointerVisibility::Disabled; |
| 3595 | } | 3595 | } |
| 3596 | fn on_touch_up<I: InputBackend>(&mut self, evt: I::TouchUpEvent) { | 3596 | fn on_touch_up<I: InputBackend>(&mut self, evt: I::TouchUpEvent) { |
| 3597 | let Some(handle) = self.niri.seat.get_touch() else { | 3597 | let Some(handle) = self.niri.seat.get_touch() else { |
src/niri.rsmodified+35 -13
| @@ -331,11 +331,7 @@ pub struct Niri { | |||
| 331 | /// taking grabs into account is expected, because we pass the information to pointer.motion() | 331 | /// taking grabs into account is expected, because we pass the information to pointer.motion() |
| 332 | /// which passes it down through grabs, which decide what to do with it as they see fit. | 332 | /// which passes it down through grabs, which decide what to do with it as they see fit. |
| 333 | pub pointer_contents: PointContents, | 333 | pub pointer_contents: PointContents, |
| 334 | - /// Whether the pointer is hidden, for example due to a previous touch input. | 334 | + pub pointer_visibility: PointerVisibility, |
| 335 | - /// | ||
| 336 | - /// When this happens, the pointer also loses any focus. This is so that touch can prevent | ||
| 337 | - /// various tooltips from sticking around. | ||
| 338 | - pub pointer_hidden: bool, | ||
| 339 | pub pointer_inactivity_timer: Option<RegistrationToken>, | 335 | pub pointer_inactivity_timer: Option<RegistrationToken>, |
| 340 | /// Whether the pointer inactivity timer got reset this event loop iteration. | 336 | /// Whether the pointer inactivity timer got reset this event loop iteration. |
| 341 | /// | 337 | /// |
| @@ -395,6 +391,28 @@ pub struct Niri { | |||
| 395 | pub dynamic_cast_id_for_portal: MappedId, | 391 | pub dynamic_cast_id_for_portal: MappedId, |
| 396 | } | 392 | } |
| 397 | 393 | ||
| 394 | +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| 395 | +pub enum PointerVisibility { | ||
| 396 | + /// The pointer is visible. | ||
| 397 | + Visible, | ||
| 398 | + /// The pointer is invisible, but retains its focus. | ||
| 399 | + /// | ||
| 400 | + /// This state is set temporarily after auto-hiding the pointer to keep tooltips open and grabs | ||
| 401 | + /// ongoing. | ||
| 402 | + Hidden, | ||
| 403 | + /// The pointer is invisible and cannot focus. | ||
| 404 | + /// | ||
| 405 | + /// Corresponds to a fully disabled pointer, for example after a touchscreen input, or after | ||
| 406 | + /// the pointer contents changed in a Hidden state. | ||
| 407 | + Disabled, | ||
| 408 | +} | ||
| 409 | + | ||
| 410 | +impl PointerVisibility { | ||
| 411 | + pub fn is_visible(&self) -> bool { | ||
| 412 | + matches!(self, Self::Visible) | ||
| 413 | + } | ||
| 414 | +} | ||
| 415 | + | ||
| 398 | #[derive(Debug)] | 416 | #[derive(Debug)] |
| 399 | pub struct DndIcon { | 417 | pub struct DndIcon { |
| 400 | pub surface: WlSurface, | 418 | pub surface: WlSurface, |
| @@ -911,10 +929,9 @@ impl State { | |||
| 911 | 929 | ||
| 912 | let pointer = &self.niri.seat.get_pointer().unwrap(); | 930 | let pointer = &self.niri.seat.get_pointer().unwrap(); |
| 913 | let location = pointer.current_location(); | 931 | let location = pointer.current_location(); |
| 914 | - let under = if self.niri.pointer_hidden { | 932 | + let under = match self.niri.pointer_visibility { |
| 915 | - PointContents::default() | 933 | + PointerVisibility::Disabled => PointContents::default(), |
| 916 | - } else { | 934 | + _ => self.niri.contents_under(location), |
| 917 | - self.niri.contents_under(location) | ||
| 918 | }; | 935 | }; |
| 919 | 936 | ||
| 920 | // We're not changing the global cursor location here, so if the contents did not change, | 937 | // We're not changing the global cursor location here, so if the contents did not change, |
| @@ -923,6 +940,11 @@ impl State { | |||
| 923 | return false; | 940 | return false; |
| 924 | } | 941 | } |
| 925 | 942 | ||
| 943 | + // Disable the hidden pointer if the contents underneath have changed. | ||
| 944 | + if !self.niri.pointer_visibility.is_visible() { | ||
| 945 | + self.niri.pointer_visibility = PointerVisibility::Disabled; | ||
| 946 | + } | ||
| 947 | + | ||
| 926 | self.niri.pointer_contents.clone_from(&under); | 948 | self.niri.pointer_contents.clone_from(&under); |
| 927 | 949 | ||
| 928 | pointer.motion( | 950 | pointer.motion( |
| @@ -2424,7 +2446,7 @@ impl Niri { | |||
| 2424 | cursor_shape_manager_state, | 2446 | cursor_shape_manager_state, |
| 2425 | dnd_icon: None, | 2447 | dnd_icon: None, |
| 2426 | pointer_contents: PointContents::default(), | 2448 | pointer_contents: PointContents::default(), |
| 2427 | - pointer_hidden: false, | 2449 | + pointer_visibility: PointerVisibility::Visible, |
| 2428 | pointer_inactivity_timer: None, | 2450 | pointer_inactivity_timer: None, |
| 2429 | pointer_inactivity_timer_got_reset: false, | 2451 | pointer_inactivity_timer_got_reset: false, |
| 2430 | notified_activity_this_iteration: false, | 2452 | notified_activity_this_iteration: false, |
| @@ -3420,7 +3442,7 @@ impl Niri { | |||
| 3420 | renderer: &mut R, | 3442 | renderer: &mut R, |
| 3421 | output: &Output, | 3443 | output: &Output, |
| 3422 | ) -> Vec<OutputRenderElements<R>> { | 3444 | ) -> Vec<OutputRenderElements<R>> { |
| 3423 | - if self.pointer_hidden { | 3445 | + if !self.pointer_visibility.is_visible() { |
| 3424 | return vec![]; | 3446 | return vec![]; |
| 3425 | } | 3447 | } |
| 3426 | 3448 | ||
| @@ -3507,7 +3529,7 @@ impl Niri { | |||
| 3507 | } | 3529 | } |
| 3508 | 3530 | ||
| 3509 | pub fn refresh_pointer_outputs(&mut self) { | 3531 | pub fn refresh_pointer_outputs(&mut self) { |
| 3510 | - if self.pointer_hidden { | 3532 | + if !self.pointer_visibility.is_visible() { |
| 3511 | return; | 3533 | return; |
| 3512 | } | 3534 | } |
| 3513 | 3535 | ||
| @@ -5850,7 +5872,7 @@ impl Niri { | |||
| 5850 | .event_loop | 5872 | .event_loop |
| 5851 | .insert_source(timer, move |_, _, state| { | 5873 | .insert_source(timer, move |_, _, state| { |
| 5852 | state.niri.pointer_inactivity_timer = None; | 5874 | state.niri.pointer_inactivity_timer = None; |
| 5853 | - state.niri.pointer_hidden = true; | 5875 | + state.niri.pointer_visibility = PointerVisibility::Hidden; |
| 5854 | state.niri.queue_redraw_all(); | 5876 | state.niri.queue_redraw_all(); |
| 5855 | 5877 | ||
| 5856 | TimeoutAction::Drop | 5878 | TimeoutAction::Drop |