From b7bedce1ca8472b9ed762d57f4d36e79eb156f8c Mon Sep 17 00:00:00 2001 From: alex-ds13 <145657253+alex-ds13@users.noreply.github.com> Date: Thu, 10 Oct 2024 11:49:02 +0100 Subject: [PATCH] feat(wm): add window_container_behaviour and float_override to workspaces This commit adds the `window_management_behaviour` and the `float_override` options to the workspace, so that these can be changed per-workspace. It allows setting this options directly on the config. --- komorebi/src/static_config.rs | 9 +++++++++ komorebi/src/window_manager.rs | 17 +++++++++++++++-- komorebi/src/workspace.rs | 15 +++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index a8b2ee606..1e9ee0ad7 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -131,6 +131,13 @@ pub struct WorkspaceConfig { /// Apply this monitor's window-based work area offset (default: true) #[serde(skip_serializing_if = "Option::is_none")] pub apply_window_based_work_area_offset: Option, + /// Determine what happens when a new window is opened (default: Create) + #[serde(skip_serializing_if = "Option::is_none")] + pub window_container_behaviour: Option, + /// Enable or disable float override, which makes it so every new window opens in floating mode + /// (default: false) + #[serde(skip_serializing_if = "Option::is_none")] + pub float_override: Option, } impl From<&Workspace> for WorkspaceConfig { @@ -183,6 +190,8 @@ impl From<&Workspace> for WorkspaceConfig { initial_workspace_rules: None, workspace_rules: None, apply_window_based_work_area_offset: Some(value.apply_window_based_work_area_offset()), + window_container_behaviour: *value.window_container_behaviour(), + float_override: *value.float_override(), } } } diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index b5a84564d..6cfb3205b 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -318,16 +318,29 @@ impl WindowManager { ) -> WindowManagementBehaviour { if let Some(monitor) = self.monitors().get(monitor_idx) { if let Some(workspace) = monitor.workspaces().get(workspace_idx) { - let current_behaviour = if workspace.containers().is_empty() && matches!(self.window_management_behaviour.current_behaviour, WindowContainerBehaviour::Append) { + let current_behaviour = if let Some(behaviour) = workspace.window_container_behaviour() { + if workspace.containers().is_empty() && matches!(behaviour, WindowContainerBehaviour::Append) { + // You can't append to an empty workspace + WindowContainerBehaviour::Create + } else { + *behaviour + } + } else if workspace.containers().is_empty() && matches!(self.window_management_behaviour.current_behaviour, WindowContainerBehaviour::Append) { // You can't append to an empty workspace WindowContainerBehaviour::Create } else { self.window_management_behaviour.current_behaviour }; + let float_override = if let Some(float_override) = workspace.float_override() { + *float_override + } else { + self.window_management_behaviour.float_override + }; + return WindowManagementBehaviour { current_behaviour, - float_override: self.window_management_behaviour.float_override, + float_override }; } } diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 39a846e91..ea6ee907d 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -30,6 +30,7 @@ use crate::static_config::WorkspaceConfig; use crate::window::Window; use crate::window::WindowDetails; use crate::windows_api::WindowsApi; +use crate::WindowContainerBehaviour; use crate::DEFAULT_CONTAINER_PADDING; use crate::DEFAULT_WORKSPACE_PADDING; use crate::INITIAL_CONFIGURATION_LOADED; @@ -83,6 +84,10 @@ pub struct Workspace { tile: bool, #[getset(get_copy = "pub", set = "pub")] apply_window_based_work_area_offset: bool, + #[getset(get = "pub", get_mut = "pub", set = "pub")] + window_container_behaviour: Option, + #[getset(get = "pub", get_mut = "pub", set = "pub")] + float_override: Option, } impl_ring_elements!(Workspace, Container); @@ -106,6 +111,8 @@ impl Default for Workspace { resize_dimensions: vec![], tile: true, apply_window_based_work_area_offset: true, + window_container_behaviour: None, + float_override: None, } } } @@ -162,6 +169,14 @@ impl Workspace { config.apply_window_based_work_area_offset.unwrap_or(true), ); + if config.window_container_behaviour.is_some() { + self.set_window_container_behaviour(config.window_container_behaviour); + } + + if config.float_override.is_some() { + self.set_float_override(config.float_override); + } + Ok(()) }