diff --git a/Cargo.lock b/Cargo.lock index 2fb64475..2891a6ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3159,7 +3159,7 @@ dependencies = [ [[package]] name = "komorebi-layouts" version = "0.1.41" -source = "git+https://github.com/LGUG2Z/komorebi?rev=e9a541d12b83db79b7d47ca85bbee6039e344c9d#e9a541d12b83db79b7d47ca85bbee6039e344c9d" +source = "git+https://github.com/LGUG2Z/komorebi?rev=d6b17bbc7c402c61fce765e2752040a6698c11a5#d6b17bbc7c402c61fce765e2752040a6698c11a5" dependencies = [ "clap", "color-eyre", @@ -3175,7 +3175,7 @@ dependencies = [ [[package]] name = "komorebi-themes" version = "0.1.41" -source = "git+https://github.com/LGUG2Z/komorebi?rev=e9a541d12b83db79b7d47ca85bbee6039e344c9d#e9a541d12b83db79b7d47ca85bbee6039e344c9d" +source = "git+https://github.com/LGUG2Z/komorebi?rev=d6b17bbc7c402c61fce765e2752040a6698c11a5#d6b17bbc7c402c61fce765e2752040a6698c11a5" dependencies = [ "base16-egui-themes", "catppuccin-egui", diff --git a/Cargo.toml b/Cargo.toml index 39c36412..8a2bc807 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,8 +13,8 @@ members = [ version = "0.1.0" [workspace.dependencies] -komorebi-themes = { git = "https://github.com/LGUG2Z/komorebi", rev = "e9a541d12b83db79b7d47ca85bbee6039e344c9d" } -komorebi-layouts = { git = "https://github.com/LGUG2Z/komorebi", rev = "e9a541d12b83db79b7d47ca85bbee6039e344c9d", features = [ +komorebi-themes = { git = "https://github.com/LGUG2Z/komorebi", rev = "d6b17bbc7c402c61fce765e2752040a6698c11a5" } +komorebi-layouts = { git = "https://github.com/LGUG2Z/komorebi", rev = "d6b17bbc7c402c61fce765e2752040a6698c11a5", features = [ "darwin", "schemars", ] } diff --git a/komorebi/src/state.rs b/komorebi/src/state.rs index 3f89ba4e..682d67ae 100644 --- a/komorebi/src/state.rs +++ b/komorebi/src/state.rs @@ -121,6 +121,7 @@ impl From<&WindowManager> for State { layout: workspace.layout.clone(), layout_options: workspace.layout_options, layout_rules: workspace.layout_rules.clone(), + layout_options_rules: workspace.layout_options_rules.clone(), layout_flip: workspace.layout_flip, workspace_padding: workspace.workspace_padding, container_padding: workspace.container_padding, diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index 662981e1..31bb360b 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -182,6 +182,12 @@ pub struct WorkspaceConfig { /// Layout-specific options #[serde(skip_serializing_if = "Option::is_none")] pub layout_options: Option, + /// Threshold-based layout options rules in the format of threshold => options. + /// When container count >= threshold, the highest matching threshold's options + /// fully replace the base `layout_options`. + /// This follows the same threshold logic as `layout_rules`. + #[serde(skip_serializing_if = "Option::is_none")] + pub layout_options_rules: Option>, // /// END OF LIFE FEATURE: Custom Layout (default: None) // #[serde(skip_serializing_if = "Option::is_none")] // #[serde_as(as = "Option")] @@ -301,6 +307,11 @@ impl From<&Workspace> for WorkspaceConfig { ); value.layout_options }, + layout_options_rules: if value.layout_options_rules.is_empty() { + None + } else { + Some(value.layout_options_rules.iter().copied().collect()) + }, // custom_layout: value // .workspace_config // .as_ref() diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 41d08885..aa4d8497 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -51,6 +51,10 @@ pub struct Workspace { pub layout: Layout, pub layout_options: Option, pub layout_rules: Vec<(usize, Layout)>, + /// Threshold-based layout options rules (container_count >= threshold -> use these options). + /// Sorted by threshold ascending at load time. + #[serde(default)] + pub layout_options_rules: Vec<(usize, LayoutOptions)>, pub layout_flip: Option, pub workspace_padding: Option, pub container_padding: Option, @@ -115,6 +119,7 @@ impl Default for Workspace { layout_flip: None, layout_options: None, layout_rules: vec![], + layout_options_rules: vec![], globals: Default::default(), layer: Default::default(), tile: true, @@ -220,12 +225,24 @@ impl Workspace { self.layout_flip = config.layout_flip; self.floating_layer_behaviour = config.floating_layer_behaviour; self.wallpaper = config.wallpaper.clone(); + // Load layout options directly (LayoutOptions is used in both config and runtime) self.layout_options = config.layout_options; + // Load threshold-based layout options rules, sorted by threshold ascending + self.layout_options_rules = if let Some(rules) = &config.layout_options_rules { + let mut sorted_rules: Vec<(usize, LayoutOptions)> = + rules.iter().map(|(t, o)| (*t, *o)).collect(); + sorted_rules.sort_by_key(|(t, _)| *t); + sorted_rules + } else { + vec![] + }; + tracing::debug!( - "Workspace '{}' loaded layout_options: {:?}", + "Workspace '{}' loaded layout_options: {:?}, layout_options_rules: {} entries", self.name.as_deref().unwrap_or("unnamed"), - self.layout_options + self.layout_options, + self.layout_options_rules.len(), ); self.workspace_config = Some(config.clone()); @@ -1264,10 +1281,34 @@ impl Workspace { window.set_position(&adjusted_work_area)?; }; } else if !self.containers().is_empty() { - tracing::debug!( - "Workspace '{}' update() - self.layout_options before calculate: {:?}", - self.name.as_deref().unwrap_or("unnamed"), + // Compute effective layout options: + // 1. If layout_options_rules has a matching threshold (container_count >= threshold), + // use the highest matching threshold's options (full replacement) + // 2. Otherwise, use the workspace base layout_options + let effective_layout_options = if !self.layout_options_rules.is_empty() { + let container_count = self.containers().len(); + let mut matched = None; + for (threshold, opts) in &self.layout_options_rules { + if container_count >= *threshold { + matched = Some(*opts); + } + } + // If a rule matched, use it entirely (replaces base layout_options) + if matched.is_some() { + matched + } else { + self.layout_options + } + } else { self.layout_options + }; + + tracing::debug!( + "Workspace '{}' update() - effective_layout_options: {:?} (base: {:?}, rules: {})", + self.name.as_deref().unwrap_or("unnamed"), + effective_layout_options, + self.layout_options, + self.layout_options_rules.len(), ); let mut layouts = self.layout.as_boxed_arrangement().calculate( &adjusted_work_area, @@ -1278,7 +1319,7 @@ impl Workspace { self.layout_flip, &self.resize_dimensions, self.focused_container_idx(), - self.layout_options, + effective_layout_options, &self.latest_layout, );