aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-04-24 22:17:53 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2024-04-24 22:17:53 +0400
commitfd6c8c7790ae4e7dca1f242263f41411a1bab96e (patch)
treeb53b04dbef2e934d2b9fc25346fbfcb1c524714c
parent3e598c565e6e8ad4c34e93aec9a49e60d51d730e (diff)
downloadniri-fd6c8c7790ae4e7dca1f242263f41411a1bab96e.tar.gz
niri-fd6c8c7790ae4e7dca1f242263f41411a1bab96e.tar.bz2
niri-fd6c8c7790ae4e7dca1f242263f41411a1bab96e.zip
Implement focus-ring window rule
-rw-r--r--niri-config/src/lib.rs25
-rw-r--r--src/layout/tile.rs13
-rw-r--r--src/window/mod.rs12
-rw-r--r--wiki/Configuration:-Window-Rules.md27
4 files changed, 67 insertions, 10 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs
index 26689d09..87e2c4a6 100644
--- a/niri-config/src/lib.rs
+++ b/niri-config/src/lib.rs
@@ -412,6 +412,19 @@ impl From<Border> for FocusRing {
}
}
+impl From<FocusRing> for Border {
+ fn from(value: FocusRing) -> Self {
+ Self {
+ off: value.off,
+ width: value.width,
+ active_color: value.active_color,
+ inactive_color: value.inactive_color,
+ active_gradient: value.active_gradient,
+ inactive_gradient: value.inactive_gradient,
+ }
+ }
+}
+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct Color {
pub r: u8,
@@ -702,6 +715,8 @@ pub struct WindowRule {
pub max_height: Option<u16>,
#[knuffel(child, default)]
+ pub focus_ring: BorderRule,
+ #[knuffel(child, default)]
pub border: BorderRule,
#[knuffel(child, unwrap(argument))]
pub draw_border_with_background: Option<bool>,
@@ -2048,6 +2063,11 @@ mod tests {
open-maximized true
open-fullscreen false
+ focus-ring {
+ off
+ width 3
+ }
+
border {
on
width 8
@@ -2254,6 +2274,11 @@ mod tests {
open_on_output: Some("eDP-1".to_owned()),
open_maximized: Some(true),
open_fullscreen: Some(false),
+ focus_ring: BorderRule {
+ off: true,
+ width: Some(3),
+ ..Default::default()
+ },
border: BorderRule {
on: true,
width: Some(8),
diff --git a/src/layout/tile.rs b/src/layout/tile.rs
index 4778db69..7294cc05 100644
--- a/src/layout/tile.rs
+++ b/src/layout/tile.rs
@@ -109,11 +109,12 @@ impl<W: LayoutElement> Tile<W> {
pub fn new(window: W, options: Rc<Options>) -> Self {
let rules = window.rules();
let border_config = rules.border.resolve_against(options.border);
+ let focus_ring_config = rules.focus_ring.resolve_against(options.focus_ring.into());
Self {
window,
border: FocusRing::new(border_config.into()),
- focus_ring: FocusRing::new(options.focus_ring),
+ focus_ring: FocusRing::new(focus_ring_config.into()),
is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size.
fullscreen_backdrop: SolidColorBuffer::new((0, 0), [0., 0., 0., 1.]),
fullscreen_size: Default::default(),
@@ -131,7 +132,11 @@ impl<W: LayoutElement> Tile<W> {
let border_config = rules.border.resolve_against(self.options.border);
self.border.update_config(border_config.into());
- self.focus_ring.update_config(options.focus_ring);
+ let focus_ring_config = rules
+ .focus_ring
+ .resolve_against(self.options.focus_ring.into());
+ self.focus_ring.update_config(focus_ring_config.into());
+
self.options = options;
}
@@ -175,6 +180,10 @@ impl<W: LayoutElement> Tile<W> {
let rules = self.window.rules();
let border_config = rules.border.resolve_against(self.options.border);
self.border.update_config(border_config.into());
+ let focus_ring_config = rules
+ .focus_ring
+ .resolve_against(self.options.focus_ring.into());
+ self.focus_ring.update_config(focus_ring_config.into());
}
pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {
diff --git a/src/window/mod.rs b/src/window/mod.rs
index a793cedb..90a6fb2c 100644
--- a/src/window/mod.rs
+++ b/src/window/mod.rs
@@ -48,6 +48,8 @@ pub struct ResolvedWindowRules {
/// Extra bound on the maximum window height.
pub max_height: Option<u16>,
+ /// Focus ring overrides.
+ pub focus_ring: BorderRule,
/// Window border overrides.
pub border: BorderRule,
@@ -90,6 +92,15 @@ impl ResolvedWindowRules {
min_height: None,
max_width: None,
max_height: None,
+ focus_ring: BorderRule {
+ off: false,
+ on: false,
+ width: None,
+ active_color: None,
+ inactive_color: None,
+ active_gradient: None,
+ inactive_gradient: None,
+ },
border: BorderRule {
off: false,
on: false,
@@ -170,6 +181,7 @@ impl ResolvedWindowRules {
resolved.max_height = Some(x);
}
+ resolved.focus_ring.merge_with(&rule.focus_ring);
resolved.border.merge_with(&rule.border);
if let Some(x) = rule.draw_border_with_background {
diff --git a/wiki/Configuration:-Window-Rules.md b/wiki/Configuration:-Window-Rules.md
index b459f8c0..289f1b1c 100644
--- a/wiki/Configuration:-Window-Rules.md
+++ b/wiki/Configuration:-Window-Rules.md
@@ -45,14 +45,18 @@ window-rule {
block-out-from "screencast"
// block-out-from "screen-capture"
- border {
+ focus-ring {
// off
on
width 4
- active-color "#ffc87f"
+ active-color "#7fc8ff"
inactive-color "#505050"
- active-gradient from="#ffbb66" to="#ffc880" angle=45 relative-to="workspace-view"
- inactive-gradient from="#505050" to="#808080" angle=45 relative-to="workspace-view"
+ // active-gradient from="#80c8ff" to="#bbddff" angle=45
+ // inactive-gradient from="#505050" to="#808080" angle=45 relative-to="workspace-view"
+ }
+
+ border {
+ // Same as focus-ring.
}
min-width 100
@@ -347,19 +351,26 @@ window-rule {
}
```
-#### `border`
+#### `focus-ring` and `border`
<sup>Since: 0.1.6</sup>
-Override the border options for the window.
+Override the focus ring and border options for the window.
-This rule has the same options as the normal border config in the [layout](./Configuration:-Layout.md) section, so check the documentation there.
+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.
-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.
+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.
The `on` flag has precedence over the `off` flag, in case both are set.
```
window-rule {
+ focus-ring {
+ off
+ width 2
+ }
+}
+
+window-rule {
border {
on
width 8