Add is_active_in_column
Browse files at this commit47a8e75fd585e351dd2846a58152a7766403ca11Parent: 6d9cfe27 changed files +52 -3
- niri-config/src/lib.rs +5 -0
- niri-visual-tests/src/test_window.rs +2 -0
- src/layout/mod.rs +3 -0
- src/layout/workspace.rs +5 -3
- src/window/mapped.rs +10 -0
- src/window/mod.rs +13 -0
- wiki/Configuration:-Window-Rules.md +14 -0
niri-config/src/lib.rsmodified+5 -0
| @@ -734,6 +734,8 @@ pub struct Match { | |||
| 734 | pub is_active: Option<bool>, | 734 | pub is_active: Option<bool>, |
| 735 | #[knuffel(property)] | 735 | #[knuffel(property)] |
| 736 | pub is_focused: Option<bool>, | 736 | pub is_focused: Option<bool>, |
| 737 | + #[knuffel(property)] | ||
| 738 | + pub is_active_in_column: Option<bool>, | ||
| 737 | } | 739 | } |
| 738 | 740 | ||
| 739 | impl PartialEq for Match { | 741 | impl PartialEq for Match { |
| @@ -2416,6 +2418,7 @@ mod tests { | |||
| 2416 | title: None, | 2418 | title: None, |
| 2417 | is_active: None, | 2419 | is_active: None, |
| 2418 | is_focused: None, | 2420 | is_focused: None, |
| 2421 | + is_active_in_column: None, | ||
| 2419 | }], | 2422 | }], |
| 2420 | excludes: vec![ | 2423 | excludes: vec![ |
| 2421 | Match { | 2424 | Match { |
| @@ -2423,12 +2426,14 @@ mod tests { | |||
| 2423 | title: Some(Regex::new("~").unwrap()), | 2426 | title: Some(Regex::new("~").unwrap()), |
| 2424 | is_active: None, | 2427 | is_active: None, |
| 2425 | is_focused: None, | 2428 | is_focused: None, |
| 2429 | + is_active_in_column: None, | ||
| 2426 | }, | 2430 | }, |
| 2427 | Match { | 2431 | Match { |
| 2428 | app_id: None, | 2432 | app_id: None, |
| 2429 | title: None, | 2433 | title: None, |
| 2430 | is_active: Some(true), | 2434 | is_active: Some(true), |
| 2431 | is_focused: Some(false), | 2435 | is_focused: Some(false), |
| 2436 | + is_active_in_column: None, | ||
| 2432 | }, | 2437 | }, |
| 2433 | ], | 2438 | ], |
| 2434 | open_on_output: Some("eDP-1".to_owned()), | 2439 | open_on_output: Some("eDP-1".to_owned()), |
niri-visual-tests/src/test_window.rsmodified+2 -0
| @@ -213,6 +213,8 @@ impl LayoutElement for TestWindow { | |||
| 213 | 213 | ||
| 214 | fn set_activated(&mut self, _active: bool) {} | 214 | fn set_activated(&mut self, _active: bool) {} |
| 215 | 215 | ||
| 216 | + fn set_active_in_column(&mut self, _active: bool) {} | ||
| 217 | + | ||
| 216 | fn set_bounds(&self, _bounds: Size<i32, Logical>) {} | 218 | fn set_bounds(&self, _bounds: Size<i32, Logical>) {} |
| 217 | 219 | ||
| 218 | fn send_pending_configure(&mut self) {} | 220 | fn send_pending_configure(&mut self) {} |
src/layout/mod.rsmodified+3 -0
| @@ -152,6 +152,7 @@ pub trait LayoutElement { | |||
| 152 | fn output_leave(&self, output: &Output); | 152 | fn output_leave(&self, output: &Output); |
| 153 | fn set_offscreen_element_id(&self, id: Option<Id>); | 153 | fn set_offscreen_element_id(&self, id: Option<Id>); |
| 154 | fn set_activated(&mut self, active: bool); | 154 | fn set_activated(&mut self, active: bool); |
| 155 | + fn set_active_in_column(&mut self, active: bool); | ||
| 155 | fn set_bounds(&self, bounds: Size<i32, Logical>); | 156 | fn set_bounds(&self, bounds: Size<i32, Logical>); |
| 156 | 157 | ||
| 157 | fn send_pending_configure(&mut self); | 158 | fn send_pending_configure(&mut self); |
| @@ -2190,6 +2191,8 @@ mod tests { | |||
| 2190 | 2191 | ||
| 2191 | fn send_pending_configure(&mut self) {} | 2192 | fn send_pending_configure(&mut self) {} |
| 2192 | 2193 | ||
| 2194 | + fn set_active_in_column(&mut self, _active: bool) {} | ||
| 2195 | + | ||
| 2193 | fn is_fullscreen(&self) -> bool { | 2196 | fn is_fullscreen(&self) -> bool { |
| 2194 | false | 2197 | false |
| 2195 | } | 2198 | } |
src/layout/workspace.rsmodified+5 -3
| @@ -2459,9 +2459,11 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 2459 | 2459 | ||
| 2460 | for (tile_idx, tile) in col.tiles.iter_mut().enumerate() { | 2460 | for (tile_idx, tile) in col.tiles.iter_mut().enumerate() { |
| 2461 | let win = tile.window_mut(); | 2461 | let win = tile.window_mut(); |
| 2462 | - let active = is_active | 2462 | + |
| 2463 | - && self.active_column_idx == col_idx | 2463 | + let active_in_column = col.active_tile_idx == tile_idx; |
| 2464 | - && col.active_tile_idx == tile_idx; | 2464 | + win.set_active_in_column(active_in_column); |
| 2465 | + | ||
| 2466 | + let active = is_active && self.active_column_idx == col_idx && active_in_column; | ||
| 2465 | win.set_activated(active); | 2467 | win.set_activated(active); |
| 2466 | 2468 | ||
| 2467 | win.set_interactive_resize(col_resize_data); | 2469 | win.set_interactive_resize(col_resize_data); |
src/window/mapped.rsmodified+10 -0
| @@ -49,6 +49,9 @@ pub struct Mapped { | |||
| 49 | /// Whether this window has the keyboard focus. | 49 | /// Whether this window has the keyboard focus. |
| 50 | is_focused: bool, | 50 | is_focused: bool, |
| 51 | 51 | ||
| 52 | + /// Whether this window is the active window in its column. | ||
| 53 | + pub is_active_in_column: bool, | ||
| 54 | + | ||
| 52 | /// Buffer to draw instead of the window when it should be blocked out. | 55 | /// Buffer to draw instead of the window when it should be blocked out. |
| 53 | block_out_buffer: RefCell<SolidColorBuffer>, | 56 | block_out_buffer: RefCell<SolidColorBuffer>, |
| 54 | 57 | ||
| @@ -102,6 +105,7 @@ impl Mapped { | |||
| 102 | rules, | 105 | rules, |
| 103 | need_to_recompute_rules: false, | 106 | need_to_recompute_rules: false, |
| 104 | is_focused: false, | 107 | is_focused: false, |
| 108 | + is_active_in_column: false, | ||
| 105 | block_out_buffer: RefCell::new(SolidColorBuffer::new((0, 0), [0., 0., 0., 1.])), | 109 | block_out_buffer: RefCell::new(SolidColorBuffer::new((0, 0), [0., 0., 0., 1.])), |
| 106 | animate_next_configure: false, | 110 | animate_next_configure: false, |
| 107 | animate_serials: Vec::new(), | 111 | animate_serials: Vec::new(), |
| @@ -458,6 +462,12 @@ impl LayoutElement for Mapped { | |||
| 458 | self.need_to_recompute_rules |= changed; | 462 | self.need_to_recompute_rules |= changed; |
| 459 | } | 463 | } |
| 460 | 464 | ||
| 465 | + fn set_active_in_column(&mut self, active: bool) { | ||
| 466 | + let changed = self.is_active_in_column != active; | ||
| 467 | + self.is_active_in_column = active; | ||
| 468 | + self.need_to_recompute_rules |= changed; | ||
| 469 | + } | ||
| 470 | + | ||
| 461 | fn set_bounds(&self, bounds: Size<i32, Logical>) { | 471 | fn set_bounds(&self, bounds: Size<i32, Logical>) { |
| 462 | self.toplevel().with_pending_state(|state| { | 472 | self.toplevel().with_pending_state(|state| { |
| 463 | state.bounds = Some(bounds); | 473 | state.bounds = Some(bounds); |
src/window/mod.rsmodified+13 -0
| @@ -85,6 +85,13 @@ impl<'a> WindowRef<'a> { | |||
| 85 | WindowRef::Mapped(mapped) => mapped.is_focused(), | 85 | WindowRef::Mapped(mapped) => mapped.is_focused(), |
| 86 | } | 86 | } |
| 87 | } | 87 | } |
| 88 | + | ||
| 89 | + pub fn is_active_in_column(self) -> bool { | ||
| 90 | + match self { | ||
| 91 | + WindowRef::Unmapped(_) => false, | ||
| 92 | + WindowRef::Mapped(mapped) => mapped.is_active_in_column, | ||
| 93 | + } | ||
| 94 | + } | ||
| 88 | } | 95 | } |
| 89 | 96 | ||
| 90 | impl ResolvedWindowRules { | 97 | impl ResolvedWindowRules { |
| @@ -254,5 +261,11 @@ fn window_matches(window: WindowRef, role: &XdgToplevelSurfaceRoleAttributes, m: | |||
| 254 | } | 261 | } |
| 255 | } | 262 | } |
| 256 | 263 | ||
| 264 | + if let Some(is_active_in_column) = m.is_active_in_column { | ||
| 265 | + if window.is_active_in_column() != is_active_in_column { | ||
| 266 | + return false; | ||
| 267 | + } | ||
| 268 | + } | ||
| 269 | + | ||
| 257 | true | 270 | true |
| 258 | } | 271 | } |
wiki/Configuration:-Window-Rules.mdmodified+14 -0
| @@ -174,6 +174,20 @@ window-rule { | |||
| 174 | } | 174 | } |
| 175 | ``` | 175 | ``` |
| 176 | 176 | ||
| 177 | +#### `is-active-in-column` | ||
| 178 | + | ||
| 179 | +Can be `true` or `false`. | ||
| 180 | +Matches the window that is the "active" window in its column. | ||
| 181 | + | ||
| 182 | +Contrary to `is-active`, there is always one `is-active-in-column` window in each column. | ||
| 183 | +It is the window that was last focused in the column, i.e. the one that will gain focus if this column is focused. | ||
| 184 | + | ||
| 185 | +``` | ||
| 186 | +window-rule { | ||
| 187 | + match is-active-in-column=true | ||
| 188 | +} | ||
| 189 | +``` | ||
| 190 | + | ||
| 177 | ### Window Opening Properties | 191 | ### Window Opening Properties |
| 178 | 192 | ||
| 179 | These properties apply once, when a window first opens. | 193 | These properties apply once, when a window first opens. |