forge
Explore
Log in

Don't you dare go Hollow

layout: Fix/add animations around tabbed columns

Browse files at this commit

02eccf7762bf01cca0bf066d769e2533e2d5a3d2Ivan MolodetskikhParent: 89cf276
src/layout/scrolling.rsmodified+76 -1
@@ -865,6 +865,19 @@ impl<W: LayoutElement> ScrollingSpace<W> {
865 }865 }
866 }866 }
867 867
868+ let target_column = &mut self.columns[col_idx];
869+ if target_column.display_mode == ColumnDisplay::Tabbed {
870+ if target_column.active_tile_idx == tile_idx {
871+ // Fade out the previously active tile.
872+ let tile = &mut target_column.tiles[prev_active_tile_idx];
873+ tile.animate_alpha(1., 0., self.options.animations.window_movement.0);
874+ } else {
875+ // Fade out when adding into a tabbed column into the background.
876+ let tile = &mut target_column.tiles[tile_idx];
877+ tile.animate_alpha(1., 0., self.options.animations.window_movement.0);
878+ }
879+ }
880+
868 // Adding a wider window into a column increases its width now (even if the window will881 // Adding a wider window into a column increases its width now (even if the window will
869 // shrink later). Move the columns to account for this.882 // shrink later). Move the columns to account for this.
870 let offset = self.column_x(col_idx + 1) - prev_next_x;883 let offset = self.column_x(col_idx + 1) - prev_next_x;
@@ -1004,6 +1017,8 @@ impl<W: LayoutElement> ScrollingSpace<W> {
1004 let column = &mut self.columns[column_idx];1017 let column = &mut self.columns[column_idx];
1005 let prev_width = self.data[column_idx].width;1018 let prev_width = self.data[column_idx].width;
1006 1019
1020+ let movement_config = anim_config.unwrap_or(self.options.animations.window_movement.0);
1021+
1007 // Animate movement of other tiles.1022 // Animate movement of other tiles.
1008 // FIXME: tiles can move by X too, in a centered or resizing layout with one window smaller1023 // FIXME: tiles can move by X too, in a centered or resizing layout with one window smaller
1009 // than the others.1024 // than the others.
@@ -1012,6 +1027,12 @@ impl<W: LayoutElement> ScrollingSpace<W> {
1012 tile.animate_move_y_from(offset_y);1027 tile.animate_move_y_from(offset_y);
1013 }1028 }
1014 1029
1030+ if column.display_mode == ColumnDisplay::Tabbed && tile_idx != column.active_tile_idx {
1031+ // Fade in when removing background tab from a tabbed column.
1032+ let tile = &mut column.tiles[tile_idx];
1033+ tile.animate_alpha(0., 1., movement_config);
1034+ }
1035+
1015 let tile = column.tiles.remove(tile_idx);1036 let tile = column.tiles.remove(tile_idx);
1016 column.data.remove(tile_idx);1037 column.data.remove(tile_idx);
1017 1038
@@ -1036,6 +1057,7 @@ impl<W: LayoutElement> ScrollingSpace<W> {
1036 is_floating: false,1057 is_floating: false,
1037 };1058 };
1038 1059
1060+ #[allow(clippy::comparison_chain)] // What do you even want here?
1039 if tile_idx < column.active_tile_idx {1061 if tile_idx < column.active_tile_idx {
1040 // A tile above was removed; preserve the current position.1062 // A tile above was removed; preserve the current position.
1041 column.active_tile_idx -= 1;1063 column.active_tile_idx -= 1;
@@ -1044,6 +1066,9 @@ impl<W: LayoutElement> ScrollingSpace<W> {
1044 if tile_idx == column.tiles.len() {1066 if tile_idx == column.tiles.len() {
1045 // The bottom tile was removed and it was active, update active idx to remain valid.1067 // The bottom tile was removed and it was active, update active idx to remain valid.
1046 column.activate_idx(tile_idx - 1);1068 column.activate_idx(tile_idx - 1);
1069+ } else {
1070+ // Ensure the newly active tile animates to opaque.
1071+ column.tiles[tile_idx].ensure_alpha_animates_to_1();
1047 }1072 }
1048 }1073 }
1049 1074
@@ -1052,7 +1077,6 @@ impl<W: LayoutElement> ScrollingSpace<W> {
1052 let offset = prev_width - column.width();1077 let offset = prev_width - column.width();
1053 1078
1054 // Animate movement of the other columns.1079 // Animate movement of the other columns.
1055- let movement_config = anim_config.unwrap_or(self.options.animations.window_movement.0);
1056 if self.active_column_idx <= column_idx {1080 if self.active_column_idx <= column_idx {
1057 for col in &mut self.columns[column_idx + 1..] {1081 for col in &mut self.columns[column_idx + 1..] {
1058 col.animate_move_from_with_config(offset, movement_config);1082 col.animate_move_from_with_config(offset, movement_config);
@@ -1980,6 +2004,7 @@ impl<W: LayoutElement> ScrollingSpace<W> {
1980 // Animations2004 // Animations
1981 self.columns[target_column_idx].tiles[target_tile_idx]2005 self.columns[target_column_idx].tiles[target_tile_idx]
1982 .animate_move_from(source_pt - target_pt);2006 .animate_move_from(source_pt - target_pt);
2007+ self.columns[target_column_idx].tiles[target_tile_idx].ensure_alpha_animates_to_1();
1983 2008
1984 // FIXME: this stop_move_animations() causes the target tile animation to "reset" when2009 // FIXME: this stop_move_animations() causes the target tile animation to "reset" when
1985 // swapping. It's here as a workaround to stop the unwanted animation of moving the source2010 // swapping. It's here as a workaround to stop the unwanted animation of moving the source
@@ -1989,6 +2014,7 @@ impl<W: LayoutElement> ScrollingSpace<W> {
1989 self.columns[source_column_idx].tiles[source_tile_idx].stop_move_animations();2014 self.columns[source_column_idx].tiles[source_tile_idx].stop_move_animations();
1990 self.columns[source_column_idx].tiles[source_tile_idx]2015 self.columns[source_column_idx].tiles[source_tile_idx]
1991 .animate_move_from(target_pt - source_pt);2016 .animate_move_from(target_pt - source_pt);
2017+ self.columns[source_column_idx].tiles[source_tile_idx].ensure_alpha_animates_to_1();
1992 2018
1993 self.activate_column(target_column_idx);2019 self.activate_column(target_column_idx);
1994 }2020 }
@@ -2602,6 +2628,12 @@ impl<W: LayoutElement> ScrollingSpace<W> {
2602 let focus_ring = focus_ring && first;2628 let focus_ring = focus_ring && first;
2603 first = false;2629 first = false;
2604 2630
2631+ // In the scrolling layout, we currently use visible only for hidden tabs in the
2632+ // tabbed mode. We want to animate their opacity when going in and out of tabbed
2633+ // mode, so we don't want to apply "visible" immediately. However, "visible" is
2634+ // also used for input handling, and there we *do* want to apply it immediately.
2635+ // So, let's just selectively ignore "visible" here when animating alpha.
2636+ let visible = visible || tile.alpha_animation.is_some();
2605 if !visible {2637 if !visible {
2606 continue;2638 continue;
2607 }2639 }
@@ -3521,6 +3553,8 @@ impl<W: LayoutElement> Column<W> {
3521 3553
3522 self.active_tile_idx = idx;3554 self.active_tile_idx = idx;
3523 3555
3556+ self.tiles[idx].ensure_alpha_animates_to_1();
3557+
3524 true3558 true
3525 }3559 }
3526 3560
@@ -4258,6 +4292,47 @@ impl<W: LayoutElement> Column<W> {
4258 return;4292 return;
4259 }4293 }
4260 4294
4295+ // Animate the movement.
4296+ //
4297+ // We're doing some shortcuts here because we know that currently normal vs. tabbed can
4298+ // only cause a vertical shift + a shift to the origin.
4299+ //
4300+ // Doing it this way to avoid storing all tile positions in a vector. If more display modes
4301+ // are added it might be simpler to just collect everything into a smallvec.
4302+ let prev_origin = self.tiles_origin();
4303+ self.display_mode = display;
4304+ let new_origin = self.tiles_origin();
4305+ let origin_delta = prev_origin - new_origin;
4306+
4307+ // When need to walk the tiles in the normal display mode to get the right offsets.
4308+ self.display_mode = ColumnDisplay::Normal;
4309+ for (tile, pos) in self.tiles_mut() {
4310+ let mut y_delta = pos.y - prev_origin.y;
4311+
4312+ // Invert the Y motion when transitioning *to* normal display mode.
4313+ if display == ColumnDisplay::Normal {
4314+ y_delta *= -1.;
4315+ }
4316+
4317+ let mut delta = origin_delta;
4318+ delta.y += y_delta;
4319+ tile.animate_move_from(delta);
4320+ }
4321+
4322+ // Animate the opacity.
4323+ for (idx, tile) in self.tiles.iter_mut().enumerate() {
4324+ let is_active = idx == self.active_tile_idx;
4325+ if !is_active {
4326+ let (from, to) = if display == ColumnDisplay::Tabbed {
4327+ (1., 0.)
4328+ } else {
4329+ (0., 1.)
4330+ };
4331+ tile.animate_alpha(from, to, self.options.animations.window_movement.0);
4332+ }
4333+ }
4334+
4335+ // Now switch the display mode for real.
4261 self.display_mode = display;4336 self.display_mode = display;
4262 self.update_tile_sizes(true);4337 self.update_tile_sizes(true);
4263 }4338 }
src/layout/tile.rsmodified+44 -4
@@ -84,6 +84,9 @@ pub struct Tile<W: LayoutElement> {
84 /// The animation of a tile visually moving vertically.84 /// The animation of a tile visually moving vertically.
85 move_y_animation: Option<MoveAnimation>,85 move_y_animation: Option<MoveAnimation>,
86 86
87+ /// The animation of the tile's opacity.
88+ pub(super) alpha_animation: Option<Animation>,
89+
87 /// Offset during the initial interactive move rubberband.90 /// Offset during the initial interactive move rubberband.
88 pub(super) interactive_move_offset: Point<f64, Logical>,91 pub(super) interactive_move_offset: Point<f64, Logical>,
89 92
@@ -168,6 +171,7 @@ impl<W: LayoutElement> Tile<W> {
168 resize_animation: None,171 resize_animation: None,
169 move_x_animation: None,172 move_x_animation: None,
170 move_y_animation: None,173 move_y_animation: None,
174+ alpha_animation: None,
171 interactive_move_offset: Point::from((0., 0.)),175 interactive_move_offset: Point::from((0., 0.)),
172 unmap_snapshot: None,176 unmap_snapshot: None,
173 rounded_corner_damage: Default::default(),177 rounded_corner_damage: Default::default(),
@@ -301,6 +305,12 @@ impl<W: LayoutElement> Tile<W> {
301 self.move_y_animation = None;305 self.move_y_animation = None;
302 }306 }
303 }307 }
308+
309+ if let Some(alpha) = &mut self.alpha_animation {
310+ if alpha.is_done() {
311+ self.alpha_animation = None;
312+ }
313+ }
304 }314 }
305 315
306 pub fn are_animations_ongoing(&self) -> bool {316 pub fn are_animations_ongoing(&self) -> bool {
@@ -308,10 +318,12 @@ impl<W: LayoutElement> Tile<W> {
308 || self.resize_animation.is_some()318 || self.resize_animation.is_some()
309 || self.move_x_animation.is_some()319 || self.move_x_animation.is_some()
310 || self.move_y_animation.is_some()320 || self.move_y_animation.is_some()
321+ || self.alpha_animation.is_some()
311 }322 }
312 323
313 pub fn update_render_elements(&mut self, is_active: bool, view_rect: Rectangle<f64, Logical>) {324 pub fn update_render_elements(&mut self, is_active: bool, view_rect: Rectangle<f64, Logical>) {
314 let rules = self.window.rules();325 let rules = self.window.rules();
326+ let alpha = self.tile_alpha();
315 327
316 let draw_border_with_background = rules328 let draw_border_with_background = rules
317 .draw_border_with_background329 .draw_border_with_background
@@ -336,7 +348,7 @@ impl<W: LayoutElement> Tile<W> {
336 ),348 ),
337 radius,349 radius,
338 self.scale,350 self.scale,
339- 1.,351+ alpha,
340 );352 );
341 353
342 let radius = if self.is_fullscreen {354 let radius = if self.is_fullscreen {
@@ -351,7 +363,7 @@ impl<W: LayoutElement> Tile<W> {
351 is_active,363 is_active,
352 radius,364 radius,
353 self.scale,365 self.scale,
354- 1.,366+ alpha,
355 );367 );
356 368
357 let draw_focus_ring_with_background = if self.effective_border_width().is_some() {369 let draw_focus_ring_with_background = if self.effective_border_width().is_some() {
@@ -367,7 +379,7 @@ impl<W: LayoutElement> Tile<W> {
367 view_rect,379 view_rect,
368 radius,380 radius,
369 self.scale,381 self.scale,
370- 1.,382+ alpha,
371 );383 );
372 }384 }
373 385
@@ -452,6 +464,31 @@ impl<W: LayoutElement> Tile<W> {
452 self.move_y_animation = None;464 self.move_y_animation = None;
453 }465 }
454 466
467+ pub fn animate_alpha(&mut self, from: f64, to: f64, config: niri_config::Animation) {
468+ let from = from.clamp(0., 1.);
469+ let to = to.clamp(0., 1.);
470+ let current = self.alpha_animation.take().map(|anim| anim.clamped_value());
471+ let current = current.unwrap_or(from);
472+ self.alpha_animation = Some(Animation::new(self.clock.clone(), current, to, 0., config));
473+ }
474+
475+ pub fn ensure_alpha_animates_to_1(&mut self) {
476+ if let Some(anim) = &self.alpha_animation {
477+ if anim.to() != 1. {
478+ // Cancel animation instead of starting a new one because the user likely wants to
479+ // see the tile right away.
480+ self.alpha_animation = None;
481+ }
482+ }
483+ }
484+
485+ /// Opacity that applies to both window and decorations.
486+ fn tile_alpha(&self) -> f32 {
487+ self.alpha_animation
488+ .as_ref()
489+ .map_or(1., |anim| anim.clamped_value()) as f32
490+ }
491+
455 pub fn window(&self) -> &W {492 pub fn window(&self) -> &W {
456 &self.window493 &self.window
457 }494 }
@@ -740,6 +777,9 @@ impl<W: LayoutElement> Tile<W> {
740 self.window.rules().opacity.unwrap_or(1.).clamp(0., 1.)777 self.window.rules().opacity.unwrap_or(1.).clamp(0., 1.)
741 };778 };
742 779
780+ let tile_alpha = self.tile_alpha();
781+ let win_alpha = win_alpha * tile_alpha;
782+
743 let window_loc = self.window_loc();783 let window_loc = self.window_loc();
744 let window_size = self.window_size().to_f64();784 let window_size = self.window_size().to_f64();
745 let animated_window_size = self.animated_window_size();785 let animated_window_size = self.animated_window_size();
@@ -921,7 +961,7 @@ impl<W: LayoutElement> Tile<W> {
921 SolidColorRenderElement::from_buffer(961 SolidColorRenderElement::from_buffer(
922 &self.fullscreen_backdrop,962 &self.fullscreen_backdrop,
923 location,963 location,
924- 1.,964+ tile_alpha,
925 Kind::Unspecified,965 Kind::Unspecified,
926 )966 )
927 .into()967 .into()
src/layout/workspace.rsmodified+7 -1
@@ -1688,7 +1688,7 @@ impl<W: LayoutElement> Workspace<W> {
1688 );1688 );
1689 }1689 }
1690 1690
1691- for (tile, tile_pos, _visible) in self.tiles_with_render_positions() {1691+ for (tile, tile_pos, visible) in self.tiles_with_render_positions() {
1692 if Some(tile.window().id()) != move_win_id {1692 if Some(tile.window().id()) != move_win_id {
1693 assert_eq!(tile.interactive_move_offset, Point::from((0., 0.)));1693 assert_eq!(tile.interactive_move_offset, Point::from((0., 0.)));
1694 }1694 }
@@ -1698,6 +1698,12 @@ impl<W: LayoutElement> Workspace<W> {
1698 // Tile positions must be rounded to physical pixels.1698 // Tile positions must be rounded to physical pixels.
1699 assert_abs_diff_eq!(tile_pos.x, rounded_pos.x, epsilon = 1e-5);1699 assert_abs_diff_eq!(tile_pos.x, rounded_pos.x, epsilon = 1e-5);
1700 assert_abs_diff_eq!(tile_pos.y, rounded_pos.y, epsilon = 1e-5);1700 assert_abs_diff_eq!(tile_pos.y, rounded_pos.y, epsilon = 1e-5);
1701+
1702+ if let Some(anim) = &tile.alpha_animation {
1703+ if visible {
1704+ assert_eq!(anim.to(), 1., "visible tiles can animate alpha only to 1");
1705+ }
1706+ }
1701 }1707 }
1702 }1708 }
1703 }1709 }