From 415e73a9ac19cf157c19df8ba904f5ce033f97db Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 22:37:54 -0700 Subject: [PATCH] refactor(kde): 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: KDE only reads and writes its own, the others are None and skipped when written. A derived schema of the union would carry the Windows-only kinds and the x-komorebi-platforms markers, so the places that print or answer the applications schema ask for the KDE view instead: komorebic (application-specific-configuration-schema; komorebic gains the komorebi-config dependency, a two-line change in the arm) and the daemon's socket answer (same view, array form as before). This is the minimum change to komorebic that keeps its output; step 4 owns the rest of the file. 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.asc.json byte-identical to the checked-in file (git: no diff against wip-main), schema.json only differs by the earlier description-only converge revisions. --- komorebi-for-kde/Cargo.lock | 1 + komorebi-for-kde/komorebi/src/core/asc.rs | 71 ++----------------- .../komorebi/src/process_command.rs | 8 +-- komorebi-for-kde/komorebic/Cargo.toml | 1 + komorebi-for-kde/komorebic/src/main.rs | 7 +- 5 files changed, 15 insertions(+), 73 deletions(-) diff --git a/komorebi-for-kde/Cargo.lock b/komorebi-for-kde/Cargo.lock index cf1873d2..d257f7ab 100644 --- a/komorebi-for-kde/Cargo.lock +++ b/komorebi-for-kde/Cargo.lock @@ -2629,6 +2629,7 @@ dependencies = [ "fs-tail", "komorebi", "komorebi-client", + "komorebi-config", "komorebi-hotkeys", "lazy_static", "pastey", diff --git a/komorebi-for-kde/komorebi/src/core/asc.rs b/komorebi-for-kde/komorebi/src/core/asc.rs index d27396ed..022dbccf 100644 --- a/komorebi-for-kde/komorebi/src/core/asc.rs +++ b/komorebi-for-kde/komorebi/src/core/asc.rs @@ -1,69 +1,8 @@ //! The application specific configuration file (`app_specific_configuration_path`): rules, by //! application, for the windows komorebi ignores, manages or floats. +//! +//! The types are defined in `komorebi-config`. -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; - -#[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-kde/komorebi/src/process_command.rs b/komorebi-for-kde/komorebi/src/process_command.rs index 3c8a3a30..9cbd8c11 100644 --- a/komorebi-for-kde/komorebi/src/process_command.rs +++ b/komorebi-for-kde/komorebi/src/process_command.rs @@ -1858,10 +1858,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-kde/komorebic/Cargo.toml b/komorebi-for-kde/komorebic/Cargo.toml index 23963548..981ea844 100644 --- a/komorebi-for-kde/komorebic/Cargo.toml +++ b/komorebi-for-kde/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 = { path = "../komorebi", default-features = false } komorebi-client = { path = "../komorebi-client", default-features = false } komorebi-hotkeys = { path = "../komorebi-hotkeys" } diff --git a/komorebi-for-kde/komorebic/src/main.rs b/komorebi-for-kde/komorebic/src/main.rs index 1f6da9c1..e2260916 100644 --- a/komorebi-for-kde/komorebic/src/main.rs +++ b/komorebi-for-kde/komorebic/src/main.rs @@ -2179,9 +2179,10 @@ fn main() -> eyre::Result<()> { 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 => {