layout: Extract Monitor::append_workspaces()
Browse files at this commitd015c7e55bf455698cc4115af39549d9c8e20efcParent: 1465cd42 changed files +38 -38
- src/layout/mod.rs +2 -38
- src/layout/monitor.rs +36 -0
src/layout/mod.rsmodified+2 -38
| @@ -769,7 +769,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 769 | 769 | monitor.workspaces[monitor.active_workspace_idx].id(), |
| 770 | 770 | ); |
| 771 | 771 | |
| 772 | - let mut workspaces = monitor.into_workspaces(); | |
| 772 | + let workspaces = monitor.into_workspaces(); | |
| 773 | 773 | |
| 774 | 774 | if monitors.is_empty() { |
| 775 | 775 | // Removed the last monitor. |
| @@ -788,43 +788,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 788 | 788 | } |
| 789 | 789 | |
| 790 | 790 | let primary = &mut monitors[primary_idx]; |
| 791 | - for ws in &mut workspaces { | |
| 792 | - ws.set_output(Some(primary.output.clone())); | |
| 793 | - } | |
| 794 | - | |
| 795 | - let mut stopped_primary_ws_switch = false; | |
| 796 | - if !workspaces.is_empty() && primary.workspace_switch.is_some() { | |
| 797 | - // FIXME: if we're adding workspaces to currently invisible positions | |
| 798 | - // (outside the workspace switch), we don't need to cancel it. | |
| 799 | - primary.workspace_switch = None; | |
| 800 | - stopped_primary_ws_switch = true; | |
| 801 | - } | |
| 802 | - | |
| 803 | - let empty_was_focused = | |
| 804 | - primary.active_workspace_idx == primary.workspaces.len() - 1; | |
| 805 | - | |
| 806 | - // Push the workspaces from the removed monitor in the end, right before the | |
| 807 | - // last, empty, workspace. | |
| 808 | - let empty = primary.workspaces.remove(primary.workspaces.len() - 1); | |
| 809 | - primary.workspaces.extend(workspaces); | |
| 810 | - primary.workspaces.push(empty); | |
| 811 | - | |
| 812 | - // If empty_workspace_above_first is set and the first workspace is now no | |
| 813 | - // longer empty, add a new empty workspace on top. | |
| 814 | - if primary.options.layout.empty_workspace_above_first | |
| 815 | - && primary.workspaces[0].has_windows_or_name() | |
| 816 | - { | |
| 817 | - primary.add_workspace_top(); | |
| 818 | - } | |
| 819 | - | |
| 820 | - // If the empty workspace was focused on the primary monitor, keep it focused. | |
| 821 | - if empty_was_focused { | |
| 822 | - primary.active_workspace_idx = primary.workspaces.len() - 1; | |
| 823 | - } | |
| 824 | - | |
| 825 | - if stopped_primary_ws_switch { | |
| 826 | - primary.clean_up_workspaces(); | |
| 827 | - } | |
| 791 | + primary.append_workspaces(workspaces); | |
| 828 | 792 | |
| 829 | 793 | MonitorSet::Normal { |
| 830 | 794 | monitors, |
src/layout/monitor.rsmodified+36 -0
| @@ -690,6 +690,42 @@ impl<W: LayoutElement> Monitor<W> { | ||
| 690 | 690 | self.clean_up_workspaces(); |
| 691 | 691 | } |
| 692 | 692 | |
| 693 | + pub fn append_workspaces(&mut self, mut workspaces: Vec<Workspace<W>>) { | |
| 694 | + if workspaces.is_empty() { | |
| 695 | + return; | |
| 696 | + } | |
| 697 | + | |
| 698 | + for ws in &mut workspaces { | |
| 699 | + ws.set_output(Some(self.output.clone())); | |
| 700 | + } | |
| 701 | + | |
| 702 | + let empty_was_focused = self.active_workspace_idx == self.workspaces.len() - 1; | |
| 703 | + | |
| 704 | + // Push the workspaces from the removed monitor in the end, right before the | |
| 705 | + // last, empty, workspace. | |
| 706 | + let empty = self.workspaces.remove(self.workspaces.len() - 1); | |
| 707 | + self.workspaces.extend(workspaces); | |
| 708 | + self.workspaces.push(empty); | |
| 709 | + | |
| 710 | + // If empty_workspace_above_first is set and the first workspace is now no longer empty, | |
| 711 | + // add a new empty workspace on top. | |
| 712 | + if self.options.layout.empty_workspace_above_first | |
| 713 | + && self.workspaces[0].has_windows_or_name() | |
| 714 | + { | |
| 715 | + self.add_workspace_top(); | |
| 716 | + } | |
| 717 | + | |
| 718 | + // If the empty workspace was focused on the primary monitor, keep it focused. | |
| 719 | + if empty_was_focused { | |
| 720 | + self.active_workspace_idx = self.workspaces.len() - 1; | |
| 721 | + } | |
| 722 | + | |
| 723 | + // FIXME: if we're adding workspaces to currently invisible positions | |
| 724 | + // (outside the workspace switch), we don't need to cancel it. | |
| 725 | + self.workspace_switch = None; | |
| 726 | + self.clean_up_workspaces(); | |
| 727 | + } | |
| 728 | + | |
| 693 | 729 | pub fn move_down_or_to_workspace_down(&mut self) { |
| 694 | 730 | if !self.active_workspace().move_down() { |
| 695 | 731 | self.move_to_workspace_down(true); |