diff options
Diffstat (limited to 'src/layout/monitor.rs')
| -rw-r--r-- | src/layout/monitor.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index 8bb92a33..3eaac97f 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -858,6 +858,53 @@ impl<W: LayoutElement> Monitor<W> { self.clean_up_workspaces(); } + pub fn move_workspace_to_idx(&mut self, old_idx: usize, new_idx: usize) { + let mut new_idx = new_idx.clamp(0, self.workspaces.len() - 1); + if old_idx == new_idx { + return; + } + + let ws = self.workspaces.remove(old_idx); + self.workspaces.insert(new_idx, ws); + + if new_idx > old_idx { + if new_idx == self.workspaces.len() - 1 { + // Insert a new empty workspace. + self.add_workspace_bottom(); + } + + if self.options.empty_workspace_above_first && old_idx == 0 { + self.add_workspace_top(); + new_idx += 1; + } + } else { + if old_idx == self.workspaces.len() - 1 { + // Insert a new empty workspace. + self.add_workspace_bottom(); + } + + if self.options.empty_workspace_above_first && new_idx == 0 { + self.add_workspace_top(); + new_idx += 1; + } + } + + // Only refocus the workspace if it was already focused + if self.active_workspace_idx == old_idx { + self.active_workspace_idx = new_idx; + // If the workspace order was switched so that the current workspace moved down the + // workspace stack, focus correctly + } else if new_idx <= self.active_workspace_idx && old_idx > self.active_workspace_idx { + self.active_workspace_idx += 1; + } else if new_idx >= self.active_workspace_idx && old_idx < self.active_workspace_idx { + self.active_workspace_idx = self.active_workspace_idx.saturating_sub(1); + } + + self.workspace_switch = None; + + self.clean_up_workspaces(); + } + /// Returns the geometry of the active tile relative to and clamped to the output. /// /// During animations, assumes the final view position. |
