feat(wm): implement replace configuration

I think this is the last SocketMessage variant I'll be bringing over
before working on docs. Haven't tested this one but it should work
pretty much the same as on Windows.
This commit is contained in:
LGUG2Z committed 2025-09-25 14:32:08 -07:00
1 parent c66db5a0bd
commit 7217f311f2
3 files changed
+45 -4

No files matched your search

+1 -1
View File
@@ -331,7 +331,7 @@ pub enum SocketMessage {
ToggleWorkspaceLayer,
// Configuration
// ReloadConfiguration,
// ReplaceConfiguration(#[serde_as(as = "ResolvedPathBuf")] PathBuf),
ReplaceConfiguration(#[serde_as(as = "ResolvedPathBuf")] PathBuf),
ReloadStaticConfiguration(#[serde_as(as = "ResolvedPathBuf")] PathBuf),
// WatchConfiguration(bool),
// CompleteConfiguration,
+31
View File
@@ -40,6 +40,7 @@ use crate::window::RuleDebug;
use crate::window::Window;
use crate::window::WindowInfo;
use crate::window_manager::WindowManager;
use crate::window_manager_event_listener;
use crate::workspace::WorkspaceLayer;
use crate::workspace::WorkspaceWindowLocation;
use color_eyre::eyre;
@@ -1629,6 +1630,36 @@ impl WindowManager {
let mut display_index_preferences = DISPLAY_INDEX_PREFERENCES.write();
display_index_preferences.insert(index_preference, display.clone());
}
SocketMessage::ReplaceConfiguration(ref config) => {
// Check that this is a valid static config file first
if StaticConfig::read(config).is_ok() {
// Clear workspace rules; these will need to be replaced
WORKSPACE_MATCHING_RULES.lock().clear();
// Pause so that restored windows come to the foreground from all workspaces
self.is_paused = true;
// Bring all windows to the foreground
self.restore_all_windows(false)?;
// Create a new wm from the config path
let mut wm = StaticConfig::preload(
config,
window_manager_event_listener::event_rx(),
self.command_listener.try_clone().ok(),
&self.run_loop.0,
)?;
// Initialize the new wm
wm.init()?;
wm.restore_all_windows(true)?;
// This is equivalent to StaticConfig::postload for this use case
StaticConfig::reload(config, &mut wm)?;
// Set self to the new wm instance
*self = wm;
}
}
}
notify_subscribers(
Notification {
+13 -3
View File
@@ -582,6 +582,13 @@ struct LoadResize {
path: PathBuf,
}
#[derive(Parser)]
struct ReplaceConfiguration {
/// Static configuration JSON file from which the configuration should be loaded
#[clap(value_parser = replace_env_in_path)]
path: PathBuf,
}
#[derive(Parser)]
struct EagerFocus {
/// Case-sensitive exe identifier
@@ -955,9 +962,9 @@ enum SubCommand {
Manage,
/// Unmanage a window that was forcibly managed
Unmanage,
// /// Replace the configuration of a running instance of komorebi from a static configuration file
// #[clap(arg_required_else_help = true)]
// ReplaceConfiguration(ReplaceConfiguration),
/// Replace the configuration of a running instance of komorebi from a static configuration file
#[clap(arg_required_else_help = true)]
ReplaceConfiguration(ReplaceConfiguration),
// /// Reload legacy komorebi.ahk or komorebi.ps1 configurations (if they exist)
// ReloadConfiguration,
// /// Enable or disable watching of legacy komorebi.ahk or komorebi.ps1 configurations (if they exist)
@@ -1816,6 +1823,9 @@ fn main() -> eyre::Result<()> {
arg.display,
))?;
}
SubCommand::ReplaceConfiguration(arg) => {
send_message(&SocketMessage::ReplaceConfiguration(arg.path))?;
}
}
Ok(())