mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-20 15:41:38 +01:00
refactor(config): move asc and the application configuration data into komorebi-config
ApplicationSpecificConfiguration, AscApplicationRulesOrSchema and AscApplicationRules are code-identical in the trees except that AscApplicationRules differs in its rule kinds: five Windows-only kinds, titleless and tabbed on KDE and macOS. The crate holds the union (declaration order floating-first as before; the platform-only fields carry x-komorebi-platforms, so a view prunes them) and, for the Windows From<Vec<ApplicationConfiguration>> conversion that the orphan rule keeps next to its types, ApplicationOptions and ApplicationConfiguration (data only: the YAML generator stays in the Windows daemon). The crate gains the color-eyre dependency. The oracle test builds the view of ApplicationSpecificConfiguration for Windows, KDE and macOS and compares it with each tree's checked-in schema.asc.json byte for byte: all three are identical. This is the first proof that per-platform views of one union reproduce the checked-in files exactly (D17/D18); the three trees still use their own copies. Verified: native cargo test -p komorebi-config: 4 unit + 6 schemas passed, 0 failed (tier 1).
This commit is contained in:
1 parent
befbc200d0
commit
89c729e731
9 files changed
+251
-1
No files matched your search
Generated
+1
@@ -3445,6 +3445,7 @@ name = "komorebi-config"
|
||||
version = "0.1.42"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"color-eyre",
|
||||
"komorebi-layouts",
|
||||
"komorebi-protocol",
|
||||
"komorebi-themes",
|
||||
|
||||
@@ -10,6 +10,7 @@ komorebi-protocol = { path = "../komorebi-protocol", default-features = false }
|
||||
komorebi-themes = { path = "../../komorebi-themes" }
|
||||
|
||||
clap = { workspace = true }
|
||||
color-eyre = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true, features = ["preserve_order"] }
|
||||
strum = { workspace = true }
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
//! The entries that the Windows `fetch-app-specific-configuration`
|
||||
//! generator reads, and the options that turn into rules.
|
||||
//!
|
||||
//! The generator itself (it reads YAML) stays in the Windows daemon; the data types are here so
|
||||
//! that the conversion into `ApplicationSpecificConfiguration` can be a `From` impl next to it.
|
||||
|
||||
use clap::ValueEnum;
|
||||
use komorebi_protocol::types::ApplicationIdentifier;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use strum::Display;
|
||||
use strum::EnumString;
|
||||
|
||||
use crate::matching::IdWithIdentifier;
|
||||
use crate::matching::MatchingRule;
|
||||
use crate::matching::MatchingStrategy;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ValueEnum)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ApplicationOptions {
|
||||
ObjectNameChange,
|
||||
Layered,
|
||||
TrayAndMultiWindow,
|
||||
Force,
|
||||
BorderOverflow,
|
||||
}
|
||||
|
||||
impl ApplicationOptions {
|
||||
#[must_use]
|
||||
pub fn raw_cfgen(&self, kind: &ApplicationIdentifier, id: &str) -> String {
|
||||
match self {
|
||||
ApplicationOptions::ObjectNameChange => {
|
||||
format!("komorebic.exe identify-object-name-change-application {kind} \"{id}\"",)
|
||||
}
|
||||
ApplicationOptions::Layered => {
|
||||
format!("komorebic.exe identify-layered-application {kind} \"{id}\"",)
|
||||
}
|
||||
ApplicationOptions::TrayAndMultiWindow => {
|
||||
format!("komorebic.exe identify-tray-application {kind} \"{id}\"",)
|
||||
}
|
||||
ApplicationOptions::Force => {
|
||||
format!("komorebic.exe manage-rule {kind} \"{id}\"")
|
||||
}
|
||||
ApplicationOptions::BorderOverflow => {
|
||||
unreachable!("deprecated");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn cfgen(&self, kind: &ApplicationIdentifier, id: &str) -> String {
|
||||
format!(
|
||||
"RunWait('{}', , \"Hide\")",
|
||||
ApplicationOptions::raw_cfgen(self, kind, id)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
pub struct ApplicationConfiguration {
|
||||
pub name: String,
|
||||
pub identifier: IdWithIdentifier,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub options: Option<Vec<ApplicationOptions>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[serde(alias = "float_identifiers")]
|
||||
pub ignore_identifiers: Option<Vec<MatchingRule>>,
|
||||
}
|
||||
|
||||
impl ApplicationConfiguration {
|
||||
pub fn populate_default_matching_strategies(&mut self) {
|
||||
if self.identifier.matching_strategy.is_none() {
|
||||
match self.identifier.kind {
|
||||
ApplicationIdentifier::Exe | ApplicationIdentifier::Path => {
|
||||
self.identifier.matching_strategy = Option::from(MatchingStrategy::Equals);
|
||||
}
|
||||
ApplicationIdentifier::Class | ApplicationIdentifier::Title => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
//! The application specific configuration file (`app_specific_configuration_path`): rules, by
|
||||
//! application, for the windows komorebi ignores, manages or floats.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::ops::Deref;
|
||||
use std::ops::DerefMut;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use color_eyre::Result;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::application_configuration::ApplicationConfiguration;
|
||||
use crate::application_configuration::ApplicationOptions;
|
||||
use crate::matching::MatchingRule;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
pub struct ApplicationSpecificConfiguration(pub BTreeMap<String, AscApplicationRulesOrSchema>);
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
#[allow(clippy::large_enum_variant)] // the rules are the common case; the enum is a map value
|
||||
#[serde(untagged)]
|
||||
pub enum AscApplicationRulesOrSchema {
|
||||
AscApplicationRules(AscApplicationRules),
|
||||
Schema(String),
|
||||
}
|
||||
|
||||
impl Deref for ApplicationSpecificConfiguration {
|
||||
type Target = BTreeMap<String, AscApplicationRulesOrSchema>;
|
||||
|
||||
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<Self> {
|
||||
let content = std::fs::read_to_string(pathbuf)?;
|
||||
Ok(serde_json::from_str(&content)?)
|
||||
}
|
||||
|
||||
pub fn format(pathbuf: &PathBuf) -> Result<String> {
|
||||
Ok(serde_json::to_string_pretty(&Self::load(pathbuf)?)?)
|
||||
}
|
||||
}
|
||||
|
||||
/// Rules that determine how an application is handled
|
||||
#[derive(Clone, Debug, Default, 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<Vec<MatchingRule>>,
|
||||
/// Rules to forcibly manage specific windows
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub manage: Option<Vec<MatchingRule>>,
|
||||
/// Rules to manage specific windows as floating windows
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub floating: Option<Vec<MatchingRule>>,
|
||||
/// Rules to ignore specific windows from the transparency feature
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))]
|
||||
pub transparency_ignore: Option<Vec<MatchingRule>>,
|
||||
/// Rules to identify applications which minimize to the tray or have multiple windows
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))]
|
||||
pub tray_and_multi_window: Option<Vec<MatchingRule>>,
|
||||
/// Rules to identify applications which have the `WS_EX_LAYERED` Extended Window Style
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))]
|
||||
pub layered: Option<Vec<MatchingRule>>,
|
||||
/// Rules to identify applications which send the `EVENT_OBJECT_NAMECHANGE` event on launch
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))]
|
||||
pub object_name_change: Option<Vec<MatchingRule>>,
|
||||
/// Rules to identify applications which are slow to send initial event notifications
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["windows"])))]
|
||||
pub slow_application: Option<Vec<MatchingRule>>,
|
||||
/// Rules to identify applications which are title-less - only accepts Simple Exe rules
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["kde", "macos"])))]
|
||||
pub titleless: Option<Vec<MatchingRule>>,
|
||||
/// Rules to identify applications which are title-less - only accepts Simple Exe rules
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("x-komorebi-platforms" = ["kde", "macos"])))]
|
||||
pub tabbed: Option<Vec<MatchingRule>>,
|
||||
}
|
||||
|
||||
impl From<Vec<ApplicationConfiguration>> for ApplicationSpecificConfiguration {
|
||||
fn from(value: Vec<ApplicationConfiguration>) -> Self {
|
||||
let mut map = BTreeMap::new();
|
||||
|
||||
for entry in &value {
|
||||
let key = entry.name.clone();
|
||||
let mut rules = AscApplicationRules {
|
||||
ignore: entry.ignore_identifiers.clone(),
|
||||
..AscApplicationRules::default()
|
||||
};
|
||||
|
||||
if let Some(options) = &entry.options {
|
||||
for opt in options {
|
||||
let rule = Some(vec![MatchingRule::Simple(entry.identifier.clone())]);
|
||||
match opt {
|
||||
ApplicationOptions::ObjectNameChange => rules.object_name_change = rule,
|
||||
ApplicationOptions::Layered => rules.layered = rule,
|
||||
ApplicationOptions::TrayAndMultiWindow => {
|
||||
rules.tray_and_multi_window = rule
|
||||
}
|
||||
ApplicationOptions::Force => rules.manage = rule,
|
||||
ApplicationOptions::BorderOverflow => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if rules.ignore.is_some()
|
||||
|| rules.manage.is_some()
|
||||
|| rules.floating.is_some()
|
||||
|| rules.transparency_ignore.is_some()
|
||||
|| rules.tray_and_multi_window.is_some()
|
||||
|| rules.layered.is_some()
|
||||
|| rules.object_name_change.is_some()
|
||||
|| rules.slow_application.is_some()
|
||||
{
|
||||
map.insert(key, AscApplicationRulesOrSchema::AscApplicationRules(rules));
|
||||
}
|
||||
}
|
||||
|
||||
Self(map)
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@
|
||||
pub mod schema;
|
||||
|
||||
pub mod animation;
|
||||
pub mod application_configuration;
|
||||
pub mod asc;
|
||||
pub mod aspect_ratio;
|
||||
pub mod behaviour;
|
||||
pub mod matching;
|
||||
@@ -6,7 +6,7 @@
|
||||
//! [`view`] drops what the platform does not read, strips the `x-komorebi-` markers and
|
||||
//! removes the definitions nothing refers to any more.
|
||||
|
||||
use komorebi_protocol::platforms::Platform;
|
||||
pub use komorebi_protocol::platforms::Platform;
|
||||
use schemars::JsonSchema;
|
||||
use serde_json::Map;
|
||||
use serde_json::Value;
|
||||
|
||||
@@ -195,3 +195,24 @@ fn the_aspect_ratio_is_the_definition_of_every_tree() {
|
||||
|
||||
assert_same_definitions::<AspectRatio>(&all(), &["AspectRatio", "PredefinedAspectRatio"]);
|
||||
}
|
||||
|
||||
/// The platform views of the union schema of the applications file are byte-identical to the
|
||||
/// three checked-in `schema.asc.json`.
|
||||
#[test]
|
||||
fn the_applications_schema_is_a_view_of_one_union() {
|
||||
use komorebi_config::asc::ApplicationSpecificConfiguration;
|
||||
use komorebi_protocol::platforms::Platform;
|
||||
|
||||
for (tree, platform) in [
|
||||
(&TREES[0], Platform::Windows),
|
||||
(&TREES[1], Platform::Kde),
|
||||
(&TREES[2], Platform::MacOs),
|
||||
] {
|
||||
let view = komorebi_config::schema::view::<ApplicationSpecificConfiguration>(platform);
|
||||
assert!(
|
||||
view == checked_in(tree, "schema.asc.json"),
|
||||
"{}: the view of the applications schema differs from schema.asc.json",
|
||||
tree.name
|
||||
);
|
||||
}
|
||||
}
|
||||
Generated
+1
@@ -2551,6 +2551,7 @@ name = "komorebi-config"
|
||||
version = "0.1.42"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"color-eyre",
|
||||
"komorebi-layouts",
|
||||
"komorebi-protocol",
|
||||
"komorebi-themes",
|
||||
|
||||
Generated
+1
@@ -3261,6 +3261,7 @@ name = "komorebi-config"
|
||||
version = "0.1.42"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"color-eyre",
|
||||
"komorebi-layouts",
|
||||
"komorebi-protocol",
|
||||
"komorebi-themes",
|
||||
|
||||
Reference in new issue
Block a user