diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-04-18 00:30:12 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-04-18 00:30:12 +0400 |
| commit | 47f6c85f64a20a9e32bf402941ecb78065aff80a (patch) | |
| tree | d06d8a646eabe919e8d2b149b47781c7d335c165 | |
| parent | 3b37f1a5579e9ae7eebb4c96d09b18ed8d6da8e2 (diff) | |
| download | niri-47f6c85f64a20a9e32bf402941ecb78065aff80a.tar.gz niri-47f6c85f64a20a9e32bf402941ecb78065aff80a.tar.bz2 niri-47f6c85f64a20a9e32bf402941ecb78065aff80a.zip | |
Preserve tile move config on animation restarts
This fixes a problem where consume-into-column would use resize
animation config instead of the window-movement config in most cases
(since a resize comes very shortly after the move starts).
A similar change to the column movement anim is more detrimental than
it's worth.
| -rw-r--r-- | src/animation/mod.rs | 39 | ||||
| -rw-r--r-- | src/layout/tile.rs | 8 |
2 files changed, 46 insertions, 1 deletions
diff --git a/src/animation/mod.rs b/src/animation/mod.rs index e22ff1f1..efdc8955 100644 --- a/src/animation/mod.rs +++ b/src/animation/mod.rs @@ -16,6 +16,7 @@ pub struct Animation { from: f64, to: f64, initial_velocity: f64, + is_off: bool, duration: Duration, /// Time until the animation first reaches `to`. /// @@ -49,6 +50,7 @@ impl Animation { pub fn new(from: f64, to: f64, initial_velocity: f64, config: niri_config::Animation) -> Self { let mut rv = Self::ease(from, to, initial_velocity, 0, Curve::EaseOutCubic); if config.off { + rv.is_off = true; return rv; } @@ -57,6 +59,7 @@ impl Animation { } pub fn replace_config(&mut self, config: niri_config::Animation) { + self.is_off = config.off; if config.off { self.duration = Duration::ZERO; self.clamped_duration = Duration::ZERO; @@ -93,6 +96,39 @@ impl Animation { self.current_time = current_time; } + /// Restarts the animation using the previous config. + pub fn restarted(self, from: f64, to: f64, initial_velocity: f64) -> Self { + if self.is_off { + return self; + } + + match self.kind { + Kind::Easing { curve } => Self::ease( + from, + to, + initial_velocity, + self.duration.as_millis() as u64, + curve, + ), + Kind::Spring(spring) => { + let spring = Spring { + from: self.from, + to: self.to, + initial_velocity: self.initial_velocity, + params: spring.params, + }; + Self::spring(spring) + } + Kind::Deceleration { + initial_velocity, + deceleration_rate, + } => { + let threshold = 0.001; // FIXME + Self::decelerate(from, initial_velocity, deceleration_rate, threshold) + } + } + } + pub fn ease(from: f64, to: f64, initial_velocity: f64, duration_ms: u64, curve: Curve) -> Self { // FIXME: ideally we shouldn't use current time here because animations started within the // same frame cycle should have the same start time to be synchronized. @@ -105,6 +141,7 @@ impl Animation { from, to, initial_velocity, + is_off: false, duration, // Our current curves never overshoot. clamped_duration: duration, @@ -129,6 +166,7 @@ impl Animation { from: spring.from, to: spring.to, initial_velocity: spring.initial_velocity, + is_off: false, duration, clamped_duration, start_time: now, @@ -166,6 +204,7 @@ impl Animation { from, to, initial_velocity, + is_off: false, duration, clamped_duration: duration, start_time: now, diff --git a/src/layout/tile.rs b/src/layout/tile.rs index 16779c10..447a8929 100644 --- a/src/layout/tile.rs +++ b/src/layout/tile.rs @@ -247,8 +247,14 @@ impl<W: LayoutElement> Tile<W> { ) { let current_offset = self.render_offset(); + // Preserve the previous config if ongoing. + let anim = self.move_animation.take().map(|move_| move_.anim); + let anim = anim + .map(|anim| anim.restarted(1., 0., 0.)) + .unwrap_or_else(|| Animation::new(1., 0., 0., config)); + self.move_animation = Some(MoveAnimation { - anim: Animation::new(1., 0., 0., config), + anim, from: from + current_offset, }); } |
