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/workspace.rs | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'src/layout/workspace.rs') diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index b26dfcc1..6432ca8b 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -19,7 +19,7 @@ use super::closing_window::{ClosingWindow, ClosingWindowRenderElement}; use super::insert_hint_element::{InsertHintElement, InsertHintRenderElement}; use super::tile::{Tile, TileRenderElement, TileRenderSnapshot}; use super::{ConfigureIntent, InteractiveResizeData, LayoutElement, Options, RemovedTile}; -use crate::animation::Animation; +use crate::animation::{Animation, Clock}; use crate::input::swipe_tracker::SwipeTracker; use crate::niri_render_elements; use crate::render_helpers::renderer::NiriRenderer; @@ -113,6 +113,9 @@ pub struct Workspace { /// Insert hint element for rendering. insert_hint_element: InsertHintElement, + /// Clock for driving animations. + pub(super) clock: Clock, + /// Configurable properties of the layout as received from the parent monitor. pub(super) base_options: Rc, @@ -293,6 +296,9 @@ pub struct Column { /// Scale of the output the column is on (and rounds its sizes to). scale: f64, + /// Clock for driving animations. + clock: Clock, + /// Configurable properties of the layout. options: Rc, } @@ -403,13 +409,14 @@ impl TileData { } impl Workspace { - pub fn new(output: Output, options: Rc) -> Self { - Self::new_with_config(output, None, options) + pub fn new(output: Output, clock: Clock, options: Rc) -> Self { + Self::new_with_config(output, None, clock, options) } pub fn new_with_config( output: Output, config: Option, + clock: Clock, base_options: Rc, ) -> Self { let original_output = config @@ -442,6 +449,7 @@ impl Workspace { closing_windows: vec![], insert_hint: None, insert_hint_element: InsertHintElement::new(options.insert_hint), + clock, base_options, options, name: config.map(|c| c.name.0), @@ -451,6 +459,7 @@ impl Workspace { pub fn new_with_config_no_outputs( config: Option, + clock: Clock, base_options: Rc, ) -> Self { let original_output = OutputId( @@ -482,6 +491,7 @@ impl Workspace { closing_windows: vec![], insert_hint: None, insert_hint_element: InsertHintElement::new(options.insert_hint), + clock, base_options, options, name: config.map(|c| c.name.0), @@ -489,8 +499,8 @@ impl Workspace { } } - pub fn new_no_outputs(options: Rc) -> Self { - Self::new_with_config_no_outputs(None, options) + pub fn new_no_outputs(clock: Clock, options: Rc) -> Self { + Self::new_with_config_no_outputs(None, clock, options) } pub fn id(&self) -> WorkspaceId { @@ -941,6 +951,7 @@ impl Workspace { // FIXME: also compute and use current velocity. self.view_offset_adj = Some(ViewOffsetAdjustment::Animation(Animation::new( + self.clock.now(), self.view_offset, new_view_offset, 0., @@ -1100,7 +1111,12 @@ impl Workspace { width: ColumnWidth, is_full_width: bool, ) { - let tile = Tile::new(window, self.scale.fractional_scale(), self.options.clone()); + let tile = Tile::new( + window, + self.scale.fractional_scale(), + self.clock.clone(), + self.options.clone(), + ); self.add_tile(col_idx, tile, activate, width, is_full_width, None); } @@ -1118,7 +1134,6 @@ impl Workspace { self.view_size, self.working_area, self.scale.fractional_scale(), - self.options.clone(), width, is_full_width, true, @@ -1682,7 +1697,13 @@ impl Workspace { ) { let output_scale = Scale::from(self.scale.fractional_scale()); - let anim = Animation::new(0., 1., 0., self.options.animations.window_close.anim); + let anim = Animation::new( + self.clock.now(), + 0., + 1., + 0., + self.options.animations.window_close.anim, + ); let blocker = if self.options.disable_transactions { TransactionBlocker::completed() @@ -1725,6 +1746,7 @@ impl Workspace { for (column, data) in zip(&self.columns, &self.data) { assert!(Rc::ptr_eq(&self.options, &column.options)); + assert_eq!(self.clock, column.clock); assert_eq!(self.scale.fractional_scale(), column.scale); column.verify_invariants(); @@ -2619,7 +2641,6 @@ impl Workspace { self.view_size, self.working_area, self.scale.fractional_scale(), - self.options.clone(), removed.width, removed.is_full_width, false, @@ -2969,6 +2990,7 @@ impl Workspace { let target_view_offset = target_snap.view_pos - new_col_x; self.view_offset_adj = Some(ViewOffsetAdjustment::Animation(Animation::new( + self.clock.now(), current_view_offset + delta, target_view_offset, velocity, @@ -3174,7 +3196,6 @@ impl Column { view_size: Size, working_area: Rectangle, scale: f64, - options: Rc, width: ColumnWidth, is_full_width: bool, animate_resize: bool, @@ -3190,7 +3211,8 @@ impl Column { view_size, working_area, scale, - options, + clock: tile.clock.clone(), + options: tile.options.clone(), }; let is_pending_fullscreen = tile.window().is_pending_fullscreen(); @@ -3313,6 +3335,7 @@ impl Column { let current_offset = self.move_animation.as_ref().map_or(0., Animation::value); self.move_animation = Some(Animation::new( + self.clock.now(), from_x_offset + current_offset, 0., 0., @@ -3716,6 +3739,7 @@ impl Column { let mut total_min_height = 0.; for (tile, data) in zip(&self.tiles, &self.data) { assert!(Rc::ptr_eq(&self.options, &tile.options)); + assert_eq!(self.clock, tile.clock); assert_eq!(self.scale, tile.scale()); assert_eq!(self.is_fullscreen, tile.window().is_pending_fullscreen()); -- cgit