diff --git a/komorebi-for-mac/Cargo.lock b/komorebi-for-mac/Cargo.lock index d9379b44..edeee297 100644 --- a/komorebi-for-mac/Cargo.lock +++ b/komorebi-for-mac/Cargo.lock @@ -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" diff --git a/komorebi-for-mac/Cargo.toml b/komorebi-for-mac/Cargo.toml index de8ef649..e1d2610f 100644 --- a/komorebi-for-mac/Cargo.toml +++ b/komorebi-for-mac/Cargo.toml @@ -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", diff --git a/komorebi-for-mac/komorebi/Cargo.toml b/komorebi-for-mac/komorebi/Cargo.toml index 330e7c91..7fcab227 100644 --- a/komorebi-for-mac/komorebi/Cargo.toml +++ b/komorebi-for-mac/komorebi/Cargo.toml @@ -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" } diff --git a/komorebi-for-mac/komorebi/src/core/config_generation.rs b/komorebi-for-mac/komorebi/src/core/config_generation.rs index 1cf9b43b..03abb7ce 100644 --- a/komorebi-for-mac/komorebi/src/core/config_generation.rs +++ b/komorebi-for-mac/komorebi/src/core/config_generation.rs @@ -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), -} - -#[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;