From a24a6e4e3c441389fd7731320f47e61e567e237f Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 27 Dec 2024 11:20:03 +0300 Subject: Implement is-floating window rule matcher --- src/window/mapped.rs | 14 ++++++++++++++ src/window/mod.rs | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'src/window') diff --git a/src/window/mapped.rs b/src/window/mapped.rs index 022a57a0..75551ef1 100644 --- a/src/window/mapped.rs +++ b/src/window/mapped.rs @@ -66,6 +66,9 @@ pub struct Mapped { /// Whether this window is the active window in its column. is_active_in_column: bool, + /// Whether this window is floating. + is_floating: bool, + /// Buffer to draw instead of the window when it should be blocked out. block_out_buffer: RefCell, @@ -163,6 +166,7 @@ impl Mapped { need_to_recompute_rules: false, is_focused: false, is_active_in_column: false, + is_floating: false, block_out_buffer: RefCell::new(SolidColorBuffer::new((0., 0.), [0., 0., 0., 1.])), animate_next_configure: false, animate_serials: Vec::new(), @@ -220,6 +224,10 @@ impl Mapped { self.is_active_in_column } + pub fn is_floating(&self) -> bool { + self.is_floating + } + pub fn set_is_focused(&mut self, is_focused: bool) { if self.is_focused == is_focused { return; @@ -690,6 +698,12 @@ impl LayoutElement for Mapped { self.need_to_recompute_rules |= changed; } + fn set_floating(&mut self, floating: bool) { + let changed = self.is_floating != floating; + self.is_floating = floating; + self.need_to_recompute_rules |= changed; + } + fn set_bounds(&self, bounds: Size) { self.toplevel().with_pending_state(|state| { state.bounds = Some(bounds); diff --git a/src/window/mod.rs b/src/window/mod.rs index 44d5359e..1cf576df 100644 --- a/src/window/mod.rs +++ b/src/window/mod.rs @@ -115,6 +115,21 @@ impl<'a> WindowRef<'a> { WindowRef::Mapped(mapped) => mapped.is_active_in_column(), } } + + pub fn is_floating(self) -> bool { + match self { + // FIXME: This means you cannot set initial configure rules based on is-floating. I'm + // not sure there's a good way to support it, since this matcher makes a cycle with the + // open-floating rule. + // + // That said, I don't think there are a lot of useful initial configure properties you + // may want to set through an is-floating matcher? Like, if you're configuring a + // specific window to open as floating, you can also set those properties in that same + // window rule, rather than relying on a different is-floating rule. + WindowRef::Unmapped(_) => false, + WindowRef::Mapped(mapped) => mapped.is_floating(), + } + } } impl ResolvedWindowRules { @@ -381,5 +396,11 @@ fn window_matches(window: WindowRef, role: &XdgToplevelSurfaceRoleAttributes, m: } } + if let Some(is_floating) = m.is_floating { + if window.is_floating() != is_floating { + return false; + } + } + true } -- cgit