diff --git a/Cargo.lock b/Cargo.lock index 11225018..15b16c0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3452,6 +3452,7 @@ dependencies = [ "schemars 1.2.3", "serde", "serde_json_lenient", + "serde_with", "strum", ] diff --git a/crates/komorebi-config/Cargo.toml b/crates/komorebi-config/Cargo.toml index 999e93be..432a1c74 100644 --- a/crates/komorebi-config/Cargo.toml +++ b/crates/komorebi-config/Cargo.toml @@ -12,6 +12,7 @@ komorebi-themes = { path = "../../komorebi-themes" } clap = { workspace = true } color-eyre = { workspace = true } serde = { workspace = true } +serde_with = { version = "3.12", features = ["schemars_1"] } serde_json = { workspace = true, features = ["preserve_order"] } strum = { workspace = true } diff --git a/crates/komorebi-config/src/changes.rs b/crates/komorebi-config/src/changes.rs new file mode 100644 index 00000000..4bb1c06f --- /dev/null +++ b/crates/komorebi-config/src/changes.rs @@ -0,0 +1,325 @@ +//! What each platform's schema says differently from the union, as data. +//! +//! The union is written once (Windows' text, Windows' defaults); a view applies the changes of +//! its platform after pruning. They are of three kinds: descriptions that read differently on +//! a platform (spelling, or a sentence about that platform), default values that are a platform +//! fact (paddings, border width and offset), and properties the platform's file never had. Each +//! entry is a candidate for convergence: removing one is a description or default change of one +//! checked-in schema, which the test of the schemas shows. +//! +//! Generated from the difference between the union's view and the checked-in schema.json of +//! each tree (the helper is `tools/schema-changes` in the work notes); the test `tests/schemas.rs` +//! proves that view and file are byte-identical. + +use komorebi_protocol::platforms::Platform; + +/// One change of a view +#[derive(Clone, Copy, Debug)] +pub enum Change { + /// Replace the value at the JSON pointer with this JSON text + Set(&'static str), + /// Remove the key at the JSON pointer + Remove, +} + +/// The changes a platform's view applies, in order +#[must_use] +pub const fn for_platform(platform: Platform) -> &'static [(&'static str, Change)] { + match platform { + Platform::Windows => WINDOWS, + Platform::Kde => KDE, + Platform::MacOs => MACOS, + } +} + +const WINDOWS: &[(&str, Change)] = &[( + "/$defs/PlacementTarget", + Change::Set( + r####"{"description":"A target position for window placement, used as a key in `InitialWindowPlacementRules::Rules`.\n\nCan be either a `WindowPlacement` variant name (e.g. `\"Primary\"`, `\"Last\"`)\nor a 1-based container index (e.g. `\"1\"`, `\"3\"`, or the integer `3`).\n\nNOTE: Integer indices are 1-based in the config for user-friendliness.","anyOf":[{"$ref":"#/$defs/WindowPlacement"},{"description":"A 1-based container index as a string","type":"string","pattern":"^[0-9]+$"},{"description":"A 1-based container index","type":"integer","minimum":0}]}"####, + ), +)]; + +const KDE: &[(&str, Change)] = &[ + ( + "/$defs/AnimationsConfig/description", + Change::Set(r####""Animation configuration""####), + ), + ( + "/$defs/AppSpecificConfigurationPath/anyOf/0/description", + Change::Set(r####""A single applications.json file""####), + ), + ( + "/$defs/AppSpecificConfigurationPath/anyOf/1/description", + Change::Set(r####""Multiple applications.json files""####), + ), + ( + "/$defs/BorderColours/description", + Change::Set( + r####""Border colours for different container states\n\nThese options will have no effect if a `theme` is set""####, + ), + ), + ( + "/$defs/MonitorConfig/properties/container_padding/description", + Change::Set(r####""Container padding""####), + ), + ( + "/$defs/MonitorConfig/properties/window_hiding_position/description", + Change::Set( + r####""Accepted so that a configuration written for another platform loads, and ignored: there is\nno hiding position on KDE Plasma""####, + ), + ), + ( + "/$defs/ThemeOptions/properties/floating_border/description", + Change::Set(r####""Border color when the window is floating""####), + ), + ( + "/$defs/ThemeOptions/properties/monocle_border/description", + Change::Set(r####""Border color when the container is in monocle mode""####), + ), + ( + "/$defs/ThemeOptions/properties/single_border/description", + Change::Set(r####""Border color when the container contains a single window""####), + ), + ( + "/$defs/ThemeOptions/properties/stack_border/description", + Change::Set(r####""Border color when the container contains multiple windows""####), + ), + ( + "/$defs/ThemeOptions/properties/unfocused_border/description", + Change::Set(r####""Border color when the container is unfocused""####), + ), + ( + "/$defs/ThemeOptions/properties/unfocused_locked_border/description", + Change::Set(r####""Border color when the container is unfocused and locked""####), + ), + ( + "/$defs/Wallpaper/properties/theme_options/description", + Change::Set(r####""Specify theme options""####), + ), + ( + "/$defs/WorkspaceConfig/properties/window_container_behaviour_rules/description", + Change::Set( + r####""Window container behavior rules in the format of threshold => behavior""####, + ), + ), + ( + "/description", + Change::Set( + r####""The `komorebi.json` static configuration file reference for komorebi for KDE Plasma""####, + ), + ), + ( + "/properties/app_specific_configuration_path/description", + Change::Set( + r####""Path to an applications.json, or a list of them, with rules for the applications that\nneed them: which windows to ignore, to manage and to float""####, + ), + ), + ( + "/properties/border_colours/description", + Change::Set( + r####""Window border colours for different container types (has no effect if a theme is defined)""####, + ), + ), + ( + "/properties/border_offset/default", + Change::Set(r####"0"####), + ), + ( + "/properties/border_width/default", + Change::Set(r####"10"####), + ), + ( + "/properties/default_container_padding/default", + Change::Set(r####"5"####), + ), + ( + "/properties/default_workspace_padding/default", + Change::Set(r####"5"####), + ), + ( + "/properties/float_rule_placement/description", + Change::Set( + r####""Determines the `Placement` to be used when spawning a window that matches a\n'floating_applications' rule""####, + ), + ), + ( + "/properties/focus_follows_mouse/description", + Change::Set( + r####""Focus the window under the pointer. On KDE this is KWin's own focus policy, whichever\nimplementation is named""####, + ), + ), + ( + "/properties/tabbed_applications/description", + Change::Set( + r####""Accepted so that a configuration written for another platform loads, and ignored: a KWin\nwindow has no native tabs""####, + ), + ), + ( + "/properties/titleless_applications/description", + Change::Set( + r####""Accepted so that a configuration written for another platform loads, and ignored: a KWin\nwindow is always a window""####, + ), + ), + ( + "/properties/transparency/description", + Change::Set(r####""Add transparency to unfocused windows (default: false)""####), + ), + ( + "/properties/transparency_alpha/description", + Change::Set( + r####""Alpha value for unfocused window transparency [[0-255]] (default: 200)""####, + ), + ), + ( + "/$defs/KomorebiThemeBase16/properties/stackbar_background", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeBase16/properties/stackbar_focused_text", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeBase16/properties/stackbar_unfocused_text", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeCatppuccin/properties/stackbar_background", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeCatppuccin/properties/stackbar_focused_text", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeCatppuccin/properties/stackbar_unfocused_text", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeCustom/properties/stackbar_background", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeCustom/properties/stackbar_focused_text", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeCustom/properties/stackbar_unfocused_text", + Change::Remove, + ), + ( + "/$defs/Wallpaper/properties/theme_options/default", + Change::Remove, + ), + ("/properties/focus_follows_mouse/deprecated", Change::Remove), + ("/properties/transparency/default", Change::Remove), + ("/properties/transparency_alpha/default", Change::Remove), +]; + +const MACOS: &[(&str, Change)] = &[ + ( + "/$defs/AnimationsConfig/description", + Change::Set(r####""Animation configuration""####), + ), + ( + "/$defs/AppSpecificConfigurationPath/anyOf/0/description", + Change::Set(r####""A single applications.json file""####), + ), + ( + "/$defs/AppSpecificConfigurationPath/anyOf/1/description", + Change::Set(r####""Multiple applications.json files""####), + ), + ( + "/$defs/BorderColours/description", + Change::Set( + r####""Border colours for different container states\n\nThese options will have no effect if a `theme` is set""####, + ), + ), + ( + "/$defs/MonitorConfig/properties/container_padding/description", + Change::Set(r####""Container padding""####), + ), + ( + "/$defs/Wallpaper/properties/theme_options/description", + Change::Set(r####""Specify theme options""####), + ), + ( + "/description", + Change::Set( + r####""The `komorebi.json` static configuration file reference for komorebi for Mac `v0.1.0`\n\n`\"$schema\": \"https://komorebi-for-mac.lgug2z.com/komorebi.0.1.0.schema.json\"`""####, + ), + ), + ( + "/properties/border_colours/description", + Change::Set( + r####""Window border colours for different container types (has no effect if a theme is defined)""####, + ), + ), + ( + "/properties/border_offset/default", + Change::Set(r####"0"####), + ), + ( + "/properties/border_width/default", + Change::Set(r####"10"####), + ), + ( + "/properties/default_container_padding/default", + Change::Set(r####"5"####), + ), + ( + "/properties/default_workspace_padding/default", + Change::Set(r####"5"####), + ), + ( + "/properties/float_rule_placement/description", + Change::Set( + r####""Determines the `Placement` to be used when spawning a window that matches a\n'floating_applications' rule""####, + ), + ), + ( + "/properties/floating_window_aspect_ratio/description", + Change::Set( + r####""Identify applications which are slow to send initial event notifications\nAspect ratio to resize with when toggling floating mode for a window""####, + ), + ), + ( + "/$defs/KomorebiThemeBase16/properties/stackbar_background", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeBase16/properties/stackbar_focused_text", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeBase16/properties/stackbar_unfocused_text", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeCatppuccin/properties/stackbar_background", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeCatppuccin/properties/stackbar_focused_text", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeCatppuccin/properties/stackbar_unfocused_text", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeCustom/properties/stackbar_background", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeCustom/properties/stackbar_focused_text", + Change::Remove, + ), + ( + "/$defs/KomorebiThemeCustom/properties/stackbar_unfocused_text", + Change::Remove, + ), + ( + "/$defs/Wallpaper/properties/theme_options/default", + Change::Remove, + ), +]; diff --git a/crates/komorebi-config/src/defaults.rs b/crates/komorebi-config/src/defaults.rs new file mode 100644 index 00000000..b0b38f52 --- /dev/null +++ b/crates/komorebi-config/src/defaults.rs @@ -0,0 +1,18 @@ +//! The values the schema says a key has when the file leaves it out. +//! +//! These are the Windows values. Each daemon keeps its own run-time default for the few that +//! differ (the paddings, the border width and offset), and the schema view of a platform says +//! that platform's value (see `schema::platform_changes`). + +pub const DEFAULT_RESIZE_DELTA: i32 = 50; +pub const DEFAULT_MOUSE_FOLLOWS_FOCUS: bool = true; +pub const DEFAULT_WORKSPACE_PADDING: i32 = 10; +pub const DEFAULT_CONTAINER_PADDING: i32 = 10; +pub const SLOW_APPLICATION_COMPENSATION_TIME: u64 = 20; +pub const ANIMATION_FPS: u64 = 60; +pub const BORDER_WIDTH: i32 = 8; +pub const BORDER_OFFSET: i32 = -1; +pub const BORDER_ENABLED: bool = true; +pub const BORDER_RADIUS: i32 = 10; +pub const TRANSPARENCY_ENABLED: bool = false; +pub const TRANSPARENCY_ALPHA: u8 = 200; diff --git a/crates/komorebi-config/src/lib.rs b/crates/komorebi-config/src/lib.rs index c910cb19..ba126d86 100644 --- a/crates/komorebi-config/src/lib.rs +++ b/crates/komorebi-config/src/lib.rs @@ -15,5 +15,8 @@ pub mod application_configuration; pub mod asc; pub mod aspect_ratio; pub mod behaviour; +pub mod changes; +pub mod defaults; pub mod matching; pub mod placement; +pub mod static_config; diff --git a/crates/komorebi-config/src/schema.rs b/crates/komorebi-config/src/schema.rs index 108617d7..3330f1a7 100644 --- a/crates/komorebi-config/src/schema.rs +++ b/crates/komorebi-config/src/schema.rs @@ -6,6 +6,8 @@ //! [`view`] drops what the platform does not read, strips the `x-komorebi-` markers and //! removes the definitions nothing refers to any more. +use crate::changes; +use crate::changes::Change; pub use komorebi_protocol::platforms::Platform; use schemars::JsonSchema; use serde_json::Map; @@ -60,6 +62,9 @@ pub fn view_of(mut schema: Value, platform: Platform) -> Value { *target = Value::String((*text).to_string()); } } + for (pointer, change) in changes::for_platform(platform) { + apply(&mut schema, pointer, *change); + } let mut reachable = Vec::new(); collect_refs(&schema, &mut reachable); if let Some(defs) = schema.get("$defs").and_then(Value::as_object).cloned() { @@ -177,3 +182,20 @@ fn platform_text(platform: Platform) -> &'static [(&'static str, &'static str, & ], } } + +fn apply(schema: &mut Value, pointer: &str, change: Change) { + match change { + Change::Set(json) => { + if let Some(target) = schema.pointer_mut(pointer) { + *target = serde_json::from_str(json).expect("a change is JSON"); + } + } + Change::Remove => { + if let Some((parent, key)) = pointer.rsplit_once('/') + && let Some(Value::Object(map)) = schema.pointer_mut(parent) + { + map.retain(|k, _| k != key); + } + } + } +} diff --git a/crates/komorebi-config/src/static_config.rs b/crates/komorebi-config/src/static_config.rs new file mode 100644 index 00000000..546a49e5 --- /dev/null +++ b/crates/komorebi-config/src/static_config.rs @@ -0,0 +1,585 @@ +//! The `komorebi.json` static configuration file: one `StaticConfig` with every key any +//! platform reads. A key that only some platforms read says so in its schema +//! (`x-komorebi-platforms`); a daemon reports the keys it does not read when it loads a file. + +use std::collections::HashMap; +use std::path::PathBuf; + +use komorebi_layouts::Axis; +use komorebi_layouts::DefaultLayout; +use komorebi_layouts::LayoutDefaultEntry; +use komorebi_layouts::LayoutOptions; +use komorebi_layouts::Rect; +use komorebi_protocol::animation::AnimationStyle; +use komorebi_protocol::pathext::ResolvedPathBuf; +use komorebi_protocol::pathext::resolve_option_hashmap_usize_path; +use komorebi_protocol::types::BorderImplementation; +use komorebi_protocol::types::BorderStyle; +use komorebi_protocol::types::FocusFollowsMouseImplementation; +use komorebi_protocol::types::HidingBehaviour; +use komorebi_protocol::types::MonocleFocusBehaviour; +use komorebi_protocol::types::MoveBehaviour; +use komorebi_protocol::types::OperationBehaviour; +use komorebi_protocol::types::StackbarLabel; +use komorebi_protocol::types::StackbarMode; +use komorebi_themes::KomorebiTheme; +use komorebi_themes::colour::Colour; +use serde::Deserialize; +use serde::Serialize; + +use crate::animation::PerAnimationPrefixConfig; +use crate::aspect_ratio::AspectRatio; +use crate::behaviour::CrossBoundaryBehaviour; +use crate::behaviour::FloatingLayerBehaviour; +use crate::behaviour::Placement; +use crate::behaviour::WindowContainerBehaviour; +use crate::behaviour::WindowHandlingBehaviour; +use crate::behaviour::WindowHidingPosition; +use crate::behaviour::ZOrder; +use crate::defaults; +use crate::matching::MatchingRule; +use crate::placement::InitialWindowPlacementRules; + +#[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)))] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + 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)))] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + 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)))] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + 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_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 + #[cfg_attr(feature = "schemars", schemars(extend("deprecated" = true)))] + #[serde(skip_serializing_if = "Option::is_none")] + #[serde_as(as = "Option")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + 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 + #[cfg_attr(feature = "schemars", schemars(extend("deprecated" = true)))] + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(deserialize_with = "resolve_option_hashmap_usize_path", default)] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + 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")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows", "kde"])))] + pub initial_window_placement_rules: Option, +} + +#[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, + /// Determine which position windows should be hidden at on this monitor + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["kde", "macos"])))] + pub window_hiding_position: Option, +} + +#[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 + #[cfg_attr(feature = "schemars", schemars(extend("deprecated" = true)))] + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + pub invisible_borders: Option, + /// DISCOURAGED: Minimum width for a window to be eligible for tiling + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + pub minimum_window_width: Option, + /// DISCOURAGED: Minimum height for a window to be eligible for tiling + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + 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::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 + #[cfg_attr(feature = "schemars", schemars(extend("deprecated" = true)))] + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows", "kde"])))] + 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" = defaults::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" = defaults::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)))] + 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("x-komorebi-platforms" = ["kde", "macos"])))] + 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)))] + 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)))] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + pub border_style: Option, + /// DEPRECATED from v0.1.31: no longer required + #[cfg_attr(feature = "schemars", schemars(extend("deprecated" = true)))] + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + pub border_z_order: Option, + /// Window border implementation + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("default" = BorderImplementation::Komorebi)))] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + pub border_implementation: Option, + /// Add transparency to unfocused windows + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::TRANSPARENCY_ENABLED)))] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows", "kde"])))] + 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" = defaults::TRANSPARENCY_ALPHA)))] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows", "kde"])))] + pub transparency_alpha: Option, + /// Individual window transparency ignore rules + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows", "kde"])))] + 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)))] + 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)))] + 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)))] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + 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 applications which should be managed despite not reporting titles to the system + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["kde", "macos"])))] + pub titleless_applications: Option>, + /// Identify applications which use native tabs for special handling + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["kde", "macos"])))] + pub tabbed_applications: Option>, + /// Identify border overflow applications + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + pub border_overflow_applications: Option>, + /// Identify tray and multi-window applications + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + 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")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + pub layered_applications: Option>, + /// Identify applications that send `EVENT_OBJECT_NAMECHANGE` on launch (very rare) + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + 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")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + pub object_name_change_title_ignore_list: Option>, + /// Set monitor index preferences + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + 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")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + 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")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + 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" = defaults::SLOW_APPLICATION_COMPENSATION_TIME)))] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + 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>")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + pub bar_configurations: Option>, + /// HEAVILY DISCOURAGED: Identify applications for which komorebi should forcibly remove title bars + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + 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)))] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + 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" = defaults::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)))] + #[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))] + pub ghost_movement: Option, +} + +#[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, +} diff --git a/crates/komorebi-config/tests/schemas.rs b/crates/komorebi-config/tests/schemas.rs index 96da3510..87c48471 100644 --- a/crates/komorebi-config/tests/schemas.rs +++ b/crates/komorebi-config/tests/schemas.rs @@ -234,3 +234,20 @@ fn the_placement_types_are_the_definitions_of_windows_and_kde() { ); assert_same_definitions::(&[kde], &["PlacementTarget"]); } + +/// The platform views of the one `StaticConfig` are byte-identical to the checked-in +/// `schema.json` of each tree. +#[test] +fn the_schema_of_each_platform_is_a_view_of_the_one_static_config() { + use komorebi_config::static_config::StaticConfig; + use komorebi_protocol::platforms::Platform; + + for (tree, platform) in [(&TREES[1], Platform::Kde), (&TREES[2], Platform::MacOs)] { + let view = komorebi_config::schema::view::(platform); + assert!( + view == checked_in(tree, "schema.json"), + "{}: the view of the schema of StaticConfig differs from schema.json", + tree.name + ); + } +} diff --git a/komorebi-for-kde/Cargo.lock b/komorebi-for-kde/Cargo.lock index d257f7ab..27a60fe3 100644 --- a/komorebi-for-kde/Cargo.lock +++ b/komorebi-for-kde/Cargo.lock @@ -2558,6 +2558,7 @@ dependencies = [ "schemars 1.2.3", "serde", "serde_json_lenient", + "serde_with", "strum", ] diff --git a/komorebi-for-mac/Cargo.lock b/komorebi-for-mac/Cargo.lock index 5becbc70..f2fb52e3 100644 --- a/komorebi-for-mac/Cargo.lock +++ b/komorebi-for-mac/Cargo.lock @@ -3268,6 +3268,7 @@ dependencies = [ "schemars 1.2.3", "serde", "serde_json_lenient", + "serde_with", "strum", ]