diff --git a/crates/komorebi-config/src/animation.rs b/crates/komorebi-config/src/animation.rs new file mode 100644 index 00000000..c593619f --- /dev/null +++ b/crates/komorebi-config/src/animation.rs @@ -0,0 +1,40 @@ +//! How the animation settings of `komorebi.json` are scoped. + +use std::collections::HashMap; + +use komorebi_protocol::animation::prefix::AnimationPrefix; +use serde::Deserialize; +use serde::Serialize; + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +#[serde(untagged)] +/// Animation configuration +/// +/// This can be either global: +/// ```json +/// { +/// "enabled": true, +/// "style": "EaseInSine", +/// "fps": 60, +/// "duration": 250 +/// } +/// ``` +/// +/// Or scoped by an animation kind prefix: +/// ```json +/// { +/// "movement": { +/// "enabled": true, +/// "style": "EaseInSine", +/// "fps": 60, +/// "duration": 250 +/// } +/// } +/// ``` +pub enum PerAnimationPrefixConfig { + /// Animation configuration prefixed for a specific animation kind + Prefix(HashMap), + /// Animation configuration for all animation kinds + Global(T), +} diff --git a/crates/komorebi-config/src/aspect_ratio.rs b/crates/komorebi-config/src/aspect_ratio.rs new file mode 100644 index 00000000..4b5c1768 --- /dev/null +++ b/crates/komorebi-config/src/aspect_ratio.rs @@ -0,0 +1,51 @@ +//! The aspect ratio a temporarily floating window is resized to. + +use serde::Deserialize; +use serde::Serialize; +use strum::Display; +use strum::EnumString; + +#[derive(Copy, Clone, Debug, Display, EnumString, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +#[serde(untagged)] +/// Aspect ratio for temporarily floating windows +pub enum AspectRatio { + /// Predefined aspect ratio + #[cfg_attr(feature = "schemars", schemars(title = "Predefined"))] + Predefined(PredefinedAspectRatio), + /// Custom W:H aspect ratio + #[cfg_attr(feature = "schemars", schemars(title = "Custom"))] + Custom(i32, i32), +} + +impl Default for AspectRatio { + fn default() -> Self { + AspectRatio::Predefined(PredefinedAspectRatio::default()) + } +} + +impl AspectRatio { + pub fn width_and_height(self) -> (i32, i32) { + match self { + AspectRatio::Predefined(predefined) => match predefined { + PredefinedAspectRatio::Ultrawide => (21, 9), + PredefinedAspectRatio::Widescreen => (16, 9), + PredefinedAspectRatio::Standard => (4, 3), + }, + AspectRatio::Custom(w, h) => (w, h), + } + } +} + +#[derive(Copy, Clone, Debug, Default, Display, EnumString, Serialize, Deserialize, PartialEq)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Predefined aspect ratio +pub enum PredefinedAspectRatio { + /// 21:9 + Ultrawide, + /// 16:9 + Widescreen, + /// 4:3 + #[default] + Standard, +} diff --git a/crates/komorebi-config/src/lib.rs b/crates/komorebi-config/src/lib.rs index c58fc67c..a479a397 100644 --- a/crates/komorebi-config/src/lib.rs +++ b/crates/komorebi-config/src/lib.rs @@ -10,5 +10,7 @@ #[cfg(feature = "schemars")] pub mod schema; +pub mod animation; +pub mod aspect_ratio; pub mod behaviour; pub mod matching; diff --git a/crates/komorebi-config/tests/schemas.rs b/crates/komorebi-config/tests/schemas.rs index 633cdc8c..11780bea 100644 --- a/crates/komorebi-config/tests/schemas.rs +++ b/crates/komorebi-config/tests/schemas.rs @@ -188,3 +188,10 @@ fn the_behaviour_enums_are_the_definitions_of_the_trees_that_have_them() { assert_same_definitions::(&[windows], &["WindowHandlingBehaviour"]); assert_same_definitions::(&[windows], &["ZOrder"]); } + +#[test] +fn the_aspect_ratio_is_the_definition_of_every_tree() { + use komorebi_config::aspect_ratio::AspectRatio; + + assert_same_definitions::(&all(), &["AspectRatio", "PredefinedAspectRatio"]); +}