Implement is-floating window rule matcher
Browse files at this commita24a6e4e3c441389fd7731320f47e61e567e237fParent: 6fba4c38 changed files +66 -0
- niri-config/src/lib.rs +5 -0
- niri-visual-tests/src/test_window.rs +2 -0
- src/layout/floating.rs +1 -0
- src/layout/mod.rs +4 -0
- src/layout/scrolling.rs +1 -0
- src/window/mapped.rs +14 -0
- src/window/mod.rs +21 -0
- wiki/Configuration:-Window-Rules.md +18 -0
niri-config/src/lib.rsmodified+5 -0
| @@ -1031,6 +1031,8 @@ pub struct Match { | ||
| 1031 | 1031 | #[knuffel(property)] |
| 1032 | 1032 | pub is_active_in_column: Option<bool>, |
| 1033 | 1033 | #[knuffel(property)] |
| 1034 | + pub is_floating: Option<bool>, | |
| 1035 | + #[knuffel(property)] | |
| 1034 | 1036 | pub at_startup: Option<bool>, |
| 1035 | 1037 | } |
| 1036 | 1038 | |
| @@ -3403,6 +3405,7 @@ mod tests { | ||
| 3403 | 3405 | is_active: None, |
| 3404 | 3406 | is_focused: None, |
| 3405 | 3407 | is_active_in_column: None, |
| 3408 | + is_floating: None, | |
| 3406 | 3409 | at_startup: None, |
| 3407 | 3410 | }], |
| 3408 | 3411 | excludes: vec![ |
| @@ -3412,6 +3415,7 @@ mod tests { | ||
| 3412 | 3415 | is_active: None, |
| 3413 | 3416 | is_focused: None, |
| 3414 | 3417 | is_active_in_column: None, |
| 3418 | + is_floating: None, | |
| 3415 | 3419 | at_startup: None, |
| 3416 | 3420 | }, |
| 3417 | 3421 | Match { |
| @@ -3420,6 +3424,7 @@ mod tests { | ||
| 3420 | 3424 | is_active: Some(true), |
| 3421 | 3425 | is_focused: Some(false), |
| 3422 | 3426 | is_active_in_column: None, |
| 3427 | + is_floating: None, | |
| 3423 | 3428 | at_startup: None, |
| 3424 | 3429 | }, |
| 3425 | 3430 | ], |
niri-visual-tests/src/test_window.rsmodified+2 -0
| @@ -220,6 +220,8 @@ impl LayoutElement for TestWindow { | ||
| 220 | 220 | |
| 221 | 221 | fn set_active_in_column(&mut self, _active: bool) {} |
| 222 | 222 | |
| 223 | + fn set_floating(&mut self, _floating: bool) {} | |
| 224 | + | |
| 223 | 225 | fn set_bounds(&self, _bounds: Size<i32, Logical>) {} |
| 224 | 226 | |
| 225 | 227 | fn configure_intent(&self) -> ConfigureIntent { |
src/layout/floating.rsmodified+1 -0
| @@ -1029,6 +1029,7 @@ impl<W: LayoutElement> FloatingSpace<W> { | ||
| 1029 | 1029 | let win = tile.window_mut(); |
| 1030 | 1030 | |
| 1031 | 1031 | win.set_active_in_column(true); |
| 1032 | + win.set_floating(true); | |
| 1032 | 1033 | |
| 1033 | 1034 | let is_active = is_active && Some(win.id()) == active.as_ref(); |
| 1034 | 1035 | win.set_activated(is_active); |
src/layout/mod.rsmodified+4 -0
| @@ -186,6 +186,7 @@ pub trait LayoutElement { | ||
| 186 | 186 | fn set_offscreen_element_id(&self, id: Option<Id>); |
| 187 | 187 | fn set_activated(&mut self, active: bool); |
| 188 | 188 | fn set_active_in_column(&mut self, active: bool); |
| 189 | + fn set_floating(&mut self, floating: bool); | |
| 189 | 190 | fn set_bounds(&self, bounds: Size<i32, Logical>); |
| 190 | 191 | |
| 191 | 192 | fn configure_intent(&self) -> ConfigureIntent; |
| @@ -3746,6 +3747,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 3746 | 3747 | let win = move_.tile.window_mut(); |
| 3747 | 3748 | |
| 3748 | 3749 | win.set_active_in_column(true); |
| 3750 | + win.set_floating(move_.is_floating); | |
| 3749 | 3751 | win.set_activated(true); |
| 3750 | 3752 | |
| 3751 | 3753 | win.set_interactive_resize(None); |
| @@ -4074,6 +4076,8 @@ mod tests { | ||
| 4074 | 4076 | |
| 4075 | 4077 | fn set_active_in_column(&mut self, _active: bool) {} |
| 4076 | 4078 | |
| 4079 | + fn set_floating(&mut self, _floating: bool) {} | |
| 4080 | + | |
| 4077 | 4081 | fn is_fullscreen(&self) -> bool { |
| 4078 | 4082 | false |
| 4079 | 4083 | } |
src/layout/scrolling.rsmodified+1 -0
| @@ -2614,6 +2614,7 @@ impl<W: LayoutElement> ScrollingSpace<W> { | ||
| 2614 | 2614 | |
| 2615 | 2615 | let active_in_column = col.active_tile_idx == tile_idx; |
| 2616 | 2616 | win.set_active_in_column(active_in_column); |
| 2617 | + win.set_floating(false); | |
| 2617 | 2618 | |
| 2618 | 2619 | let active = is_active && self.active_column_idx == col_idx && active_in_column; |
| 2619 | 2620 | win.set_activated(active); |
src/window/mapped.rsmodified+14 -0
| @@ -66,6 +66,9 @@ pub struct Mapped { | ||
| 66 | 66 | /// Whether this window is the active window in its column. |
| 67 | 67 | is_active_in_column: bool, |
| 68 | 68 | |
| 69 | + /// Whether this window is floating. | |
| 70 | + is_floating: bool, | |
| 71 | + | |
| 69 | 72 | /// Buffer to draw instead of the window when it should be blocked out. |
| 70 | 73 | block_out_buffer: RefCell<SolidColorBuffer>, |
| 71 | 74 | |
| @@ -163,6 +166,7 @@ impl Mapped { | ||
| 163 | 166 | need_to_recompute_rules: false, |
| 164 | 167 | is_focused: false, |
| 165 | 168 | is_active_in_column: false, |
| 169 | + is_floating: false, | |
| 166 | 170 | block_out_buffer: RefCell::new(SolidColorBuffer::new((0., 0.), [0., 0., 0., 1.])), |
| 167 | 171 | animate_next_configure: false, |
| 168 | 172 | animate_serials: Vec::new(), |
| @@ -220,6 +224,10 @@ impl Mapped { | ||
| 220 | 224 | self.is_active_in_column |
| 221 | 225 | } |
| 222 | 226 | |
| 227 | + pub fn is_floating(&self) -> bool { | |
| 228 | + self.is_floating | |
| 229 | + } | |
| 230 | + | |
| 223 | 231 | pub fn set_is_focused(&mut self, is_focused: bool) { |
| 224 | 232 | if self.is_focused == is_focused { |
| 225 | 233 | return; |
| @@ -690,6 +698,12 @@ impl LayoutElement for Mapped { | ||
| 690 | 698 | self.need_to_recompute_rules |= changed; |
| 691 | 699 | } |
| 692 | 700 | |
| 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 | + | |
| 693 | 707 | fn set_bounds(&self, bounds: Size<i32, Logical>) { |
| 694 | 708 | self.toplevel().with_pending_state(|state| { |
| 695 | 709 | state.bounds = Some(bounds); |
src/window/mod.rsmodified+21 -0
| @@ -115,6 +115,21 @@ impl<'a> WindowRef<'a> { | ||
| 115 | 115 | WindowRef::Mapped(mapped) => mapped.is_active_in_column(), |
| 116 | 116 | } |
| 117 | 117 | } |
| 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 | + } | |
| 118 | 133 | } |
| 119 | 134 | |
| 120 | 135 | impl ResolvedWindowRules { |
| @@ -381,5 +396,11 @@ fn window_matches(window: WindowRef, role: &XdgToplevelSurfaceRoleAttributes, m: | ||
| 381 | 396 | } |
| 382 | 397 | } |
| 383 | 398 | |
| 399 | + if let Some(is_floating) = m.is_floating { | |
| 400 | + if window.is_floating() != is_floating { | |
| 401 | + return false; | |
| 402 | + } | |
| 403 | + } | |
| 404 | + | |
| 384 | 405 | true |
| 385 | 406 | } |
wiki/Configuration:-Window-Rules.mdmodified+18 -0
| @@ -33,6 +33,7 @@ window-rule { | ||
| 33 | 33 | match is-active=true |
| 34 | 34 | match is-focused=false |
| 35 | 35 | match is-active-in-column=true |
| 36 | + match is-floating=true | |
| 36 | 37 | match at-startup=true |
| 37 | 38 | |
| 38 | 39 | // Properties that apply once upon window opening. |
| @@ -198,6 +199,23 @@ window-rule { | ||
| 198 | 199 | } |
| 199 | 200 | ``` |
| 200 | 201 | |
| 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 | + | |
| 201 | 219 | #### `at-startup` |
| 202 | 220 | |
| 203 | 221 | <sup>Since: 0.1.6</sup> |