From dc0b9751a5a1c8e682b809a1c30175f0336e4599 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 22:05:02 -0700 Subject: [PATCH] refactor(windows): use the matching types of komorebi-config komorebi depends on komorebi-config and core::config_generation re-exports MatchingRule, WorkspaceMatchingRule, IdWithIdentifier, MatchingStrategy and IdWithIdentifierAndComment from it, so no call site changes. The 84 duplicated lines (five types and the From impl) are removed; ApplicationOptions, ApplicationConfiguration and the generator stay. Verified: Windows cargo clippy --workspace --locked --all-targets -D warnings: clean (tier 2, persistent target). Schema files untouched. --- Cargo.lock | 1 + komorebi/Cargo.toml | 2 + komorebi/src/core/config_generation.rs | 89 ++------------------------ 3 files changed, 8 insertions(+), 84 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9b69ce31..68a33d3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3338,6 +3338,7 @@ dependencies = [ "ed25519-dalek", "hotwatch", "komorebi-collections", + "komorebi-config", "komorebi-layouts", "komorebi-protocol", "komorebi-scrolling", diff --git a/komorebi/Cargo.toml b/komorebi/Cargo.toml index 9c6aa4c9..13074951 100644 --- a/komorebi/Cargo.toml +++ b/komorebi/Cargo.toml @@ -9,6 +9,7 @@ edition = "2024" [dependencies] komorebi-collections = { path = "../crates/komorebi-collections" } +komorebi-config = { path = "../crates/komorebi-config", default-features = false } komorebi-layouts = { path = "../komorebi-layouts", features = ["win32"] } komorebi-scrolling = { path = "../komorebi-scrolling" } komorebi-themes = { path = "../komorebi-themes" } @@ -70,6 +71,7 @@ deadlock_detection = ["parking_lot/deadlock_detection"] schemars = [ "dep:schemars", "komorebi-collections/schemars", + "komorebi-config/schemars", "komorebi-layouts/schemars", "komorebi-protocol/schemars", ] diff --git a/komorebi/src/core/config_generation.rs b/komorebi/src/core/config_generation.rs index a189a0da..4a64d22a 100644 --- a/komorebi/src/core/config_generation.rs +++ b/komorebi/src/core/config_generation.rs @@ -50,90 +50,11 @@ impl ApplicationOptions { } } -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -#[serde(untagged)] -/// Rule for matching applications -pub enum MatchingRule { - /// Simple matching rule which must evaluate to true - Simple(IdWithIdentifier), - /// Composite matching rule where all conditions must evaluate to true - Composite(Vec), -} - -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Rule for assigning applications to a workspace -pub struct WorkspaceMatchingRule { - /// Target monitor index - pub monitor_index: usize, - /// Target workspace index - pub workspace_index: usize, - /// Matching rule for the application - pub matching_rule: MatchingRule, - /// Whether to apply the rule only when the application is initially launched - pub initial_only: bool, -} - -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Rule for matching applications -pub struct IdWithIdentifier { - /// Kind of identifier to target - pub kind: ApplicationIdentifier, - /// Target identifier - pub id: String, - #[serde(skip_serializing_if = "Option::is_none")] - /// Matching strategy to use - pub matching_strategy: Option, -} - -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Display)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -/// Strategy for matching identifiers -pub enum MatchingStrategy { - /// Should not be used, only kept for backward compatibility - Legacy, - /// Equals - Equals, - /// Starts With - StartsWith, - /// Ends With - EndsWith, - /// Contains - Contains, - /// Regex - Regex, - /// Does not end with - DoesNotEndWith, - /// Does not start with - DoesNotStartWith, - /// Does not equal - DoesNotEqual, - /// Does not contain - DoesNotContain, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -pub struct IdWithIdentifierAndComment { - pub kind: ApplicationIdentifier, - pub id: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub comment: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub matching_strategy: Option, -} - -impl From for IdWithIdentifier { - fn from(value: IdWithIdentifierAndComment) -> Self { - Self { - kind: value.kind, - id: value.id.clone(), - matching_strategy: value.matching_strategy, - } - } -} +pub use komorebi_config::matching::IdWithIdentifier; +pub use komorebi_config::matching::IdWithIdentifierAndComment; +pub use komorebi_config::matching::MatchingRule; +pub use komorebi_config::matching::MatchingStrategy; +pub use komorebi_config::matching::WorkspaceMatchingRule; #[derive(Clone, Debug, Serialize, Deserialize)] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]