forge
Explore
Log in

Don't you dare go Hollow

Simplify pointer handling in constraint check

Browse files at this commit

51b6a495c5ab701bb3ef4d1180e4fe190acc4f60abmantisParent: bb40a35
Minor change so that `get_pointer()` (which has a lock) does not get
called twice. Also moved the call to `current_location()` to the scope
where it is needed.
src/niri.rsmodified+4 -5
@@ -5769,18 +5769,16 @@ impl Niri {
5769 ///5769 ///
5770 /// Make sure the pointer location and contents are up to date before calling this.5770 /// Make sure the pointer location and contents are up to date before calling this.
5771 pub fn maybe_activate_pointer_constraint(&self) {5771 pub fn maybe_activate_pointer_constraint(&self) {
5772- let pointer = self.seat.get_pointer().unwrap();
5773- let pointer_pos = pointer.current_location();
5774-
5775 let Some((surface, surface_loc)) = &self.pointer_contents.surface else {5772 let Some((surface, surface_loc)) = &self.pointer_contents.surface else {
5776 return;5773 return;
5777 };5774 };
5775+
5776+ let pointer = self.seat.get_pointer().unwrap();
5778 if Some(surface) != pointer.current_focus().as_ref() {5777 if Some(surface) != pointer.current_focus().as_ref() {
5779 return;5778 return;
5780 }5779 }
5781 5780
5782- let pointer = &self.seat.get_pointer().unwrap();5781+ with_pointer_constraint(surface, &pointer, |constraint| {
5783- with_pointer_constraint(surface, pointer, |constraint| {
5784 let Some(constraint) = constraint else { return };5782 let Some(constraint) = constraint else { return };
5785 5783
5786 if constraint.is_active() {5784 if constraint.is_active() {
@@ -5789,6 +5787,7 @@ impl Niri {
5789 5787
5790 // Constraint does not apply if not within region.5788 // Constraint does not apply if not within region.
5791 if let Some(region) = constraint.region() {5789 if let Some(region) = constraint.region() {
5790+ let pointer_pos = pointer.current_location();
5792 let pos_within_surface = pointer_pos - *surface_loc;5791 let pos_within_surface = pointer_pos - *surface_loc;
5793 if !region.contains(pos_within_surface.to_i32_round()) {5792 if !region.contains(pos_within_surface.to_i32_round()) {
5794 return;5793 return;