mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 05:41:16 +01:00
feat(probe): a prober of komorebi for KDE, and findings that name KWin
This commit is contained in:
1 parent
cbf7441009
commit
bdd0a5593c
2 files changed
+39
-6
No files matched your search
@@ -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()
|
||||
),
|
||||
|
||||
@@ -196,7 +196,7 @@ fn shortened(text: String) -> String {
|
||||
cut
|
||||
}
|
||||
|
||||
type Inspect = Box<dyn FnMut(u32) -> Option<WindowFacts> + Send>;
|
||||
type Inspect = Box<dyn FnMut(u32, &Value) -> Option<WindowFacts> + Send>;
|
||||
type Ask = Box<dyn FnMut(u32) -> Option<String> + Send>;
|
||||
|
||||
/// Reads the real state of the window a komorebi event is about.
|
||||
@@ -239,6 +239,7 @@ type Ask = Box<dyn FnMut(u32) -> Option<String> + Send>;
|
||||
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
/// ```
|
||||
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<WindowFacts> + Send + 'static,
|
||||
mut inspect: impl FnMut(u32) -> Option<WindowFacts> + Send + 'static,
|
||||
ask: impl FnMut(u32) -> Option<String> + 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<WindowFacts> + Send + 'static,
|
||||
ask: impl FnMut(u32) -> Option<String> + 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<WindowFacts> {
|
||||
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);
|
||||
|
||||
Reference in new issue
Block a user