From 93cee2994ab9ccf59a09f61d5b8acf6cd937d654 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sat, 23 Nov 2024 11:27:27 +0300 Subject: Refactor animations to take explicit current time --- src/layout/monitor.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/layout/monitor.rs') diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index aecad889..aad921bb 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -15,7 +15,7 @@ use super::workspace::{ WorkspaceRenderElement, }; use super::{LayoutElement, Options}; -use crate::animation::Animation; +use crate::animation::{Animation, Clock}; use crate::input::swipe_tracker::SwipeTracker; use crate::render_helpers::renderer::NiriRenderer; use crate::render_helpers::RenderTarget; @@ -45,6 +45,8 @@ pub struct Monitor { pub(super) previous_workspace_id: Option, /// In-progress switch between workspaces. pub(super) workspace_switch: Option, + /// Clock for driving animations. + pub(super) clock: Clock, /// Configurable properties of the layout. pub(super) options: Rc, } @@ -94,7 +96,12 @@ impl WorkspaceSwitch { } impl Monitor { - pub fn new(output: Output, workspaces: Vec>, options: Rc) -> Self { + pub fn new( + output: Output, + workspaces: Vec>, + clock: Clock, + options: Rc, + ) -> Self { Self { output_name: output.name(), output, @@ -102,6 +109,7 @@ impl Monitor { active_workspace_idx: 0, previous_workspace_id: None, workspace_switch: None, + clock, options, } } @@ -151,7 +159,11 @@ impl Monitor { } pub fn add_workspace_bottom(&mut self) { - let ws = Workspace::new(self.output.clone(), self.options.clone()); + let ws = Workspace::new( + self.output.clone(), + self.clock.clone(), + self.options.clone(), + ); self.workspaces.push(ws); } @@ -172,6 +184,7 @@ impl Monitor { self.active_workspace_idx = idx; self.workspace_switch = Some(WorkspaceSwitch::Animation(Animation::new( + self.clock.now(), current_idx, idx as f64, 0., @@ -1099,6 +1112,7 @@ impl Monitor { self.active_workspace_idx = new_idx; self.workspace_switch = Some(WorkspaceSwitch::Animation(Animation::new( + self.clock.now(), gesture.current_idx, new_idx as f64, velocity, -- cgit