Skip to content

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

feat: remove `WorkspaceMoved` event in favor of new `WorkspaceUpdated` event

Lars Berger74d802f488e1
diff --git a/packages/wm/src/app_command.rs b/packages/wm/src/app_command.rs
index 3ee5db20..d6e8e6d6 100644
--- a/packages/wm/src/app_command.rs
+++ b/packages/wm/src/app_command.rs
@@ -169,7 +169,7 @@ pub enum SubscribableEvent {
WindowUnmanaged,
WorkspaceActivated,
WorkspaceDeactivated,
- WorkspaceMoved,
+ WorkspaceUpdated,
}
#[derive(Clone, Debug, Parser, PartialEq, Serialize)]
diff --git a/packages/wm/src/common/commands/reload_config.rs b/packages/wm/src/common/commands/reload_config.rs
index 71eba71e..be50ab30 100644
--- a/packages/wm/src/common/commands/reload_config.rs
+++ b/packages/wm/src/common/commands/reload_config.rs
@@ -68,30 +68,33 @@ fn update_workspace_configs(
let workspaces = state.workspaces();
for workspace in &workspaces {
+ let monitor = workspace.monitor().context("No monitor.")?;
+
let workspace_config = config
.value
.workspaces
.iter()
- .find(|config| config.name == workspace.config().name);
+ .find(|config| config.name == workspace.config().name)
+ .or_else(|| {
+ // When the workspace config is not found, the current name of the
+ // workspace has been removed. So, we reassign the first suitable
+ // workspace config to the workspace.
+ config.workspace_config_for_monitor(&monitor, &workspaces)
+ });
match workspace_config {
- Some(workspace_config) => {
- workspace.set_config(workspace_config.clone());
- }
- // When the workspace config is not found, the current name of the
- // workspace has been removed. So, we reassign the first suitable
- // workspace config to the workspace.
None => {
- let monitor = workspace.monitor().context("No monitor.")?;
- let inactive_config =
- config.workspace_config_for_monitor(&monitor, &workspaces);
-
- if let Some(inactive_config) = inactive_config {
- workspace.set_config(inactive_config.clone());
- } else {
- warn!(
- "Unable to update workspace config. No available workspace configs."
- );
+ warn!(
+ "Unable to update workspace config. No available workspace configs."
+ );
+ }
+ Some(workspace_config) => {
+ if *workspace_config != workspace.config() {
+ workspace.set_config(workspace_config.clone());
+
+ state.emit_event(WmEvent::WorkspaceUpdated {
+ updated_workspace: workspace.to_dto()?,
+ });
}
}
}
diff --git a/packages/wm/src/ipc_server.rs b/packages/wm/src/ipc_server.rs
index f61d5908..567f1364 100644
--- a/packages/wm/src/ipc_server.rs
+++ b/packages/wm/src/ipc_server.rs
@@ -436,7 +436,9 @@ impl IpcServer {
WmEvent::WorkspaceDeactivated { .. } => {
SubscribableEvent::WorkspaceDeactivated
}
- WmEvent::WorkspaceMoved { .. } => SubscribableEvent::WorkspaceMoved,
+ WmEvent::WorkspaceUpdated { .. } => {
+ SubscribableEvent::WorkspaceUpdated
+ }
};
self.event_tx.send((event_type, event))?;
diff --git a/packages/wm/src/monitors/commands/remove_monitor.rs b/packages/wm/src/monitors/commands/remove_monitor.rs
index 969ca331..ebca1944 100644
--- a/packages/wm/src/monitors/commands/remove_monitor.rs
+++ b/packages/wm/src/monitors/commands/remove_monitor.rs
@@ -48,9 +48,8 @@ pub fn remove_monitor(
state,
)?;
- state.emit_event(WmEvent::WorkspaceMoved {
- moved_workspace: workspace.to_dto()?,
- new_monitor: target_monitor.to_dto()?,
+ state.emit_event(WmEvent::WorkspaceUpdated {
+ updated_workspace: workspace.to_dto()?,
});
}
diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rs
index 109878be..38a530d4 100644
--- a/packages/wm/src/user_config.rs
+++ b/packages/wm/src/user_config.rs
@@ -541,7 +541,7 @@ pub enum WindowRuleEvent {
TitleChange,
}
-#[derive(Clone, Debug, Deserialize, Serialize)]
+#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[serde(rename_all(serialize = "camelCase"))]
pub struct WorkspaceConfig {
pub name: String,
diff --git a/packages/wm/src/wm_event.rs b/packages/wm/src/wm_event.rs
index 73397cff..ebc1311d 100644
--- a/packages/wm/src/wm_event.rs
+++ b/packages/wm/src/wm_event.rs
@@ -53,8 +53,7 @@ pub enum WmEvent {
deactivated_id: Uuid,
deactivated_name: String,
},
- WorkspaceMoved {
- moved_workspace: ContainerDto,
- new_monitor: ContainerDto,
+ WorkspaceUpdated {
+ updated_workspace: ContainerDto,
},
}
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 38551706..4a384e89 100644
--- a/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs
+++ b/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs
@@ -55,9 +55,8 @@ pub fn move_workspace_in_direction(
activate_workspace(None, &monitor, state, config)?;
}
- state.emit_event(WmEvent::WorkspaceMoved {
- moved_workspace: workspace.to_dto()?,
- new_monitor: target_monitor.to_dto()?,
+ state.emit_event(WmEvent::WorkspaceUpdated {
+ updated_workspace: workspace.to_dto()?,
});
}
diff --git a/packages/wm/src/workspaces/workspace.rs b/packages/wm/src/workspaces/workspace.rs
index 20aa74c0..1c935517 100644
--- a/packages/wm/src/workspaces/workspace.rs
+++ b/packages/wm/src/workspaces/workspace.rs
@@ -26,7 +26,6 @@ pub struct Workspace(Rc<RefCell<WorkspaceInner>>);
#[derive(Debug)]
struct WorkspaceInner {
id: Uuid,
- name: String,
parent: Option<Container>,
children: VecDeque<Container>,
child_focus_order: VecDeque<Uuid>,
@@ -43,6 +42,7 @@ struct WorkspaceInner {
pub struct WorkspaceDto {
id: Uuid,
name: String,
+ display_name: Option<String>,
parent: Option<Uuid>,
children: Vec<ContainerDto>,
child_focus_order: Vec<Uuid>,
@@ -63,7 +63,6 @@ impl Workspace {
) -> Self {
let workspace = WorkspaceInner {
id: Uuid::new_v4(),
- name: config.name.clone(),
parent: None,
children: VecDeque::new(),
child_focus_order: VecDeque::new(),
@@ -100,6 +99,8 @@ impl Workspace {
pub fn to_dto(&self) -> anyhow::Result<ContainerDto> {
let rect = self.to_rect()?;
+ let config = self.config();
+
let children = self
.children()
.iter()
@@ -108,7 +109,8 @@ impl Workspace {
Ok(ContainerDto::Workspace(WorkspaceDto {
id: self.id(),
- name: self.0.borrow().name.clone(),
+ name: config.name,
+ display_name: config.display_name,
parent: self.parent().map(|parent| parent.id()),
children,
child_focus_order: self.0.borrow().child_focus_order.clone().into(),