forge
Explore
Log in

Don't you dare go Hollow

layout/monitor: Keep track of workspace switch gesture start idx

Browse files at this commit

cee11dc329684fda261db43cedfe3c46a2c309d7Ivan MolodetskikhParent: 59a4224
Fixes jump when "catching" an animation with a gesture.
src/layout/monitor.rsmodified+10 -3
@@ -60,6 +60,11 @@ pub enum WorkspaceSwitch {
60 pub struct WorkspaceSwitchGesture {60 pub struct WorkspaceSwitchGesture {
61 /// Index of the workspace where the gesture was started.61 /// Index of the workspace where the gesture was started.
62 center_idx: usize,62 center_idx: usize,
63+ /// Fractional workspace index where the gesture was started.
64+ ///
65+ /// Can differ from center_idx when starting a gesture in the middle between workspaces, for
66+ /// example by "catching" an animation.
67+ start_idx: f64,
63 /// Current, fractional workspace index.68 /// Current, fractional workspace index.
64 pub(super) current_idx: f64,69 pub(super) current_idx: f64,
65 tracker: SwipeTracker,70 tracker: SwipeTracker,
@@ -111,6 +116,7 @@ impl WorkspaceSwitch {
111 } else {116 } else {
112 gesture.center_idx -= (-delta) as usize;117 gesture.center_idx -= (-delta) as usize;
113 }118 }
119+ gesture.start_idx += delta as f64;
114 gesture.current_idx += delta as f64;120 gesture.current_idx += delta as f64;
115 }121 }
116 }122 }
@@ -983,6 +989,7 @@ impl<W: LayoutElement> Monitor<W> {
983 989
984 let gesture = WorkspaceSwitchGesture {990 let gesture = WorkspaceSwitchGesture {
985 center_idx,991 center_idx,
992+ start_idx: current_idx,
986 current_idx,993 current_idx,
987 tracker: SwipeTracker::new(),994 tracker: SwipeTracker::new(),
988 is_touchpad,995 is_touchpad,
@@ -1015,7 +1022,7 @@ impl<W: LayoutElement> Monitor<W> {
1015 1022
1016 let min = gesture.center_idx.saturating_sub(1) as f64;1023 let min = gesture.center_idx.saturating_sub(1) as f64;
1017 let max = (gesture.center_idx + 1).min(self.workspaces.len() - 1) as f64;1024 let max = (gesture.center_idx + 1).min(self.workspaces.len() - 1) as f64;
1018- let new_idx = gesture.center_idx as f64 + pos;1025+ let new_idx = gesture.start_idx + pos;
1019 let new_idx = WORKSPACE_GESTURE_RUBBER_BAND.clamp(min, max, new_idx);1026 let new_idx = WORKSPACE_GESTURE_RUBBER_BAND.clamp(min, max, new_idx);
1020 1027
1021 if gesture.current_idx == new_idx {1028 if gesture.current_idx == new_idx {
@@ -1051,7 +1058,7 @@ impl<W: LayoutElement> Monitor<W> {
1051 1058
1052 let min = gesture.center_idx.saturating_sub(1) as f64;1059 let min = gesture.center_idx.saturating_sub(1) as f64;
1053 let max = (gesture.center_idx + 1).min(self.workspaces.len() - 1) as f64;1060 let max = (gesture.center_idx + 1).min(self.workspaces.len() - 1) as f64;
1054- let new_idx = gesture.center_idx as f64 + pos;1061+ let new_idx = gesture.start_idx + pos;
1055 1062
1056 let new_idx = WORKSPACE_GESTURE_RUBBER_BAND.clamp(min, max, new_idx);1063 let new_idx = WORKSPACE_GESTURE_RUBBER_BAND.clamp(min, max, new_idx);
1057 let new_idx = new_idx.round() as usize;1064 let new_idx = new_idx.round() as usize;
@@ -1059,7 +1066,7 @@ impl<W: LayoutElement> Monitor<W> {
1059 velocity *= WORKSPACE_GESTURE_RUBBER_BAND.clamp_derivative(1066 velocity *= WORKSPACE_GESTURE_RUBBER_BAND.clamp_derivative(
1060 min,1067 min,
1061 max,1068 max,
1062- gesture.center_idx as f64 + current_pos,1069+ gesture.start_idx + current_pos,
1063 );1070 );
1064 1071
1065 self.previous_workspace_id = Some(self.workspaces[self.active_workspace_idx].id());1072 self.previous_workspace_id = Some(self.workspaces[self.active_workspace_idx].id());