Rename pointer_focus to pointer_contents, clarify comments
Browse files at this commitf5d91c5ecc8d2f8ee0e7dd03889844f46e480026Parent: 69e3edb3 changed files +56 -42
- src/handlers/mod.rs +11 -10
- src/input/mod.rs +19 -19
- src/niri.rs +26 -13
src/handlers/mod.rsmodified+11 -10
| @@ -140,7 +140,7 @@ impl PointerConstraintsHandler for State { | |||
| 140 | fn new_constraint(&mut self, _surface: &WlSurface, pointer: &PointerHandle<Self>) { | 140 | fn new_constraint(&mut self, _surface: &WlSurface, pointer: &PointerHandle<Self>) { |
| 141 | self.niri.maybe_activate_pointer_constraint( | 141 | self.niri.maybe_activate_pointer_constraint( |
| 142 | pointer.current_location(), | 142 | pointer.current_location(), |
| 143 | - &self.niri.pointer_focus, | 143 | + &self.niri.pointer_contents, |
| 144 | ); | 144 | ); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| @@ -158,19 +158,20 @@ impl PointerConstraintsHandler for State { | |||
| 158 | return; | 158 | return; |
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | - // Logically the following two checks should always succeed (so, they should print | 161 | + // Note: this is surface under pointer, not pointer focus. So if you start, say, a |
| 162 | - // error!()s if they fail). However, currently both can fail because niri's pointer focus | 162 | + // middle-drag in Blender, then touchpad-swipe the window away, the surface under pointer |
| 163 | - // doesn't take pointer grabs into account. So if you start, say, a middle-drag in Blender, | 163 | + // will change, even though the real pointer focus remains on the Blender surface due to |
| 164 | - // then touchpad-swipe the window away, the niri pointer focus will change, even though the | 164 | + // the click grab. |
| 165 | - // real pointer focus remains on the Blender surface due to the click grab. | ||
| 166 | // | 165 | // |
| 167 | - // FIXME: add error!()s when niri pointer focus takes grabs into account. Alternatively, | 166 | + // Ideally we would just use the constraint surface, but we need its origin. So this is |
| 168 | - // recompute the surface origin here (but that is a bit clunky). | 167 | + // more of a hack because pointer contents has the surface origin available. |
| 169 | - let Some((ref focused_surface, origin)) = self.niri.pointer_focus.surface else { | 168 | + // |
| 169 | + // FIXME: use the constraint surface somehow, don't use pointer contents. | ||
| 170 | + let Some((ref surface_under_pointer, origin)) = self.niri.pointer_contents.surface else { | ||
| 170 | return; | 171 | return; |
| 171 | }; | 172 | }; |
| 172 | 173 | ||
| 173 | - if focused_surface != surface { | 174 | + if surface_under_pointer != surface { |
| 174 | return; | 175 | return; |
| 175 | } | 176 | } |
| 176 | 177 | ||
src/input/mod.rsmodified+19 -19
| @@ -1321,11 +1321,11 @@ impl State { | |||
| 1321 | 1321 | ||
| 1322 | // Check if we have an active pointer constraint. | 1322 | // Check if we have an active pointer constraint. |
| 1323 | let mut pointer_confined = None; | 1323 | let mut pointer_confined = None; |
| 1324 | - if let Some(focus) = &self.niri.pointer_focus.surface { | 1324 | + if let Some(under) = &self.niri.pointer_contents.surface { |
| 1325 | - let pos_within_surface = pos - focus.1; | 1325 | + let pos_within_surface = pos - under.1; |
| 1326 | 1326 | ||
| 1327 | let mut pointer_locked = false; | 1327 | let mut pointer_locked = false; |
| 1328 | - with_pointer_constraint(&focus.0, &pointer, |constraint| { | 1328 | + with_pointer_constraint(&under.0, &pointer, |constraint| { |
| 1329 | let Some(constraint) = constraint else { return }; | 1329 | let Some(constraint) = constraint else { return }; |
| 1330 | if !constraint.is_active() { | 1330 | if !constraint.is_active() { |
| 1331 | return; | 1331 | return; |
| @@ -1343,7 +1343,7 @@ impl State { | |||
| 1343 | pointer_locked = true; | 1343 | pointer_locked = true; |
| 1344 | } | 1344 | } |
| 1345 | PointerConstraint::Confined(confine) => { | 1345 | PointerConstraint::Confined(confine) => { |
| 1346 | - pointer_confined = Some((focus.clone(), confine.region().cloned())); | 1346 | + pointer_confined = Some((under.clone(), confine.region().cloned())); |
| 1347 | } | 1347 | } |
| 1348 | } | 1348 | } |
| 1349 | }); | 1349 | }); |
| @@ -1352,7 +1352,7 @@ impl State { | |||
| 1352 | if pointer_locked { | 1352 | if pointer_locked { |
| 1353 | pointer.relative_motion( | 1353 | pointer.relative_motion( |
| 1354 | self, | 1354 | self, |
| 1355 | - Some(focus.clone()), | 1355 | + Some(under.clone()), |
| 1356 | &RelativeMotionEvent { | 1356 | &RelativeMotionEvent { |
| 1357 | delta: event.delta(), | 1357 | delta: event.delta(), |
| 1358 | delta_unaccel: event.delta_unaccel(), | 1358 | delta_unaccel: event.delta_unaccel(), |
| @@ -1451,7 +1451,7 @@ impl State { | |||
| 1451 | // Activate a new confinement if necessary. | 1451 | // Activate a new confinement if necessary. |
| 1452 | self.niri.maybe_activate_pointer_constraint(new_pos, &under); | 1452 | self.niri.maybe_activate_pointer_constraint(new_pos, &under); |
| 1453 | 1453 | ||
| 1454 | - self.niri.pointer_focus.clone_from(&under); | 1454 | + self.niri.pointer_contents.clone_from(&under); |
| 1455 | 1455 | ||
| 1456 | pointer.motion( | 1456 | pointer.motion( |
| 1457 | self, | 1457 | self, |
| @@ -1514,7 +1514,7 @@ impl State { | |||
| 1514 | self.niri.handle_focus_follows_mouse(&under); | 1514 | self.niri.handle_focus_follows_mouse(&under); |
| 1515 | 1515 | ||
| 1516 | self.niri.maybe_activate_pointer_constraint(pos, &under); | 1516 | self.niri.maybe_activate_pointer_constraint(pos, &under); |
| 1517 | - self.niri.pointer_focus.clone_from(&under); | 1517 | + self.niri.pointer_contents.clone_from(&under); |
| 1518 | 1518 | ||
| 1519 | pointer.motion( | 1519 | pointer.motion( |
| 1520 | self, | 1520 | self, |
| @@ -1693,11 +1693,11 @@ impl State { | |||
| 1693 | } | 1693 | } |
| 1694 | }; | 1694 | }; |
| 1695 | 1695 | ||
| 1696 | - self.update_pointer_focus(); | 1696 | + self.update_pointer_contents(); |
| 1697 | 1697 | ||
| 1698 | if ButtonState::Pressed == button_state { | 1698 | if ButtonState::Pressed == button_state { |
| 1699 | - let layer_focus = self.niri.pointer_focus.layer.clone(); | 1699 | + let layer_under = self.niri.pointer_contents.layer.clone(); |
| 1700 | - self.niri.focus_layer_surface_if_on_demand(layer_focus); | 1700 | + self.niri.focus_layer_surface_if_on_demand(layer_under); |
| 1701 | } | 1701 | } |
| 1702 | 1702 | ||
| 1703 | if let Some(button) = event.button() { | 1703 | if let Some(button) = event.button() { |
| @@ -1914,7 +1914,7 @@ impl State { | |||
| 1914 | } | 1914 | } |
| 1915 | } | 1915 | } |
| 1916 | 1916 | ||
| 1917 | - self.update_pointer_focus(); | 1917 | + self.update_pointer_contents(); |
| 1918 | 1918 | ||
| 1919 | let pointer = &self.niri.seat.get_pointer().unwrap(); | 1919 | let pointer = &self.niri.seat.get_pointer().unwrap(); |
| 1920 | pointer.axis(self, frame); | 1920 | pointer.axis(self, frame); |
| @@ -2077,7 +2077,7 @@ impl State { | |||
| 2077 | let serial = SERIAL_COUNTER.next_serial(); | 2077 | let serial = SERIAL_COUNTER.next_serial(); |
| 2078 | let pointer = self.niri.seat.get_pointer().unwrap(); | 2078 | let pointer = self.niri.seat.get_pointer().unwrap(); |
| 2079 | 2079 | ||
| 2080 | - if self.update_pointer_focus() { | 2080 | + if self.update_pointer_contents() { |
| 2081 | pointer.frame(self); | 2081 | pointer.frame(self); |
| 2082 | } | 2082 | } |
| 2083 | 2083 | ||
| @@ -2168,7 +2168,7 @@ impl State { | |||
| 2168 | 2168 | ||
| 2169 | let pointer = self.niri.seat.get_pointer().unwrap(); | 2169 | let pointer = self.niri.seat.get_pointer().unwrap(); |
| 2170 | 2170 | ||
| 2171 | - if self.update_pointer_focus() { | 2171 | + if self.update_pointer_contents() { |
| 2172 | pointer.frame(self); | 2172 | pointer.frame(self); |
| 2173 | } | 2173 | } |
| 2174 | 2174 | ||
| @@ -2211,7 +2211,7 @@ impl State { | |||
| 2211 | let serial = SERIAL_COUNTER.next_serial(); | 2211 | let serial = SERIAL_COUNTER.next_serial(); |
| 2212 | let pointer = self.niri.seat.get_pointer().unwrap(); | 2212 | let pointer = self.niri.seat.get_pointer().unwrap(); |
| 2213 | 2213 | ||
| 2214 | - if self.update_pointer_focus() { | 2214 | + if self.update_pointer_contents() { |
| 2215 | pointer.frame(self); | 2215 | pointer.frame(self); |
| 2216 | } | 2216 | } |
| 2217 | 2217 | ||
| @@ -2229,7 +2229,7 @@ impl State { | |||
| 2229 | let serial = SERIAL_COUNTER.next_serial(); | 2229 | let serial = SERIAL_COUNTER.next_serial(); |
| 2230 | let pointer = self.niri.seat.get_pointer().unwrap(); | 2230 | let pointer = self.niri.seat.get_pointer().unwrap(); |
| 2231 | 2231 | ||
| 2232 | - if self.update_pointer_focus() { | 2232 | + if self.update_pointer_contents() { |
| 2233 | pointer.frame(self); | 2233 | pointer.frame(self); |
| 2234 | } | 2234 | } |
| 2235 | 2235 | ||
| @@ -2246,7 +2246,7 @@ impl State { | |||
| 2246 | fn on_gesture_pinch_update<I: InputBackend>(&mut self, event: I::GesturePinchUpdateEvent) { | 2246 | fn on_gesture_pinch_update<I: InputBackend>(&mut self, event: I::GesturePinchUpdateEvent) { |
| 2247 | let pointer = self.niri.seat.get_pointer().unwrap(); | 2247 | let pointer = self.niri.seat.get_pointer().unwrap(); |
| 2248 | 2248 | ||
| 2249 | - if self.update_pointer_focus() { | 2249 | + if self.update_pointer_contents() { |
| 2250 | pointer.frame(self); | 2250 | pointer.frame(self); |
| 2251 | } | 2251 | } |
| 2252 | 2252 | ||
| @@ -2265,7 +2265,7 @@ impl State { | |||
| 2265 | let serial = SERIAL_COUNTER.next_serial(); | 2265 | let serial = SERIAL_COUNTER.next_serial(); |
| 2266 | let pointer = self.niri.seat.get_pointer().unwrap(); | 2266 | let pointer = self.niri.seat.get_pointer().unwrap(); |
| 2267 | 2267 | ||
| 2268 | - if self.update_pointer_focus() { | 2268 | + if self.update_pointer_contents() { |
| 2269 | pointer.frame(self); | 2269 | pointer.frame(self); |
| 2270 | } | 2270 | } |
| 2271 | 2271 | ||
| @@ -2283,7 +2283,7 @@ impl State { | |||
| 2283 | let serial = SERIAL_COUNTER.next_serial(); | 2283 | let serial = SERIAL_COUNTER.next_serial(); |
| 2284 | let pointer = self.niri.seat.get_pointer().unwrap(); | 2284 | let pointer = self.niri.seat.get_pointer().unwrap(); |
| 2285 | 2285 | ||
| 2286 | - if self.update_pointer_focus() { | 2286 | + if self.update_pointer_contents() { |
| 2287 | pointer.frame(self); | 2287 | pointer.frame(self); |
| 2288 | } | 2288 | } |
| 2289 | 2289 | ||
| @@ -2301,7 +2301,7 @@ impl State { | |||
| 2301 | let serial = SERIAL_COUNTER.next_serial(); | 2301 | let serial = SERIAL_COUNTER.next_serial(); |
| 2302 | let pointer = self.niri.seat.get_pointer().unwrap(); | 2302 | let pointer = self.niri.seat.get_pointer().unwrap(); |
| 2303 | 2303 | ||
| 2304 | - if self.update_pointer_focus() { | 2304 | + if self.update_pointer_contents() { |
| 2305 | pointer.frame(self); | 2305 | pointer.frame(self); |
| 2306 | } | 2306 | } |
| 2307 | 2307 | ||
src/niri.rsmodified+26 -13
| @@ -262,7 +262,20 @@ pub struct Niri { | |||
| 262 | pub cursor_texture_cache: CursorTextureCache, | 262 | pub cursor_texture_cache: CursorTextureCache, |
| 263 | pub cursor_shape_manager_state: CursorShapeManagerState, | 263 | pub cursor_shape_manager_state: CursorShapeManagerState, |
| 264 | pub dnd_icon: Option<DndIcon>, | 264 | pub dnd_icon: Option<DndIcon>, |
| 265 | - pub pointer_focus: PointContents, | 265 | + /// Contents under pointer. |
| 266 | + /// | ||
| 267 | + /// Periodically updated: on motion and other events and in the loop callback. If you require | ||
| 268 | + /// the real up-to-date contents somewhere, it's better to recompute on the spot. | ||
| 269 | + /// | ||
| 270 | + /// This is not pointer focus. I.e. during a click grab, the pointer focus remains on the | ||
| 271 | + /// client with the grab, but this field will keep updating to the latest contents as if no | ||
| 272 | + /// grab was active. | ||
| 273 | + /// | ||
| 274 | + /// This is primarily useful for emitting pointer motion events for surfaces that move | ||
| 275 | + /// underneath the cursor on their own (i.e. when the tiling layout moves). In this case, not | ||
| 276 | + /// taking grabs into account is expected, because we pass the information to pointer.motion() | ||
| 277 | + /// which passes it down through grabs, which decide what to do with it as they see fit. | ||
| 278 | + pub pointer_contents: PointContents, | ||
| 266 | /// Whether the pointer is hidden, for example due to a previous touch input. | 279 | /// Whether the pointer is hidden, for example due to a previous touch input. |
| 267 | /// | 280 | /// |
| 268 | /// When this happens, the pointer also loses any focus. This is so that touch can prevent | 281 | /// When this happens, the pointer also loses any focus. This is so that touch can prevent |
| @@ -553,7 +566,7 @@ impl State { | |||
| 553 | self.niri.refresh_pointer_outputs(); | 566 | self.niri.refresh_pointer_outputs(); |
| 554 | self.niri.global_space.refresh(); | 567 | self.niri.global_space.refresh(); |
| 555 | self.niri.refresh_idle_inhibit(); | 568 | self.niri.refresh_idle_inhibit(); |
| 556 | - self.refresh_pointer_focus(); | 569 | + self.refresh_pointer_contents(); |
| 557 | foreign_toplevel::refresh(self); | 570 | foreign_toplevel::refresh(self); |
| 558 | self.niri.refresh_window_rules(); | 571 | self.niri.refresh_window_rules(); |
| 559 | self.refresh_ipc_outputs(); | 572 | self.refresh_ipc_outputs(); |
| @@ -577,7 +590,7 @@ impl State { | |||
| 577 | let under = self.niri.contents_under(location); | 590 | let under = self.niri.contents_under(location); |
| 578 | self.niri | 591 | self.niri |
| 579 | .maybe_activate_pointer_constraint(location, &under); | 592 | .maybe_activate_pointer_constraint(location, &under); |
| 580 | - self.niri.pointer_focus.clone_from(&under); | 593 | + self.niri.pointer_contents.clone_from(&under); |
| 581 | 594 | ||
| 582 | let pointer = &self.niri.seat.get_pointer().unwrap(); | 595 | let pointer = &self.niri.seat.get_pointer().unwrap(); |
| 583 | pointer.motion( | 596 | pointer.motion( |
| @@ -676,8 +689,8 @@ impl State { | |||
| 676 | self.move_cursor_to_focused_tile(CenterCoords::Both) | 689 | self.move_cursor_to_focused_tile(CenterCoords::Both) |
| 677 | } | 690 | } |
| 678 | 691 | ||
| 679 | - pub fn refresh_pointer_focus(&mut self) { | 692 | + pub fn refresh_pointer_contents(&mut self) { |
| 680 | - let _span = tracy_client::span!("Niri::refresh_pointer_focus"); | 693 | + let _span = tracy_client::span!("Niri::refresh_pointer_contents"); |
| 681 | 694 | ||
| 682 | let pointer = &self.niri.seat.get_pointer().unwrap(); | 695 | let pointer = &self.niri.seat.get_pointer().unwrap(); |
| 683 | let location = pointer.current_location(); | 696 | let location = pointer.current_location(); |
| @@ -692,7 +705,7 @@ impl State { | |||
| 692 | } | 705 | } |
| 693 | } | 706 | } |
| 694 | 707 | ||
| 695 | - if !self.update_pointer_focus() { | 708 | + if !self.update_pointer_contents() { |
| 696 | return; | 709 | return; |
| 697 | } | 710 | } |
| 698 | 711 | ||
| @@ -701,8 +714,8 @@ impl State { | |||
| 701 | self.niri.queue_redraw_all(); | 714 | self.niri.queue_redraw_all(); |
| 702 | } | 715 | } |
| 703 | 716 | ||
| 704 | - pub fn update_pointer_focus(&mut self) -> bool { | 717 | + pub fn update_pointer_contents(&mut self) -> bool { |
| 705 | - let _span = tracy_client::span!("Niri::update_pointer_focus"); | 718 | + let _span = tracy_client::span!("Niri::update_pointer_contents"); |
| 706 | 719 | ||
| 707 | let pointer = &self.niri.seat.get_pointer().unwrap(); | 720 | let pointer = &self.niri.seat.get_pointer().unwrap(); |
| 708 | let location = pointer.current_location(); | 721 | let location = pointer.current_location(); |
| @@ -712,16 +725,16 @@ impl State { | |||
| 712 | self.niri.contents_under(location) | 725 | self.niri.contents_under(location) |
| 713 | }; | 726 | }; |
| 714 | 727 | ||
| 715 | - // We're not changing the global cursor location here, so if the focus did not change, then | 728 | + // We're not changing the global cursor location here, so if the contents did not change, |
| 716 | - // nothing changed. | 729 | + // then nothing changed. |
| 717 | - if self.niri.pointer_focus == under { | 730 | + if self.niri.pointer_contents == under { |
| 718 | return false; | 731 | return false; |
| 719 | } | 732 | } |
| 720 | 733 | ||
| 721 | self.niri | 734 | self.niri |
| 722 | .maybe_activate_pointer_constraint(location, &under); | 735 | .maybe_activate_pointer_constraint(location, &under); |
| 723 | 736 | ||
| 724 | - self.niri.pointer_focus.clone_from(&under); | 737 | + self.niri.pointer_contents.clone_from(&under); |
| 725 | 738 | ||
| 726 | pointer.motion( | 739 | pointer.motion( |
| 727 | self, | 740 | self, |
| @@ -1858,7 +1871,7 @@ impl Niri { | |||
| 1858 | cursor_texture_cache: Default::default(), | 1871 | cursor_texture_cache: Default::default(), |
| 1859 | cursor_shape_manager_state, | 1872 | cursor_shape_manager_state, |
| 1860 | dnd_icon: None, | 1873 | dnd_icon: None, |
| 1861 | - pointer_focus: PointContents::default(), | 1874 | + pointer_contents: PointContents::default(), |
| 1862 | pointer_hidden: false, | 1875 | pointer_hidden: false, |
| 1863 | pointer_inactivity_timer: None, | 1876 | pointer_inactivity_timer: None, |
| 1864 | pointer_grab_ongoing: false, | 1877 | pointer_grab_ongoing: false, |