diff --git a/src/it/tests.rs b/src/it/tests.rs index 6b0e44cb..e900b9d3 100644 --- a/src/it/tests.rs +++ b/src/it/tests.rs @@ -42,6 +42,7 @@ mod t0013_graphics_initialized; mod t0014_container_scroll_focus; mod t0015_scroll_partial; mod t0016_scroll_ws; +mod t0017_remove_unused_ws; pub trait TestCase: Sync { fn name(&self) -> &'static str; @@ -76,5 +77,6 @@ pub fn tests() -> Vec<&'static dyn TestCase> { t0014_container_scroll_focus, t0015_scroll_partial, t0016_scroll_ws, + t0017_remove_unused_ws, } } diff --git a/src/it/tests/t0017_remove_unused_ws.rs b/src/it/tests/t0017_remove_unused_ws.rs new file mode 100644 index 00000000..27d39be7 --- /dev/null +++ b/src/it/tests/t0017_remove_unused_ws.rs @@ -0,0 +1,35 @@ +use { + crate::it::{test_error::TestResult, testrun::TestRun}, + std::rc::Rc, +}; + +testcase!(); + +async fn test(run: Rc) -> TestResult { + let ds = run.create_default_setup().await?; + run.cfg.show_workspace(ds.seat.id(), "1")?; + + tassert_eq!(run.state.workspaces.len(), 1); + + run.cfg.show_workspace(ds.seat.id(), "2")?; + + tassert_eq!(run.state.workspaces.len(), 1); + + run.cfg.show_workspace(ds.seat.id(), "1")?; + + tassert_eq!(run.state.workspaces.len(), 1); + + let client = run.create_client().await?; + let win = client.create_window().await?; + win.map().await?; + + run.cfg.show_workspace(ds.seat.id(), "2")?; + + tassert_eq!(run.state.workspaces.len(), 2); + + run.cfg.show_workspace(ds.seat.id(), "1")?; + + tassert_eq!(run.state.workspaces.len(), 1); + + Ok(()) +} diff --git a/src/tree/output.rs b/src/tree/output.rs index 2cc086a7..06c7ba95 100644 --- a/src/tree/output.rs +++ b/src/tree/output.rs @@ -180,6 +180,10 @@ impl OutputNode { } collect_kb_foci2(old.clone(), &mut seats); old.set_visible(false); + if old.is_empty() { + old.clear(); + self.state.workspaces.remove(&old.name); + } } ws.set_visible(true); if let Some(fs) = ws.fullscreen.get() { diff --git a/src/tree/workspace.rs b/src/tree/workspace.rs index 78f25ad4..073e4d69 100644 --- a/src/tree/workspace.rs +++ b/src/tree/workspace.rs @@ -47,6 +47,10 @@ impl WorkspaceNode { self.container.set(Some(container.clone())); } + pub fn is_empty(&self) -> bool { + self.stacked.is_empty() && self.fullscreen.get().is_none() && self.container.get().is_none() + } + pub fn stacked_visible(&self) -> bool { self.visible.get() && self.fullscreen.get().is_none() }