Skip to content

Commit

Permalink
feat(wm): add window_container_behaviour and float_override to worksp…
Browse files Browse the repository at this point in the history
…aces

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.
  • Loading branch information
alex-ds13 committed Oct 10, 2024
1 parent 30bdaf3 commit b7bedce
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
9 changes: 9 additions & 0 deletions komorebi/src/static_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>,
/// Determine what happens when a new window is opened (default: Create)
#[serde(skip_serializing_if = "Option::is_none")]
pub window_container_behaviour: Option<WindowContainerBehaviour>,
/// 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<bool>,
}

impl From<&Workspace> for WorkspaceConfig {
Expand Down Expand Up @@ -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(),
}
}
}
Expand Down
17 changes: 15 additions & 2 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
}
Expand Down
15 changes: 15 additions & 0 deletions komorebi/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<WindowContainerBehaviour>,
#[getset(get = "pub", get_mut = "pub", set = "pub")]
float_override: Option<bool>,
}

impl_ring_elements!(Workspace, Container);
Expand All @@ -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,
}
}
}
Expand Down Expand Up @@ -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(())
}

Expand Down

0 comments on commit b7bedce

Please sign in to comment.