refactor(mac): use the matching types of komorebi-config

komorebi depends on komorebi-config (workspace dependency with the schemars feature, like komorebi-protocol) and core::config_generation re-exports the five matching types from it, so no call site changes. 84 duplicated lines are removed. Cargo.lock gains the komorebi-config package.

Verified: macOS fake-CC cargo check --locked --target aarch64-apple-darwin --workspace --all-targets: finished, 0 errors (tier 2, type-check only). Not verified: macOS unit tests (cannot run).
This commit is contained in:
LGUG2Z committed 2026-10-31 01:37:54 -07:00
1 parent 6c44f62787
commit 5b7e769207
4 files changed
+24 -89

No files matched your search

+14
View File
@@ -3166,6 +3166,7 @@ dependencies = [
"ed25519-dalek",
"hotwatch",
"komorebi-collections",
"komorebi-config",
"komorebi-layouts",
"komorebi-protocol",
"komorebi-themes",
@@ -3255,6 +3256,19 @@ dependencies = [
"serde",
]
[[package]]
name = "komorebi-config"
version = "0.1.42"
dependencies = [
"komorebi-layouts",
"komorebi-protocol",
"komorebi-themes",
"schemars 1.2.3",
"serde",
"serde_json_lenient",
"strum",
]
[[package]]
name = "komorebi-layouts"
version = "0.1.42"
+1
View File
@@ -15,6 +15,7 @@ version = "0.1.0"
[workspace.dependencies]
komorebi-themes = { path = "../komorebi-themes" }
komorebi-collections = { path = "../crates/komorebi-collections" }
komorebi-config = { path = "../crates/komorebi-config", default-features = false, features = ["schemars"] }
komorebi-protocol = { path = "../crates/komorebi-protocol", default-features = false, features = ["schemars"] }
komorebi-layouts = { path = "../komorebi-layouts", features = [
"darwin",
+1
View File
@@ -8,6 +8,7 @@ edition = "2024"
komorebi-themes = { workspace = true }
komorebi-collections = { workspace = true }
komorebi-layouts = { workspace = true }
komorebi-config = { workspace = true }
komorebi-protocol = { workspace = true }
quickxml_to_serde = { git = "https://github.com/LGUG2Z/quickxml_to_serde.git", version = "0.6.1" }
version = { path = "../version" }
@@ -1,90 +1,9 @@
use serde::Deserialize;
use serde::Serialize;
use strum::Display;
//! Rules that match an application by how it identifies itself.
//!
//! The types are defined in `komorebi-config`, which `komorebi.json` is read with.
use super::ApplicationIdentifier;
#[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<IdWithIdentifier>),
}
#[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<MatchingStrategy>,
}
#[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<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub matching_strategy: Option<MatchingStrategy>,
}
impl From<IdWithIdentifierAndComment> 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;