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 => {