From bdd0a5593c033bb8214765afaaa3958de40b717a Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Wed, 28 Oct 2026 22:17:46 -0700 Subject: [PATCH] feat(probe): a prober of komorebi for KDE, and findings that name KWin --- komorebi-recorder/src/analysis/invariants.rs | 10 ++++-- komorebi-recorder/src/sources/winprobe.rs | 35 +++++++++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/komorebi-recorder/src/analysis/invariants.rs b/komorebi-recorder/src/analysis/invariants.rs index c8e1c298..dc6a8312 100644 --- a/komorebi-recorder/src/analysis/invariants.rs +++ b/komorebi-recorder/src/analysis/invariants.rs @@ -251,6 +251,12 @@ pub fn check_probed(snapshot: &Snapshot, facts: &WindowFacts, exe: Option<&str>) } let id = u64::from(facts.hwnd); + // who was asked about the window + let os = if snapshot.flavor == crate::analysis::flavor::Flavor::Kde { + "KWin" + } else { + "Windows" + }; let named = |window: Option<&Window>| match (window, exe) { (Some(window), _) => name(window), (None, Some(exe)) => format!("{exe} window {id}"), @@ -291,7 +297,7 @@ pub fn check_probed(snapshot: &Snapshot, facts: &WindowFacts, exe: Option<&str>) "visible-window-hidden", Severity::Error, format!( - "{} is in front on {}, which is showing, but Windows has it {how}", + "{} is in front on {}, which is showing, but {os} has it {how}", named(Some(window)), location.describe() ), @@ -322,7 +328,7 @@ pub fn check_probed(snapshot: &Snapshot, facts: &WindowFacts, exe: Option<&str>) "hidden-window-visible", Severity::Warn, format!( - "{} is on {}, which is not showing its windows, but Windows has it on screen", + "{} is on {}, which is not showing its windows, but {os} has it on screen", named(Some(window)), location.describe() ), diff --git a/komorebi-recorder/src/sources/winprobe.rs b/komorebi-recorder/src/sources/winprobe.rs index 25e58656..adf0977a 100644 --- a/komorebi-recorder/src/sources/winprobe.rs +++ b/komorebi-recorder/src/sources/winprobe.rs @@ -196,7 +196,7 @@ fn shortened(text: String) -> String { cut } -type Inspect = Box Option + Send>; +type Inspect = Box Option + Send>; type Ask = Box Option + Send>; /// Reads the real state of the window a komorebi event is about. @@ -239,6 +239,7 @@ type Ask = Box Option + Send>; /// # Ok::<(), Box>(()) /// ``` pub struct EventProber { + flavor: Flavor, inspect: Inspect, ask: Ask, policy: AskPolicy, @@ -250,16 +251,36 @@ impl EventProber { /// Both are given a window handle. `inspect` returns `None` for a window it cannot read, and /// `ask` returns komorebi's answer, or `None` for none. pub fn new( - inspect: impl FnMut(u32) -> Option + Send + 'static, + mut inspect: impl FnMut(u32) -> Option + Send + 'static, + ask: impl FnMut(u32) -> Option + Send + 'static, + ) -> Self { + Self::reading(Flavor::Windows, move |hwnd, _| inspect(hwnd), ask) + } + + /// Returns a prober of the komorebi of `flavor`, that reads a window with `inspect`, which is + /// given the id and komorebi's own description of the window, and asks komorebi with `ask`. + pub fn reading( + flavor: Flavor, + inspect: impl FnMut(u32, &Value) -> Option + Send + 'static, ask: impl FnMut(u32) -> Option + Send + 'static, ) -> Self { Self { + flavor, inspect: Box::new(inspect), ask: Box::new(ask), policy: AskPolicy::default(), } } + /// Returns the prober of komorebi for KDE: KWin is asked about each window ([`crate::platform::window::inspect_window`]). + /// komorebi for KDE has no query that says why it would not manage a window, so it is not asked. + #[must_use] + pub fn kde() -> Self { + Self::reading(Flavor::Kde, crate::platform::window::inspect_window, |_| { + None + }) + } + /// Returns the real prober: Win32 for the window ([`crate::platform::window::inspect`]), /// komorebi's socket for its verdict (a `DebugWindow` query, see [`crate::komorebi_link`]). /// @@ -289,13 +310,19 @@ impl EventProber { /// handle, and when the window cannot be read. komorebi is asked about the window only if it /// still exists and the [`AskPolicy`] says it is due. pub fn probe(&mut self, event: &Value, now_ns: u64) -> Option { - let info = Flavor::Windows.rules().describe_event(event); + let info = self.flavor.rules().describe_event(event); if info.family != Family::WindowManager { return None; } let hwnd = info.window_id?; - let mut facts = (self.inspect)(hwnd)?; + // the window an event is about is the last of its content: the notification, then the window + let window = event + .get("content") + .and_then(Value::as_array) + .and_then(|content| content.last()) + .unwrap_or(&Value::Null); + let mut facts = (self.inspect)(hwnd, window)?; facts.at_ns = now_ns; if facts.exists && self.policy.should_ask(hwnd, &info.name, now_ns) { facts.komorebi_says = (self.ask)(hwnd);