diff options
Diffstat (limited to 'src/layout/monitor.rs')
| -rw-r--r-- | src/layout/monitor.rs | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index 70a6981d..ee02a204 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -15,6 +15,7 @@ use super::workspace::{ use super::{LayoutElement, Options}; use crate::animation::Animation; use crate::render_helpers::renderer::NiriRenderer; +use crate::swipe_tracker::SwipeTracker; use crate::utils::output_size; #[derive(Debug)] @@ -43,6 +44,7 @@ pub struct WorkspaceSwitchGesture { pub center_idx: usize, /// Current, fractional workspace index. pub current_idx: f64, + pub tracker: SwipeTracker, } pub type MonitorRenderElement<R> = @@ -703,21 +705,28 @@ impl<W: LayoutElement> Monitor<W> { let gesture = WorkspaceSwitchGesture { center_idx, current_idx, + tracker: SwipeTracker::new(), }; self.workspace_switch = Some(WorkspaceSwitch::Gesture(gesture)); } - pub fn workspace_switch_gesture_update(&mut self, delta_y: f64) -> Option<bool> { + pub fn workspace_switch_gesture_update( + &mut self, + delta_y: f64, + timestamp: Duration, + ) -> Option<bool> { let Some(WorkspaceSwitch::Gesture(gesture)) = &mut self.workspace_switch else { return None; }; + gesture.tracker.push(delta_y, timestamp); + // Normalize like GNOME Shell's workspace switching. - let delta_y = delta_y / 400.; + let pos = gesture.tracker.pos() / 400.; 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.current_idx + delta_y).clamp(min, max); + let new_idx = (gesture.center_idx as f64 + pos).clamp(min, max); if gesture.current_idx == new_idx { return Some(false); @@ -738,15 +747,17 @@ impl<W: LayoutElement> Monitor<W> { return true; } - // FIXME: keep track of gesture velocity and use it to compute the final point and to - // animate to it. - let current_idx = gesture.current_idx; - let idx = current_idx.round() as usize; + let pos = gesture.tracker.projected_end_pos() / 400.; - self.active_workspace_idx = idx; + 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).clamp(min, max); + let new_idx = new_idx.round() as usize; + + self.active_workspace_idx = new_idx; self.workspace_switch = Some(WorkspaceSwitch::Animation(Animation::new( - current_idx, - idx as f64, + gesture.current_idx, + new_idx as f64, self.options.animations.workspace_switch, niri_config::Animation::default_workspace_switch(), ))); |
