From fab53bd1f8ed60eda9a4cfe95b9a26f17ac7eff3 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 20:11:06 -0700 Subject: [PATCH] refactor(core,kde,mac): the unmanaged-window gate of the router is the CommandHost::gate_message hook Section 22.1 of core-model.md: KDE and macOS refuse every message before the router's match while the focused window is not managed (handle_unmanaged_window_behaviour); Windows gates inside 18 functions. CommandHost gets a defaulted gate_message(&mut self, &SocketMessage) that lets everything through (the Windows form, its impl is untouched); the KDE and macOS impls call handle_unmanaged_window_behaviour and their routers call the hook where they called the method, so behaviour is identical per daemon. komorebi-core now depends on komorebi-protocol (for SocketMessage; Cargo.lock gains that one edge). This is the groundwork only: the router itself is still per daemon, because a shared router needs WindowManager

in core (see the struct-move analysis in core-model.md). No BEHAVIOUR change. Verified: KDE cargo test -p komorebi-linux 670 passed, 0 failed; fake-CC clippy -D warnings for the four macOS packages passes; cargo clippy -p komorebi-windows -p komorebi-core --all-targets -D warnings passes; tools/format-all --check clean. Not verified: KDE VM, macOS hand check (no behaviour change expected). --- Cargo.lock | 1 + crates/komorebi-core/Cargo.toml | 1 + crates/komorebi-core/src/command.rs | 10 ++++++++++ komorebi-for-kde/komorebi/src/process_command.rs | 9 ++++++++- komorebi-for-mac/komorebi/src/process_command.rs | 9 ++++++++- 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 07f6653e..fb02c6e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3583,6 +3583,7 @@ dependencies = [ "komorebi-collections", "komorebi-config", "komorebi-layouts", + "komorebi-protocol", "komorebi-scrolling", "nanoid 0.5.0", "schemars 1.2.3", diff --git a/crates/komorebi-core/Cargo.toml b/crates/komorebi-core/Cargo.toml index cbd60db4..b0e0fb1c 100644 --- a/crates/komorebi-core/Cargo.toml +++ b/crates/komorebi-core/Cargo.toml @@ -8,6 +8,7 @@ edition = "2024" komorebi-collections = { path = "../komorebi-collections" } komorebi-config = { path = "../komorebi-config", default-features = false } komorebi-layouts = { path = "../../komorebi-layouts" } +komorebi-protocol = { path = "../komorebi-protocol" } komorebi-scrolling = { path = "../../komorebi-scrolling" } color-eyre = { workspace = true } nanoid = "0.5" diff --git a/crates/komorebi-core/src/command.rs b/crates/komorebi-core/src/command.rs index c5383cab..cc796ca4 100644 --- a/crates/komorebi-core/src/command.rs +++ b/crates/komorebi-core/src/command.rs @@ -14,6 +14,7 @@ use color_eyre::eyre; use color_eyre::eyre::OptionExt; use komorebi_layouts::CycleDirection; use komorebi_layouts::OperationDirection; +use komorebi_protocol::message::SocketMessage; use std::collections::VecDeque; use std::num::NonZeroUsize; @@ -43,6 +44,15 @@ pub trait CommandHost { /// Shows workspace `idx` on the focused monitor and focuses it. fn focus_workspace(&mut self, idx: usize) -> eyre::Result<()>; + /// Whether the router may run `message` at all: an error refuses it before any arm runs. The + /// default lets everything through (Windows, which gates inside 18 window manager functions + /// instead, section 22.1 of docs/dev/core-model.md); KDE and macOS refuse every message while the + /// focused window is not managed and `unmanaged_window_operation_behaviour` is `NoOp`. + fn gate_message(&mut self, message: &SocketMessage) -> eyre::Result<()> { + let _ = message; + Ok(()) + } + /// Shows workspace `workspace_idx` on the monitor at `monitor_idx` (creating it if it is not /// there) without focusing that monitor. fn show_workspace_on(&mut self, monitor_idx: usize, workspace_idx: usize) -> eyre::Result<()>; diff --git a/komorebi-for-kde/komorebi/src/process_command.rs b/komorebi-for-kde/komorebi/src/process_command.rs index 9a9e4dc6..b6a4d61c 100644 --- a/komorebi-for-kde/komorebi/src/process_command.rs +++ b/komorebi-for-kde/komorebi/src/process_command.rs @@ -999,7 +999,7 @@ impl WindowManager { // We don't have From implemented for &mut WindowManager let initial_state = State::from(self.as_ref()); - self.handle_unmanaged_window_behaviour()?; + komorebi_core::CommandHost::gate_message(self, &message)?; match message { SocketMessage::Promote => self.promote_container_to_front()?, @@ -2013,6 +2013,13 @@ fn push_simple_rule(rules: &mut Vec, kind: ApplicationIdentifier, impl komorebi_core::CommandHost for WindowManager { type P = crate::workspace::KdePlatform; + fn gate_message( + &mut self, + _message: &komorebi_protocol::message::SocketMessage, + ) -> eyre::Result<()> { + self.handle_unmanaged_window_behaviour() + } + fn monitors(&self) -> &std::collections::VecDeque { WindowManager::monitors(self) } diff --git a/komorebi-for-mac/komorebi/src/process_command.rs b/komorebi-for-mac/komorebi/src/process_command.rs index 3b3f0732..e540bb32 100644 --- a/komorebi-for-mac/komorebi/src/process_command.rs +++ b/komorebi-for-mac/komorebi/src/process_command.rs @@ -416,7 +416,7 @@ impl WindowManager { // We don't have From implemented for &mut WindowManager let initial_state = State::from(self.as_ref()); - self.handle_unmanaged_window_behaviour()?; + komorebi_core::CommandHost::gate_message(self, &message)?; match message { SocketMessage::Promote => self.promote_container_to_front()?, @@ -1696,6 +1696,13 @@ impl WindowManager { impl komorebi_core::CommandHost for WindowManager { type P = crate::workspace::MacosPlatform; + fn gate_message( + &mut self, + _message: &komorebi_protocol::message::SocketMessage, + ) -> eyre::Result<()> { + self.handle_unmanaged_window_behaviour() + } + fn monitors(&self) -> &std::collections::VecDeque { WindowManager::monitors(self) }