forge
Explore
Log in

Don't you dare go Hollow

Implement draw-border-with-background window rule

Browse files at this commit

db49deb7fd2fbe805ceec060aa4dec65009ad7a7Ivan MolodetskikhParent: c61361d
niri-config/src/lib.rsmodified+3 -0
@@ -693,6 +693,9 @@ pub struct WindowRule {
693 pub max_width: Option<u16>,693 pub max_width: Option<u16>,
694 #[knuffel(child, unwrap(argument))]694 #[knuffel(child, unwrap(argument))]
695 pub max_height: Option<u16>,695 pub max_height: Option<u16>,
696+
697+ #[knuffel(child, unwrap(argument))]
698+ pub draw_border_with_background: Option<bool>,
696 }699 }
697 700
698 #[derive(knuffel::Decode, Debug, Default, Clone)]701 #[derive(knuffel::Decode, Debug, Default, Clone)]
niri-visual-tests/src/test_window.rsmodified+6 -0
@@ -4,6 +4,7 @@ use std::rc::Rc;
4 4
5 use niri::layout::{LayoutElement, LayoutElementRenderElement};5 use niri::layout::{LayoutElement, LayoutElementRenderElement};
6 use niri::render_helpers::renderer::NiriRenderer;6 use niri::render_helpers::renderer::NiriRenderer;
7+use niri::window::ResolvedWindowRules;
7 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};8 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
8 use smithay::backend::renderer::element::{Id, Kind};9 use smithay::backend::renderer::element::{Id, Kind};
9 use smithay::output::Output;10 use smithay::output::Output;
@@ -217,4 +218,9 @@ impl LayoutElement for TestWindow {
217 }218 }
218 219
219 fn refresh(&self) {}220 fn refresh(&self) {}
221+
222+ fn rules(&self) -> &ResolvedWindowRules {
223+ static EMPTY: ResolvedWindowRules = ResolvedWindowRules::empty();
224+ &EMPTY
225+ }
220 }226 }
resources/default-config.kdlmodified+10 -0
@@ -123,6 +123,9 @@ layout {
123 // If you don't like that, you should uncomment `prefer-no-csd` below.123 // If you don't like that, you should uncomment `prefer-no-csd` below.
124 // Niri will draw focus ring and border *around* windows that agree to omit their124 // Niri will draw focus ring and border *around* windows that agree to omit their
125 // client-side decorations.125 // client-side decorations.
126+ //
127+ // Alternatively, you can override it with a window rule called
128+ // `draw-border-with-background`.
126 129
127 // You can change how the focus ring looks.130 // You can change how the focus ring looks.
128 focus-ring {131 focus-ring {
@@ -393,6 +396,13 @@ animations {
393 // if it is equal to min-height. Either set this equal to min-height,396 // if it is equal to min-height. Either set this equal to min-height,
394 // or change the window height manually for this to apply.397 // or change the window height manually for this to apply.
395 max-height 300398 max-height 300
399+
400+ // Override whether the border and the focus ring draw with a background.
401+ // Set this to `true` to draw them as solid colored rectangles even for
402+ // windows which agreed to omit their client-side decorations.
403+ // Set this to `false` to draw them as borders around the window even for
404+ // windows which use client-side decorations.
405+ draw-border-with-background false
396 }406 }
397 407
398 // Here's a useful example. Work around WezTerm's initial configure bug408 // Here's a useful example. Work around WezTerm's initial configure bug
src/handlers/compositor.rsmodified+1 -1
@@ -123,7 +123,7 @@ impl CompositorHandler for State {
123 (rules, width, is_full_width, output)123 (rules, width, is_full_width, output)
124 } else {124 } else {
125 error!("window map must happen after initial configure");125 error!("window map must happen after initial configure");
126- (ResolvedWindowRules::default(), None, false, None)126+ (ResolvedWindowRules::empty(), None, false, None)
127 };127 };
128 128
129 let parent = window129 let parent = window
src/layout/mod.rsmodified+8 -0
@@ -49,6 +49,7 @@ use self::workspace::{compute_working_area, Column, ColumnWidth, OutputId, Works
49 use crate::niri_render_elements;49 use crate::niri_render_elements;
50 use crate::render_helpers::renderer::NiriRenderer;50 use crate::render_helpers::renderer::NiriRenderer;
51 use crate::utils::output_size;51 use crate::utils::output_size;
52+use crate::window::ResolvedWindowRules;
52 53
53 pub mod focus_ring;54 pub mod focus_ring;
54 pub mod monitor;55 pub mod monitor;
@@ -121,6 +122,8 @@ pub trait LayoutElement {
121 /// This *will* switch immediately after a [`LayoutElement::request_fullscreen()`] call.122 /// This *will* switch immediately after a [`LayoutElement::request_fullscreen()`] call.
122 fn is_pending_fullscreen(&self) -> bool;123 fn is_pending_fullscreen(&self) -> bool;
123 124
125+ fn rules(&self) -> &ResolvedWindowRules;
126+
124 /// Runs periodic clean-up tasks.127 /// Runs periodic clean-up tasks.
125 fn refresh(&self);128 fn refresh(&self);
126 }129 }
@@ -1905,6 +1908,11 @@ mod tests {
1905 }1908 }
1906 1909
1907 fn refresh(&self) {}1910 fn refresh(&self) {}
1911+
1912+ fn rules(&self) -> &ResolvedWindowRules {
1913+ static EMPTY: ResolvedWindowRules = ResolvedWindowRules::empty();
1914+ &EMPTY
1915+ }
1908 }1916 }
1909 1917
1910 fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> {1918 fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> {
src/layout/tile.rsmodified+22 -4
@@ -85,11 +85,22 @@ impl<W: LayoutElement> Tile<W> {
85 }85 }
86 86
87 pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {87 pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {
88+ let draw_border_with_background = self
89+ .window
90+ .rules()
91+ .draw_border_with_background
92+ .unwrap_or_else(|| !self.window.has_ssd());
88 self.border93 self.border
89- .update(self.window.size(), self.window.has_ssd());94+ .update(self.window.size(), !draw_border_with_background);
90 self.border.set_active(is_active);95 self.border.set_active(is_active);
91 96
92- self.focus_ring.update(self.tile_size(), self.has_ssd());97+ let draw_focus_ring_with_background = if self.effective_border_width().is_some() {
98+ false
99+ } else {
100+ draw_border_with_background
101+ };
102+ self.focus_ring
103+ .update(self.tile_size(), !draw_focus_ring_with_background);
93 self.focus_ring.set_active(is_active);104 self.focus_ring.set_active(is_active);
94 105
95 match &mut self.open_animation {106 match &mut self.open_animation {
@@ -295,8 +306,15 @@ impl<W: LayoutElement> Tile<W> {
295 size306 size
296 }307 }
297 308
298- pub fn has_ssd(&self) -> bool {309+ pub fn draw_border_with_background(&self) -> bool {
299- self.effective_border_width().is_some() || self.window.has_ssd()310+ if self.effective_border_width().is_some() {
311+ return false;
312+ }
313+
314+ self.window
315+ .rules()
316+ .draw_border_with_background
317+ .unwrap_or_else(|| !self.window.has_ssd())
300 }318 }
301 319
302 fn render_inner<R: NiriRenderer>(320 fn render_inner<R: NiriRenderer>(
src/window/mapped.rsmodified+4 -0
@@ -184,4 +184,8 @@ impl LayoutElement for Mapped {
184 fn refresh(&self) {184 fn refresh(&self) {
185 self.window.refresh();185 self.window.refresh();
186 }186 }
187+
188+ fn rules(&self) -> &ResolvedWindowRules {
189+ &self.rules
190+ }
187 }191 }
src/window/mod.rsmodified+25 -2
@@ -13,7 +13,7 @@ pub mod unmapped;
13 pub use unmapped::{InitialConfigureState, Unmapped};13 pub use unmapped::{InitialConfigureState, Unmapped};
14 14
15 /// Rules fully resolved for a window.15 /// Rules fully resolved for a window.
16-#[derive(Debug, Default, PartialEq)]16+#[derive(Debug, PartialEq)]
17 pub struct ResolvedWindowRules {17 pub struct ResolvedWindowRules {
18 /// Default width for this window.18 /// Default width for this window.
19 ///19 ///
@@ -39,13 +39,32 @@ pub struct ResolvedWindowRules {
39 pub max_width: Option<u16>,39 pub max_width: Option<u16>,
40 /// Extra bound on the maximum window height.40 /// Extra bound on the maximum window height.
41 pub max_height: Option<u16>,41 pub max_height: Option<u16>,
42+
43+ /// Whether or not to draw the border with a solid background.
44+ ///
45+ /// `None` means using the SSD heuristic.
46+ pub draw_border_with_background: Option<bool>,
42 }47 }
43 48
44 impl ResolvedWindowRules {49 impl ResolvedWindowRules {
50+ pub const fn empty() -> Self {
51+ Self {
52+ default_width: None,
53+ open_on_output: None,
54+ open_maximized: None,
55+ open_fullscreen: None,
56+ min_width: None,
57+ min_height: None,
58+ max_width: None,
59+ max_height: None,
60+ draw_border_with_background: None,
61+ }
62+ }
63+
45 pub fn compute(rules: &[WindowRule], toplevel: &ToplevelSurface) -> Self {64 pub fn compute(rules: &[WindowRule], toplevel: &ToplevelSurface) -> Self {
46 let _span = tracy_client::span!("ResolvedWindowRules::compute");65 let _span = tracy_client::span!("ResolvedWindowRules::compute");
47 66
48- let mut resolved = ResolvedWindowRules::default();67+ let mut resolved = ResolvedWindowRules::empty();
49 68
50 with_states(toplevel.wl_surface(), |states| {69 with_states(toplevel.wl_surface(), |states| {
51 let role = states70 let role = states
@@ -100,6 +119,10 @@ impl ResolvedWindowRules {
100 if let Some(x) = rule.max_height {119 if let Some(x) = rule.max_height {
101 resolved.max_height = Some(x);120 resolved.max_height = Some(x);
102 }121 }
122+
123+ if let Some(x) = rule.draw_border_with_background {
124+ resolved.draw_border_with_background = Some(x);
125+ }
103 }126 }
104 127
105 resolved.open_on_output = open_on_output.map(|x| x.to_owned());128 resolved.open_on_output = open_on_output.map(|x| x.to_owned());