aboutsummaryrefslogtreecommitdiff
path: root/src/window
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-03-23 16:16:52 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2024-03-23 16:16:52 +0400
commit6ec65bc0d6f6141a3951c076b693b6ce430c503a (patch)
tree3c601ca9310357935f1c95066797571fcc5a797d /src/window
parentd65446421fb989c74329b053fd3ccc387403fdc5 (diff)
downloadniri-6ec65bc0d6f6141a3951c076b693b6ce430c503a.tar.gz
niri-6ec65bc0d6f6141a3951c076b693b6ce430c503a.tar.bz2
niri-6ec65bc0d6f6141a3951c076b693b6ce430c503a.zip
Add is-focused window rule matcher
Diffstat (limited to 'src/window')
-rw-r--r--src/window/mapped.rs17
-rw-r--r--src/window/mod.rs23
2 files changed, 35 insertions, 5 deletions
diff --git a/src/window/mapped.rs b/src/window/mapped.rs
index 087bf0e7..a48ca636 100644
--- a/src/window/mapped.rs
+++ b/src/window/mapped.rs
@@ -29,6 +29,9 @@ pub struct Mapped {
/// This is not used in all cases; for example, app ID and title changes recompute the rules
/// immediately, rather than setting this flag.
need_to_recompute_rules: bool,
+
+ /// Whether this window has the keyboard focus.
+ is_focused: bool,
}
impl Mapped {
@@ -37,6 +40,7 @@ impl Mapped {
window,
rules,
need_to_recompute_rules: false,
+ is_focused: false,
}
}
@@ -64,6 +68,19 @@ impl Mapped {
self.recompute_window_rules(rules)
}
+
+ pub fn is_focused(&self) -> bool {
+ self.is_focused
+ }
+
+ pub fn set_is_focused(&mut self, is_focused: bool) {
+ if self.is_focused == is_focused {
+ return;
+ }
+
+ self.is_focused = is_focused;
+ self.need_to_recompute_rules = true;
+ }
}
impl LayoutElement for Mapped {
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