From 657360d358067afbdd658872eb1c3ef58b1f152e Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 23:26:19 -0700 Subject: [PATCH] refactor(windows): use StaticConfig and its family of komorebi-config static_config re-exports StaticConfig, WorkspaceConfig, MonitorConfig, BorderColours, ThemeOptions, Wallpaper, AnimationsConfig, AppSpecificConfigurationPath, TabsConfig and StackbarConfig from komorebi-config and loses their definitions, the end_of_life/aliases/deprecated notices and read_raw/read (about 650 lines). The inherent impl StaticConfig cannot stay in the daemon (orphan rule): apply_globals is a private trait (ApplyGlobals) and preload, postload and reload are the public extension trait StaticConfigExt, bodies unchanged; process_command, window_manager and main import the trait (komorebic only calls read and the notices, which are inherent in the crate, so it is untouched). The From<&WindowManager> and From<&Monitor> conversions fill the keys Windows never writes (border_radius, titleless_applications, tabbed_applications, window_hiding_position) with None or Default. The five #[deprecated] attributes of the old fields are gone (the schema marker replaced them; see the crate). Verified: Windows cargo clippy --workspace --locked --all-targets -D warnings: clean (tier 2); the oracle test proves the Windows view of this StaticConfig equals schema.json byte for byte. Not verified: Windows unit tests (cannot run), running komorebic.exe or the daemon. --- komorebi/src/main.rs | 1 + komorebi/src/process_command.rs | 1 + komorebi/src/static_config.rs | 650 ++------------------------------ komorebi/src/window_manager.rs | 1 + 4 files changed, 42 insertions(+), 611 deletions(-) diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index a023de69..9b4f12d3 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -52,6 +52,7 @@ use komorebi::reaper; use komorebi::stackbar_manager; use komorebi::state::State; use komorebi::static_config::StaticConfig; +use komorebi::static_config::StaticConfigExt; use komorebi::theme_manager; use komorebi::transparency_manager; use komorebi::window_manager::WindowManager; diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 67f16398..2461f913 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -83,6 +83,7 @@ use crate::state; use crate::state::GlobalState; use crate::state::State; use crate::static_config::StaticConfig; +use crate::static_config::StaticConfigExt; use crate::theme_manager; use crate::transparency_manager; use crate::window::RuleDebug; diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index c66c2fa7..c84b98e9 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -1,5 +1,4 @@ use crate::AspectRatio; -use crate::Axis; use crate::CrossBoundaryBehaviour; use crate::DATA_DIR; use crate::DEFAULT_CONTAINER_PADDING; @@ -22,7 +21,6 @@ use crate::OBJECT_NAME_CHANGE_TITLE_IGNORE_LIST; use crate::Placement; use crate::PredefinedAspectRatio; use crate::REGEX_IDENTIFIERS; -use crate::ResolvedPathBuf; use crate::SLOW_APPLICATION_COMPENSATION_TIME; use crate::SLOW_APPLICATION_IDENTIFIERS; use crate::TRANSPARENCY_BLACKLIST; @@ -30,7 +28,6 @@ use crate::TRAY_AND_MULTI_WINDOW_IDENTIFIERS; use crate::WINDOW_HANDLING_BEHAVIOUR; use crate::WINDOWS_11; use crate::WORKSPACE_MATCHING_RULES; -use crate::WindowHandlingBehaviour; use crate::animation::ANIMATION_DURATION_GLOBAL; use crate::animation::ANIMATION_DURATION_PER_ANIMATION; use crate::animation::ANIMATION_ENABLED_GLOBAL; @@ -47,25 +44,14 @@ use crate::asc::AscApplicationRulesOrSchema; use crate::border_manager; use crate::border_manager::IMPLEMENTATION; use crate::border_manager::STYLE; -use crate::border_manager::ZOrder; use crate::config_generation::WorkspaceMatchingRule; -use crate::core::AnimationStyle; use crate::core::BorderImplementation; -use crate::core::BorderStyle; -use crate::core::DefaultLayout; use crate::core::FocusFollowsMouseImplementation; -use crate::core::HidingBehaviour; -use crate::core::InitialWindowPlacementRules; use crate::core::Layout; -use crate::core::LayoutDefaultEntry; -use crate::core::LayoutOptions; -use crate::core::MonocleFocusBehaviour; use crate::core::MoveBehaviour; use crate::core::OperationBehaviour; use crate::core::Rect; use crate::core::SocketMessage; -use crate::core::StackbarLabel; -use crate::core::StackbarMode; use crate::core::WindowContainerBehaviour; use crate::core::WindowManagementBehaviour; use crate::core::config_generation::ApplicationConfiguration; @@ -77,7 +63,6 @@ use crate::current_virtual_desktop; use crate::monitor; use crate::monitor::Monitor; use crate::monitor_reconciliator; -use crate::resolve_option_hashmap_usize_path; use crate::ring::Ring; use crate::stackbar_manager::STACKBAR_FOCUSED_TEXT_COLOUR; use crate::stackbar_manager::STACKBAR_FONT_FAMILY; @@ -102,8 +87,6 @@ use hotwatch::Hotwatch; use komorebi_themes::colour::Colour; use parking_lot::Mutex; use regex::Regex; -use serde::Deserialize; -use serde::Serialize; use std::collections::HashMap; use std::collections::HashSet; use std::io::ErrorKind; @@ -114,185 +97,17 @@ use std::sync::atomic::Ordering; use uds_windows::UnixListener; use uds_windows::UnixStream; -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Border colours for different container states -pub struct BorderColours { - /// Border colour when the container contains a single window - #[serde(skip_serializing_if = "Option::is_none")] - pub single: Option, - /// Border colour when the container contains multiple windows - #[serde(skip_serializing_if = "Option::is_none")] - pub stack: Option, - /// Border colour when the container is in monocle mode - #[serde(skip_serializing_if = "Option::is_none")] - pub monocle: Option, - /// Border colour when the container is in floating mode - #[serde(skip_serializing_if = "Option::is_none")] - pub floating: Option, - /// Border colour when the container is unfocused - #[serde(skip_serializing_if = "Option::is_none")] - pub unfocused: Option, - /// Border colour when the container is unfocused and locked - #[serde(skip_serializing_if = "Option::is_none")] - pub unfocused_locked: Option, -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Theme options -pub struct ThemeOptions { - /// Specify Light or Dark variant for theme generation - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = komorebi_themes::ThemeVariant::Dark)))] - pub theme_variant: Option, - /// Border colour when the container contains a single window - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = komorebi_themes::Base16Value::Base0D)))] - pub single_border: Option, - /// Border colour when the container contains multiple windows - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = komorebi_themes::Base16Value::Base0B)))] - pub stack_border: Option, - /// Border colour when the container is in monocle mode - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = komorebi_themes::Base16Value::Base0F)))] - pub monocle_border: Option, - /// Border colour when the window is floating - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = komorebi_themes::Base16Value::Base09)))] - pub floating_border: Option, - /// Border colour when the container is unfocused - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = komorebi_themes::Base16Value::Base01)))] - pub unfocused_border: Option, - /// Border colour when the container is unfocused and locked - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = komorebi_themes::Base16Value::Base08)))] - pub unfocused_locked_border: Option, - /// Stackbar focused tab text colour - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = komorebi_themes::Base16Value::Base0B)))] - pub stackbar_focused_text: Option, - /// Stackbar unfocused tab text colour - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = komorebi_themes::Base16Value::Base05)))] - pub stackbar_unfocused_text: Option, - /// Stackbar tab background colour - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = komorebi_themes::Base16Value::Base01)))] - pub stackbar_background: Option, - /// Komorebi status bar accent - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = komorebi_themes::Base16Value::Base0D)))] - pub bar_accent: Option, -} - -#[serde_with::serde_as] -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Wallpaper configuration -pub struct Wallpaper { - /// Path to the wallpaper image file - #[serde_as(as = "ResolvedPathBuf")] - 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" = true)))] - pub generate_theme: Option, - /// Specify Light or Dark variant for theme generation - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = komorebi_themes::ThemeVariant::Dark)))] - pub theme_options: Option, -} - // serde_as must be before derive -#[serde_with::serde_as] -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Workspace configuration -pub struct WorkspaceConfig { - /// Name - pub name: String, - /// Layout - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = DefaultLayout::BSP)))] - pub layout: Option, - /// 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 - #[deprecated(note = "End of life feature")] - #[serde(skip_serializing_if = "Option::is_none")] - #[serde_as(as = "Option")] - pub custom_layout: Option, - /// Layout rules in the format of threshold => layout - #[serde(skip_serializing_if = "Option::is_none")] - pub layout_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>, - /// END OF LIFE FEATURE: Custom layout rules - #[deprecated(note = "End of life feature")] - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(deserialize_with = "resolve_option_hashmap_usize_path", default)] - pub custom_layout_rules: Option>, - /// Container padding (default: global) - #[serde(skip_serializing_if = "Option::is_none")] - pub container_padding: Option, - /// Workspace padding (default: global) - #[serde(skip_serializing_if = "Option::is_none")] - pub workspace_padding: Option, - /// Initial workspace application rules - #[serde(skip_serializing_if = "Option::is_none")] - pub initial_workspace_rules: Option>, - /// Permanent workspace application rules - #[serde(skip_serializing_if = "Option::is_none")] - pub workspace_rules: Option>, - /// Workspace specific work area offset - #[serde(skip_serializing_if = "Option::is_none")] - 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" = 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")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = WindowContainerBehaviour::Create)))] - pub window_container_behaviour: Option, - /// Window container behaviour rules in the format of threshold => behaviour - #[serde(skip_serializing_if = "Option::is_none")] - 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" = 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" = true)))] - pub tile: Option, - /// Specify an axis on which to flip the selected layout - #[serde(skip_serializing_if = "Option::is_none")] - pub layout_flip: Option, - /// Determine what happens to a new window when the Floating workspace layer is active - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = FloatingLayerBehaviour::Tile)))] - pub floating_layer_behaviour: Option, - /// Specify a wallpaper for this workspace - #[serde(skip_serializing_if = "Option::is_none")] - pub wallpaper: Option, - /// Initial window placement rules that determine where new tiled windows are placed - /// in the container list. Can be a placement target (a `WindowPlacement` string like - /// `"Primary"` or a 1-based container index), or a map of placement targets to matching rules. - #[serde(skip_serializing_if = "Option::is_none")] - pub initial_window_placement_rules: Option, -} +pub use komorebi_config::static_config::AnimationsConfig; +pub use komorebi_config::static_config::AppSpecificConfigurationPath; +pub use komorebi_config::static_config::BorderColours; +pub use komorebi_config::static_config::MonitorConfig; +pub use komorebi_config::static_config::StackbarConfig; +pub use komorebi_config::static_config::StaticConfig; +pub use komorebi_config::static_config::TabsConfig; +pub use komorebi_config::static_config::ThemeOptions; +pub use komorebi_config::static_config::Wallpaper; +pub use komorebi_config::static_config::WorkspaceConfig; impl From<&Workspace> for WorkspaceConfig { fn from(value: &Workspace) -> Self { @@ -400,37 +215,6 @@ impl From<&Workspace> for WorkspaceConfig { } } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Monitor configuration -pub struct MonitorConfig { - /// Workspace configurations - pub workspaces: Vec, - /// Monitor-specific work area offset - #[serde(skip_serializing_if = "Option::is_none")] - pub work_area_offset: Option, - /// Window based work area offset - #[serde(skip_serializing_if = "Option::is_none")] - 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" = 1)))] - pub window_based_work_area_offset_limit: Option, - /// Container padding (default: global) - #[serde(skip_serializing_if = "Option::is_none")] - pub container_padding: Option, - /// Workspace padding (default: global) - #[serde(skip_serializing_if = "Option::is_none")] - pub workspace_padding: Option, - /// Specify a wallpaper for this monitor - #[serde(skip_serializing_if = "Option::is_none")] - pub wallpaper: Option, - /// Determine what happens to a new window when the Floating workspace layer is active - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = FloatingLayerBehaviour::Tile)))] - pub floating_layer_behaviour: Option, -} - impl From<&Monitor> for MonitorConfig { fn from(value: &Monitor) -> Self { let mut workspaces = vec![]; @@ -466,386 +250,13 @@ impl From<&Monitor> for MonitorConfig { workspace_padding, wallpaper: value.wallpaper.clone(), floating_layer_behaviour: value.floating_layer_behaviour, + window_hiding_position: None, } } } -#[serde_with::serde_as] -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -#[serde(untagged)] -/// Path(s) to application-specific configuration file(s) -pub enum AppSpecificConfigurationPath { - /// A single `applications.json` file - Single(#[serde_as(as = "ResolvedPathBuf")] PathBuf), - /// Multiple `applications.json` files - Multiple(#[serde_as(as = "Vec")] Vec), -} - -#[serde_with::serde_as] -#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// The `komorebi.json` static configuration file reference for `v0.1.42` -pub struct StaticConfig { - /// DEPRECATED from v0.1.22: no longer required - #[deprecated(note = "No longer required")] - #[serde(skip_serializing_if = "Option::is_none")] - pub invisible_borders: Option, - /// DISCOURAGED: Minimum width for a window to be eligible for tiling - #[serde(skip_serializing_if = "Option::is_none")] - pub minimum_window_width: Option, - /// DISCOURAGED: Minimum height for a window to be eligible for tiling - #[serde(skip_serializing_if = "Option::is_none")] - pub minimum_window_height: Option, - /// Delta to resize windows by - #[serde(skip_serializing_if = "Option::is_none")] - #[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")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = WindowContainerBehaviour::Create)))] - 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" = false)))] - pub float_override: Option, - /// Determines what happens on a new window when on the `FloatingLayer` - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = FloatingLayerBehaviour::Tile)))] - pub floating_layer_behaviour: Option, - /// Determines the placement of a new window when toggling to float - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = Placement::CenterAndResize)))] - pub toggle_float_placement: Option, - /// Determines the `Placement` to be used when spawning a window on the floating layer with the - /// `FloatingLayerBehaviour` set to `FloatingLayerBehaviour::Float` - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = Placement::Center)))] - pub floating_layer_placement: Option, - /// Determines the `Placement` to be used when spawning a window with float override active - #[serde(skip_serializing_if = "Option::is_none")] - pub float_override_placement: Option, - /// Determines the `Placement` to be used when spawning a window that matches a - /// `floating_applications` rule - #[serde(skip_serializing_if = "Option::is_none")] - pub float_rule_placement: Option, - /// Determine what happens when a window is moved across a monitor boundary - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = MoveBehaviour::Swap)))] - pub cross_monitor_move_behaviour: Option, - /// Determine what happens when an action is called on a window at a monitor boundary - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = CrossBoundaryBehaviour::Monitor)))] - pub cross_boundary_behaviour: Option, - /// Determine what happens when focusing in a direction while a monocle container is active - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = MonocleFocusBehaviour::NoOp)))] - pub monocle_focus_behaviour: Option, - /// Determine what happens when commands are sent while an unmanaged window is in the foreground - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = OperationBehaviour::Op)))] - pub unmanaged_window_operation_behaviour: Option, - /// END OF LIFE FEATURE: Use https://github.com/LGUG2Z/masir instead - #[deprecated( - note = "End of life feature, use [masir](https://github.com/LGUG2Z/masir) instead" - )] - #[serde(skip_serializing_if = "Option::is_none")] - pub focus_follows_mouse: Option, - /// Enable or disable mouse follows focus - #[serde(skip_serializing_if = "Option::is_none")] - #[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")] - pub app_specific_configuration_path: Option, - /// Width of window borders - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(alias = "active_window_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" = border_manager::BORDER_OFFSET)))] - pub border_offset: Option, - /// Display window borders - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(alias = "active_window_border")] - #[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 [`theme`] is defined) - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(alias = "active_window_border_colours")] - pub border_colours: Option, - /// Window border style - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(alias = "active_window_border_style")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = BorderStyle::System)))] - pub border_style: Option, - /// DEPRECATED from v0.1.31: no longer required - #[deprecated(note = "No longer required")] - #[serde(skip_serializing_if = "Option::is_none")] - pub border_z_order: Option, - /// Window border implementation - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = BorderImplementation::Komorebi)))] - pub border_implementation: Option, - /// Add transparency to unfocused windows - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = transparency_manager::TRANSPARENCY_ENABLED)))] - pub transparency: Option, - /// Alpha value for unfocused window transparency [[0-255]] - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = transparency_manager::TRANSPARENCY_ALPHA)))] - pub transparency_alpha: Option, - /// Individual window transparency ignore rules - #[serde(skip_serializing_if = "Option::is_none")] - pub transparency_ignore_rules: Option>, - /// Global default workspace padding - #[serde(skip_serializing_if = "Option::is_none")] - #[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" = DEFAULT_CONTAINER_PADDING)))] - pub default_container_padding: Option, - /// Per-layout default options and rules, keyed by layout name. - /// Applied as fallback when a workspace does not define its own layout_options or layout_options_rules. - /// If a workspace defines either setting, all global defaults for that layout are completely replaced. - #[serde(skip_serializing_if = "Option::is_none")] - pub layout_defaults: Option>, - /// Monitor and workspace configurations - #[serde(skip_serializing_if = "Option::is_none")] - pub monitors: Option>, - /// Which Windows signal to use when hiding windows - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = HidingBehaviour::Cloak)))] - pub window_hiding_behaviour: Option, - /// Global work area (space used for tiling) offset - #[serde(skip_serializing_if = "Option::is_none")] - pub global_work_area_offset: Option, - /// Individual window floating rules - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(alias = "float_rules")] - pub ignore_rules: Option>, - /// Individual window force-manage rules - #[serde(skip_serializing_if = "Option::is_none")] - pub manage_rules: Option>, - /// Identify applications which should be managed as floating windows - #[serde(skip_serializing_if = "Option::is_none")] - pub floating_applications: Option>, - /// Identify border overflow applications - #[serde(skip_serializing_if = "Option::is_none")] - pub border_overflow_applications: Option>, - /// Identify tray and multi-window applications - #[serde(skip_serializing_if = "Option::is_none")] - pub tray_and_multi_window_applications: Option>, - /// Identify applications that have the `WS_EX_LAYERED` extended window style - #[serde(skip_serializing_if = "Option::is_none")] - pub layered_applications: Option>, - /// Identify applications that send `EVENT_OBJECT_NAMECHANGE` on launch (very rare) - #[serde(skip_serializing_if = "Option::is_none")] - pub object_name_change_applications: Option>, - /// Do not process `EVENT_OBJECT_NAMECHANGE` events as Show events for identified applications matching these title regexes - #[serde(skip_serializing_if = "Option::is_none")] - pub object_name_change_title_ignore_list: Option>, - /// Set monitor index preferences - #[serde(skip_serializing_if = "Option::is_none")] - pub monitor_index_preferences: Option>, - /// Set display index preferences - #[serde(skip_serializing_if = "Option::is_none")] - pub display_index_preferences: Option>, - /// Stackbar configuration options - #[serde(skip_serializing_if = "Option::is_none")] - pub stackbar: Option, - /// Animations configuration options - #[serde(skip_serializing_if = "Option::is_none")] - pub animation: Option, - /// Theme configuration options - /// - /// If a theme is specified, `border_colours` will have no effect - #[serde(skip_serializing_if = "Option::is_none")] - pub theme: Option, - /// Identify applications which are slow to send initial event notifications - #[serde(skip_serializing_if = "Option::is_none")] - pub slow_application_identifiers: Option>, - /// How long to wait when compensating for slow applications, in milliseconds - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = SLOW_APPLICATION_COMPENSATION_TIME)))] - pub slow_application_compensation_time: Option, - /// Komorebi status bar configuration files for multiple instances on different monitors - // this option is a little special because it is only consumed by komorebic - #[serde(skip_serializing_if = "Option::is_none")] - #[serde_as(as = "Option>")] - pub bar_configurations: Option>, - /// HEAVILY DISCOURAGED: Identify applications for which komorebi should forcibly remove title bars - #[serde(skip_serializing_if = "Option::is_none")] - pub remove_titlebar_applications: Option>, - /// Aspect ratio to resize with when toggling floating mode for a window - #[serde(skip_serializing_if = "Option::is_none")] - pub floating_window_aspect_ratio: Option, - /// Which Windows API behaviour to use when manipulating windows - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = WindowHandlingBehaviour::Sync)))] - pub window_handling_behaviour: Option, -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Animations configuration options -pub struct AnimationsConfig { - /// Enable or disable animations - #[cfg_attr(feature = "schemars", schemars(extend("default" = PerAnimationPrefixConfig::Global(false))))] - pub enabled: PerAnimationPrefixConfig, - /// Set the animation duration in ms - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = PerAnimationPrefixConfig::Global(250))))] - pub duration: Option>, - /// Set the animation style - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = PerAnimationPrefixConfig::Global(AnimationStyle::Linear))))] - pub style: Option>, - /// Set the animation FPS - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = ANIMATION_FPS)))] - pub fps: Option, - /// Render movement animations on a GPU-composited ghost surface (recommended). - /// When false, falls back to the legacy per-frame MoveWindow path. - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = false)))] - pub ghost_movement: Option, -} - pub use komorebi_themes::KomorebiTheme; -impl StaticConfig { - pub fn end_of_life(raw: &str) { - let features = vec![ - "focus_follows_mouse", - "custom_layout", - "custom_layout_rules", - ]; - - let mut display = false; - - for feature in features { - if raw.contains(feature) { - if !display { - display = true; - println!("\n\"{feature}\" is now end-of-life"); - } else { - println!(r#""{feature}" is now end-of-life"#); - } - } - } - - if display { - println!( - "\nEnd-of-life features will not receive any further bug fixes or updates; they should not be used\n" - ) - } - } - - pub fn aliases(raw: &str) { - let mut map = HashMap::new(); - map.insert("border", ["active_window_border"]); - map.insert("border_width", ["active_window_border_width"]); - map.insert("border_offset", ["active_window_border_offset"]); - map.insert("border_colours", ["active_window_border_colours"]); - map.insert("border_style", ["active_window_border_style"]); - map.insert("applications.json", ["applications.yaml"]); - map.insert("ignore_rules", ["float_rules"]); - - let mut display = false; - - for aliases in map.values() { - for a in aliases { - if raw.contains(a) { - display = true; - } - } - } - - if display { - println!( - "\nYour configuration file contains some options that have been renamed or deprecated:\n" - ); - for (canonical, aliases) in map { - for alias in aliases { - if raw.contains(alias) { - println!(r#""{alias}" is now "{canonical}""#); - } - } - } - } - } - - pub fn deprecated(raw: &str) { - let deprecated_options = ["invisible_borders", "border_z_order"]; - let deprecated_variants = vec![ - ("Hide", "window_hiding_behaviour", "Cloak"), - ("Minimize", "window_hiding_behaviour", "Cloak"), - ]; - - for option in deprecated_options { - if raw.contains(option) { - println!(r#""{option}" is deprecated and can be removed"#); - } - } - - for (variant, option, recommended) in deprecated_variants { - if raw.contains(option) && raw.contains(variant) { - println!( - r#"The "{variant}" option for "{option}" is deprecated and can be removed or replaced with "{recommended}""# - ); - } - } - } -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Stackbar tabs configuration -pub struct TabsConfig { - /// Width of a stackbar tab - #[serde(skip_serializing_if = "Option::is_none")] - pub width: Option, - /// Focused tab text colour - #[serde(skip_serializing_if = "Option::is_none")] - pub focused_text: Option, - /// Unfocused tab text colour - #[serde(skip_serializing_if = "Option::is_none")] - pub unfocused_text: Option, - /// Tab background colour - #[serde(skip_serializing_if = "Option::is_none")] - pub background: Option, - /// Font family - #[serde(skip_serializing_if = "Option::is_none")] - pub font_family: Option, - /// Font size - #[serde(skip_serializing_if = "Option::is_none")] - pub font_size: Option, -} - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Stackbar configuration -pub struct StackbarConfig { - /// Stackbar height - #[serde(skip_serializing_if = "Option::is_none")] - pub height: Option, - /// Stackbar label - #[serde(skip_serializing_if = "Option::is_none")] - pub label: Option, - /// Stackbar mode - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr(feature = "schemars", schemars(extend("default" = StackbarMode::Never)))] - pub mode: Option, - /// Stackbar tab configuration options - #[serde(skip_serializing_if = "Option::is_none")] - pub tabs: Option, -} - impl From<&WindowManager> for StaticConfig { #[allow(clippy::too_many_lines)] fn from(value: &WindowManager) -> Self { @@ -970,11 +381,17 @@ impl From<&WindowManager> for StaticConfig { remove_titlebar_applications: Option::from(NO_TITLEBAR.lock().clone()), floating_window_aspect_ratio: Option::from(*FLOATING_WINDOW_TOGGLE_ASPECT_RATIO.lock()), window_handling_behaviour: Option::from(WINDOW_HANDLING_BEHAVIOUR.load()), + ..Default::default() } } } -impl StaticConfig { +/// Applies the settings of a configuration that are not the window manager's own +trait ApplyGlobals { + fn apply_globals(&mut self) -> eyre::Result<()>; +} + +impl ApplyGlobals for StaticConfig { #[allow(clippy::cognitive_complexity, clippy::too_many_lines)] fn apply_globals(&mut self) -> eyre::Result<()> { *FLOATING_WINDOW_TOGGLE_ASPECT_RATIO.lock() = self @@ -1292,18 +709,29 @@ impl StaticConfig { Ok(()) } +} - pub fn read_raw(raw: &str) -> eyre::Result { - Ok(serde_json::from_str(raw)?) - } +/// What loading a configuration needs from the window manager: the part of `StaticConfig` +/// that cannot be an inherent impl now that the type lives in `komorebi-config`. +#[allow(clippy::ptr_arg)] // the signatures are the ones the inherent functions had +pub trait StaticConfigExt: Sized { + /// Makes the window manager from the file at `path`, and starts watching the file + fn preload( + path: &PathBuf, + incoming: Receiver, + unix_listener: Option, + ) -> eyre::Result; - pub fn read(path: &PathBuf) -> eyre::Result { - let content = std::fs::read_to_string(path)?; - serde_json::from_str(&content).map_err(Into::into) - } + /// Gives the monitors of the window manager what the file says about them + fn postload(path: &PathBuf, wm: &Arc>) -> eyre::Result<()>; + /// Replaces the configuration of the window manager with the file at `path` + fn reload(path: &PathBuf, wm: &mut WindowManager) -> eyre::Result<()>; +} + +impl StaticConfigExt for StaticConfig { #[allow(clippy::too_many_lines)] - pub fn preload( + fn preload( path: &PathBuf, incoming: Receiver, unix_listener: Option, @@ -1407,7 +835,7 @@ impl StaticConfig { Ok(wm) } - pub fn postload(path: &PathBuf, wm: &Arc>) -> eyre::Result<()> { + fn postload(path: &PathBuf, wm: &Arc>) -> eyre::Result<()> { let mut value = Self::read(path)?; let mut wm = wm.lock(); @@ -1571,7 +999,7 @@ impl StaticConfig { Ok(()) } - pub fn reload(path: &PathBuf, wm: &mut WindowManager) -> eyre::Result<()> { + fn reload(path: &PathBuf, wm: &mut WindowManager) -> eyre::Result<()> { let mut value = Self::read(path)?; value.apply_globals()?; diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 5e09998b..a4e6502c 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -68,6 +68,7 @@ use crate::should_act; use crate::should_act_individual; use crate::state::State; use crate::static_config::StaticConfig; +use crate::static_config::StaticConfigExt; use crate::transparency_manager; use crate::window::Window; use crate::window_manager_event::WindowManagerEvent;