Add view anim functions with config argument
Browse files at this commit7ca39baf9e54103e4f0dc3efae59284662055870Parent: 73e9ef51 changed file +71 -27
- src/layout/workspace.rs +71 -27
src/layout/workspace.rsmodified+71 -27
| @@ -501,6 +501,21 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 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 | 519 | let new_col_x = self.column_x(idx); |
| 505 | 520 | let from_view_offset = current_x - new_col_x; |
| 506 | 521 | self.view_offset = from_view_offset; |
| @@ -525,23 +540,33 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 525 | 540 | self.view_offset as f64, |
| 526 | 541 | new_view_offset as f64, |
| 527 | 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 | 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 | 563 | if self.columns.is_empty() { |
| 539 | 564 | return; |
| 540 | 565 | } |
| 541 | 566 | |
| 542 | 567 | let col = &self.columns[idx]; |
| 543 | 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 | 570 | return; |
| 546 | 571 | } |
| 547 | 572 | |
| @@ -551,13 +576,13 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 551 | 576 | // edge alignment by the usual positioning code, so there's no use in trying to center it |
| 552 | 577 | // here. |
| 553 | 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 | 580 | return; |
| 556 | 581 | } |
| 557 | 582 | |
| 558 | 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 | 588 | fn animate_view_offset_to_column( |
| @@ -565,14 +590,29 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 565 | 590 | current_x: i32, |
| 566 | 591 | idx: usize, |
| 567 | 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 | 609 | match self.options.center_focused_column { |
| 570 | 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 | 613 | CenterFocusedColumn::OnOverflow => { |
| 574 | 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 | 616 | return; |
| 577 | 617 | }; |
| 578 | 618 | |
| @@ -599,12 +639,14 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 599 | 639 | |
| 600 | 640 | // If it fits together, do a normal animation, otherwise center the new column. |
| 601 | 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 | 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 | 1068 | column.update_tile_sizes(false); |
| 1027 | 1069 | |
| 1028 | 1070 | // 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 { | |
| 1031 | 1074 | if self.active_column_idx <= col_idx { |
| 1032 | 1075 | for col in &mut self.columns[col_idx + 1..] { |
| 1033 | 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 | 1113 | // FIXME: we will want to skip the animation in some cases here to make continuously |
| 1063 | 1114 | // 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); | |
| 1076 | 1116 | } |
| 1077 | 1117 | } |
| 1078 | 1118 | |
| @@ -1517,7 +1557,11 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 1517 | 1557 | |
| 1518 | 1558 | pub fn center_column(&mut self) { |
| 1519 | 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 | 1567 | fn view_pos(&self) -> i32 { |