From 04139cce010a53a8d7367e0a33ca526dd9a7f369 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 22:37:54 -0700 Subject: [PATCH] refactor(mac): use asc of komorebi-config core::asc re-exports ApplicationSpecificConfiguration, AscApplicationRules and AscApplicationRulesOrSchema from komorebi-config; the local copy (60 lines) is removed. AscApplicationRules is now the union with the five Windows-only rule kinds, which macOS never sets. As for KDE, the applications schema is printed and answered as the macOS view of the union (komorebic application-specific-configuration-schema, with the komorebi-config dependency, and the daemon's socket answer), so the printed text stays what schema.asc.json holds; the oracle test compares that view with the checked-in file byte for byte. Verified: macOS fake-CC cargo check --locked --target aarch64-apple-darwin --workspace --all-targets: finished, 0 errors (tier 2). Not verified: macOS unit tests, running komorebic. --- komorebi-for-mac/Cargo.lock | 1 + komorebi-for-mac/komorebi/src/core/asc.rs | 71 ++----------------- .../komorebi/src/process_command.rs | 8 +-- komorebi-for-mac/komorebic/Cargo.toml | 1 + komorebi-for-mac/komorebic/src/main.rs | 7 +- 5 files changed, 16 insertions(+), 72 deletions(-) diff --git a/komorebi-for-mac/Cargo.lock b/komorebi-for-mac/Cargo.lock index aba2bd4f..5becbc70 100644 --- a/komorebi-for-mac/Cargo.lock +++ b/komorebi-for-mac/Cargo.lock @@ -3332,6 +3332,7 @@ dependencies = [ "dirs 6.0.0", "fs-tail", "komorebi-client", + "komorebi-config", "lazy_static", "pastey 0.2.3", "reqwest", diff --git a/komorebi-for-mac/komorebi/src/core/asc.rs b/komorebi-for-mac/komorebi/src/core/asc.rs index 2141685d..f11db2f6 100644 --- a/komorebi-for-mac/komorebi/src/core/asc.rs +++ b/komorebi-for-mac/komorebi/src/core/asc.rs @@ -1,66 +1,7 @@ -use crate::core::config_generation::MatchingRule; -use color_eyre::Result; -use serde::Deserialize; -use serde::Serialize; -use std::collections::BTreeMap; -use std::ops::Deref; -use std::ops::DerefMut; -use std::path::PathBuf; +//! The application specific configuration file (`app_specific_configuration_path`). +//! +//! The types are defined in `komorebi-config`. -#[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -pub struct ApplicationSpecificConfiguration(pub BTreeMap); - -#[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -#[serde(untagged)] -pub enum AscApplicationRulesOrSchema { - AscApplicationRules(AscApplicationRules), - Schema(String), -} - -impl Deref for ApplicationSpecificConfiguration { - type Target = BTreeMap; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl DerefMut for ApplicationSpecificConfiguration { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } -} - -impl ApplicationSpecificConfiguration { - pub fn load(pathbuf: &PathBuf) -> Result { - let content = std::fs::read_to_string(pathbuf)?; - Ok(serde_json::from_str(&content)?) - } - - pub fn format(pathbuf: &PathBuf) -> Result { - Ok(serde_json::to_string_pretty(&Self::load(pathbuf)?)?) - } -} - -/// Rules that determine how an application is handled -#[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -pub struct AscApplicationRules { - /// Rules to ignore specific windows - #[serde(skip_serializing_if = "Option::is_none")] - pub ignore: Option>, - /// Rules to forcibly manage specific windows - #[serde(skip_serializing_if = "Option::is_none")] - pub manage: Option>, - /// Rules to manage specific windows as floating windows - #[serde(skip_serializing_if = "Option::is_none")] - pub floating: Option>, - /// Rules to identify applications which are title-less - only accepts Simple Exe rules - #[serde(skip_serializing_if = "Option::is_none")] - pub titleless: Option>, - /// Rules to identify applications which are title-less - only accepts Simple Exe rules - #[serde(skip_serializing_if = "Option::is_none")] - pub tabbed: Option>, -} +pub use komorebi_config::asc::ApplicationSpecificConfiguration; +pub use komorebi_config::asc::AscApplicationRules; +pub use komorebi_config::asc::AscApplicationRulesOrSchema; diff --git a/komorebi-for-mac/komorebi/src/process_command.rs b/komorebi-for-mac/komorebi/src/process_command.rs index 6e8cb5db..32b5787a 100644 --- a/komorebi-for-mac/komorebi/src/process_command.rs +++ b/komorebi-for-mac/komorebi/src/process_command.rs @@ -1599,10 +1599,10 @@ impl WindowManager { SocketMessage::ApplicationSpecificConfigurationSchema => { #[cfg(feature = "schemars")] { - let asc = schemars::schema_for!( - Vec - ); - let schema = serde_json::to_string_pretty(&asc)?; + let schema = komorebi_config::schema::view::< + Vec, + >(komorebi_config::schema::Platform::CURRENT); + let schema = schema.trim_end(); reply.write_all(schema.as_bytes())?; } diff --git a/komorebi-for-mac/komorebic/Cargo.toml b/komorebi-for-mac/komorebic/Cargo.toml index 20117bc2..1a41c23b 100644 --- a/komorebi-for-mac/komorebic/Cargo.toml +++ b/komorebi-for-mac/komorebic/Cargo.toml @@ -5,6 +5,7 @@ description = "The command-line interface for Komorebi, a tiling window manager edition = "2024" [dependencies] +komorebi-config = { workspace = true } komorebi-client = { path = "../komorebi-client", default-features = false } version = { path = "../version" } diff --git a/komorebi-for-mac/komorebic/src/main.rs b/komorebi-for-mac/komorebic/src/main.rs index 88f62916..1f06c950 100644 --- a/komorebi-for-mac/komorebic/src/main.rs +++ b/komorebi-for-mac/komorebic/src/main.rs @@ -2558,9 +2558,10 @@ exit 1 SubCommand::ApplicationSpecificConfigurationSchema => { #[cfg(feature = "schemars")] { - let asc = schemars::schema_for!(komorebi_client::ApplicationSpecificConfiguration); - let schema = serde_json::to_string_pretty(&asc)?; - println!("{schema}"); + let schema = komorebi_config::schema::view::< + komorebi_client::ApplicationSpecificConfiguration, + >(komorebi_config::schema::Platform::CURRENT); + print!("{schema}"); } } SubCommand::NotificationSchema => {