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) }