tab indicator: Animate opening
Browse files at this commit20769b4c2f843566880f020f117e7bde36edc332Parent: 14ac2cf5 changed files +98 -7
- src/layout/floating.rs +9 -0
- src/layout/mod.rs +2 -5
- src/layout/scrolling.rs +54 -1
- src/layout/tab_indicator.rs +29 -1
- src/layout/workspace.rs +4 -0
src/layout/floating.rsmodified+9 -0
| @@ -641,6 +641,15 @@ impl<W: LayoutElement> FloatingSpace<W> { | |||
| 641 | self.interactive_resize_end(Some(&id)); | 641 | self.interactive_resize_end(Some(&id)); |
| 642 | } | 642 | } |
| 643 | 643 | ||
| 644 | + pub fn start_open_animation(&mut self, id: &W::Id) -> bool { | ||
| 645 | + let Some(idx) = self.idx_of(id) else { | ||
| 646 | + return false; | ||
| 647 | + }; | ||
| 648 | + | ||
| 649 | + self.tiles[idx].start_open_animation(); | ||
| 650 | + true | ||
| 651 | + } | ||
| 652 | + | ||
| 644 | pub fn toggle_window_height(&mut self, id: Option<&W::Id>) { | 653 | pub fn toggle_window_height(&mut self, id: Option<&W::Id>) { |
| 645 | let Some(id) = id.or(self.active_window_id.as_ref()).cloned() else { | 654 | let Some(id) = id.or(self.active_window_id.as_ref()).cloned() else { |
| 646 | return; | 655 | return; |
src/layout/mod.rsmodified+2 -5
| @@ -4112,11 +4112,8 @@ impl<W: LayoutElement> Layout<W> { | |||
| 4112 | } | 4112 | } |
| 4113 | 4113 | ||
| 4114 | for ws in self.workspaces_mut() { | 4114 | for ws in self.workspaces_mut() { |
| 4115 | - for tile in ws.tiles_mut() { | 4115 | + if ws.start_open_animation(window) { |
| 4116 | - if tile.window().id() == window { | 4116 | + return; |
| 4117 | - tile.start_open_animation(); | ||
| 4118 | - return; | ||
| 4119 | - } | ||
| 4120 | } | 4117 | } |
| 4121 | } | 4118 | } |
| 4122 | } | 4119 | } |
src/layout/scrolling.rsmodified+54 -1
| @@ -1429,6 +1429,12 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 1429 | } | 1429 | } |
| 1430 | } | 1430 | } |
| 1431 | 1431 | ||
| 1432 | + pub fn start_open_animation(&mut self, id: &W::Id) -> bool { | ||
| 1433 | + self.columns | ||
| 1434 | + .iter_mut() | ||
| 1435 | + .any(|col| col.start_open_animation(id)) | ||
| 1436 | + } | ||
| 1437 | + | ||
| 1432 | pub fn focus_left(&mut self) -> bool { | 1438 | pub fn focus_left(&mut self) -> bool { |
| 1433 | if self.active_column_idx == 0 { | 1439 | if self.active_column_idx == 0 { |
| 1434 | return false; | 1440 | return false; |
| @@ -3432,6 +3438,17 @@ impl<W: LayoutElement> Column<W> { | |||
| 3432 | rv.set_fullscreen(true); | 3438 | rv.set_fullscreen(true); |
| 3433 | } | 3439 | } |
| 3434 | 3440 | ||
| 3441 | + // Animate the tab indicator for new columns. | ||
| 3442 | + if display_mode == ColumnDisplay::Tabbed | ||
| 3443 | + && !rv.options.tab_indicator.hide_when_single_tab | ||
| 3444 | + && !is_pending_fullscreen | ||
| 3445 | + { | ||
| 3446 | + // Usually new columns are created together with window movement actions. For new | ||
| 3447 | + // windows, we handle that in start_open_animation(). | ||
| 3448 | + rv.tab_indicator | ||
| 3449 | + .start_open_animation(rv.clock.clone(), rv.options.animations.window_movement.0); | ||
| 3450 | + } | ||
| 3451 | + | ||
| 3435 | rv | 3452 | rv |
| 3436 | } | 3453 | } |
| 3437 | 3454 | ||
| @@ -3499,10 +3516,14 @@ impl<W: LayoutElement> Column<W> { | |||
| 3499 | for tile in &mut self.tiles { | 3516 | for tile in &mut self.tiles { |
| 3500 | tile.advance_animations(); | 3517 | tile.advance_animations(); |
| 3501 | } | 3518 | } |
| 3519 | + | ||
| 3520 | + self.tab_indicator.advance_animations(); | ||
| 3502 | } | 3521 | } |
| 3503 | 3522 | ||
| 3504 | pub fn are_animations_ongoing(&self) -> bool { | 3523 | pub fn are_animations_ongoing(&self) -> bool { |
| 3505 | - self.move_animation.is_some() || self.tiles.iter().any(Tile::are_animations_ongoing) | 3524 | + self.move_animation.is_some() |
| 3525 | + || self.tab_indicator.are_animations_ongoing() | ||
| 3526 | + || self.tiles.iter().any(Tile::are_animations_ongoing) | ||
| 3506 | } | 3527 | } |
| 3507 | 3528 | ||
| 3508 | pub fn update_render_elements(&mut self, is_active: bool, view_rect: Rectangle<f64, Logical>) { | 3529 | pub fn update_render_elements(&mut self, is_active: bool, view_rect: Rectangle<f64, Logical>) { |
| @@ -4375,6 +4396,14 @@ impl<W: LayoutElement> Column<W> { | |||
| 4375 | } | 4396 | } |
| 4376 | } | 4397 | } |
| 4377 | 4398 | ||
| 4399 | + // Animate the appearance of the tab indicator. | ||
| 4400 | + if display == ColumnDisplay::Tabbed { | ||
| 4401 | + self.tab_indicator.start_open_animation( | ||
| 4402 | + self.clock.clone(), | ||
| 4403 | + self.options.animations.window_movement.0, | ||
| 4404 | + ); | ||
| 4405 | + } | ||
| 4406 | + | ||
| 4378 | // Now switch the display mode for real. | 4407 | // Now switch the display mode for real. |
| 4379 | self.display_mode = display; | 4408 | self.display_mode = display; |
| 4380 | self.update_tile_sizes(true); | 4409 | self.update_tile_sizes(true); |
| @@ -4555,6 +4584,30 @@ impl<W: LayoutElement> Column<W> { | |||
| 4555 | Rectangle::new(self.tiles_origin(), area_size) | 4584 | Rectangle::new(self.tiles_origin(), area_size) |
| 4556 | } | 4585 | } |
| 4557 | 4586 | ||
| 4587 | + pub fn start_open_animation(&mut self, id: &W::Id) -> bool { | ||
| 4588 | + for tile in &mut self.tiles { | ||
| 4589 | + if tile.window().id() == id { | ||
| 4590 | + tile.start_open_animation(); | ||
| 4591 | + | ||
| 4592 | + // Animate the appearance of the tab indicator. | ||
| 4593 | + if self.display_mode == ColumnDisplay::Tabbed | ||
| 4594 | + && !self.is_fullscreen | ||
| 4595 | + && self.tiles.len() == 1 | ||
| 4596 | + && !self.tab_indicator.config().hide_when_single_tab | ||
| 4597 | + { | ||
| 4598 | + self.tab_indicator.start_open_animation( | ||
| 4599 | + self.clock.clone(), | ||
| 4600 | + self.options.animations.window_open.anim, | ||
| 4601 | + ); | ||
| 4602 | + } | ||
| 4603 | + | ||
| 4604 | + return true; | ||
| 4605 | + } | ||
| 4606 | + } | ||
| 4607 | + | ||
| 4608 | + false | ||
| 4609 | + } | ||
| 4610 | + | ||
| 4558 | #[cfg(test)] | 4611 | #[cfg(test)] |
| 4559 | fn verify_invariants(&self) { | 4612 | fn verify_invariants(&self) { |
| 4560 | assert!(!self.tiles.is_empty(), "columns can't be empty"); | 4613 | assert!(!self.tiles.is_empty(), "columns can't be empty"); |
src/layout/tab_indicator.rsmodified+29 -1
| @@ -6,6 +6,7 @@ use smithay::utils::{Logical, Point, Rectangle, Size}; | |||
| 6 | 6 | ||
| 7 | use super::tile::Tile; | 7 | use super::tile::Tile; |
| 8 | use super::LayoutElement; | 8 | use super::LayoutElement; |
| 9 | +use crate::animation::{Animation, Clock}; | ||
| 9 | use crate::niri_render_elements; | 10 | use crate::niri_render_elements; |
| 10 | use crate::render_helpers::border::BorderRenderElement; | 11 | use crate::render_helpers::border::BorderRenderElement; |
| 11 | use crate::render_helpers::renderer::NiriRenderer; | 12 | use crate::render_helpers::renderer::NiriRenderer; |
| @@ -15,6 +16,7 @@ use crate::utils::{floor_logical_in_physical_max1, round_logical_in_physical}; | |||
| 15 | pub struct TabIndicator { | 16 | pub struct TabIndicator { |
| 16 | shader_locs: Vec<Point<f64, Logical>>, | 17 | shader_locs: Vec<Point<f64, Logical>>, |
| 17 | shaders: Vec<BorderRenderElement>, | 18 | shaders: Vec<BorderRenderElement>, |
| 19 | + open_anim: Option<Animation>, | ||
| 18 | config: niri_config::TabIndicator, | 20 | config: niri_config::TabIndicator, |
| 19 | } | 21 | } |
| 20 | 22 | ||
| @@ -37,6 +39,7 @@ impl TabIndicator { | |||
| 37 | Self { | 39 | Self { |
| 38 | shader_locs: Vec::new(), | 40 | shader_locs: Vec::new(), |
| 39 | shaders: Vec::new(), | 41 | shaders: Vec::new(), |
| 42 | + open_anim: None, | ||
| 40 | config, | 43 | config, |
| 41 | } | 44 | } |
| 42 | } | 45 | } |
| @@ -51,6 +54,22 @@ impl TabIndicator { | |||
| 51 | } | 54 | } |
| 52 | } | 55 | } |
| 53 | 56 | ||
| 57 | + pub fn advance_animations(&mut self) { | ||
| 58 | + if let Some(anim) = &mut self.open_anim { | ||
| 59 | + if anim.is_done() { | ||
| 60 | + self.open_anim = None; | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + pub fn are_animations_ongoing(&self) -> bool { | ||
| 66 | + self.open_anim.is_some() | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + pub fn start_open_animation(&mut self, clock: Clock, config: niri_config::Animation) { | ||
| 70 | + self.open_anim = Some(Animation::new(clock, 0., 1., 0., config)); | ||
| 71 | + } | ||
| 72 | + | ||
| 54 | fn tab_rects( | 73 | fn tab_rects( |
| 55 | &self, | 74 | &self, |
| 56 | area: Rectangle<f64, Logical>, | 75 | area: Rectangle<f64, Logical>, |
| @@ -59,6 +78,8 @@ impl TabIndicator { | |||
| 59 | ) -> impl Iterator<Item = Rectangle<f64, Logical>> { | 78 | ) -> impl Iterator<Item = Rectangle<f64, Logical>> { |
| 60 | let round = |logical: f64| round_logical_in_physical(scale, logical); | 79 | let round = |logical: f64| round_logical_in_physical(scale, logical); |
| 61 | 80 | ||
| 81 | + let progress = self.open_anim.as_ref().map_or(1., |a| a.value().max(0.)); | ||
| 82 | + | ||
| 62 | let width = round(self.config.width.0); | 83 | let width = round(self.config.width.0); |
| 63 | let gap = round(self.config.gap.0); | 84 | let gap = round(self.config.gap.0); |
| 64 | let gaps_between = round(self.config.gaps_between_tabs.0); | 85 | let gaps_between = round(self.config.gaps_between_tabs.0); |
| @@ -71,13 +92,20 @@ impl TabIndicator { | |||
| 71 | let total_prop = self.config.length.total_proportion.unwrap_or(0.5); | 92 | let total_prop = self.config.length.total_proportion.unwrap_or(0.5); |
| 72 | let min_length = round(side * total_prop.clamp(0., 2.)); | 93 | let min_length = round(side * total_prop.clamp(0., 2.)); |
| 73 | 94 | ||
| 95 | + // Compute px_per_tab before applying the animation to gaps_between in order to avoid it | ||
| 96 | + // growing and shrinking over the duration of the animation. | ||
| 74 | let pixel = 1. / scale; | 97 | let pixel = 1. / scale; |
| 75 | let shortest_length = count as f64 * (pixel + gaps_between) - gaps_between; | 98 | let shortest_length = count as f64 * (pixel + gaps_between) - gaps_between; |
| 76 | let length = f64::max(min_length, shortest_length); | 99 | let length = f64::max(min_length, shortest_length); |
| 77 | let px_per_tab = (length + gaps_between) / count as f64 - gaps_between; | 100 | let px_per_tab = (length + gaps_between) / count as f64 - gaps_between; |
| 101 | + | ||
| 102 | + let px_per_tab = px_per_tab * progress; | ||
| 103 | + let gaps_between = round(self.config.gaps_between_tabs.0 * progress); | ||
| 104 | + | ||
| 105 | + let length = count as f64 * (px_per_tab + gaps_between) - gaps_between; | ||
| 78 | let px_per_tab = floor_logical_in_physical_max1(scale, px_per_tab); | 106 | let px_per_tab = floor_logical_in_physical_max1(scale, px_per_tab); |
| 79 | let floored_length = count as f64 * (px_per_tab + gaps_between) - gaps_between; | 107 | let floored_length = count as f64 * (px_per_tab + gaps_between) - gaps_between; |
| 80 | - let mut ones_left = ((length - floored_length) / pixel).max(0.).round() as usize; | 108 | + let mut ones_left = ((length - floored_length) / pixel).round() as usize; |
| 81 | 109 | ||
| 82 | let mut shader_loc = Point::from((-gap - width, round((side - length) / 2.))); | 110 | let mut shader_loc = Point::from((-gap - width, round((side - length) / 2.))); |
| 83 | match position { | 111 | match position { |
src/layout/workspace.rsmodified+4 -0
| @@ -1474,6 +1474,10 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1474 | .start_close_animation_for_tile(renderer, snapshot, tile_size, tile_pos, blocker); | 1474 | .start_close_animation_for_tile(renderer, snapshot, tile_size, tile_pos, blocker); |
| 1475 | } | 1475 | } |
| 1476 | 1476 | ||
| 1477 | + pub fn start_open_animation(&mut self, id: &W::Id) -> bool { | ||
| 1478 | + self.scrolling.start_open_animation(id) || self.floating.start_open_animation(id) | ||
| 1479 | + } | ||
| 1480 | + | ||
| 1477 | pub fn window_under(&self, pos: Point<f64, Logical>) -> Option<(&W, HitType)> { | 1481 | pub fn window_under(&self, pos: Point<f64, Logical>) -> Option<(&W, HitType)> { |
| 1478 | // This logic is consistent with tiles_with_render_positions(). | 1482 | // This logic is consistent with tiles_with_render_positions(). |
| 1479 | if self.is_floating_visible() { | 1483 | if self.is_floating_visible() { |