mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 22:01:22 +01:00
refactor(config): move AspectRatio and PerAnimationPrefixConfig into komorebi-config
AspectRatio and PredefinedAspectRatio (with the Default and width_and_height impls) and the generic PerAnimationPrefixConfig<T> have identical code in the three trees and, after the previous converge revisions, identical docs; the crate takes the Windows copy. The trees keep their copies until the next revisions. The oracle gains a check that the generated AspectRatio and PredefinedAspectRatio definitions equal those of all three checked-in schema.json files. PerAnimationPrefixConfig has no check of its own: its definitions are numbered per instantiation, so the AnimationsConfig move covers it. Verified: native cargo test -p komorebi-config: 4 unit + 5 schemas passed, 0 failed (tier 1).
This commit is contained in:
1 parent
7ebead10aa
commit
44e0b32459
4 files changed
+100
No files matched your search
@@ -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<T> {
|
||||
/// Animation configuration prefixed for a specific animation kind
|
||||
Prefix(HashMap<AnimationPrefix, T>),
|
||||
/// Animation configuration for all animation kinds
|
||||
Global(T),
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
@@ -10,5 +10,7 @@
|
||||
#[cfg(feature = "schemars")]
|
||||
pub mod schema;
|
||||
|
||||
pub mod animation;
|
||||
pub mod aspect_ratio;
|
||||
pub mod behaviour;
|
||||
pub mod matching;
|
||||
@@ -188,3 +188,10 @@ fn the_behaviour_enums_are_the_definitions_of_the_trees_that_have_them() {
|
||||
assert_same_definitions::<WindowHandlingBehaviour>(&[windows], &["WindowHandlingBehaviour"]);
|
||||
assert_same_definitions::<ZOrder>(&[windows], &["ZOrder"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_aspect_ratio_is_the_definition_of_every_tree() {
|
||||
use komorebi_config::aspect_ratio::AspectRatio;
|
||||
|
||||
assert_same_definitions::<AspectRatio>(&all(), &["AspectRatio", "PredefinedAspectRatio"]);
|
||||
}
|
||||
Reference in new issue
Block a user