aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-04-22 08:28:03 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-04-25 02:00:18 -0700
commitcee11dc329684fda261db43cedfe3c46a2c309d7 (patch)
tree6719259689b0bbf65eef54c77861a2c49624cfeb /src
parent59a42249a4da4bda44fa08a2e6a460ac1bd2000f (diff)
downloadniri-cee11dc329684fda261db43cedfe3c46a2c309d7.tar.gz
niri-cee11dc329684fda261db43cedfe3c46a2c309d7.tar.bz2
niri-cee11dc329684fda261db43cedfe3c46a2c309d7.zip
layout/monitor: Keep track of workspace switch gesture start idx
Fixes jump when "catching" an animation with a gesture.
Diffstat (limited to 'src')
-rw-r--r--src/layout/monitor.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs
index 4b816116..4f44f328 100644
--- a/src/layout/monitor.rs
+++ b/src/layout/monitor.rs
@@ -60,6 +60,11 @@ pub enum WorkspaceSwitch {
pub struct WorkspaceSwitchGesture {
/// Index of the workspace where the gesture was started.
center_idx: usize,
+ /// Fractional workspace index where the gesture was started.
+ ///
+ /// Can differ from center_idx when starting a gesture in the middle between workspaces, for
+ /// example by "catching" an animation.
+ start_idx: f64,
/// Current, fractional workspace index.
pub(super) current_idx: f64,
tracker: SwipeTracker,
@@ -111,6 +116,7 @@ impl WorkspaceSwitch {
} else {
gesture.center_idx -= (-delta) as usize;
}
+ gesture.start_idx += delta as f64;
gesture.current_idx += delta as f64;
}
}
@@ -983,6 +989,7 @@ impl<W: LayoutElement> Monitor<W> {
let gesture = WorkspaceSwitchGesture {
center_idx,
+ start_idx: current_idx,
current_idx,
tracker: SwipeTracker::new(),
is_touchpad,
@@ -1015,7 +1022,7 @@ impl<W: LayoutElement> Monitor<W> {
let min = gesture.center_idx.saturating_sub(1) as f64;
let max = (gesture.center_idx + 1).min(self.workspaces.len() - 1) as f64;
- let new_idx = gesture.center_idx as f64 + pos;
+ let new_idx = gesture.start_idx + pos;
let new_idx = WORKSPACE_GESTURE_RUBBER_BAND.clamp(min, max, new_idx);
if gesture.current_idx == new_idx {
@@ -1051,7 +1058,7 @@ impl<W: LayoutElement> Monitor<W> {
let min = gesture.center_idx.saturating_sub(1) as f64;
let max = (gesture.center_idx + 1).min(self.workspaces.len() - 1) as f64;
- let new_idx = gesture.center_idx as f64 + pos;
+ let new_idx = gesture.start_idx + pos;
let new_idx = WORKSPACE_GESTURE_RUBBER_BAND.clamp(min, max, new_idx);
let new_idx = new_idx.round() as usize;
@@ -1059,7 +1066,7 @@ impl<W: LayoutElement> Monitor<W> {
velocity *= WORKSPACE_GESTURE_RUBBER_BAND.clamp_derivative(
min,
max,
- gesture.center_idx as f64 + current_pos,
+ gesture.start_idx + current_pos,
);
self.previous_workspace_id = Some(self.workspaces[self.active_workspace_idx].id());