diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-03-23 16:16:52 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-03-23 16:16:52 +0400 |
| commit | 6ec65bc0d6f6141a3951c076b693b6ce430c503a (patch) | |
| tree | 3c601ca9310357935f1c95066797571fcc5a797d /src/window/mod.rs | |
| parent | d65446421fb989c74329b053fd3ccc387403fdc5 (diff) | |
| download | niri-6ec65bc0d6f6141a3951c076b693b6ce430c503a.tar.gz niri-6ec65bc0d6f6141a3951c076b693b6ce430c503a.tar.bz2 niri-6ec65bc0d6f6141a3951c076b693b6ce430c503a.zip | |
Add is-focused window rule matcher
Diffstat (limited to 'src/window/mod.rs')
| -rw-r--r-- | src/window/mod.rs | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/window/mod.rs b/src/window/mod.rs index 4ff943aa..63cdbe3f 100644 --- a/src/window/mod.rs +++ b/src/window/mod.rs @@ -61,6 +61,13 @@ impl<'a> WindowRef<'a> { WindowRef::Mapped(mapped) => mapped.toplevel(), } } + + pub fn is_focused(self) -> bool { + match self { + WindowRef::Unmapped(_) => false, + WindowRef::Mapped(mapped) => mapped.is_focused(), + } + } } impl ResolvedWindowRules { @@ -100,13 +107,13 @@ impl ResolvedWindowRules { let mut open_on_output = None; for rule in rules { - if !(rule.matches.is_empty() - || rule.matches.iter().any(|m| window_matches(&role, m))) - { + let matches = |m| window_matches(window, &role, m); + + if !(rule.matches.is_empty() || rule.matches.iter().any(matches)) { continue; } - if rule.excludes.iter().any(|m| window_matches(&role, m)) { + if rule.excludes.iter().any(matches) { continue; } @@ -155,10 +162,16 @@ impl ResolvedWindowRules { } } -fn window_matches(role: &XdgToplevelSurfaceRoleAttributes, m: &Match) -> bool { +fn window_matches(window: WindowRef, role: &XdgToplevelSurfaceRoleAttributes, m: &Match) -> bool { // Must be ensured by the caller. let server_pending = role.server_pending.as_ref().unwrap(); + if let Some(is_focused) = m.is_focused { + if window.is_focused() != is_focused { + return false; + } + } + if let Some(is_active) = m.is_active { // Our "is-active" definition corresponds to the window having a pending Activated state. let pending_activated = server_pending |
