From d015c7e55bf455698cc4115af39549d9c8e20efc Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Thu, 25 Sep 2025 18:15:46 +0300 Subject: [PATCH] layout: Extract Monitor::append_workspaces() --- src/layout/mod.rs | 40 ++-------------------------------------- src/layout/monitor.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/layout/mod.rs b/src/layout/mod.rs index dbbabc7d..b5b137ea 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -769,7 +769,7 @@ impl Layout { monitor.workspaces[monitor.active_workspace_idx].id(), ); - let mut workspaces = monitor.into_workspaces(); + let workspaces = monitor.into_workspaces(); if monitors.is_empty() { // Removed the last monitor. @@ -788,43 +788,7 @@ impl Layout { } let primary = &mut monitors[primary_idx]; - for ws in &mut workspaces { - ws.set_output(Some(primary.output.clone())); - } - - let mut stopped_primary_ws_switch = false; - if !workspaces.is_empty() && primary.workspace_switch.is_some() { - // FIXME: if we're adding workspaces to currently invisible positions - // (outside the workspace switch), we don't need to cancel it. - primary.workspace_switch = None; - stopped_primary_ws_switch = true; - } - - let empty_was_focused = - primary.active_workspace_idx == primary.workspaces.len() - 1; - - // Push the workspaces from the removed monitor in the end, right before the - // last, empty, workspace. - let empty = primary.workspaces.remove(primary.workspaces.len() - 1); - primary.workspaces.extend(workspaces); - primary.workspaces.push(empty); - - // If empty_workspace_above_first is set and the first workspace is now no - // longer empty, add a new empty workspace on top. - if primary.options.layout.empty_workspace_above_first - && primary.workspaces[0].has_windows_or_name() - { - primary.add_workspace_top(); - } - - // If the empty workspace was focused on the primary monitor, keep it focused. - if empty_was_focused { - primary.active_workspace_idx = primary.workspaces.len() - 1; - } - - if stopped_primary_ws_switch { - primary.clean_up_workspaces(); - } + primary.append_workspaces(workspaces); MonitorSet::Normal { monitors, diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index af3925bc..ec513857 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -690,6 +690,42 @@ impl Monitor { self.clean_up_workspaces(); } + pub fn append_workspaces(&mut self, mut workspaces: Vec>) { + if workspaces.is_empty() { + return; + } + + for ws in &mut workspaces { + ws.set_output(Some(self.output.clone())); + } + + let empty_was_focused = self.active_workspace_idx == self.workspaces.len() - 1; + + // Push the workspaces from the removed monitor in the end, right before the + // last, empty, workspace. + let empty = self.workspaces.remove(self.workspaces.len() - 1); + self.workspaces.extend(workspaces); + self.workspaces.push(empty); + + // If empty_workspace_above_first is set and the first workspace is now no longer empty, + // add a new empty workspace on top. + if self.options.layout.empty_workspace_above_first + && self.workspaces[0].has_windows_or_name() + { + self.add_workspace_top(); + } + + // If the empty workspace was focused on the primary monitor, keep it focused. + if empty_was_focused { + self.active_workspace_idx = self.workspaces.len() - 1; + } + + // FIXME: if we're adding workspaces to currently invisible positions + // (outside the workspace switch), we don't need to cancel it. + self.workspace_switch = None; + self.clean_up_workspaces(); + } + pub fn move_down_or_to_workspace_down(&mut self) { if !self.active_workspace().move_down() { self.move_to_workspace_down(true);