From dee46f58043ab36617be98ba17b640cfc2f690f8 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Tue, 24 Dec 2024 10:50:07 -0800 Subject: [PATCH] feat(wm): add enforce-workspace-rules command This commit adds a new komorebic command "enforce-workspace-rules" which will enforce all persistent and initial workspace rules regardless of whether they have already been applied (in the case of initial workspace rules). resolve #1196 --- komorebi/src/core/mod.rs | 1 + komorebi/src/process_command.rs | 3 +++ komorebi/src/process_event.rs | 2 +- komorebi/src/static_config.rs | 4 ++-- komorebi/src/window_manager.rs | 4 ++-- komorebic/src/main.rs | 5 +++++ 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index 4d733fd4..8fc903e2 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -109,6 +109,7 @@ pub enum SocketMessage { TogglePause, Retile, RetileWithResizeDimensions, + EnforceWorkspaceRules, QuickSave, QuickLoad, Save(PathBuf), diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index a53e624c..2665782f 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -675,6 +675,9 @@ impl WindowManager { border_manager::destroy_all_borders()?; self.retile_all(true)? } + SocketMessage::EnforceWorkspaceRules => { + self.enforce_workspace_rules(true)?; + } SocketMessage::FlipLayout(layout_flip) => self.flip_layout(layout_flip)?, SocketMessage::ChangeLayout(layout) => self.change_workspace_layout_default(layout)?, SocketMessage::CycleLayout(direction) => self.cycle_layout(direction)?, diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index c2c2660f..70262926 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -159,7 +159,7 @@ impl WindowManager { _ => {} } - self.enforce_workspace_rules()?; + self.enforce_workspace_rules(false)?; if matches!(event, WindowManagerEvent::MouseCapture(..)) { tracing::trace!( diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index 80dd190e..6411c91c 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -1175,7 +1175,7 @@ impl StaticConfig { } } - wm.enforce_workspace_rules()?; + wm.enforce_workspace_rules(false)?; if value.border == Some(true) { border_manager::BORDER_ENABLED.store(true, Ordering::SeqCst); @@ -1236,7 +1236,7 @@ impl StaticConfig { } } - wm.enforce_workspace_rules()?; + wm.enforce_workspace_rules(false)?; if let Some(enabled) = value.border { border_manager::BORDER_ENABLED.store(enabled, Ordering::SeqCst); diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 95446733..54e21d06 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -709,7 +709,7 @@ impl WindowManager { } #[tracing::instrument(skip(self), level = "debug")] - pub fn enforce_workspace_rules(&mut self) -> Result<()> { + pub fn enforce_workspace_rules(&mut self, reapply_initial_rules: bool) -> Result<()> { let mut to_move = vec![]; let focused_monitor_idx = self.focused_monitor_idx(); @@ -762,7 +762,7 @@ impl WindowManager { if matched { let floating = workspace.floating_windows().contains(window); - if rule.initial_only { + if !reapply_initial_rules && rule.initial_only { if !already_moved_window_handles.contains(&window.hwnd) { already_moved_window_handles.insert(window.hwnd); diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index acbde19c..c82d121d 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -1162,6 +1162,8 @@ enum SubCommand { PromoteWindow(PromoteWindow), /// Force the retiling of all managed windows Retile, + /// Enforce all workspace rules, including initial workspace rules that have already been applied + EnforceWorkspaceRules, /// Set the monitor index preference for a monitor identified using its size #[clap(arg_required_else_help = true)] MonitorIndexPreference(MonitorIndexPreference), @@ -1715,6 +1717,9 @@ fn main() -> Result<()> { SubCommand::Retile => { send_message(&SocketMessage::Retile)?; } + SubCommand::EnforceWorkspaceRules => { + send_message(&SocketMessage::EnforceWorkspaceRules)?; + } SubCommand::Move(arg) => { send_message(&SocketMessage::MoveWindow(arg.operation_direction))?; }