forge
Explore
Log in

Don't you dare go Hollow

Set window-resize animation config for view-offset anim caused by resize

Browse files at this commit

8b0dc1902c251569fe710b87c4a74b46c536272dIvan MolodetskikhParent: 9d5f1c7
src/animation/mod.rsmodified+33 -7
@@ -15,6 +15,7 @@ pub static ANIMATION_SLOWDOWN: AtomicF64 = AtomicF64::new(1.);
15 pub struct Animation {15 pub struct Animation {
16 from: f64,16 from: f64,
17 to: f64,17 to: f64,
18+ initial_velocity: f64,
18 duration: Duration,19 duration: Duration,
19 /// Time until the animation first reaches `to`.20 /// Time until the animation first reaches `to`.
20 ///21 ///
@@ -52,10 +53,23 @@ impl Animation {
52 config: niri_config::Animation,53 config: niri_config::Animation,
53 default: niri_config::Animation,54 default: niri_config::Animation,
54 ) -> Self {55 ) -> Self {
56+ let mut rv = Self::ease(from, to, initial_velocity, 0, Curve::EaseOutCubic);
55 if config.off {57 if config.off {
56- return Self::ease(from, to, 0, Curve::EaseOutCubic);58+ return rv;
57 }59 }
58 60
61+ rv.replace_config(config, default);
62+ rv
63+ }
64+
65+ pub fn replace_config(
66+ &mut self,
67+ config: niri_config::Animation,
68+ default: niri_config::Animation,
69+ ) {
70+ let start_time = self.start_time;
71+ let current_time = self.current_time;
72+
59 // Resolve defaults.73 // Resolve defaults.
60 let (kind, easing_defaults) = match (config.kind, default.kind) {74 let (kind, easing_defaults) = match (config.kind, default.kind) {
61 // Configured spring.75 // Configured spring.
@@ -82,23 +96,32 @@ impl Animation {
82 let params = SpringParams::new(p.damping_ratio, f64::from(p.stiffness), p.epsilon);96 let params = SpringParams::new(p.damping_ratio, f64::from(p.stiffness), p.epsilon);
83 97
84 let spring = Spring {98 let spring = Spring {
85- from,99+ from: self.from,
86- to,100+ to: self.to,
87- initial_velocity,101+ initial_velocity: self.initial_velocity,
88 params,102 params,
89 };103 };
90- Self::spring(spring)104+ *self = Self::spring(spring);
91 }105 }
92 niri_config::AnimationKind::Easing(p) => {106 niri_config::AnimationKind::Easing(p) => {
93 let defaults = easing_defaults.unwrap_or(niri_config::EasingParams::default());107 let defaults = easing_defaults.unwrap_or(niri_config::EasingParams::default());
94 let duration_ms = p.duration_ms.or(defaults.duration_ms).unwrap();108 let duration_ms = p.duration_ms.or(defaults.duration_ms).unwrap();
95 let curve = Curve::from(p.curve.or(defaults.curve).unwrap());109 let curve = Curve::from(p.curve.or(defaults.curve).unwrap());
96- Self::ease(from, to, u64::from(duration_ms), curve)110+ *self = Self::ease(
111+ self.from,
112+ self.to,
113+ self.initial_velocity,
114+ u64::from(duration_ms),
115+ curve,
116+ );
97 }117 }
98 }118 }
119+
120+ self.start_time = start_time;
121+ self.current_time = current_time;
99 }122 }
100 123
101- pub fn ease(from: f64, to: f64, duration_ms: u64, curve: Curve) -> Self {124+ pub fn ease(from: f64, to: f64, initial_velocity: f64, duration_ms: u64, curve: Curve) -> Self {
102 // FIXME: ideally we shouldn't use current time here because animations started within the125 // FIXME: ideally we shouldn't use current time here because animations started within the
103 // same frame cycle should have the same start time to be synchronized.126 // same frame cycle should have the same start time to be synchronized.
104 let now = get_monotonic_time();127 let now = get_monotonic_time();
@@ -109,6 +132,7 @@ impl Animation {
109 Self {132 Self {
110 from,133 from,
111 to,134 to,
135+ initial_velocity,
112 duration,136 duration,
113 // Our current curves never overshoot.137 // Our current curves never overshoot.
114 clamped_duration: duration,138 clamped_duration: duration,
@@ -132,6 +156,7 @@ impl Animation {
132 Self {156 Self {
133 from: spring.from,157 from: spring.from,
134 to: spring.to,158 to: spring.to,
159+ initial_velocity: spring.initial_velocity,
135 duration,160 duration,
136 clamped_duration,161 clamped_duration,
137 start_time: now,162 start_time: now,
@@ -168,6 +193,7 @@ impl Animation {
168 Self {193 Self {
169 from,194 from,
170 to,195 to,
196+ initial_velocity,
171 duration,197 duration,
172 clamped_duration: duration,198 clamped_duration: duration,
173 start_time: now,199 start_time: now,
src/layout/workspace.rsmodified+16 -1
@@ -903,7 +903,8 @@ impl<W: LayoutElement> Workspace<W> {
903 column.update_tile_sizes(false);903 column.update_tile_sizes(false);
904 904
905 // Move other columns in tandem with resizing.905 // Move other columns in tandem with resizing.
906- if column.tiles[tile_idx].resize_animation().is_some() && offset != 0 {906+ let started_animation = column.tiles[tile_idx].resize_animation().is_some() && offset != 0;
907+ if started_animation {
907 if self.active_column_idx <= col_idx {908 if self.active_column_idx <= col_idx {
908 for col in &mut self.columns[col_idx + 1..] {909 for col in &mut self.columns[col_idx + 1..] {
909 col.animate_move_from_with_config(910 col.animate_move_from_with_config(
@@ -932,6 +933,20 @@ impl<W: LayoutElement> Workspace<W> {
932 // FIXME: we will want to skip the animation in some cases here to make continuously933 // FIXME: we will want to skip the animation in some cases here to make continuously
933 // resizing windows not look janky.934 // resizing windows not look janky.
934 self.animate_view_offset_to_column(current_x, col_idx, None);935 self.animate_view_offset_to_column(current_x, col_idx, None);
936+
937+ // If this animated resize caused a view animation, make sure that it uses the same
938+ // config. This is important for always-centered view.
939+ if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj {
940+ // FIXME: animate_view_offset_to_column() will keep the previous running view
941+ // offset animation if the target was the same; maybe we shouldn't replace in this
942+ // case?
943+ if started_animation {
944+ anim.replace_config(
945+ self.options.animations.window_resize,
946+ niri_config::Animation::default_window_resize(),
947+ );
948+ }
949+ }
935 }950 }
936 }951 }
937 952
wiki/Configuration:-Animations.mdmodified+1 -0
@@ -139,6 +139,7 @@ All horizontal camera view movement animations, such as:
139 - When a window off-screen is focused and the camera scrolls to it.139 - When a window off-screen is focused and the camera scrolls to it.
140 - When a new window appears off-screen and the camera scrolls to it.140 - When a new window appears off-screen and the camera scrolls to it.
141 - When a window resizes bigger and the camera scrolls to show it in full.141 - When a window resizes bigger and the camera scrolls to show it in full.
142+ - Since 0.1.5, animated window resizes will use the `window-resize` animation parameters for the view animation to make them synchronized.
142 - After a horizontal touchpad gesture (a spring is recommended).143 - After a horizontal touchpad gesture (a spring is recommended).
143 144
144 ```145 ```