forge
Explore
Log in

Don't you dare go Hollow

Implement column movement animation

Browse files at this commit

c1432bfa96e40c12f2d10174f8cd23ec9c2a68b0Ivan MolodetskikhParent: ec05312
niri-config/src/lib.rsmodified+14 -0
@@ -483,6 +483,8 @@ pub struct Animations {
483483 pub workspace_switch: Animation,
484484 #[knuffel(child, default = Animation::default_horizontal_view_movement())]
485485 pub horizontal_view_movement: Animation,
486+ #[knuffel(child, default = Animation::default_window_movement())]
487+ pub window_movement: Animation,
486488 #[knuffel(child, default = Animation::default_window_open())]
487489 pub window_open: Animation,
488490 #[knuffel(child, default = Animation::default_config_notification_open_close())]
@@ -496,6 +498,7 @@ impl Default for Animations {
496498 slowdown: 1.,
497499 workspace_switch: Animation::default_workspace_switch(),
498500 horizontal_view_movement: Animation::default_horizontal_view_movement(),
501+ window_movement: Animation::default_window_movement(),
499502 window_open: Animation::default_window_open(),
500503 config_notification_open_close: Animation::default_config_notification_open_close(),
501504 }
@@ -545,6 +548,17 @@ impl Animation {
545548 }
546549 }
547550
551+ pub const fn default_window_movement() -> Self {
552+ Self {
553+ off: false,
554+ kind: AnimationKind::Spring(SpringParams {
555+ damping_ratio: 1.,
556+ stiffness: 800,
557+ epsilon: 0.0001,
558+ }),
559+ }
560+ }
561+
548562 pub const fn default_config_notification_open_close() -> Self {
549563 Self {
550564 off: false,
src/layout/workspace.rsmodified+59 -4
@@ -181,6 +181,9 @@ pub struct Column<W: LayoutElement> {
181181 /// Whether this column contains a single full-screened window.
182182 pub is_fullscreen: bool,
183183
184+ /// Animation of the render offset during window swapping.
185+ move_animation: Option<Animation>,
186+
184187 /// Latest known view size for this column's workspace.
185188 view_size: Size<i32, Logical>,
186189
@@ -967,7 +970,10 @@ impl<W: LayoutElement> Workspace<W> {
967970 return;
968971 }
969972
970- let current_x = self.view_pos();
973+ let current_col_x = self.column_x(self.active_column_idx);
974+ let next_col_x = self.column_x(self.active_column_idx + 1);
975+
976+ let current_x = current_col_x + self.view_offset;
971977
972978 let column = self.columns.remove(self.active_column_idx);
973979 self.columns.insert(new_idx, column);
@@ -975,6 +981,22 @@ impl<W: LayoutElement> Workspace<W> {
975981 // Preserve the camera position when moving to the left.
976982 self.view_offset = current_x - self.column_x(self.active_column_idx);
977983
984+ // The column we just moved is offset by the difference between its new and old position.
985+ let new_col_x = self.column_x(new_idx);
986+ self.columns[new_idx].animate_move_from(current_col_x - new_col_x);
987+
988+ // All columns in between moved by the width of the column that we just moved.
989+ let others_x_offset = next_col_x - current_col_x;
990+ if self.active_column_idx < new_idx {
991+ for col in &mut self.columns[self.active_column_idx..new_idx] {
992+ col.animate_move_from(others_x_offset);
993+ }
994+ } else {
995+ for col in &mut self.columns[new_idx + 1..=self.active_column_idx] {
996+ col.animate_move_from(-others_x_offset);
997+ }
998+ }
999+
9781000 self.activate_column(new_idx);
9791001 }
9801002
@@ -1150,7 +1172,7 @@ impl<W: LayoutElement> Workspace<W> {
11501172 let tile_pos = Point::from((
11511173 self.visual_column_x(self.active_column_idx) - view_pos,
11521174 col.tile_y(col.active_tile_idx),
1153- ));
1175+ )) + col.render_offset();
11541176 let first = iter::once((tile, tile_pos));
11551177
11561178 let mut x = -view_pos;
@@ -1172,7 +1194,7 @@ impl<W: LayoutElement> Workspace<W> {
11721194 return None;
11731195 }
11741196
1175- let tile_pos = Point::from((x, y));
1197+ let tile_pos = Point::from((x, y)) + col.render_offset();
11761198 Some((tile, tile_pos))
11771199 },
11781200 )
@@ -1604,6 +1626,7 @@ impl<W: LayoutElement> Column<W> {
16041626 width,
16051627 is_full_width,
16061628 is_fullscreen: false,
1629+ move_animation: None,
16071630 view_size,
16081631 working_area,
16091632 options,
@@ -1669,6 +1692,16 @@ impl<W: LayoutElement> Column<W> {
16691692 }
16701693
16711694 pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {
1695+ match &mut self.move_animation {
1696+ Some(anim) => {
1697+ anim.set_current_time(current_time);
1698+ if anim.is_done() {
1699+ self.move_animation = None;
1700+ }
1701+ }
1702+ None => (),
1703+ }
1704+
16721705 for (tile_idx, tile) in self.tiles.iter_mut().enumerate() {
16731706 let is_active = is_active && tile_idx == self.active_tile_idx;
16741707 tile.advance_animations(current_time, is_active);
@@ -1676,7 +1709,29 @@ impl<W: LayoutElement> Column<W> {
16761709 }
16771710
16781711 pub fn are_animations_ongoing(&self) -> bool {
1679- self.tiles.iter().any(Tile::are_animations_ongoing)
1712+ self.move_animation.is_some() || self.tiles.iter().any(Tile::are_animations_ongoing)
1713+ }
1714+
1715+ pub fn render_offset(&self) -> Point<i32, Logical> {
1716+ let mut offset = Point::from((0., 0.));
1717+
1718+ if let Some(anim) = &self.move_animation {
1719+ offset.x += anim.value();
1720+ }
1721+
1722+ offset.to_i32_round()
1723+ }
1724+
1725+ pub fn animate_move_from(&mut self, from_x_offset: i32) {
1726+ let current_offset = self.move_animation.as_ref().map_or(0., Animation::value);
1727+
1728+ self.move_animation = Some(Animation::new(
1729+ f64::from(from_x_offset) + current_offset,
1730+ 0.,
1731+ 0.,
1732+ self.options.animations.window_movement,
1733+ niri_config::Animation::default_window_movement(),
1734+ ));
16801735 }
16811736
16821737 pub fn contains(&self, window: &W::Id) -> bool {
wiki/Configuration:-Animations.mdmodified+19 -0
@@ -24,6 +24,10 @@ animations {
2424 spring damping-ratio=1.0 stiffness=800 epsilon=0.0001
2525 }
2626
27+ window-movement {
28+ spring damping-ratio=1.0 stiffness=800 epsilon=0.0001
29+ }
30+
2731 window-open {
2832 duration-ms 150
2933 curve "ease-out-expo"
@@ -131,6 +135,21 @@ animations {
131135 }
132136 ```
133137
138+#### `window-movement`
139+
140+Window movement animations, currently cover only horizontal column movement.
141+
142+This animation runs on actions like `move-column-left` and `move-column-right` to move the windows themselves.
143+It can sometimes run together with the `horizontal-view-movement` animation, if the camera also moves.
144+
145+```
146+animations {
147+ window-movement {
148+ spring damping-ratio=1.0 stiffness=800 epsilon=0.0001
149+ }
150+}
151+```
152+
134153 #### `window-open`
135154
136155 Window opening animation.