diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-11-03 09:32:58 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-11-03 10:15:19 +0300 |
| commit | 9193245871bf16e0e5b513806dc988caee994c13 (patch) | |
| tree | 62db8cce1b02016c6630900cf9428423ef28d75e /src | |
| parent | 7baf10b751697de0d17a4bac003e5f5207900bf2 (diff) | |
| download | niri-9193245871bf16e0e5b513806dc988caee994c13.tar.gz niri-9193245871bf16e0e5b513806dc988caee994c13.tar.bz2 niri-9193245871bf16e0e5b513806dc988caee994c13.zip | |
Correct pointer constraint activation logic
Internally it uses the pointer focus, so make sure we have up-to-date
focus before setting it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/handlers/mod.rs | 11 | ||||
| -rw-r--r-- | src/input/mod.rs | 9 | ||||
| -rw-r--r-- | src/niri.rs | 29 |
3 files changed, 27 insertions, 22 deletions
diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index a60de97f..f3f5cb82 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -137,11 +137,12 @@ impl TabletSeatHandler for State { delegate_tablet_manager!(State); impl PointerConstraintsHandler for State { - fn new_constraint(&mut self, _surface: &WlSurface, pointer: &PointerHandle<Self>) { - self.niri.maybe_activate_pointer_constraint( - pointer.current_location(), - &self.niri.pointer_contents, - ); + fn new_constraint(&mut self, _surface: &WlSurface, _pointer: &PointerHandle<Self>) { + // Pointer constraints track pointer focus internally, so make sure it's up to date before + // activating a new one. + self.refresh_pointer_contents(); + + self.niri.maybe_activate_pointer_constraint(); } fn cursor_position_hint( diff --git a/src/input/mod.rs b/src/input/mod.rs index 24d72bc0..888631e2 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1448,9 +1448,6 @@ impl State { self.niri.handle_focus_follows_mouse(&under); - // Activate a new confinement if necessary. - self.niri.maybe_activate_pointer_constraint(new_pos, &under); - self.niri.pointer_contents.clone_from(&under); pointer.motion( @@ -1475,6 +1472,9 @@ impl State { pointer.frame(self); + // Activate a new confinement if necessary. + self.niri.maybe_activate_pointer_constraint(); + // Redraw to update the cursor position. // FIXME: redraw only outputs overlapping the cursor. self.niri.queue_redraw_all(); @@ -1513,7 +1513,6 @@ impl State { self.niri.handle_focus_follows_mouse(&under); - self.niri.maybe_activate_pointer_constraint(pos, &under); self.niri.pointer_contents.clone_from(&under); pointer.motion( @@ -1528,6 +1527,8 @@ impl State { pointer.frame(self); + self.niri.maybe_activate_pointer_constraint(); + // We moved the pointer, show it. self.niri.pointer_hidden = false; diff --git a/src/niri.rs b/src/niri.rs index 8c5f0a52..c3f267c2 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -588,8 +588,6 @@ impl State { pub fn move_cursor(&mut self, location: Point<f64, Logical>) { let under = self.niri.contents_under(location); - self.niri - .maybe_activate_pointer_constraint(location, &under); self.niri.pointer_contents.clone_from(&under); let pointer = &self.niri.seat.get_pointer().unwrap(); @@ -604,6 +602,8 @@ impl State { ); pointer.frame(self); + self.niri.maybe_activate_pointer_constraint(); + // We do not show the pointer on programmatic or keyboard movement. // FIXME: granular @@ -735,9 +735,6 @@ impl State { return false; } - self.niri - .maybe_activate_pointer_constraint(location, &under); - self.niri.pointer_contents.clone_from(&under); pointer.motion( @@ -750,6 +747,8 @@ impl State { }, ); + self.niri.maybe_activate_pointer_constraint(); + true } @@ -4517,17 +4516,21 @@ impl Niri { output_state.lock_surface = Some(surface); } - pub fn maybe_activate_pointer_constraint( - &self, - new_pos: Point<f64, Logical>, - new_under: &PointContents, - ) { - let Some((surface, surface_loc)) = &new_under.surface else { + /// Activates the pointer constraint if necessary according to the current pointer contents. + /// + /// Make sure the pointer location and contents are up to date before calling this. + pub fn maybe_activate_pointer_constraint(&self) { + let pointer = self.seat.get_pointer().unwrap(); + let pointer_pos = pointer.current_location(); + + let Some((surface, surface_loc)) = &self.pointer_contents.surface else { return; }; + if self.pointer_grab_ongoing { return; } + let pointer = &self.seat.get_pointer().unwrap(); with_pointer_constraint(surface, pointer, |constraint| { let Some(constraint) = constraint else { return }; @@ -4538,8 +4541,8 @@ impl Niri { // Constraint does not apply if not within region. if let Some(region) = constraint.region() { - let new_pos_within_surface = new_pos - *surface_loc; - if !region.contains(new_pos_within_surface.to_i32_round()) { + let pos_within_surface = pointer_pos - *surface_loc; + if !region.contains(pos_within_surface.to_i32_round()) { return; } } |
