From 4095f45fd3657c69e49e20cb5c5ec9914c637fba Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 22:24:51 -0700 Subject: [PATCH] refactor(kde): use AspectRatio and PerAnimationPrefixConfig of komorebi-config window and animation re-export the three types from komorebi-config; the local definitions (82 lines) and their imports are removed, so no call site changes. Verified: KDE cargo check --workspace --all-targets: no warnings; cargo test -p komorebi --lib: 289 passed, 0 failed; --test schemas: 5 passed; komorebic regeneration: schema.json and schema.asc.json byte-identical to the checked-in files. --- .../komorebi/src/animation/mod.rs | 36 +------------- komorebi-for-kde/komorebi/src/window.rs | 49 +------------------ 2 files changed, 3 insertions(+), 82 deletions(-) diff --git a/komorebi-for-kde/komorebi/src/animation/mod.rs b/komorebi-for-kde/komorebi/src/animation/mod.rs index af2efa44..3946ec98 100644 --- a/komorebi-for-kde/komorebi/src/animation/mod.rs +++ b/komorebi-for-kde/komorebi/src/animation/mod.rs @@ -12,6 +12,7 @@ use crate::core::animation::AnimationStyle; use parking_lot::Mutex; pub use prefix::AnimationPrefix; +pub use komorebi_config::animation::PerAnimationPrefixConfig; use std::collections::HashMap; use std::sync::Arc; use std::sync::LazyLock; @@ -20,41 +21,6 @@ use std::sync::atomic::AtomicU64; pub mod prefix; -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), -} pub const DEFAULT_ANIMATION_ENABLED: bool = false; pub const DEFAULT_ANIMATION_STYLE: AnimationStyle = AnimationStyle::Linear; diff --git a/komorebi-for-kde/komorebi/src/window.rs b/komorebi-for-kde/komorebi/src/window.rs index 8ba0ea16..90a55c83 100644 --- a/komorebi-for-kde/komorebi/src/window.rs +++ b/komorebi-for-kde/komorebi/src/window.rs @@ -27,6 +27,8 @@ use crate::REGEX_IDENTIFIERS; use crate::backend::backend; use crate::core::ApplicationIdentifier; use crate::core::Rect; +pub use komorebi_config::aspect_ratio::AspectRatio; +pub use komorebi_config::aspect_ratio::PredefinedAspectRatio; use crate::core::config_generation::IdWithIdentifier; use crate::core::config_generation::MatchingRule; use crate::core::config_generation::MatchingStrategy; @@ -43,8 +45,6 @@ use std::fmt::Display; use std::fmt::Formatter; use std::fmt::Write; use std::path::PathBuf; -use strum::Display; -use strum::EnumString; /// The windows the user is resizing by dragging an edge of: komorebi does not move them while they /// are (the other tiles follow the drag, and the window is put in its tile when they let go) @@ -431,51 +431,6 @@ impl Window { } } -#[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()) - } -} - -#[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, -} - -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), - } - } -} - /// Why [`Window::should_manage`] decided as it did: what it read of the window, and the rule of /// each kind that matched it #[derive(Debug, Default, Serialize, Deserialize)]