forge
Explore
Log in

Don't you dare go Hollow

Add view anim functions with config argument

Browse files at this commit

7ca39baf9e54103e4f0dc3efae59284662055870Ivan MolodetskikhParent: 73e9ef5
src/layout/workspace.rsmodified+71 -27
@@ -501,6 +501,21 @@ impl<W: LayoutElement> Workspace<W> {
501501 }
502502
503503 fn animate_view_offset(&mut self, current_x: i32, idx: usize, new_view_offset: i32) {
504+ self.animate_view_offset_with_config(
505+ current_x,
506+ idx,
507+ new_view_offset,
508+ self.options.animations.horizontal_view_movement.0,
509+ );
510+ }
511+
512+ fn animate_view_offset_with_config(
513+ &mut self,
514+ current_x: i32,
515+ idx: usize,
516+ new_view_offset: i32,
517+ config: niri_config::Animation,
518+ ) {
504519 let new_col_x = self.column_x(idx);
505520 let from_view_offset = current_x - new_col_x;
506521 self.view_offset = from_view_offset;
@@ -525,23 +540,33 @@ impl<W: LayoutElement> Workspace<W> {
525540 self.view_offset as f64,
526541 new_view_offset as f64,
527542 0.,
528- self.options.animations.horizontal_view_movement.0,
543+ config,
529544 )));
530545 }
531546
532- fn animate_view_offset_to_column_fit(&mut self, current_x: i32, idx: usize) {
547+ fn animate_view_offset_to_column_fit(
548+ &mut self,
549+ current_x: i32,
550+ idx: usize,
551+ config: niri_config::Animation,
552+ ) {
533553 let new_view_offset = self.compute_new_view_offset_for_column(current_x, idx);
534- self.animate_view_offset(current_x, idx, new_view_offset);
554+ self.animate_view_offset_with_config(current_x, idx, new_view_offset, config);
535555 }
536556
537- fn animate_view_offset_to_column_centered(&mut self, current_x: i32, idx: usize) {
557+ fn animate_view_offset_to_column_centered(
558+ &mut self,
559+ current_x: i32,
560+ idx: usize,
561+ config: niri_config::Animation,
562+ ) {
538563 if self.columns.is_empty() {
539564 return;
540565 }
541566
542567 let col = &self.columns[idx];
543568 if col.is_fullscreen {
544- self.animate_view_offset_to_column_fit(current_x, idx);
569+ self.animate_view_offset_to_column_fit(current_x, idx, config);
545570 return;
546571 }
547572
@@ -551,13 +576,13 @@ impl<W: LayoutElement> Workspace<W> {
551576 // edge alignment by the usual positioning code, so there's no use in trying to center it
552577 // here.
553578 if self.working_area.size.w <= width {
554- self.animate_view_offset_to_column_fit(current_x, idx);
579+ self.animate_view_offset_to_column_fit(current_x, idx, config);
555580 return;
556581 }
557582
558583 let new_view_offset = -(self.working_area.size.w - width) / 2 - self.working_area.loc.x;
559584
560- self.animate_view_offset(current_x, idx, new_view_offset);
585+ self.animate_view_offset_with_config(current_x, idx, new_view_offset, config);
561586 }
562587
563588 fn animate_view_offset_to_column(
@@ -565,14 +590,29 @@ impl<W: LayoutElement> Workspace<W> {
565590 current_x: i32,
566591 idx: usize,
567592 prev_idx: Option<usize>,
593+ ) {
594+ self.animate_view_offset_to_column_with_config(
595+ current_x,
596+ idx,
597+ prev_idx,
598+ self.options.animations.horizontal_view_movement.0,
599+ )
600+ }
601+
602+ fn animate_view_offset_to_column_with_config(
603+ &mut self,
604+ current_x: i32,
605+ idx: usize,
606+ prev_idx: Option<usize>,
607+ config: niri_config::Animation,
568608 ) {
569609 match self.options.center_focused_column {
570610 CenterFocusedColumn::Always => {
571- self.animate_view_offset_to_column_centered(current_x, idx)
611+ self.animate_view_offset_to_column_centered(current_x, idx, config)
572612 }
573613 CenterFocusedColumn::OnOverflow => {
574614 let Some(prev_idx) = prev_idx else {
575- self.animate_view_offset_to_column_fit(current_x, idx);
615+ self.animate_view_offset_to_column_fit(current_x, idx, config);
576616 return;
577617 };
578618
@@ -599,12 +639,14 @@ impl<W: LayoutElement> Workspace<W> {
599639
600640 // If it fits together, do a normal animation, otherwise center the new column.
601641 if total_width <= self.working_area.size.w {
602- self.animate_view_offset_to_column_fit(current_x, idx);
642+ self.animate_view_offset_to_column_fit(current_x, idx, config);
603643 } else {
604- self.animate_view_offset_to_column_centered(current_x, idx);
644+ self.animate_view_offset_to_column_centered(current_x, idx, config);
605645 }
606646 }
607- CenterFocusedColumn::Never => self.animate_view_offset_to_column_fit(current_x, idx),
647+ CenterFocusedColumn::Never => {
648+ self.animate_view_offset_to_column_fit(current_x, idx, config)
649+ }
608650 };
609651 }
610652
@@ -1026,8 +1068,9 @@ impl<W: LayoutElement> Workspace<W> {
10261068 column.update_tile_sizes(false);
10271069
10281070 // Move other columns in tandem with resizing.
1029- let started_animation = column.tiles[tile_idx].resize_animation().is_some() && offset != 0;
1030- if started_animation {
1071+ let started_resize_anim =
1072+ column.tiles[tile_idx].resize_animation().is_some() && offset != 0;
1073+ if started_resize_anim {
10311074 if self.active_column_idx <= col_idx {
10321075 for col in &mut self.columns[col_idx + 1..] {
10331076 col.animate_move_from_with_config(
@@ -1059,20 +1102,17 @@ impl<W: LayoutElement> Workspace<W> {
10591102 }
10601103 }
10611104
1105+ // Synchronize the horizontal view movement with the resize so that it looks nice. This
1106+ // is especially important for always-centered view.
1107+ let config = if started_resize_anim {
1108+ self.options.animations.window_resize.0
1109+ } else {
1110+ self.options.animations.horizontal_view_movement.0
1111+ };
1112+
10621113 // FIXME: we will want to skip the animation in some cases here to make continuously
10631114 // resizing windows not look janky.
1064- self.animate_view_offset_to_column(current_x, col_idx, None);
1065-
1066- // If this animated resize caused a view animation, make sure that it uses the same
1067- // config. This is important for always-centered view.
1068- if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj {
1069- // FIXME: animate_view_offset_to_column() will keep the previous running view
1070- // offset animation if the target was the same; maybe we shouldn't replace in this
1071- // case?
1072- if started_animation {
1073- anim.replace_config(self.options.animations.window_resize.0);
1074- }
1075- }
1115+ self.animate_view_offset_to_column_with_config(current_x, col_idx, None, config);
10761116 }
10771117 }
10781118
@@ -1517,7 +1557,11 @@ impl<W: LayoutElement> Workspace<W> {
15171557
15181558 pub fn center_column(&mut self) {
15191559 let center_x = self.view_pos();
1520- self.animate_view_offset_to_column_centered(center_x, self.active_column_idx);
1560+ self.animate_view_offset_to_column_centered(
1561+ center_x,
1562+ self.active_column_idx,
1563+ self.options.animations.horizontal_view_movement.0,
1564+ );
15211565 }
15221566
15231567 fn view_pos(&self) -> i32 {