From 8f36549fae07685946e96dd618bb62fd343dc393 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Thu, 25 Sep 2025 12:41:10 -0700 Subject: [PATCH] feat(cli): implement generate-static-config cmd --- komorebi/src/core/mod.rs | 2 +- komorebi/src/process_command.rs | 6 ++++++ komorebi/src/static_config.rs | 6 +++++- komorebic/src/main.rs | 7 +++++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index 1f573bfe..06184ea4 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -406,7 +406,7 @@ pub enum SocketMessage { NotificationSchema, SocketSchema, StaticConfigSchema, - // GenerateStaticConfig, + GenerateStaticConfig, // DebugWindow(isize), } diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index bc8e3ab0..62382f64 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -29,6 +29,7 @@ use crate::monitor::MonitorInformation; use crate::notify_subscribers; use crate::state::GlobalState; use crate::state::State; +use crate::static_config::StaticConfig; use crate::window::AdhocWindow; use crate::window_manager::WindowManager; use crate::workspace::WorkspaceLayer; @@ -1533,6 +1534,11 @@ impl WindowManager { SocketMessage::StopIgnoreRestore => { self.stop(true)?; } + SocketMessage::GenerateStaticConfig => { + let config = serde_json::to_string_pretty(&StaticConfig::from(&*self))?; + + reply.write_all(config.as_bytes())?; + } } notify_subscribers( diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index 72ba23fa..58759718 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -258,7 +258,11 @@ impl From<&Workspace> for WorkspaceConfig { work_area_offset: value.work_area_offset, apply_window_based_work_area_offset: Some(value.apply_window_based_work_area_offset), window_container_behaviour: value.window_container_behaviour, - window_container_behaviour_rules: Option::from(window_container_behaviour_rules), + window_container_behaviour_rules: if window_container_behaviour_rules.is_empty() { + None + } else { + Some(window_container_behaviour_rules) + }, float_override: value.float_override, tile, layout_flip: value.layout_flip, diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 0eccc56f..18019743 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -1098,8 +1098,8 @@ enum SubCommand { SocketSchema, /// Generate a JSON Schema of the static configuration file StaticConfigSchema, - // /// Generates a static configuration JSON file based on the current window manager state - // GenerateStaticConfig, + /// Generates a static configuration JSON file based on the current window manager state + GenerateStaticConfig, // /// Generates the komorebi.lnk shortcut in shell:startup to autostart komorebi // EnableAutostart(EnableAutostart), // /// Deletes the komorebi.lnk shortcut in shell:startup to disable autostart @@ -1773,6 +1773,9 @@ fn main() -> eyre::Result<()> { SubCommand::UnsubscribeSocket(arg) => { send_message(&SocketMessage::RemoveSubscriberSocket(arg.socket))?; } + SubCommand::GenerateStaticConfig => { + print_query(&SocketMessage::GenerateStaticConfig); + } } Ok(())