forge
Explore
Log in

Don't you dare go Hollow

Preserve tile move config on animation restarts

Browse files at this commit

47f6c85f64a20a9e32bf402941ecb78065aff80aIvan MolodetskikhParent: 3b37f1a
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.
src/animation/mod.rsmodified+39 -0
@@ -16,6 +16,7 @@ pub struct Animation {
16 from: f64,16 from: f64,
17 to: f64,17 to: f64,
18 initial_velocity: f64,18 initial_velocity: f64,
19+ is_off: bool,
19 duration: Duration,20 duration: Duration,
20 /// Time until the animation first reaches `to`.21 /// Time until the animation first reaches `to`.
21 ///22 ///
@@ -49,6 +50,7 @@ impl Animation {
49 pub fn new(from: f64, to: f64, initial_velocity: f64, config: niri_config::Animation) -> Self {50 pub fn new(from: f64, to: f64, initial_velocity: f64, config: niri_config::Animation) -> Self {
50 let mut rv = Self::ease(from, to, initial_velocity, 0, Curve::EaseOutCubic);51 let mut rv = Self::ease(from, to, initial_velocity, 0, Curve::EaseOutCubic);
51 if config.off {52 if config.off {
53+ rv.is_off = true;
52 return rv;54 return rv;
53 }55 }
54 56
@@ -57,6 +59,7 @@ impl Animation {
57 }59 }
58 60
59 pub fn replace_config(&mut self, config: niri_config::Animation) {61 pub fn replace_config(&mut self, config: niri_config::Animation) {
62+ self.is_off = config.off;
60 if config.off {63 if config.off {
61 self.duration = Duration::ZERO;64 self.duration = Duration::ZERO;
62 self.clamped_duration = Duration::ZERO;65 self.clamped_duration = Duration::ZERO;
@@ -93,6 +96,39 @@ impl Animation {
93 self.current_time = current_time;96 self.current_time = current_time;
94 }97 }
95 98
99+ /// Restarts the animation using the previous config.
100+ pub fn restarted(self, from: f64, to: f64, initial_velocity: f64) -> Self {
101+ if self.is_off {
102+ return self;
103+ }
104+
105+ match self.kind {
106+ Kind::Easing { curve } => Self::ease(
107+ from,
108+ to,
109+ initial_velocity,
110+ self.duration.as_millis() as u64,
111+ curve,
112+ ),
113+ Kind::Spring(spring) => {
114+ let spring = Spring {
115+ from: self.from,
116+ to: self.to,
117+ initial_velocity: self.initial_velocity,
118+ params: spring.params,
119+ };
120+ Self::spring(spring)
121+ }
122+ Kind::Deceleration {
123+ initial_velocity,
124+ deceleration_rate,
125+ } => {
126+ let threshold = 0.001; // FIXME
127+ Self::decelerate(from, initial_velocity, deceleration_rate, threshold)
128+ }
129+ }
130+ }
131+
96 pub fn ease(from: f64, to: f64, initial_velocity: f64, duration_ms: u64, curve: Curve) -> Self {132 pub fn ease(from: f64, to: f64, initial_velocity: f64, duration_ms: u64, curve: Curve) -> Self {
97 // FIXME: ideally we shouldn't use current time here because animations started within the133 // FIXME: ideally we shouldn't use current time here because animations started within the
98 // same frame cycle should have the same start time to be synchronized.134 // same frame cycle should have the same start time to be synchronized.
@@ -105,6 +141,7 @@ impl Animation {
105 from,141 from,
106 to,142 to,
107 initial_velocity,143 initial_velocity,
144+ is_off: false,
108 duration,145 duration,
109 // Our current curves never overshoot.146 // Our current curves never overshoot.
110 clamped_duration: duration,147 clamped_duration: duration,
@@ -129,6 +166,7 @@ impl Animation {
129 from: spring.from,166 from: spring.from,
130 to: spring.to,167 to: spring.to,
131 initial_velocity: spring.initial_velocity,168 initial_velocity: spring.initial_velocity,
169+ is_off: false,
132 duration,170 duration,
133 clamped_duration,171 clamped_duration,
134 start_time: now,172 start_time: now,
@@ -166,6 +204,7 @@ impl Animation {
166 from,204 from,
167 to,205 to,
168 initial_velocity,206 initial_velocity,
207+ is_off: false,
169 duration,208 duration,
170 clamped_duration: duration,209 clamped_duration: duration,
171 start_time: now,210 start_time: now,
src/layout/tile.rsmodified+7 -1
@@ -247,8 +247,14 @@ impl<W: LayoutElement> Tile<W> {
247 ) {247 ) {
248 let current_offset = self.render_offset();248 let current_offset = self.render_offset();
249 249
250+ // Preserve the previous config if ongoing.
251+ let anim = self.move_animation.take().map(|move_| move_.anim);
252+ let anim = anim
253+ .map(|anim| anim.restarted(1., 0., 0.))
254+ .unwrap_or_else(|| Animation::new(1., 0., 0., config));
255+
250 self.move_animation = Some(MoveAnimation {256 self.move_animation = Some(MoveAnimation {
251- anim: Animation::new(1., 0., 0., config),257+ anim,
252 from: from + current_offset,258 from: from + current_offset,
253 });259 });
254 }260 }