From 49bdf41bfc2e243d621202e6b92bb6cfde4cfae7 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Wed, 31 Dec 2025 12:38:37 -0800 Subject: [PATCH] refactor(schema): simplify defaults in static_config --- komorebi/src/lib.rs | 2 + komorebi/src/static_config.rs | 100 +++++++----------- nix/komorebi-bar-options.nix | 194 +++++++++++++++++----------------- nix/komorebi-options.nix | 94 ++++++++-------- schema.json | 4 +- 5 files changed, 188 insertions(+), 206 deletions(-) diff --git a/komorebi/src/lib.rs b/komorebi/src/lib.rs index 33635f30..28423ee8 100644 --- a/komorebi/src/lib.rs +++ b/komorebi/src/lib.rs @@ -152,6 +152,8 @@ lazy_static! { pub static DEFAULT_WORKSPACE_PADDING: AtomicI32 = AtomicI32::new(5); pub static DEFAULT_CONTAINER_PADDING: AtomicI32 = AtomicI32::new(5); +pub static DEFAULT_RESIZE_DELTA: i32 = 50; +pub static DEFAULT_MOUSE_FOLLOWS_FOCUS: bool = true; pub const PUBLIC_KEY: [u8; 32] = [ 0x5a, 0x69, 0x4a, 0xe1, 0x3c, 0x4b, 0xc8, 0x4e, 0xc3, 0x79, 0x0f, 0xab, 0x27, 0x6b, 0x7e, 0xdd, diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index a67c32ed..dade8cc5 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -1,6 +1,8 @@ use crate::CoreFoundationRunLoop; use crate::DATA_DIR; use crate::DEFAULT_CONTAINER_PADDING; +use crate::DEFAULT_MOUSE_FOLLOWS_FOCUS; +use crate::DEFAULT_RESIZE_DELTA; use crate::DEFAULT_WORKSPACE_PADDING; use crate::DISPLAY_INDEX_PREFERENCES; use crate::FLOATING_APPLICATIONS; @@ -72,27 +74,6 @@ use std::path::PathBuf; use std::sync::Arc; use std::sync::atomic::Ordering; -mod defaults { - pub const RESIZE_DELTA: i32 = 50; - pub const BORDER_WIDTH: i32 = 6; - pub const BORDER_OFFSET: i32 = 5; - pub const BORDER_RADIUS: i32 = 10; - pub const BORDER_ENABLED: bool = true; - pub const MOUSE_FOLLOWS_FOCUS: bool = true; - pub const FLOAT_OVERRIDE: bool = false; - pub const DEFAULT_WORKSPACE_PADDING: i32 = 10; - pub const DEFAULT_CONTAINER_PADDING: i32 = 10; - // MonitorConfig defaults - pub const WINDOW_BASED_WORK_AREA_OFFSET_LIMIT: isize = 1; - // WorkspaceConfig defaults - pub const APPLY_WINDOW_BASED_WORK_AREA_OFFSET: bool = true; - pub const TILE: bool = true; - // Wallpaper defaults - pub const GENERATE_THEME: bool = true; - // AnimationsConfig defaults - pub const ANIMATION_FPS: u64 = 60; -} - #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] /// Border colours for different container states @@ -176,7 +157,7 @@ pub struct Wallpaper { pub path: PathBuf, /// Generate and apply Base16 theme for this wallpaper #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::GENERATE_THEME)))] + #[cfg_attr(feature = "schemars", schemars(extend("default" = true)))] pub generate_theme: Option, /// Specify theme options #[serde(skip_serializing_if = "Option::is_none")] @@ -222,7 +203,7 @@ pub struct WorkspaceConfig { pub work_area_offset: Option, /// Apply this monitor's window-based work area offset #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::APPLY_WINDOW_BASED_WORK_AREA_OFFSET)))] + #[cfg_attr(feature = "schemars", schemars(extend("default" = true)))] pub apply_window_based_work_area_offset: Option, /// Determine what happens when a new window is opened #[serde(skip_serializing_if = "Option::is_none")] @@ -233,11 +214,11 @@ pub struct WorkspaceConfig { pub window_container_behaviour_rules: Option>, /// Enable or disable float override, which makes it so every new window opens in floating mode #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::FLOAT_OVERRIDE)))] + #[cfg_attr(feature = "schemars", schemars(extend("default" = false)))] pub float_override: Option, /// Enable or disable tiling for the workspace #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::TILE)))] + #[cfg_attr(feature = "schemars", schemars(extend("default" = true)))] pub tile: Option, /// Specify an axis on which to flip the selected layout #[serde(skip_serializing_if = "Option::is_none")] @@ -347,7 +328,7 @@ pub struct MonitorConfig { pub window_based_work_area_offset: Option, /// Open window limit after which the window based work area offset will no longer be applied #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::WINDOW_BASED_WORK_AREA_OFFSET_LIMIT)))] + #[cfg_attr(feature = "schemars", schemars(extend("default" = 1)))] pub window_based_work_area_offset_limit: Option, /// Container padding #[serde(skip_serializing_if = "Option::is_none")] @@ -434,7 +415,7 @@ pub struct StaticConfig { // pub minimum_window_height: Option, /// Delta to resize windows by #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::RESIZE_DELTA)))] + #[cfg_attr(feature = "schemars", schemars(extend("default" = DEFAULT_RESIZE_DELTA)))] pub resize_delta: Option, /// Determine what happens when a new window is opened #[serde(skip_serializing_if = "Option::is_none")] @@ -442,7 +423,7 @@ pub struct StaticConfig { pub window_container_behaviour: Option, /// Enable or disable float override, which makes it so every new window opens in floating mode #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::FLOAT_OVERRIDE)))] + #[cfg_attr(feature = "schemars", schemars(extend("default" = false)))] pub float_override: Option, /// Determines what happens on a new window when on the `FloatingLayer` #[serde(skip_serializing_if = "Option::is_none")] @@ -478,7 +459,7 @@ pub struct StaticConfig { pub unmanaged_window_operation_behaviour: Option, /// Enable or disable mouse follows focus #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::MOUSE_FOLLOWS_FOCUS)))] + #[cfg_attr(feature = "schemars", schemars(extend("default" = DEFAULT_MOUSE_FOLLOWS_FOCUS)))] pub mouse_follows_focus: Option, /// Path to applications.json from komorebi-application-specific-configurations #[serde(skip_serializing_if = "Option::is_none")] @@ -486,21 +467,21 @@ pub struct StaticConfig { /// Width of window borders #[serde(skip_serializing_if = "Option::is_none")] #[serde(alias = "active_window_border_width")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::BORDER_WIDTH)))] + #[cfg_attr(feature = "schemars", schemars(extend("default" = border_manager::BORDER_WIDTH)))] pub border_width: Option, /// Offset of window borders #[serde(skip_serializing_if = "Option::is_none")] #[serde(alias = "active_window_border_offset")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::BORDER_OFFSET)))] + #[cfg_attr(feature = "schemars", schemars(extend("default" = border_manager::BORDER_OFFSET)))] pub border_offset: Option, /// Radius of window borders #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::BORDER_RADIUS)))] + #[cfg_attr(feature = "schemars", schemars(extend("default" = border_manager::BORDER_RADIUS)))] pub border_radius: Option, /// Display window borders #[serde(skip_serializing_if = "Option::is_none")] #[serde(alias = "active_window_border")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::BORDER_ENABLED)))] + #[cfg_attr(feature = "schemars", schemars(extend("default" = border_manager::BORDER_ENABLED)))] pub border: Option, /// Window border colours for different container types (has no effect if a theme is defined) #[serde(skip_serializing_if = "Option::is_none")] @@ -524,11 +505,11 @@ pub struct StaticConfig { // pub transparency_ignore_rules: Option>, /// Global default workspace padding #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::DEFAULT_WORKSPACE_PADDING)))] + #[cfg_attr(feature = "schemars", schemars(extend("default" = DEFAULT_WORKSPACE_PADDING)))] pub default_workspace_padding: Option, /// Global default container padding #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::DEFAULT_CONTAINER_PADDING)))] + #[cfg_attr(feature = "schemars", schemars(extend("default" = DEFAULT_CONTAINER_PADDING)))] pub default_container_padding: Option, /// Monitor and workspace configurations #[serde(skip_serializing_if = "Option::is_none")] @@ -620,7 +601,7 @@ pub struct AnimationsConfig { pub style: Option>, /// Set the animation FPS #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::ANIMATION_FPS)))] + #[cfg_attr(feature = "schemars", schemars(extend("default" = DEFAULT_ANIMATION_FPS)))] pub fps: Option, } @@ -851,22 +832,21 @@ impl StaticConfig { DEFAULT_WORKSPACE_PADDING.store(workspace, Ordering::SeqCst); } - border_manager::BORDER_WIDTH.store( - self.border_width.unwrap_or(defaults::BORDER_WIDTH), - Ordering::SeqCst, - ); - border_manager::BORDER_OFFSET.store( - self.border_offset.unwrap_or(defaults::BORDER_OFFSET), - Ordering::SeqCst, - ); - border_manager::BORDER_RADIUS.store( - self.border_radius.unwrap_or(defaults::BORDER_RADIUS), - Ordering::SeqCst, - ); - border_manager::BORDER_ENABLED.store( - self.border.unwrap_or(defaults::BORDER_ENABLED), - Ordering::SeqCst, - ); + if let Some(border_width) = self.border_width { + border_manager::BORDER_WIDTH.store(border_width, Ordering::SeqCst); + } + + if let Some(border_offset) = self.border_offset { + border_manager::BORDER_OFFSET.store(border_offset, Ordering::SeqCst); + } + + if let Some(border_radius) = self.border_radius { + border_manager::BORDER_RADIUS.store(border_radius, Ordering::SeqCst); + } + + if let Some(border_enabled) = self.border { + border_manager::BORDER_ENABLED.store(border_enabled, Ordering::SeqCst); + } if let Some(colours) = &self.border_colours { if let Some(single) = colours.single { @@ -1150,10 +1130,10 @@ impl StaticConfig { unmanaged_window_operation_behaviour: value .unmanaged_window_operation_behaviour .unwrap_or(OperationBehaviour::Op), - resize_delta: value.resize_delta.unwrap_or(defaults::RESIZE_DELTA), + resize_delta: value.resize_delta.unwrap_or(DEFAULT_RESIZE_DELTA), mouse_follows_focus: value .mouse_follows_focus - .unwrap_or(defaults::MOUSE_FOLLOWS_FOCUS), + .unwrap_or(DEFAULT_MOUSE_FOLLOWS_FOCUS), hotwatch: Hotwatch::new()?, run_loop: CoreFoundationRunLoop(run_loop.clone()), minimized_windows: HashMap::new(), @@ -1496,10 +1476,10 @@ impl StaticConfig { wm.enforce_workspace_rules()?; - border_manager::BORDER_ENABLED.store( - value.border.unwrap_or(defaults::BORDER_ENABLED), - Ordering::SeqCst, - ); + if let Some(border_enabled) = value.border { + border_manager::BORDER_ENABLED.store(border_enabled, Ordering::SeqCst); + } + wm.window_management_behaviour.current_behaviour = value.window_container_behaviour.unwrap_or_default(); wm.window_management_behaviour.float_override = value.float_override.unwrap_or_default(); @@ -1519,10 +1499,10 @@ impl StaticConfig { wm.unmanaged_window_operation_behaviour = value .unmanaged_window_operation_behaviour .unwrap_or_default(); - wm.resize_delta = value.resize_delta.unwrap_or(defaults::RESIZE_DELTA); + wm.resize_delta = value.resize_delta.unwrap_or(DEFAULT_RESIZE_DELTA); wm.mouse_follows_focus = value .mouse_follows_focus - .unwrap_or(defaults::MOUSE_FOLLOWS_FOCUS); + .unwrap_or(DEFAULT_MOUSE_FOLLOWS_FOCUS); wm.work_area_offset = value.global_work_area_offset; // wm.focus_follows_mouse = value.focus_follows_mouse; diff --git a/nix/komorebi-bar-options.nix b/nix/komorebi-bar-options.nix index 3dcdfb9a..f47eab01 100644 --- a/nix/komorebi-bar-options.nix +++ b/nix/komorebi-bar-options.nix @@ -962,103 +962,6 @@ 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; - }; - auto_select_fill = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; - auto_select_text = 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 ( @@ -1345,6 +1248,81 @@ in ); 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 ( @@ -1356,6 +1334,28 @@ 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; + }; + auto_select_text = 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 9ca7a9b6..ae1236fd 100644 --- a/nix/komorebi-options.nix +++ b/nix/komorebi-options.nix @@ -449,12 +449,12 @@ in }; default_container_padding = lib.mkOption { type = (lib.types.nullOr lib.types.int); - default = 10; + default = 5; description = "Global default container padding"; }; default_workspace_padding = lib.mkOption { type = (lib.types.nullOr lib.types.int); - default = 10; + default = 5; description = "Global default workspace padding"; }; display_index_preferences = lib.mkOption { @@ -755,39 +755,6 @@ in ] ); }; - stack_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; - }; - single_border = lib.mkOption { - type = ( - lib.types.nullOr ( - lib.types.oneOf [ - (lib.types.nullOr catppuccinValue) - (lib.types.nullOr base16Value) - ] - ) - ); - default = null; - }; unfocused_locked_border = lib.mkOption { type = ( lib.types.nullOr ( @@ -874,7 +841,7 @@ in ); default = null; }; - floating_border = lib.mkOption { + monocle_border = lib.mkOption { type = ( lib.types.nullOr ( lib.types.oneOf [ @@ -896,17 +863,6 @@ in ); default = null; }; - monocle_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 ( @@ -1193,6 +1149,50 @@ in ); 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; + }; + single_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; + }; }; } ) diff --git a/schema.json b/schema.json index 9006e443..417c9815 100644 --- a/schema.json +++ b/schema.json @@ -103,7 +103,7 @@ "null" ], "format": "int32", - "default": 10 + "default": 5 }, "default_workspace_padding": { "description": "Global default workspace padding", @@ -112,7 +112,7 @@ "null" ], "format": "int32", - "default": 10 + "default": 5 }, "display_index_preferences": { "description": "Set display index preferences",