aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-09-26 15:49:05 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-10-02 09:33:08 +0300
commit1465cd4139ad136da637ce269fafe93eb1b8b17a (patch)
treee0dbdfff4b3324aa9e92481ee876ac1c35f383d4 /src
parent7fc544b9d67229008bd4b6f85f110a7a9361aa08 (diff)
downloadniri-1465cd4139ad136da637ce269fafe93eb1b8b17a.tar.gz
niri-1465cd4139ad136da637ce269fafe93eb1b8b17a.tar.bz2
niri-1465cd4139ad136da637ce269fafe93eb1b8b17a.zip
layout: Move empty workspace handling to Monitor::new()
Diffstat (limited to 'src')
-rw-r--r--src/layout/mod.rs73
-rw-r--r--src/layout/monitor.rs27
2 files changed, 39 insertions, 61 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index e771a450..dbbabc7d 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -654,9 +654,6 @@ impl<W: LayoutElement> Layout<W> {
} => {
let primary = &mut monitors[primary_idx];
- let ws_id_to_activate = self.last_active_workspace_id.remove(&output.name());
- let mut active_workspace_idx = None;
-
let mut stopped_primary_ws_switch = false;
let mut workspaces = vec![];
@@ -676,10 +673,6 @@ impl<W: LayoutElement> Layout<W> {
// another monitor. However, we will add an empty workspace in the end
// instead.
if ws.has_windows_or_name() {
- if Some(ws.id()) == ws_id_to_activate {
- active_workspace_idx = Some(workspaces.len());
- }
-
workspaces.push(ws);
}
@@ -717,33 +710,15 @@ impl<W: LayoutElement> Layout<W> {
workspaces.reverse();
- if let Some(idx) = &mut active_workspace_idx {
- *idx = workspaces.len() - *idx - 1;
- }
- let mut active_workspace_idx = active_workspace_idx.unwrap_or(0);
+ let ws_id_to_activate = self.last_active_workspace_id.remove(&output.name());
- // Make sure there's always an empty workspace.
- workspaces.push(Workspace::new(
- output.clone(),
+ let mut monitor = Monitor::new(
+ output,
+ workspaces,
+ ws_id_to_activate,
self.clock.clone(),
self.options.clone(),
- ));
-
- if self.options.layout.empty_workspace_above_first && workspaces.len() > 1 {
- workspaces.insert(
- 0,
- Workspace::new(output.clone(), self.clock.clone(), self.options.clone()),
- );
- active_workspace_idx += 1;
- }
-
- for ws in &mut workspaces {
- ws.set_output(Some(output.clone()));
- }
-
- let mut monitor =
- Monitor::new(output, workspaces, self.clock.clone(), self.options.clone());
- monitor.active_workspace_idx = active_workspace_idx;
+ );
monitor.overview_open = self.overview_open;
monitor.set_overview_progress(self.overview_progress.as_ref());
monitors.push(monitor);
@@ -754,36 +729,16 @@ impl<W: LayoutElement> Layout<W> {
active_monitor_idx,
}
}
- MonitorSet::NoOutputs { mut workspaces } => {
- // We know there are no empty workspaces there, so add one.
- workspaces.push(Workspace::new(
- output.clone(),
- self.clock.clone(),
- self.options.clone(),
- ));
-
- let mut active_workspace_idx = 0;
- if self.options.layout.empty_workspace_above_first && workspaces.len() > 1 {
- workspaces.insert(
- 0,
- Workspace::new(output.clone(), self.clock.clone(), self.options.clone()),
- );
- active_workspace_idx += 1;
- }
-
+ MonitorSet::NoOutputs { workspaces } => {
let ws_id_to_activate = self.last_active_workspace_id.remove(&output.name());
- for (i, workspace) in workspaces.iter_mut().enumerate() {
- workspace.set_output(Some(output.clone()));
-
- if Some(workspace.id()) == ws_id_to_activate {
- active_workspace_idx = i;
- }
- }
-
- let mut monitor =
- Monitor::new(output, workspaces, self.clock.clone(), self.options.clone());
- monitor.active_workspace_idx = active_workspace_idx;
+ let mut monitor = Monitor::new(
+ output,
+ workspaces,
+ ws_id_to_activate,
+ self.clock.clone(),
+ self.options.clone(),
+ );
monitor.overview_open = self.overview_open;
monitor.set_overview_progress(self.overview_progress.as_ref());
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs
index 6433688a..af3925bc 100644
--- a/src/layout/monitor.rs
+++ b/src/layout/monitor.rs
@@ -275,7 +275,8 @@ impl From<&super::OverviewProgress> for OverviewProgress {
impl<W: LayoutElement> Monitor<W> {
pub fn new(
output: Output,
- workspaces: Vec<Workspace<W>>,
+ mut workspaces: Vec<Workspace<W>>,
+ ws_id_to_activate: Option<WorkspaceId>,
clock: Clock,
options: Rc<Options>,
) -> Self {
@@ -283,6 +284,28 @@ impl<W: LayoutElement> Monitor<W> {
let view_size = output_size(&output);
let working_area = compute_working_area(&output);
+ // Prepare the workspaces: set output, empty first, empty last.
+ let mut active_workspace_idx = 0;
+
+ for (idx, ws) in workspaces.iter_mut().enumerate() {
+ assert!(ws.has_windows_or_name());
+
+ ws.set_output(Some(output.clone()));
+
+ if ws_id_to_activate.is_some_and(|id| ws.id() == id) {
+ active_workspace_idx = idx;
+ }
+ }
+
+ if options.layout.empty_workspace_above_first && !workspaces.is_empty() {
+ let ws = Workspace::new(output.clone(), clock.clone(), options.clone());
+ workspaces.insert(0, ws);
+ active_workspace_idx += 1;
+ }
+
+ let ws = Workspace::new(output.clone(), clock.clone(), options.clone());
+ workspaces.push(ws);
+
Self {
output_name: output.name(),
output,
@@ -290,7 +313,7 @@ impl<W: LayoutElement> Monitor<W> {
view_size,
working_area,
workspaces,
- active_workspace_idx: 0,
+ active_workspace_idx,
previous_workspace_id: None,
insert_hint: None,
insert_hint_element: InsertHintElement::new(options.layout.insert_hint),