From 692da90890ecdc355fd027b8cb0eda8fdd3a0a86 Mon Sep 17 00:00:00 2001 From: alex-ds13 <145657253+alex-ds13@users.noreply.github.com> Date: Thu, 19 Dec 2024 11:06:10 +0000 Subject: [PATCH] feat(wm): allow reapplying initial workspace rules This commit adds the following new socket messages and commands: - `EnforceWorkspaceRules`: resets the `already_moved_window_handles` and calls `enforce_workspace_rules` so that all workspace rules, including initial workspace rules are applied again - `enforce-workspace-rules`: cli command which sends the EnforceWorkspaceRules socket message --- komorebi/src/core/mod.rs | 1 + komorebi/src/process_command.rs | 7 +++++++ komorebic/src/main.rs | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index 4d733fd4..131c55ea 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -185,6 +185,7 @@ pub enum SocketMessage { ClearWorkspaceRules(usize, usize), ClearNamedWorkspaceRules(String), ClearAllWorkspaceRules, + EnforceWorkspaceRules, #[serde(alias = "FloatRule")] IgnoreRule(ApplicationIdentifier, String), ManageRule(ApplicationIdentifier, String), diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index a53e624c..bdd7718a 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -396,6 +396,13 @@ impl WindowManager { let mut workspace_rules = WORKSPACE_MATCHING_RULES.lock(); workspace_rules.clear(); } + SocketMessage::EnforceWorkspaceRules => { + { + let mut already_moved = self.already_moved_window_handles.lock(); + already_moved.clear(); + } + self.enforce_workspace_rules()?; + } SocketMessage::ManageRule(identifier, ref id) => { let mut manage_identifiers = MANAGE_IDENTIFIERS.lock(); diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index acbde19c..6b32c60b 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -1309,6 +1309,8 @@ enum SubCommand { ClearNamedWorkspaceRules(ClearNamedWorkspaceRules), /// Remove all application association rules for all workspaces ClearAllWorkspaceRules, + /// Enforce all workspace rules, including initial workspace rules that have already been applied + EnforceWorkspaceRules, /// Identify an application that sends EVENT_OBJECT_NAMECHANGE on launch #[clap(arg_required_else_help = true)] IdentifyObjectNameChangeApplication(IdentifyObjectNameChangeApplication), @@ -2457,6 +2459,9 @@ if (Get-Command Get-CimInstance -ErrorAction SilentlyContinue) { SubCommand::ClearAllWorkspaceRules => { send_message(&SocketMessage::ClearAllWorkspaceRules)?; } + SubCommand::EnforceWorkspaceRules => { + send_message(&SocketMessage::EnforceWorkspaceRules)?; + } SubCommand::Stack(arg) => { send_message(&SocketMessage::StackWindow(arg.operation_direction))?; }