From 3b4cf1ec8f0eea992740a33e143917edb761eb7d Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Thu, 25 Sep 2025 18:15:46 +0300 Subject: layout: Extract Monitor::remove_workspace_by_idx() --- src/layout/monitor.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/layout/monitor.rs') diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index 600907cc..3c258d49 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -604,6 +604,31 @@ impl Monitor { true } + pub fn remove_workspace_by_idx(&mut self, mut idx: usize) -> Workspace { + if idx == self.workspaces.len() - 1 { + self.add_workspace_bottom(); + } + if self.options.layout.empty_workspace_above_first && idx == 0 { + self.add_workspace_top(); + idx += 1; + } + + let mut ws = self.workspaces.remove(idx); + ws.set_output(None); + + // For monitor current workspace removal, we focus previous rather than next (<= rather + // than <). This is different from columns and tiles, but it lets move-workspace-to-monitor + // back and forth to preserve position. + if idx <= self.active_workspace_idx && self.active_workspace_idx > 0 { + self.active_workspace_idx -= 1; + } + + self.workspace_switch = None; + self.clean_up_workspaces(); + + ws + } + pub fn move_down_or_to_workspace_down(&mut self) { if !self.active_workspace().move_down() { self.move_to_workspace_down(true); -- cgit