Implement column movement animation
Browse files at this commitc1432bfa96e40c12f2d10174f8cd23ec9c2a68b0Parent: ec053123 changed files +92 -4
- niri-config/src/lib.rs +14 -0
- src/layout/workspace.rs +59 -4
- wiki/Configuration:-Animations.md +19 -0
niri-config/src/lib.rsmodified+14 -0
| @@ -483,6 +483,8 @@ pub struct Animations { | ||
| 483 | 483 | pub workspace_switch: Animation, |
| 484 | 484 | #[knuffel(child, default = Animation::default_horizontal_view_movement())] |
| 485 | 485 | pub horizontal_view_movement: Animation, |
| 486 | + #[knuffel(child, default = Animation::default_window_movement())] | |
| 487 | + pub window_movement: Animation, | |
| 486 | 488 | #[knuffel(child, default = Animation::default_window_open())] |
| 487 | 489 | pub window_open: Animation, |
| 488 | 490 | #[knuffel(child, default = Animation::default_config_notification_open_close())] |
| @@ -496,6 +498,7 @@ impl Default for Animations { | ||
| 496 | 498 | slowdown: 1., |
| 497 | 499 | workspace_switch: Animation::default_workspace_switch(), |
| 498 | 500 | horizontal_view_movement: Animation::default_horizontal_view_movement(), |
| 501 | + window_movement: Animation::default_window_movement(), | |
| 499 | 502 | window_open: Animation::default_window_open(), |
| 500 | 503 | config_notification_open_close: Animation::default_config_notification_open_close(), |
| 501 | 504 | } |
| @@ -545,6 +548,17 @@ impl Animation { | ||
| 545 | 548 | } |
| 546 | 549 | } |
| 547 | 550 | |
| 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 | + | |
| 548 | 562 | pub const fn default_config_notification_open_close() -> Self { |
| 549 | 563 | Self { |
| 550 | 564 | off: false, |
src/layout/workspace.rsmodified+59 -4
| @@ -181,6 +181,9 @@ pub struct Column<W: LayoutElement> { | ||
| 181 | 181 | /// Whether this column contains a single full-screened window. |
| 182 | 182 | pub is_fullscreen: bool, |
| 183 | 183 | |
| 184 | + /// Animation of the render offset during window swapping. | |
| 185 | + move_animation: Option<Animation>, | |
| 186 | + | |
| 184 | 187 | /// Latest known view size for this column's workspace. |
| 185 | 188 | view_size: Size<i32, Logical>, |
| 186 | 189 | |
| @@ -967,7 +970,10 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 967 | 970 | return; |
| 968 | 971 | } |
| 969 | 972 | |
| 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; | |
| 971 | 977 | |
| 972 | 978 | let column = self.columns.remove(self.active_column_idx); |
| 973 | 979 | self.columns.insert(new_idx, column); |
| @@ -975,6 +981,22 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 975 | 981 | // Preserve the camera position when moving to the left. |
| 976 | 982 | self.view_offset = current_x - self.column_x(self.active_column_idx); |
| 977 | 983 | |
| 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 | + | |
| 978 | 1000 | self.activate_column(new_idx); |
| 979 | 1001 | } |
| 980 | 1002 | |
| @@ -1150,7 +1172,7 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 1150 | 1172 | let tile_pos = Point::from(( |
| 1151 | 1173 | self.visual_column_x(self.active_column_idx) - view_pos, |
| 1152 | 1174 | col.tile_y(col.active_tile_idx), |
| 1153 | - )); | |
| 1175 | + )) + col.render_offset(); | |
| 1154 | 1176 | let first = iter::once((tile, tile_pos)); |
| 1155 | 1177 | |
| 1156 | 1178 | let mut x = -view_pos; |
| @@ -1172,7 +1194,7 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 1172 | 1194 | return None; |
| 1173 | 1195 | } |
| 1174 | 1196 | |
| 1175 | - let tile_pos = Point::from((x, y)); | |
| 1197 | + let tile_pos = Point::from((x, y)) + col.render_offset(); | |
| 1176 | 1198 | Some((tile, tile_pos)) |
| 1177 | 1199 | }, |
| 1178 | 1200 | ) |
| @@ -1604,6 +1626,7 @@ impl<W: LayoutElement> Column<W> { | ||
| 1604 | 1626 | width, |
| 1605 | 1627 | is_full_width, |
| 1606 | 1628 | is_fullscreen: false, |
| 1629 | + move_animation: None, | |
| 1607 | 1630 | view_size, |
| 1608 | 1631 | working_area, |
| 1609 | 1632 | options, |
| @@ -1669,6 +1692,16 @@ impl<W: LayoutElement> Column<W> { | ||
| 1669 | 1692 | } |
| 1670 | 1693 | |
| 1671 | 1694 | 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 | + | |
| 1672 | 1705 | for (tile_idx, tile) in self.tiles.iter_mut().enumerate() { |
| 1673 | 1706 | let is_active = is_active && tile_idx == self.active_tile_idx; |
| 1674 | 1707 | tile.advance_animations(current_time, is_active); |
| @@ -1676,7 +1709,29 @@ impl<W: LayoutElement> Column<W> { | ||
| 1676 | 1709 | } |
| 1677 | 1710 | |
| 1678 | 1711 | 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 | + )); | |
| 1680 | 1735 | } |
| 1681 | 1736 | |
| 1682 | 1737 | pub fn contains(&self, window: &W::Id) -> bool { |
wiki/Configuration:-Animations.mdmodified+19 -0
| @@ -24,6 +24,10 @@ animations { | ||
| 24 | 24 | spring damping-ratio=1.0 stiffness=800 epsilon=0.0001 |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | + window-movement { | |
| 28 | + spring damping-ratio=1.0 stiffness=800 epsilon=0.0001 | |
| 29 | + } | |
| 30 | + | |
| 27 | 31 | window-open { |
| 28 | 32 | duration-ms 150 |
| 29 | 33 | curve "ease-out-expo" |
| @@ -131,6 +135,21 @@ animations { | ||
| 131 | 135 | } |
| 132 | 136 | ``` |
| 133 | 137 | |
| 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 | + | |
| 134 | 153 | #### `window-open` |
| 135 | 154 | |
| 136 | 155 | Window opening animation. |