aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-09-25 18:15:46 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-10-02 09:33:08 +0300
commitd015c7e55bf455698cc4115af39549d9c8e20efc (patch)
treefe7da4667d00e0e0dd2eebd3997ed8897df2be41
parent1465cd4139ad136da637ce269fafe93eb1b8b17a (diff)
downloadniri-d015c7e55bf455698cc4115af39549d9c8e20efc.tar.gz
niri-d015c7e55bf455698cc4115af39549d9c8e20efc.tar.bz2
niri-d015c7e55bf455698cc4115af39549d9c8e20efc.zip
layout: Extract Monitor::append_workspaces()
-rw-r--r--src/layout/mod.rs40
-rw-r--r--src/layout/monitor.rs36
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<W: LayoutElement> Layout<W> {
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<W: LayoutElement> Layout<W> {
}
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<W: LayoutElement> Monitor<W> {
self.clean_up_workspaces();
}
+ pub fn append_workspaces(&mut self, mut workspaces: Vec<Workspace<W>>) {
+ 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);