mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-21 08:01:39 +01:00
feat(wm): add threshold-based layout_options_rules for workspaces
This commit migrates this feature as it was implemented in LGUG2Z/komorebi@d6b17bbc7c by @CtByte.
This commit is contained in:
1 parent
d8b0c2964a
commit
7e54fed8de
5 files changed
+63
-10
No files matched your search
Generated
+2
-2
@@ -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",
|
||||
|
||||
+2
-2
@@ -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",
|
||||
] }
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -182,6 +182,12 @@ pub struct WorkspaceConfig {
|
||||
/// Layout-specific options
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub layout_options: Option<LayoutOptions>,
|
||||
/// 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<HashMap<usize, LayoutOptions>>,
|
||||
// /// END OF LIFE FEATURE: Custom Layout (default: None)
|
||||
// #[serde(skip_serializing_if = "Option::is_none")]
|
||||
// #[serde_as(as = "Option<ResolvedPathBuf>")]
|
||||
@@ -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()
|
||||
|
||||
@@ -51,6 +51,10 @@ pub struct Workspace {
|
||||
pub layout: Layout,
|
||||
pub layout_options: Option<LayoutOptions>,
|
||||
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<Axis>,
|
||||
pub workspace_padding: Option<i32>,
|
||||
pub container_padding: Option<i32>,
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user