Animate focus-workspace by idx/back and forth/previous
Browse files at this commit8eb34b2e185aa0e0affea450226369cd3f9e6a78Parent: 74d1b1f2 changed files +6 -43
- src/layout/mod.rs +2 -34
- src/layout/monitor.rs +4 -9
src/layout/mod.rsmodified+2 -34
| @@ -1011,7 +1011,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1011 | Some(WorkspaceSwitch::Gesture(gesture)) | 1011 | Some(WorkspaceSwitch::Gesture(gesture)) |
| 1012 | if gesture.current_idx.floor() == workspace_idx as f64 | 1012 | if gesture.current_idx.floor() == workspace_idx as f64 |
| 1013 | || gesture.current_idx.ceil() == workspace_idx as f64 => {} | 1013 | || gesture.current_idx.ceil() == workspace_idx as f64 => {} |
| 1014 | - _ => mon.switch_workspace(workspace_idx, true), | 1014 | + _ => mon.switch_workspace(workspace_idx), |
| 1015 | } | 1015 | } |
| 1016 | 1016 | ||
| 1017 | break; | 1017 | break; |
| @@ -1532,7 +1532,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1532 | let Some(monitor) = self.active_monitor() else { | 1532 | let Some(monitor) = self.active_monitor() else { |
| 1533 | return; | 1533 | return; |
| 1534 | }; | 1534 | }; |
| 1535 | - monitor.switch_workspace(idx, false); | 1535 | + monitor.switch_workspace(idx); |
| 1536 | } | 1536 | } |
| 1537 | 1537 | ||
| 1538 | pub fn switch_workspace_auto_back_and_forth(&mut self, idx: usize) { | 1538 | pub fn switch_workspace_auto_back_and_forth(&mut self, idx: usize) { |
| @@ -3776,38 +3776,6 @@ mod tests { | |||
| 3776 | assert!(monitors[0].workspaces[0].has_windows()); | 3776 | assert!(monitors[0].workspaces[0].has_windows()); |
| 3777 | } | 3777 | } |
| 3778 | 3778 | ||
| 3779 | - #[test] | ||
| 3780 | - fn focus_workspace_by_idx_does_not_leave_empty_workspaces() { | ||
| 3781 | - let ops = [ | ||
| 3782 | - Op::AddOutput(1), | ||
| 3783 | - Op::AddWindow { | ||
| 3784 | - id: 0, | ||
| 3785 | - bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), | ||
| 3786 | - min_max_size: Default::default(), | ||
| 3787 | - }, | ||
| 3788 | - Op::FocusWorkspaceDown, | ||
| 3789 | - Op::AddWindow { | ||
| 3790 | - id: 1, | ||
| 3791 | - bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), | ||
| 3792 | - min_max_size: Default::default(), | ||
| 3793 | - }, | ||
| 3794 | - Op::FocusWorkspaceUp, | ||
| 3795 | - Op::CloseWindow(0), | ||
| 3796 | - Op::FocusWorkspace(3), | ||
| 3797 | - ]; | ||
| 3798 | - | ||
| 3799 | - let mut layout = Layout::default(); | ||
| 3800 | - for op in ops { | ||
| 3801 | - op.apply(&mut layout); | ||
| 3802 | - } | ||
| 3803 | - | ||
| 3804 | - let MonitorSet::Normal { monitors, .. } = layout.monitor_set else { | ||
| 3805 | - unreachable!() | ||
| 3806 | - }; | ||
| 3807 | - | ||
| 3808 | - assert!(monitors[0].workspaces[0].has_windows()); | ||
| 3809 | - } | ||
| 3810 | - | ||
| 3811 | #[test] | 3779 | #[test] |
| 3812 | fn empty_workspaces_dont_move_back_to_original_output() { | 3780 | fn empty_workspaces_dont_move_back_to_original_output() { |
| 3813 | let ops = [ | 3781 | let ops = [ |
src/layout/monitor.rsmodified+4 -9
| @@ -594,13 +594,8 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 594 | self.workspaces.iter().position(|w| w.id() == id) | 594 | self.workspaces.iter().position(|w| w.id() == id) |
| 595 | } | 595 | } |
| 596 | 596 | ||
| 597 | - pub fn switch_workspace(&mut self, idx: usize, animate: bool) { | 597 | + pub fn switch_workspace(&mut self, idx: usize) { |
| 598 | self.activate_workspace(min(idx, self.workspaces.len() - 1)); | 598 | self.activate_workspace(min(idx, self.workspaces.len() - 1)); |
| 599 | - | ||
| 600 | - if !animate { | ||
| 601 | - self.workspace_switch = None; | ||
| 602 | - self.clean_up_workspaces(); | ||
| 603 | - } | ||
| 604 | } | 599 | } |
| 605 | 600 | ||
| 606 | pub fn switch_workspace_auto_back_and_forth(&mut self, idx: usize) { | 601 | pub fn switch_workspace_auto_back_and_forth(&mut self, idx: usize) { |
| @@ -608,16 +603,16 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 608 | 603 | ||
| 609 | if idx == self.active_workspace_idx { | 604 | if idx == self.active_workspace_idx { |
| 610 | if let Some(prev_idx) = self.previous_workspace_idx() { | 605 | if let Some(prev_idx) = self.previous_workspace_idx() { |
| 611 | - self.switch_workspace(prev_idx, false); | 606 | + self.switch_workspace(prev_idx); |
| 612 | } | 607 | } |
| 613 | } else { | 608 | } else { |
| 614 | - self.switch_workspace(idx, false); | 609 | + self.switch_workspace(idx); |
| 615 | } | 610 | } |
| 616 | } | 611 | } |
| 617 | 612 | ||
| 618 | pub fn switch_workspace_previous(&mut self) { | 613 | pub fn switch_workspace_previous(&mut self) { |
| 619 | if let Some(idx) = self.previous_workspace_idx() { | 614 | if let Some(idx) = self.previous_workspace_idx() { |
| 620 | - self.switch_workspace(idx, false); | 615 | + self.switch_workspace(idx); |
| 621 | } | 616 | } |
| 622 | } | 617 | } |
| 623 | 618 | ||