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> {
501 }501 }
502 502
503 fn animate_view_offset(&mut self, current_x: i32, idx: usize, new_view_offset: i32) {503 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+ ) {
504 let new_col_x = self.column_x(idx);519 let new_col_x = self.column_x(idx);
505 let from_view_offset = current_x - new_col_x;520 let from_view_offset = current_x - new_col_x;
506 self.view_offset = from_view_offset;521 self.view_offset = from_view_offset;
@@ -525,23 +540,33 @@ impl<W: LayoutElement> Workspace<W> {
525 self.view_offset as f64,540 self.view_offset as f64,
526 new_view_offset as f64,541 new_view_offset as f64,
527 0.,542 0.,
528- self.options.animations.horizontal_view_movement.0,543+ config,
529 )));544 )));
530 }545 }
531 546
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+ ) {
533 let new_view_offset = self.compute_new_view_offset_for_column(current_x, idx);553 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);
535 }555 }
536 556
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+ ) {
538 if self.columns.is_empty() {563 if self.columns.is_empty() {
539 return;564 return;
540 }565 }
541 566
542 let col = &self.columns[idx];567 let col = &self.columns[idx];
543 if col.is_fullscreen {568 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);
545 return;570 return;
546 }571 }
547 572
@@ -551,13 +576,13 @@ impl<W: LayoutElement> Workspace<W> {
551 // edge alignment by the usual positioning code, so there's no use in trying to center it576 // edge alignment by the usual positioning code, so there's no use in trying to center it
552 // here.577 // here.
553 if self.working_area.size.w <= width {578 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);
555 return;580 return;
556 }581 }
557 582
558 let new_view_offset = -(self.working_area.size.w - width) / 2 - self.working_area.loc.x;583 let new_view_offset = -(self.working_area.size.w - width) / 2 - self.working_area.loc.x;
559 584
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);
561 }586 }
562 587
563 fn animate_view_offset_to_column(588 fn animate_view_offset_to_column(
@@ -565,14 +590,29 @@ impl<W: LayoutElement> Workspace<W> {
565 current_x: i32,590 current_x: i32,
566 idx: usize,591 idx: usize,
567 prev_idx: Option<usize>,592 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,
568 ) {608 ) {
569 match self.options.center_focused_column {609 match self.options.center_focused_column {
570 CenterFocusedColumn::Always => {610 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)
572 }612 }
573 CenterFocusedColumn::OnOverflow => {613 CenterFocusedColumn::OnOverflow => {
574 let Some(prev_idx) = prev_idx else {614 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);
576 return;616 return;
577 };617 };
578 618
@@ -599,12 +639,14 @@ impl<W: LayoutElement> Workspace<W> {
599 639
600 // If it fits together, do a normal animation, otherwise center the new column.640 // If it fits together, do a normal animation, otherwise center the new column.
601 if total_width <= self.working_area.size.w {641 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);
603 } else {643 } else {
604- self.animate_view_offset_to_column_centered(current_x, idx);644+ self.animate_view_offset_to_column_centered(current_x, idx, config);
605 }645 }
606 }646 }
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+ }
608 };650 };
609 }651 }
610 652
@@ -1026,8 +1068,9 @@ impl<W: LayoutElement> Workspace<W> {
1026 column.update_tile_sizes(false);1068 column.update_tile_sizes(false);
1027 1069
1028 // Move other columns in tandem with resizing.1070 // Move other columns in tandem with resizing.
1029- let started_animation = column.tiles[tile_idx].resize_animation().is_some() && offset != 0;1071+ let started_resize_anim =
1030- if started_animation {1072+ column.tiles[tile_idx].resize_animation().is_some() && offset != 0;
1073+ if started_resize_anim {
1031 if self.active_column_idx <= col_idx {1074 if self.active_column_idx <= col_idx {
1032 for col in &mut self.columns[col_idx + 1..] {1075 for col in &mut self.columns[col_idx + 1..] {
1033 col.animate_move_from_with_config(1076 col.animate_move_from_with_config(
@@ -1059,20 +1102,17 @@ impl<W: LayoutElement> Workspace<W> {
1059 }1102 }
1060 }1103 }
1061 1104
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+
1062 // FIXME: we will want to skip the animation in some cases here to make continuously1113 // FIXME: we will want to skip the animation in some cases here to make continuously
1063 // resizing windows not look janky.1114 // resizing windows not look janky.
1064- self.animate_view_offset_to_column(current_x, col_idx, None);1115+ self.animate_view_offset_to_column_with_config(current_x, col_idx, None, config);
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- }
1076 }1116 }
1077 }1117 }
1078 1118
@@ -1517,7 +1557,11 @@ impl<W: LayoutElement> Workspace<W> {
1517 1557
1518 pub fn center_column(&mut self) {1558 pub fn center_column(&mut self) {
1519 let center_x = self.view_pos();1559 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+ );
1521 }1565 }
1522 1566
1523 fn view_pos(&self) -> i32 {1567 fn view_pos(&self) -> i32 {