Implement focus-ring window rule
Browse files at this commitfd6c8c7790ae4e7dca1f242263f41411a1bab96eParent: 3e598c54 changed files +67 -10
- niri-config/src/lib.rs +25 -0
- src/layout/tile.rs +11 -2
- src/window/mod.rs +12 -0
- wiki/Configuration:-Window-Rules.md +19 -8
niri-config/src/lib.rsmodified+25 -0
| @@ -412,6 +412,19 @@ impl From<Border> for FocusRing { | |||
| 412 | } | 412 | } |
| 413 | } | 413 | } |
| 414 | 414 | ||
| 415 | +impl From<FocusRing> for Border { | ||
| 416 | + fn from(value: FocusRing) -> Self { | ||
| 417 | + Self { | ||
| 418 | + off: value.off, | ||
| 419 | + width: value.width, | ||
| 420 | + active_color: value.active_color, | ||
| 421 | + inactive_color: value.inactive_color, | ||
| 422 | + active_gradient: value.active_gradient, | ||
| 423 | + inactive_gradient: value.inactive_gradient, | ||
| 424 | + } | ||
| 425 | + } | ||
| 426 | +} | ||
| 427 | + | ||
| 415 | #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] | 428 | #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] |
| 416 | pub struct Color { | 429 | pub struct Color { |
| 417 | pub r: u8, | 430 | pub r: u8, |
| @@ -701,6 +714,8 @@ pub struct WindowRule { | |||
| 701 | #[knuffel(child, unwrap(argument))] | 714 | #[knuffel(child, unwrap(argument))] |
| 702 | pub max_height: Option<u16>, | 715 | pub max_height: Option<u16>, |
| 703 | 716 | ||
| 717 | + #[knuffel(child, default)] | ||
| 718 | + pub focus_ring: BorderRule, | ||
| 704 | #[knuffel(child, default)] | 719 | #[knuffel(child, default)] |
| 705 | pub border: BorderRule, | 720 | pub border: BorderRule, |
| 706 | #[knuffel(child, unwrap(argument))] | 721 | #[knuffel(child, unwrap(argument))] |
| @@ -2048,6 +2063,11 @@ mod tests { | |||
| 2048 | open-maximized true | 2063 | open-maximized true |
| 2049 | open-fullscreen false | 2064 | open-fullscreen false |
| 2050 | 2065 | ||
| 2066 | + focus-ring { | ||
| 2067 | + off | ||
| 2068 | + width 3 | ||
| 2069 | + } | ||
| 2070 | + | ||
| 2051 | border { | 2071 | border { |
| 2052 | on | 2072 | on |
| 2053 | width 8 | 2073 | width 8 |
| @@ -2254,6 +2274,11 @@ mod tests { | |||
| 2254 | open_on_output: Some("eDP-1".to_owned()), | 2274 | open_on_output: Some("eDP-1".to_owned()), |
| 2255 | open_maximized: Some(true), | 2275 | open_maximized: Some(true), |
| 2256 | open_fullscreen: Some(false), | 2276 | open_fullscreen: Some(false), |
| 2277 | + focus_ring: BorderRule { | ||
| 2278 | + off: true, | ||
| 2279 | + width: Some(3), | ||
| 2280 | + ..Default::default() | ||
| 2281 | + }, | ||
| 2257 | border: BorderRule { | 2282 | border: BorderRule { |
| 2258 | on: true, | 2283 | on: true, |
| 2259 | width: Some(8), | 2284 | width: Some(8), |
src/layout/tile.rsmodified+11 -2
| @@ -109,11 +109,12 @@ impl<W: LayoutElement> Tile<W> { | |||
| 109 | pub fn new(window: W, options: Rc<Options>) -> Self { | 109 | pub fn new(window: W, options: Rc<Options>) -> Self { |
| 110 | let rules = window.rules(); | 110 | let rules = window.rules(); |
| 111 | let border_config = rules.border.resolve_against(options.border); | 111 | let border_config = rules.border.resolve_against(options.border); |
| 112 | + let focus_ring_config = rules.focus_ring.resolve_against(options.focus_ring.into()); | ||
| 112 | 113 | ||
| 113 | Self { | 114 | Self { |
| 114 | window, | 115 | window, |
| 115 | border: FocusRing::new(border_config.into()), | 116 | border: FocusRing::new(border_config.into()), |
| 116 | - focus_ring: FocusRing::new(options.focus_ring), | 117 | + focus_ring: FocusRing::new(focus_ring_config.into()), |
| 117 | is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size. | 118 | is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size. |
| 118 | fullscreen_backdrop: SolidColorBuffer::new((0, 0), [0., 0., 0., 1.]), | 119 | fullscreen_backdrop: SolidColorBuffer::new((0, 0), [0., 0., 0., 1.]), |
| 119 | fullscreen_size: Default::default(), | 120 | fullscreen_size: Default::default(), |
| @@ -131,7 +132,11 @@ impl<W: LayoutElement> Tile<W> { | |||
| 131 | let border_config = rules.border.resolve_against(self.options.border); | 132 | let border_config = rules.border.resolve_against(self.options.border); |
| 132 | self.border.update_config(border_config.into()); | 133 | self.border.update_config(border_config.into()); |
| 133 | 134 | ||
| 134 | - self.focus_ring.update_config(options.focus_ring); | 135 | + let focus_ring_config = rules |
| 136 | + .focus_ring | ||
| 137 | + .resolve_against(self.options.focus_ring.into()); | ||
| 138 | + self.focus_ring.update_config(focus_ring_config.into()); | ||
| 139 | + | ||
| 135 | self.options = options; | 140 | self.options = options; |
| 136 | } | 141 | } |
| 137 | 142 | ||
| @@ -175,6 +180,10 @@ impl<W: LayoutElement> Tile<W> { | |||
| 175 | let rules = self.window.rules(); | 180 | let rules = self.window.rules(); |
| 176 | let border_config = rules.border.resolve_against(self.options.border); | 181 | let border_config = rules.border.resolve_against(self.options.border); |
| 177 | self.border.update_config(border_config.into()); | 182 | self.border.update_config(border_config.into()); |
| 183 | + let focus_ring_config = rules | ||
| 184 | + .focus_ring | ||
| 185 | + .resolve_against(self.options.focus_ring.into()); | ||
| 186 | + self.focus_ring.update_config(focus_ring_config.into()); | ||
| 178 | } | 187 | } |
| 179 | 188 | ||
| 180 | pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) { | 189 | pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) { |
src/window/mod.rsmodified+12 -0
| @@ -48,6 +48,8 @@ pub struct ResolvedWindowRules { | |||
| 48 | /// Extra bound on the maximum window height. | 48 | /// Extra bound on the maximum window height. |
| 49 | pub max_height: Option<u16>, | 49 | pub max_height: Option<u16>, |
| 50 | 50 | ||
| 51 | + /// Focus ring overrides. | ||
| 52 | + pub focus_ring: BorderRule, | ||
| 51 | /// Window border overrides. | 53 | /// Window border overrides. |
| 52 | pub border: BorderRule, | 54 | pub border: BorderRule, |
| 53 | 55 | ||
| @@ -90,6 +92,15 @@ impl ResolvedWindowRules { | |||
| 90 | min_height: None, | 92 | min_height: None, |
| 91 | max_width: None, | 93 | max_width: None, |
| 92 | max_height: None, | 94 | max_height: None, |
| 95 | + focus_ring: BorderRule { | ||
| 96 | + off: false, | ||
| 97 | + on: false, | ||
| 98 | + width: None, | ||
| 99 | + active_color: None, | ||
| 100 | + inactive_color: None, | ||
| 101 | + active_gradient: None, | ||
| 102 | + inactive_gradient: None, | ||
| 103 | + }, | ||
| 93 | border: BorderRule { | 104 | border: BorderRule { |
| 94 | off: false, | 105 | off: false, |
| 95 | on: false, | 106 | on: false, |
| @@ -170,6 +181,7 @@ impl ResolvedWindowRules { | |||
| 170 | resolved.max_height = Some(x); | 181 | resolved.max_height = Some(x); |
| 171 | } | 182 | } |
| 172 | 183 | ||
| 184 | + resolved.focus_ring.merge_with(&rule.focus_ring); | ||
| 173 | resolved.border.merge_with(&rule.border); | 185 | resolved.border.merge_with(&rule.border); |
| 174 | 186 | ||
| 175 | if let Some(x) = rule.draw_border_with_background { | 187 | if let Some(x) = rule.draw_border_with_background { |
wiki/Configuration:-Window-Rules.mdmodified+19 -8
| @@ -45,14 +45,18 @@ window-rule { | |||
| 45 | block-out-from "screencast" | 45 | block-out-from "screencast" |
| 46 | // block-out-from "screen-capture" | 46 | // block-out-from "screen-capture" |
| 47 | 47 | ||
| 48 | - border { | 48 | + focus-ring { |
| 49 | // off | 49 | // off |
| 50 | on | 50 | on |
| 51 | width 4 | 51 | width 4 |
| 52 | - active-color "#ffc87f" | 52 | + active-color "#7fc8ff" |
| 53 | inactive-color "#505050" | 53 | inactive-color "#505050" |
| 54 | - active-gradient from="#ffbb66" to="#ffc880" angle=45 relative-to="workspace-view" | 54 | + // active-gradient from="#80c8ff" to="#bbddff" angle=45 |
| 55 | - inactive-gradient from="#505050" to="#808080" angle=45 relative-to="workspace-view" | 55 | + // inactive-gradient from="#505050" to="#808080" angle=45 relative-to="workspace-view" |
| 56 | + } | ||
| 57 | + | ||
| 58 | + border { | ||
| 59 | + // Same as focus-ring. | ||
| 56 | } | 60 | } |
| 57 | 61 | ||
| 58 | min-width 100 | 62 | min-width 100 |
| @@ -347,18 +351,25 @@ window-rule { | |||
| 347 | } | 351 | } |
| 348 | ``` | 352 | ``` |
| 349 | 353 | ||
| 350 | -#### `border` | 354 | +#### `focus-ring` and `border` |
| 351 | 355 | ||
| 352 | <sup>Since: 0.1.6</sup> | 356 | <sup>Since: 0.1.6</sup> |
| 353 | 357 | ||
| 354 | -Override the border options for the window. | 358 | +Override the focus ring and border options for the window. |
| 355 | 359 | ||
| 356 | -This rule has the same options as the normal border config in the [layout](./Configuration:-Layout.md) section, so check the documentation there. | 360 | +These rules have the same options as the normal focus ring and border config in the [layout](./Configuration:-Layout.md) section, so check the documentation there. |
| 357 | 361 | ||
| 358 | -However, in addition to `off` to disable the border, this window rule has an `on` flag that enables the border for the window even if the border is otherwise disabled. | 362 | +However, in addition to `off` to disable the border/focus ring, this window rule has an `on` flag that enables the border/focus ring for the window even if it was otherwise disabled. |
| 359 | The `on` flag has precedence over the `off` flag, in case both are set. | 363 | The `on` flag has precedence over the `off` flag, in case both are set. |
| 360 | 364 | ||
| 361 | ``` | 365 | ``` |
| 366 | +window-rule { | ||
| 367 | + focus-ring { | ||
| 368 | + off | ||
| 369 | + width 2 | ||
| 370 | + } | ||
| 371 | +} | ||
| 372 | + | ||
| 362 | window-rule { | 373 | window-rule { |
| 363 | border { | 374 | border { |
| 364 | on | 375 | on |