Warp pointer across the screen during spatial movement grabs

This commit is contained in:
Ivan Molodetskikh
2025-12-20 10:49:50 +03:00
parent 47e217c00e
commit 813c5ee05f
3 changed files with 41 additions and 0 deletions
+29
View File
@@ -2456,6 +2456,35 @@ impl State {
}
}
// Warp pointer across the screen during the spatial movement grabs.
let spatial_grab = pointer.with_grab(|_, grab| {
let grab = grab.as_any();
if let Some(grab) = grab.downcast_ref::<SpatialMovementGrab>() {
if let Some(output) = grab.view_offset_output() {
return Some((output.clone(), true));
} else if let Some(output) = grab.workspace_switch_output() {
return Some((output.clone(), false));
}
} else if let Some(grab) = grab.downcast_ref::<MoveGrab>() {
if let Some(output) = grab.view_offset_output() {
return Some((output.clone(), true));
}
}
None
});
if let Some((output, horizontal)) = spatial_grab.flatten() {
if let Some(geo) = self.niri.global_space.output_geometry(&output) {
let geo = geo.to_f64();
if horizontal {
new_pos.x = (new_pos.x - geo.loc.x).rem_euclid(geo.size.w) + geo.loc.x;
new_pos.y = new_pos.y.clamp(geo.loc.y, geo.loc.y + geo.size.h - 1.);
} else {
new_pos.x = new_pos.x.clamp(geo.loc.x, geo.loc.x + geo.size.w - 1.);
new_pos.y = (new_pos.y - geo.loc.y).rem_euclid(geo.size.h) + geo.loc.y;
}
}
}
if self
.niri
.global_space
+4
View File
@@ -74,6 +74,10 @@ impl MoveGrab {
self.gesture == GestureState::Move
}
pub fn view_offset_output(&self) -> Option<&Output> {
(self.gesture == GestureState::ViewOffset).then_some(&self.start_output)
}
fn on_ungrab(&mut self, data: &mut State) {
let layout = &mut data.niri.layout;
match self.gesture {
+8
View File
@@ -60,6 +60,14 @@ impl SpatialMovementGrab {
}
}
pub fn view_offset_output(&self) -> Option<&Output> {
(self.gesture == GestureState::ViewOffset).then_some(&self.output)
}
pub fn workspace_switch_output(&self) -> Option<&Output> {
(self.gesture == GestureState::WorkspaceSwitch).then_some(&self.output)
}
fn on_frame(&mut self, data: &mut State) -> bool {
let Some(timestamp) = self.event_timestamp.take() else {
return true;