Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

fix: remove any empty workspaces after `move-workspace` command (#743)

lars-bergerf7ece4c69b7e
diff --git a/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs b/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs
index 551f61f4..3ca6f881 100644
--- a/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs
+++ b/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs
@@ -1,6 +1,6 @@
use anyhow::Context;
-use super::{activate_workspace, sort_workspaces};
+use super::{activate_workspace, deactivate_workspace, sort_workspaces};
use crate::{
common::Direction,
containers::{
@@ -60,6 +60,19 @@ pub fn move_workspace_in_direction(
activate_workspace(None, Some(monitor), state, config)?;
}
+ // Get empty workspace to destroy (if one is found). Cannot destroy
+ // empty workspaces if they're the only workspace on the monitor.
+ let workspace_to_destroy =
+ state.workspaces().into_iter().find(|workspace| {
+ !workspace.config().keep_alive
+ && !workspace.has_children()
+ && !workspace.is_displayed()
+ });
+
+ if let Some(workspace) = workspace_to_destroy {
+ deactivate_workspace(workspace, state)?;
+ }
+
sort_workspaces(target_monitor, config)?;
state.emit_event(WmEvent::WorkspaceUpdated {