Hide pointer on touch interaction
Browse files at this commit83aec41df31100df0b0ab553ac9220d03bd01bbaParent: 8be93812 changed files +32 -1
- src/input.rs +9 -0
- src/niri.rs +23 -1
src/input.rsmodified+9 -0
| @@ -822,6 +822,7 @@ impl State { | |||
| 822 | let mut new_pos = pos + event.delta(); | 822 | let mut new_pos = pos + event.delta(); |
| 823 | 823 | ||
| 824 | // We received an event for the regular pointer, so show it now. | 824 | // We received an event for the regular pointer, so show it now. |
| 825 | + self.niri.pointer_hidden = false; | ||
| 825 | self.niri.tablet_cursor_location = None; | 826 | self.niri.tablet_cursor_location = None; |
| 826 | 827 | ||
| 827 | // Check if we have an active pointer constraint. | 828 | // Check if we have an active pointer constraint. |
| @@ -1035,6 +1036,9 @@ impl State { | |||
| 1035 | 1036 | ||
| 1036 | pointer.frame(self); | 1037 | pointer.frame(self); |
| 1037 | 1038 | ||
| 1039 | + // We moved the pointer, show it. | ||
| 1040 | + self.niri.pointer_hidden = false; | ||
| 1041 | + | ||
| 1038 | // We moved the regular pointer, so show it now. | 1042 | // We moved the regular pointer, so show it now. |
| 1039 | self.niri.tablet_cursor_location = None; | 1043 | self.niri.tablet_cursor_location = None; |
| 1040 | 1044 | ||
| @@ -1333,6 +1337,7 @@ impl State { | |||
| 1333 | event.time_msec(), | 1337 | event.time_msec(), |
| 1334 | ); | 1338 | ); |
| 1335 | 1339 | ||
| 1340 | + self.niri.pointer_hidden = false; | ||
| 1336 | self.niri.tablet_cursor_location = Some(pos); | 1341 | self.niri.tablet_cursor_location = Some(pos); |
| 1337 | } | 1342 | } |
| 1338 | 1343 | ||
| @@ -1398,6 +1403,7 @@ impl State { | |||
| 1398 | event.time_msec(), | 1403 | event.time_msec(), |
| 1399 | ); | 1404 | ); |
| 1400 | } | 1405 | } |
| 1406 | + self.niri.pointer_hidden = false; | ||
| 1401 | self.niri.tablet_cursor_location = Some(pos); | 1407 | self.niri.tablet_cursor_location = Some(pos); |
| 1402 | } | 1408 | } |
| 1403 | ProximityState::Out => { | 1409 | ProximityState::Out => { |
| @@ -1735,6 +1741,9 @@ impl State { | |||
| 1735 | time: evt.time_msec(), | 1741 | time: evt.time_msec(), |
| 1736 | }, | 1742 | }, |
| 1737 | ); | 1743 | ); |
| 1744 | + | ||
| 1745 | + // We're using touch, hide the pointer. | ||
| 1746 | + self.niri.pointer_hidden = true; | ||
| 1738 | } | 1747 | } |
| 1739 | fn on_touch_up<I: InputBackend>(&mut self, evt: I::TouchUpEvent) { | 1748 | fn on_touch_up<I: InputBackend>(&mut self, evt: I::TouchUpEvent) { |
| 1740 | let Some(handle) = self.niri.seat.get_touch() else { | 1749 | let Some(handle) = self.niri.seat.get_touch() else { |
src/niri.rsmodified+23 -1
| @@ -207,6 +207,11 @@ pub struct Niri { | |||
| 207 | pub cursor_shape_manager_state: CursorShapeManagerState, | 207 | pub cursor_shape_manager_state: CursorShapeManagerState, |
| 208 | pub dnd_icon: Option<WlSurface>, | 208 | pub dnd_icon: Option<WlSurface>, |
| 209 | pub pointer_focus: PointerFocus, | 209 | pub pointer_focus: PointerFocus, |
| 210 | + /// Whether the pointer is hidden, for example due to a previous touch input. | ||
| 211 | + /// | ||
| 212 | + /// When this happens, the pointer also loses any focus. This is so that touch can prevent | ||
| 213 | + /// various tooltips from sticking around. | ||
| 214 | + pub pointer_hidden: bool, | ||
| 210 | pub tablet_cursor_location: Option<Point<f64, Logical>>, | 215 | pub tablet_cursor_location: Option<Point<f64, Logical>>, |
| 211 | pub gesture_swipe_3f_cumulative: Option<(f64, f64)>, | 216 | pub gesture_swipe_3f_cumulative: Option<(f64, f64)>, |
| 212 | pub vertical_wheel_tracker: ScrollTracker, | 217 | pub vertical_wheel_tracker: ScrollTracker, |
| @@ -481,6 +486,10 @@ impl State { | |||
| 481 | }, | 486 | }, |
| 482 | ); | 487 | ); |
| 483 | pointer.frame(self); | 488 | pointer.frame(self); |
| 489 | + | ||
| 490 | + // We moved the pointer, show it. | ||
| 491 | + self.niri.pointer_hidden = false; | ||
| 492 | + | ||
| 484 | // FIXME: granular | 493 | // FIXME: granular |
| 485 | self.niri.queue_redraw_all(); | 494 | self.niri.queue_redraw_all(); |
| 486 | } | 495 | } |
| @@ -595,7 +604,11 @@ impl State { | |||
| 595 | 604 | ||
| 596 | let pointer = &self.niri.seat.get_pointer().unwrap(); | 605 | let pointer = &self.niri.seat.get_pointer().unwrap(); |
| 597 | let location = pointer.current_location(); | 606 | let location = pointer.current_location(); |
| 598 | - let under = self.niri.surface_under_and_global_space(location); | 607 | + let under = if self.niri.pointer_hidden { |
| 608 | + PointerFocus::default() | ||
| 609 | + } else { | ||
| 610 | + self.niri.surface_under_and_global_space(location) | ||
| 611 | + }; | ||
| 599 | 612 | ||
| 600 | // We're not changing the global cursor location here, so if the focus did not change, then | 613 | // We're not changing the global cursor location here, so if the focus did not change, then |
| 601 | // nothing changed. | 614 | // nothing changed. |
| @@ -1371,6 +1384,7 @@ impl Niri { | |||
| 1371 | cursor_shape_manager_state, | 1384 | cursor_shape_manager_state, |
| 1372 | dnd_icon: None, | 1385 | dnd_icon: None, |
| 1373 | pointer_focus: PointerFocus::default(), | 1386 | pointer_focus: PointerFocus::default(), |
| 1387 | + pointer_hidden: false, | ||
| 1374 | tablet_cursor_location: None, | 1388 | tablet_cursor_location: None, |
| 1375 | gesture_swipe_3f_cumulative: None, | 1389 | gesture_swipe_3f_cumulative: None, |
| 1376 | vertical_wheel_tracker: ScrollTracker::new(120), | 1390 | vertical_wheel_tracker: ScrollTracker::new(120), |
| @@ -2023,6 +2037,10 @@ impl Niri { | |||
| 2023 | renderer: &mut R, | 2037 | renderer: &mut R, |
| 2024 | output: &Output, | 2038 | output: &Output, |
| 2025 | ) -> Vec<OutputRenderElements<R>> { | 2039 | ) -> Vec<OutputRenderElements<R>> { |
| 2040 | + if self.pointer_hidden { | ||
| 2041 | + return vec![]; | ||
| 2042 | + } | ||
| 2043 | + | ||
| 2026 | let _span = tracy_client::span!("Niri::pointer_element"); | 2044 | let _span = tracy_client::span!("Niri::pointer_element"); |
| 2027 | let output_scale = output.current_scale(); | 2045 | let output_scale = output.current_scale(); |
| 2028 | let output_pos = self.global_space.output_geometry(output).unwrap().loc; | 2046 | let output_pos = self.global_space.output_geometry(output).unwrap().loc; |
| @@ -2106,6 +2124,10 @@ impl Niri { | |||
| 2106 | } | 2124 | } |
| 2107 | 2125 | ||
| 2108 | pub fn refresh_pointer_outputs(&mut self) { | 2126 | pub fn refresh_pointer_outputs(&mut self) { |
| 2127 | + if self.pointer_hidden { | ||
| 2128 | + return; | ||
| 2129 | + } | ||
| 2130 | + | ||
| 2109 | let _span = tracy_client::span!("Niri::refresh_pointer_outputs"); | 2131 | let _span = tracy_client::span!("Niri::refresh_pointer_outputs"); |
| 2110 | 2132 | ||
| 2111 | // Check whether we need to draw the tablet cursor or the regular cursor. | 2133 | // Check whether we need to draw the tablet cursor or the regular cursor. |