diff --git a/komorebi/src/state.rs b/komorebi/src/state.rs index 6c71081e..3f89ba4e 100644 --- a/komorebi/src/state.rs +++ b/komorebi/src/state.rs @@ -128,6 +128,7 @@ impl From<&WindowManager> for State { resize_dimensions: workspace.resize_dimensions.clone(), tile: workspace.tile, work_area_offset: workspace.work_area_offset, + work_area_offset_rules: workspace.work_area_offset_rules.clone(), apply_window_based_work_area_offset: workspace .apply_window_based_work_area_offset, window_container_behaviour: workspace.window_container_behaviour, diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index f754f167..662981e1 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -201,6 +201,9 @@ pub struct WorkspaceConfig { /// Permanent workspace application rules #[serde(skip_serializing_if = "Option::is_none")] pub workspace_rules: Option>, + /// Work area offset rules in the format of threshold => Rect (default: None) + #[serde(skip_serializing_if = "Option::is_none")] + pub work_area_offset_rules: Option>, /// Workspace specific work area offset #[serde(skip_serializing_if = "Option::is_none")] pub work_area_offset: Option, @@ -247,6 +250,13 @@ impl From<&Workspace> for WorkspaceConfig { } let layout_rules = (!layout_rules.is_empty()).then_some(layout_rules); + let mut work_area_offset_rules = HashMap::new(); + for (threshold, rect) in &value.work_area_offset_rules { + work_area_offset_rules.insert(*threshold, *rect); + } + let work_area_offset_rules = + (!work_area_offset_rules.is_empty()).then_some(work_area_offset_rules); + let mut window_container_behaviour_rules = HashMap::new(); for (threshold, behaviour) in value.window_container_behaviour_rules.iter().flatten() { window_container_behaviour_rules.insert(*threshold, *behaviour); @@ -306,6 +316,7 @@ impl From<&Workspace> for WorkspaceConfig { .workspace_config .as_ref() .and_then(|c| c.workspace_rules.clone()), + work_area_offset_rules, work_area_offset: value.work_area_offset, apply_window_based_work_area_offset: Some(value.apply_window_based_work_area_offset), window_container_behaviour: value.window_container_behaviour, diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 181fa129..41d08885 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -58,6 +58,7 @@ pub struct Workspace { pub resize_dimensions: Vec>, pub tile: bool, pub work_area_offset: Option, + pub work_area_offset_rules: Vec<(usize, Rect)>, pub apply_window_based_work_area_offset: bool, pub window_container_behaviour: Option, pub window_container_behaviour_rules: Option>, @@ -109,6 +110,7 @@ impl Default for Workspace { resize_dimensions: vec![], layout: Layout::Default(DefaultLayout::BSP), work_area_offset: None, + work_area_offset_rules: vec![], latest_layout: vec![], layout_flip: None, layout_options: None, @@ -182,6 +184,17 @@ impl Workspace { self.work_area_offset = config.work_area_offset; + let mut all_work_area_offset_rules = vec![]; + if let Some(work_area_offset_rules) = &config.work_area_offset_rules { + for (count, rect) in work_area_offset_rules { + all_work_area_offset_rules.push((*count, *rect)); + } + + all_work_area_offset_rules.sort_by_key(|(i, _)| *i); + } + + self.work_area_offset_rules = all_work_area_offset_rules; + self.apply_window_based_work_area_offset = config.apply_window_based_work_area_offset.unwrap_or(true); @@ -1155,7 +1168,25 @@ impl Workspace { let border_width = self.globals.border_width; let border_offset = self.globals.border_offset; let work_area = self.globals.work_area; - let work_area_offset = self.work_area_offset.or(self.globals.work_area_offset); + let mut rules_work_area_offset = None; + + if !self.work_area_offset_rules.is_empty() { + let count = if self.monocle_container.is_some() { + 1 + } else { + self.containers().len() + }; + + for (threshold, work_area_offset_rule) in &self.work_area_offset_rules { + if count >= *threshold { + rules_work_area_offset = Some(*work_area_offset_rule); + } + } + }; + + let work_area_offset = rules_work_area_offset + .or(self.work_area_offset) + .or(self.globals.work_area_offset); let window_based_work_area_offset = self.globals.window_based_work_area_offset; let window_based_work_area_offset_limit = self.globals.window_based_work_area_offset_limit; diff --git a/nix/komorebi-bar-options.nix b/nix/komorebi-bar-options.nix index 07559ac2..b2c78a29 100644 --- a/nix/komorebi-bar-options.nix +++ b/nix/komorebi-bar-options.nix @@ -979,6 +979,103 @@ in ] ); }; + colours = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.submodule { + options = { + base_00 = lib.mkOption { + type = colour; + description = "Base00"; + }; + base_01 = lib.mkOption { + type = colour; + description = "Base01"; + }; + base_02 = lib.mkOption { + type = colour; + description = "Base02"; + }; + base_03 = lib.mkOption { + type = colour; + description = "Base03"; + }; + base_04 = lib.mkOption { + type = colour; + description = "Base04"; + }; + base_05 = lib.mkOption { + type = colour; + description = "Base05"; + }; + base_06 = lib.mkOption { + type = colour; + description = "Base06"; + }; + base_07 = lib.mkOption { + type = colour; + description = "Base07"; + }; + base_08 = lib.mkOption { + type = colour; + description = "Base08"; + }; + base_09 = lib.mkOption { + type = colour; + description = "Base09"; + }; + base_0a = lib.mkOption { + type = colour; + description = "Base0A"; + }; + base_0b = lib.mkOption { + type = colour; + description = "Base0B"; + }; + base_0c = lib.mkOption { + type = colour; + description = "Base0C"; + }; + base_0d = lib.mkOption { + type = colour; + description = "Base0D"; + }; + base_0e = lib.mkOption { + type = colour; + description = "Base0E"; + }; + base_0f = lib.mkOption { + type = colour; + description = "Base0F"; + }; + }; + } + ) + ); + default = null; + }; + accent = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; + auto_select_fill = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; name = lib.mkOption { type = ( lib.types.nullOr ( @@ -1276,103 +1373,6 @@ in ); default = null; }; - auto_select_fill = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; - colours = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.submodule { - options = { - base_00 = lib.mkOption { - type = colour; - description = "Base00"; - }; - base_01 = lib.mkOption { - type = colour; - description = "Base01"; - }; - base_02 = lib.mkOption { - type = colour; - description = "Base02"; - }; - base_03 = lib.mkOption { - type = colour; - description = "Base03"; - }; - base_04 = lib.mkOption { - type = colour; - description = "Base04"; - }; - base_05 = lib.mkOption { - type = colour; - description = "Base05"; - }; - base_06 = lib.mkOption { - type = colour; - description = "Base06"; - }; - base_07 = lib.mkOption { - type = colour; - description = "Base07"; - }; - base_08 = lib.mkOption { - type = colour; - description = "Base08"; - }; - base_09 = lib.mkOption { - type = colour; - description = "Base09"; - }; - base_0a = lib.mkOption { - type = colour; - description = "Base0A"; - }; - base_0b = lib.mkOption { - type = colour; - description = "Base0B"; - }; - base_0c = lib.mkOption { - type = colour; - description = "Base0C"; - }; - base_0d = lib.mkOption { - type = colour; - description = "Base0D"; - }; - base_0e = lib.mkOption { - type = colour; - description = "Base0E"; - }; - base_0f = lib.mkOption { - type = colour; - description = "Base0F"; - }; - }; - } - ) - ); - default = null; - }; - accent = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; }; } ) diff --git a/nix/komorebi-options.nix b/nix/komorebi-options.nix index 32659ffc..28c0e40c 100644 --- a/nix/komorebi-options.nix +++ b/nix/komorebi-options.nix @@ -735,6 +735,11 @@ in default = null; description = "Workspace specific work area offset"; }; + work_area_offset_rules = lib.mkOption { + type = (lib.types.nullOr (lib.types.attrsOf rect)); + default = null; + description = "Work area offset rules in the format of threshold => Rect (default: None)"; + }; workspace_padding = lib.mkOption { type = (lib.types.nullOr lib.types.int); default = null; @@ -788,6 +793,17 @@ in ] ); }; + floating_border = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; colours = lib.mkOption { type = ( lib.types.nullOr ( @@ -863,72 +879,6 @@ in ); default = null; }; - unfocused_locked_border = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; - bar_accent = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; - monocle_border = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; - stack_border = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; - floating_border = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; - unfocused_border = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; name = lib.mkOption { type = ( lib.types.nullOr ( @@ -1215,6 +1165,50 @@ in ); default = null; }; + monocle_border = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; + unfocused_border = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; + stack_border = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; + bar_accent = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; single_border = lib.mkOption { type = ( lib.types.nullOr ( @@ -1226,6 +1220,17 @@ in ); default = null; }; + unfocused_locked_border = lib.mkOption { + type = ( + lib.types.nullOr ( + lib.types.oneOf [ + (lib.types.nullOr catppuccinValue) + (lib.types.nullOr base16Value) + ] + ) + ); + default = null; + }; }; } ) diff --git a/schema.json b/schema.json index c1543f63..1534b649 100644 --- a/schema.json +++ b/schema.json @@ -3685,6 +3685,19 @@ } ] }, + "work_area_offset_rules": { + "description": "Work area offset rules in the format of threshold => Rect (default: None)", + "type": [ + "object", + "null" + ], + "additionalProperties": false, + "patternProperties": { + "^\\d+$": { + "$ref": "#/$defs/Rect" + } + } + }, "workspace_padding": { "description": "Workspace padding (default: global)", "type": [