Skip to content

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

feat: activate `keep_alive` workspaces on their bound monitor (#998)

HolbyFPV7ca7bcc1f775
diff --git a/packages/wm/src/commands/monitor/add_monitor.rs b/packages/wm/src/commands/monitor/add_monitor.rs
index 08272a3a..11cdbe95 100644
--- a/packages/wm/src/commands/monitor/add_monitor.rs
+++ b/packages/wm/src/commands/monitor/add_monitor.rs
@@ -1,11 +1,12 @@
use anyhow::Context;
-use tracing::info;
+use tracing::{info, warn};
use wm_common::WmEvent;
use wm_platform::NativeMonitor;
use crate::{
commands::{container::attach_container, workspace::activate_workspace},
models::Monitor,
+ traits::CommonGetters,
user_config::UserConfig,
wm_state::WmState,
};
@@ -32,6 +33,22 @@ pub fn add_monitor(
added_monitor: monitor.to_dto()?,
});
+ // Active all keep_alive workspaces for this monitor
+ config.keep_alive_workspace_configs().iter().for_each(
+ |workspace_config| {
+ #[allow(clippy::cast_possible_truncation)]
+ if workspace_config.bind_to_monitor == Some(monitor.index() as u32) {
+ activate_workspace(
+ Some(&workspace_config.name),
+ Some(monitor.clone()),
+ state,
+ config,
+ )
+ .unwrap_or_else(|err| warn!("{err}"));
+ }
+ },
+ );
+
// Activate a workspace on the newly added monitor.
activate_workspace(None, Some(monitor), state, config)
.context("At least 1 workspace is required per monitor.")?;
diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rs
index cbfefba1..1d169278 100644
--- a/packages/wm/src/user_config.rs
+++ b/packages/wm/src/user_config.rs
@@ -281,6 +281,15 @@ impl UserConfig {
.collect()
}
+ pub fn keep_alive_workspace_configs(&self) -> Vec<&WorkspaceConfig> {
+ self
+ .value
+ .workspaces
+ .iter()
+ .filter(|config| config.keep_alive)
+ .collect()
+ }
+
pub fn workspace_config_for_monitor(
&self,
monitor: &Monitor,