From 52340a14876d25d4d1d72dd35e6e46af634b882d Mon Sep 17 00:00:00 2001 From: alex-ds13 <145657253+alex-ds13@users.noreply.github.com> Date: Thu, 16 Jan 2025 18:19:01 +0000 Subject: [PATCH] refactor(wm): store config on workspace Store the `WorkspaceConfig` on the `Workspace` itself so that when we want to cache the workspace as `WorkspaceConfig` on the monitor cache it properly saves things like the workspace rules and the custom layout and custom layout rules. --- komorebi/src/static_config.rs | 21 ++++++++++++++++----- komorebi/src/workspace.rs | 5 +++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index da5c2c58..751b54e4 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -206,7 +206,6 @@ impl From<&Workspace> for WorkspaceConfig { .name() .clone() .unwrap_or_else(|| String::from("unnamed")), - custom_layout: None, layout: value .tile() .then_some(match value.layout() { @@ -214,13 +213,25 @@ impl From<&Workspace> for WorkspaceConfig { Layout::Custom(_) => None, }) .flatten(), + custom_layout: value + .workspace_config() + .as_ref() + .and_then(|c| c.custom_layout.clone()), layout_rules: Option::from(layout_rules), - // TODO: figure out how we might resolve file references in the future - custom_layout_rules: None, + custom_layout_rules: value + .workspace_config() + .as_ref() + .and_then(|c| c.custom_layout_rules.clone()), container_padding, workspace_padding, - initial_workspace_rules: None, - workspace_rules: None, + initial_workspace_rules: value + .workspace_config() + .as_ref() + .and_then(|c| c.initial_workspace_rules.clone()), + workspace_rules: value + .workspace_config() + .as_ref() + .and_then(|c| c.workspace_rules.clone()), apply_window_based_work_area_offset: Some(value.apply_window_based_work_area_offset()), window_container_behaviour: *value.window_container_behaviour(), window_container_behaviour_rules: Option::from(window_container_behaviour_rules), diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 79f326f5..13cbb817 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -92,6 +92,8 @@ pub struct Workspace { window_container_behaviour_rules: Option>, #[getset(get = "pub", get_mut = "pub", set = "pub")] float_override: Option, + #[getset(get = "pub", set = "pub")] + workspace_config: Option, } impl_ring_elements!(Workspace, Container); @@ -118,6 +120,7 @@ impl Default for Workspace { window_container_behaviour: None, window_container_behaviour_rules: None, float_override: None, + workspace_config: None, } } } @@ -209,6 +212,8 @@ impl Workspace { self.set_float_override(config.float_override); self.set_layout_flip(config.layout_flip); + self.set_workspace_config(Some(config.clone())); + Ok(()) }