From 4f55f4127b3393545e361e6ffdce49265ac40534 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Wed, 28 Feb 2024 19:56:15 +0100 Subject: [PATCH] minimize: Slower animation --- src/shell/layout/floating/mod.rs | 34 ++++++++++++++++++-------------- src/shell/layout/tiling/mod.rs | 15 +++++++++++--- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/shell/layout/floating/mod.rs b/src/shell/layout/floating/mod.rs index a5782559..57e016e6 100644 --- a/src/shell/layout/floating/mod.rs +++ b/src/shell/layout/floating/mod.rs @@ -47,6 +47,7 @@ mod grabs; pub use self::grabs::*; pub const ANIMATION_DURATION: Duration = Duration::from_millis(200); +pub const MINIMIZE_ANIMATION_DURATION: Duration = Duration::from_millis(300); #[derive(Debug, Default)] pub struct FloatingLayout { @@ -91,16 +92,16 @@ impl Animation { Animation::Minimize { start, .. } => { 1.0 - (Instant::now() .duration_since(*start) - .min(ANIMATION_DURATION) + .min(MINIMIZE_ANIMATION_DURATION) .as_secs_f32() - / ANIMATION_DURATION.as_secs_f32()) + / MINIMIZE_ANIMATION_DURATION.as_secs_f32()) } Animation::Unminimize { start, .. } => { Instant::now() .duration_since(*start) - .min(ANIMATION_DURATION) + .min(MINIMIZE_ANIMATION_DURATION) .as_secs_f32() - / ANIMATION_DURATION.as_secs_f32() + / MINIMIZE_ANIMATION_DURATION.as_secs_f32() } } } @@ -125,31 +126,29 @@ impl Animation { current_geometry: Rectangle, tiled_state: Option<&TiledCorners>, ) -> Rectangle { - let target_rect = match self { + let (duration, target_rect) = match self { Animation::Minimize { target_geometry, .. } | Animation::Unminimize { target_geometry, .. - } => target_geometry.clone(), + } => (MINIMIZE_ANIMATION_DURATION, target_geometry.clone()), Animation::Tiled { .. } => { - if let Some(target_rect) = + let target_geometry = if let Some(target_rect) = tiled_state.map(|state| state.relative_geometry(output_geometry)) { target_rect } else { current_geometry - } + }; + (ANIMATION_DURATION, target_geometry) } }; let previous_rect = self.previous_geometry().clone(); let start = *self.start(); let now = Instant::now(); - let progress = now - .duration_since(start) - .min(ANIMATION_DURATION) - .as_secs_f64() - / ANIMATION_DURATION.as_secs_f64(); + let progress = + now.duration_since(start).min(duration).as_secs_f64() / duration.as_secs_f64(); ease( EaseInOutCubic, @@ -1107,8 +1106,13 @@ impl FloatingLayout { pub fn update_animation_state(&mut self) { let was_empty = self.animations.is_empty(); - self.animations - .retain(|_, anim| Instant::now().duration_since(*anim.start()) < ANIMATION_DURATION); + self.animations.retain(|_, anim| { + let duration = match anim { + Animation::Tiled { .. } => ANIMATION_DURATION, + _ => MINIMIZE_ANIMATION_DURATION, + }; + Instant::now().duration_since(*anim.start()) < duration + }); if self.animations.is_empty() != was_empty { self.dirty.store(true, Ordering::SeqCst); } diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index a2a40e05..80212e38 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -68,6 +68,7 @@ pub use self::blocker::*; pub use self::grabs::*; pub const ANIMATION_DURATION: Duration = Duration::from_millis(200); +pub const MINIMIZE_ANIMATION_DURATION: Duration = Duration::from_millis(300); pub const MOUSE_ANIMATION_DELAY: Duration = Duration::from_millis(150); pub const INITIAL_MOUSE_ANIMATION_DELAY: Duration = Duration::from_millis(500); @@ -395,6 +396,12 @@ impl TilingLayout { let last_active = focus_stack .and_then(|focus_stack| TilingLayout::last_active_window(&mut tree, focus_stack)) .map(|(node_id, _)| node_id); + let duration = if minimize_rect.is_some() { + MINIMIZE_ANIMATION_DURATION + } else { + ANIMATION_DURATION + }; + TilingLayout::map_to_tree( &mut tree, window, @@ -404,7 +411,7 @@ impl TilingLayout { minimize_rect, ); let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps); - self.queue.push_tree(tree, ANIMATION_DURATION, blocker); + self.queue.push_tree(tree, duration, blocker); } pub fn remap_minimized<'a>( @@ -469,7 +476,8 @@ impl TilingLayout { *window.tiling_node_id.lock().unwrap() = Some(new_id); let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps); - self.queue.push_tree(tree, ANIMATION_DURATION, blocker); + self.queue + .push_tree(tree, MINIMIZE_ANIMATION_DURATION, blocker); return; } } @@ -507,7 +515,8 @@ impl TilingLayout { *window.tiling_node_id.lock().unwrap() = Some(new_id); let blocker = TilingLayout::update_positions(&self.output, &mut tree, gaps); - self.queue.push_tree(tree, ANIMATION_DURATION, blocker); + self.queue + .push_tree(tree, MINIMIZE_ANIMATION_DURATION, blocker); return; } }