layout: Replace move_to_workspace_up/down with move_to_workspace
Browse files at this commitb537dda4d0afa428a2dc63c11825fff78de5ba7fParent: 76a901b2 changed files +30 -68
- src/layout/mod.rs +12 -2
- src/layout/monitor.rs +18 -66
src/layout/mod.rsmodified+12 -2
| @@ -2107,14 +2107,24 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2107 | let Some(monitor) = self.active_monitor() else { | 2107 | let Some(monitor) = self.active_monitor() else { |
| 2108 | return; | 2108 | return; |
| 2109 | }; | 2109 | }; |
| 2110 | - monitor.move_to_workspace_up(focus); | 2110 | + let activate = if focus { |
| 2111 | + ActivateWindow::Smart | ||
| 2112 | + } else { | ||
| 2113 | + ActivateWindow::No | ||
| 2114 | + }; | ||
| 2115 | + monitor.move_to_workspace_up(activate); | ||
| 2111 | } | 2116 | } |
| 2112 | 2117 | ||
| 2113 | pub fn move_to_workspace_down(&mut self, focus: bool) { | 2118 | pub fn move_to_workspace_down(&mut self, focus: bool) { |
| 2114 | let Some(monitor) = self.active_monitor() else { | 2119 | let Some(monitor) = self.active_monitor() else { |
| 2115 | return; | 2120 | return; |
| 2116 | }; | 2121 | }; |
| 2117 | - monitor.move_to_workspace_down(focus); | 2122 | + let activate = if focus { |
| 2123 | + ActivateWindow::Smart | ||
| 2124 | + } else { | ||
| 2125 | + ActivateWindow::No | ||
| 2126 | + }; | ||
| 2127 | + monitor.move_to_workspace_down(activate); | ||
| 2118 | } | 2128 | } |
| 2119 | 2129 | ||
| 2120 | pub fn move_to_workspace( | 2130 | pub fn move_to_workspace( |
src/layout/monitor.rsmodified+18 -66
| @@ -760,13 +760,13 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 760 | 760 | ||
| 761 | pub fn move_down_or_to_workspace_down(&mut self) { | 761 | pub fn move_down_or_to_workspace_down(&mut self) { |
| 762 | if !self.active_workspace().move_down() { | 762 | if !self.active_workspace().move_down() { |
| 763 | - self.move_to_workspace_down(true); | 763 | + self.move_to_workspace_down(ActivateWindow::Smart); |
| 764 | } | 764 | } |
| 765 | } | 765 | } |
| 766 | 766 | ||
| 767 | pub fn move_up_or_to_workspace_up(&mut self) { | 767 | pub fn move_up_or_to_workspace_up(&mut self) { |
| 768 | if !self.active_workspace().move_up() { | 768 | if !self.active_workspace().move_up() { |
| 769 | - self.move_to_workspace_up(true); | 769 | + self.move_to_workspace_up(ActivateWindow::Smart); |
| 770 | } | 770 | } |
| 771 | } | 771 | } |
| 772 | 772 | ||
| @@ -782,72 +782,14 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 782 | } | 782 | } |
| 783 | } | 783 | } |
| 784 | 784 | ||
| 785 | - pub fn move_to_workspace_up(&mut self, focus: bool) { | 785 | + pub fn move_to_workspace_up(&mut self, activate: ActivateWindow) { |
| 786 | - let source_workspace_idx = self.active_workspace_idx; | 786 | + let new_idx = self.active_workspace_idx.saturating_sub(1); |
| 787 | - | 787 | + self.move_to_workspace(None, new_idx, activate); |
| 788 | - let new_idx = source_workspace_idx.saturating_sub(1); | ||
| 789 | - if new_idx == source_workspace_idx { | ||
| 790 | - return; | ||
| 791 | - } | ||
| 792 | - let new_id = self.workspaces[new_idx].id(); | ||
| 793 | - | ||
| 794 | - let workspace = &mut self.workspaces[source_workspace_idx]; | ||
| 795 | - let Some(removed) = workspace.remove_active_tile(Transaction::new()) else { | ||
| 796 | - return; | ||
| 797 | - }; | ||
| 798 | - | ||
| 799 | - let activate = if focus { | ||
| 800 | - ActivateWindow::Yes | ||
| 801 | - } else { | ||
| 802 | - ActivateWindow::Smart | ||
| 803 | - }; | ||
| 804 | - | ||
| 805 | - self.add_tile( | ||
| 806 | - removed.tile, | ||
| 807 | - MonitorAddWindowTarget::Workspace { | ||
| 808 | - id: new_id, | ||
| 809 | - column_idx: None, | ||
| 810 | - }, | ||
| 811 | - activate, | ||
| 812 | - true, | ||
| 813 | - removed.width, | ||
| 814 | - removed.is_full_width, | ||
| 815 | - removed.is_floating, | ||
| 816 | - ); | ||
| 817 | } | 788 | } |
| 818 | 789 | ||
| 819 | - pub fn move_to_workspace_down(&mut self, focus: bool) { | 790 | + pub fn move_to_workspace_down(&mut self, activate: ActivateWindow) { |
| 820 | - let source_workspace_idx = self.active_workspace_idx; | 791 | + let new_idx = min(self.active_workspace_idx + 1, self.workspaces.len() - 1); |
| 821 | - | 792 | + self.move_to_workspace(None, new_idx, activate); |
| 822 | - let new_idx = min(source_workspace_idx + 1, self.workspaces.len() - 1); | ||
| 823 | - if new_idx == source_workspace_idx { | ||
| 824 | - return; | ||
| 825 | - } | ||
| 826 | - let new_id = self.workspaces[new_idx].id(); | ||
| 827 | - | ||
| 828 | - let workspace = &mut self.workspaces[source_workspace_idx]; | ||
| 829 | - let Some(removed) = workspace.remove_active_tile(Transaction::new()) else { | ||
| 830 | - return; | ||
| 831 | - }; | ||
| 832 | - | ||
| 833 | - let activate = if focus { | ||
| 834 | - ActivateWindow::Yes | ||
| 835 | - } else { | ||
| 836 | - ActivateWindow::Smart | ||
| 837 | - }; | ||
| 838 | - | ||
| 839 | - self.add_tile( | ||
| 840 | - removed.tile, | ||
| 841 | - MonitorAddWindowTarget::Workspace { | ||
| 842 | - id: new_id, | ||
| 843 | - column_idx: None, | ||
| 844 | - }, | ||
| 845 | - activate, | ||
| 846 | - true, | ||
| 847 | - removed.width, | ||
| 848 | - removed.is_full_width, | ||
| 849 | - removed.is_floating, | ||
| 850 | - ); | ||
| 851 | } | 793 | } |
| 852 | 794 | ||
| 853 | pub fn move_to_workspace( | 795 | pub fn move_to_workspace( |
| @@ -917,6 +859,11 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 917 | 859 | ||
| 918 | let workspace = &mut self.workspaces[source_workspace_idx]; | 860 | let workspace = &mut self.workspaces[source_workspace_idx]; |
| 919 | if workspace.floating_is_active() { | 861 | if workspace.floating_is_active() { |
| 862 | + let activate = if activate { | ||
| 863 | + ActivateWindow::Smart | ||
| 864 | + } else { | ||
| 865 | + ActivateWindow::No | ||
| 866 | + }; | ||
| 920 | self.move_to_workspace_up(activate); | 867 | self.move_to_workspace_up(activate); |
| 921 | return; | 868 | return; |
| 922 | } | 869 | } |
| @@ -938,6 +885,11 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 938 | 885 | ||
| 939 | let workspace = &mut self.workspaces[source_workspace_idx]; | 886 | let workspace = &mut self.workspaces[source_workspace_idx]; |
| 940 | if workspace.floating_is_active() { | 887 | if workspace.floating_is_active() { |
| 888 | + let activate = if activate { | ||
| 889 | + ActivateWindow::Smart | ||
| 890 | + } else { | ||
| 891 | + ActivateWindow::No | ||
| 892 | + }; | ||
| 941 | self.move_to_workspace_down(activate); | 893 | self.move_to_workspace_down(activate); |
| 942 | return; | 894 | return; |
| 943 | } | 895 | } |