forge
Explore
Log in

Don't you dare go Hollow

Implement is-floating window rule matcher

Browse files at this commit

a24a6e4e3c441389fd7731320f47e61e567e237fIvan MolodetskikhParent: 6fba4c3
niri-config/src/lib.rsmodified+5 -0
@@ -1031,6 +1031,8 @@ pub struct Match {
10311031 #[knuffel(property)]
10321032 pub is_active_in_column: Option<bool>,
10331033 #[knuffel(property)]
1034+ pub is_floating: Option<bool>,
1035+ #[knuffel(property)]
10341036 pub at_startup: Option<bool>,
10351037 }
10361038
@@ -3403,6 +3405,7 @@ mod tests {
34033405 is_active: None,
34043406 is_focused: None,
34053407 is_active_in_column: None,
3408+ is_floating: None,
34063409 at_startup: None,
34073410 }],
34083411 excludes: vec![
@@ -3412,6 +3415,7 @@ mod tests {
34123415 is_active: None,
34133416 is_focused: None,
34143417 is_active_in_column: None,
3418+ is_floating: None,
34153419 at_startup: None,
34163420 },
34173421 Match {
@@ -3420,6 +3424,7 @@ mod tests {
34203424 is_active: Some(true),
34213425 is_focused: Some(false),
34223426 is_active_in_column: None,
3427+ is_floating: None,
34233428 at_startup: None,
34243429 },
34253430 ],
niri-visual-tests/src/test_window.rsmodified+2 -0
@@ -220,6 +220,8 @@ impl LayoutElement for TestWindow {
220220
221221 fn set_active_in_column(&mut self, _active: bool) {}
222222
223+ fn set_floating(&mut self, _floating: bool) {}
224+
223225 fn set_bounds(&self, _bounds: Size<i32, Logical>) {}
224226
225227 fn configure_intent(&self) -> ConfigureIntent {
src/layout/floating.rsmodified+1 -0
@@ -1029,6 +1029,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
10291029 let win = tile.window_mut();
10301030
10311031 win.set_active_in_column(true);
1032+ win.set_floating(true);
10321033
10331034 let is_active = is_active && Some(win.id()) == active.as_ref();
10341035 win.set_activated(is_active);
src/layout/mod.rsmodified+4 -0
@@ -186,6 +186,7 @@ pub trait LayoutElement {
186186 fn set_offscreen_element_id(&self, id: Option<Id>);
187187 fn set_activated(&mut self, active: bool);
188188 fn set_active_in_column(&mut self, active: bool);
189+ fn set_floating(&mut self, floating: bool);
189190 fn set_bounds(&self, bounds: Size<i32, Logical>);
190191
191192 fn configure_intent(&self) -> ConfigureIntent;
@@ -3746,6 +3747,7 @@ impl<W: LayoutElement> Layout<W> {
37463747 let win = move_.tile.window_mut();
37473748
37483749 win.set_active_in_column(true);
3750+ win.set_floating(move_.is_floating);
37493751 win.set_activated(true);
37503752
37513753 win.set_interactive_resize(None);
@@ -4074,6 +4076,8 @@ mod tests {
40744076
40754077 fn set_active_in_column(&mut self, _active: bool) {}
40764078
4079+ fn set_floating(&mut self, _floating: bool) {}
4080+
40774081 fn is_fullscreen(&self) -> bool {
40784082 false
40794083 }
src/layout/scrolling.rsmodified+1 -0
@@ -2614,6 +2614,7 @@ impl<W: LayoutElement> ScrollingSpace<W> {
26142614
26152615 let active_in_column = col.active_tile_idx == tile_idx;
26162616 win.set_active_in_column(active_in_column);
2617+ win.set_floating(false);
26172618
26182619 let active = is_active && self.active_column_idx == col_idx && active_in_column;
26192620 win.set_activated(active);
src/window/mapped.rsmodified+14 -0
@@ -66,6 +66,9 @@ pub struct Mapped {
6666 /// Whether this window is the active window in its column.
6767 is_active_in_column: bool,
6868
69+ /// Whether this window is floating.
70+ is_floating: bool,
71+
6972 /// Buffer to draw instead of the window when it should be blocked out.
7073 block_out_buffer: RefCell<SolidColorBuffer>,
7174
@@ -163,6 +166,7 @@ impl Mapped {
163166 need_to_recompute_rules: false,
164167 is_focused: false,
165168 is_active_in_column: false,
169+ is_floating: false,
166170 block_out_buffer: RefCell::new(SolidColorBuffer::new((0., 0.), [0., 0., 0., 1.])),
167171 animate_next_configure: false,
168172 animate_serials: Vec::new(),
@@ -220,6 +224,10 @@ impl Mapped {
220224 self.is_active_in_column
221225 }
222226
227+ pub fn is_floating(&self) -> bool {
228+ self.is_floating
229+ }
230+
223231 pub fn set_is_focused(&mut self, is_focused: bool) {
224232 if self.is_focused == is_focused {
225233 return;
@@ -690,6 +698,12 @@ impl LayoutElement for Mapped {
690698 self.need_to_recompute_rules |= changed;
691699 }
692700
701+ fn set_floating(&mut self, floating: bool) {
702+ let changed = self.is_floating != floating;
703+ self.is_floating = floating;
704+ self.need_to_recompute_rules |= changed;
705+ }
706+
693707 fn set_bounds(&self, bounds: Size<i32, Logical>) {
694708 self.toplevel().with_pending_state(|state| {
695709 state.bounds = Some(bounds);
src/window/mod.rsmodified+21 -0
@@ -115,6 +115,21 @@ impl<'a> WindowRef<'a> {
115115 WindowRef::Mapped(mapped) => mapped.is_active_in_column(),
116116 }
117117 }
118+
119+ pub fn is_floating(self) -> bool {
120+ match self {
121+ // FIXME: This means you cannot set initial configure rules based on is-floating. I'm
122+ // not sure there's a good way to support it, since this matcher makes a cycle with the
123+ // open-floating rule.
124+ //
125+ // That said, I don't think there are a lot of useful initial configure properties you
126+ // may want to set through an is-floating matcher? Like, if you're configuring a
127+ // specific window to open as floating, you can also set those properties in that same
128+ // window rule, rather than relying on a different is-floating rule.
129+ WindowRef::Unmapped(_) => false,
130+ WindowRef::Mapped(mapped) => mapped.is_floating(),
131+ }
132+ }
118133 }
119134
120135 impl ResolvedWindowRules {
@@ -381,5 +396,11 @@ fn window_matches(window: WindowRef, role: &XdgToplevelSurfaceRoleAttributes, m:
381396 }
382397 }
383398
399+ if let Some(is_floating) = m.is_floating {
400+ if window.is_floating() != is_floating {
401+ return false;
402+ }
403+ }
404+
384405 true
385406 }
wiki/Configuration:-Window-Rules.mdmodified+18 -0
@@ -33,6 +33,7 @@ window-rule {
3333 match is-active=true
3434 match is-focused=false
3535 match is-active-in-column=true
36+ match is-floating=true
3637 match at-startup=true
3738
3839 // Properties that apply once upon window opening.
@@ -198,6 +199,23 @@ window-rule {
198199 }
199200 ```
200201
202+#### `is-floating`
203+
204+<sup>Since: next release</sup>
205+
206+Can be `true` or `false`.
207+Matches floating windows.
208+
209+> [!NOTE]
210+> This matcher will apply only after the window is already open.
211+> This means that you cannot use it to change the window opening properties like `default-window-height` or `open-on-workspace`.
212+
213+```kdl
214+window-rule {
215+ match is-floating=true
216+}
217+```
218+
201219 #### `at-startup`
202220
203221 <sup>Since: 0.1.6</sup>