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 {
693693 pub max_width: Option<u16>,
694694 #[knuffel(child, unwrap(argument))]
695695 pub max_height: Option<u16>,
696+
697+ #[knuffel(child, unwrap(argument))]
698+ pub draw_border_with_background: Option<bool>,
696699 }
697700
698701 #[derive(knuffel::Decode, Debug, Default, Clone)]
niri-visual-tests/src/test_window.rsmodified+6 -0
@@ -4,6 +4,7 @@ use std::rc::Rc;
44
55 use niri::layout::{LayoutElement, LayoutElementRenderElement};
66 use niri::render_helpers::renderer::NiriRenderer;
7+use niri::window::ResolvedWindowRules;
78 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
89 use smithay::backend::renderer::element::{Id, Kind};
910 use smithay::output::Output;
@@ -217,4 +218,9 @@ impl LayoutElement for TestWindow {
217218 }
218219
219220 fn refresh(&self) {}
221+
222+ fn rules(&self) -> &ResolvedWindowRules {
223+ static EMPTY: ResolvedWindowRules = ResolvedWindowRules::empty();
224+ &EMPTY
225+ }
220226 }
resources/default-config.kdlmodified+10 -0
@@ -123,6 +123,9 @@ layout {
123123 // If you don't like that, you should uncomment `prefer-no-csd` below.
124124 // Niri will draw focus ring and border *around* windows that agree to omit their
125125 // client-side decorations.
126+ //
127+ // Alternatively, you can override it with a window rule called
128+ // `draw-border-with-background`.
126129
127130 // You can change how the focus ring looks.
128131 focus-ring {
@@ -393,6 +396,13 @@ animations {
393396 // if it is equal to min-height. Either set this equal to min-height,
394397 // or change the window height manually for this to apply.
395398 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
396406 }
397407
398408 // 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 {
123123 (rules, width, is_full_width, output)
124124 } else {
125125 error!("window map must happen after initial configure");
126- (ResolvedWindowRules::default(), None, false, None)
126+ (ResolvedWindowRules::empty(), None, false, None)
127127 };
128128
129129 let parent = window
src/layout/mod.rsmodified+8 -0
@@ -49,6 +49,7 @@ use self::workspace::{compute_working_area, Column, ColumnWidth, OutputId, Works
4949 use crate::niri_render_elements;
5050 use crate::render_helpers::renderer::NiriRenderer;
5151 use crate::utils::output_size;
52+use crate::window::ResolvedWindowRules;
5253
5354 pub mod focus_ring;
5455 pub mod monitor;
@@ -121,6 +122,8 @@ pub trait LayoutElement {
121122 /// This *will* switch immediately after a [`LayoutElement::request_fullscreen()`] call.
122123 fn is_pending_fullscreen(&self) -> bool;
123124
125+ fn rules(&self) -> &ResolvedWindowRules;
126+
124127 /// Runs periodic clean-up tasks.
125128 fn refresh(&self);
126129 }
@@ -1905,6 +1908,11 @@ mod tests {
19051908 }
19061909
19071910 fn refresh(&self) {}
1911+
1912+ fn rules(&self) -> &ResolvedWindowRules {
1913+ static EMPTY: ResolvedWindowRules = ResolvedWindowRules::empty();
1914+ &EMPTY
1915+ }
19081916 }
19091917
19101918 fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> {
src/layout/tile.rsmodified+22 -4
@@ -85,11 +85,22 @@ impl<W: LayoutElement> Tile<W> {
8585 }
8686
8787 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());
8893 self.border
89- .update(self.window.size(), self.window.has_ssd());
94+ .update(self.window.size(), !draw_border_with_background);
9095 self.border.set_active(is_active);
9196
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);
93104 self.focus_ring.set_active(is_active);
94105
95106 match &mut self.open_animation {
@@ -295,8 +306,15 @@ impl<W: LayoutElement> Tile<W> {
295306 size
296307 }
297308
298- pub fn has_ssd(&self) -> bool {
299- self.effective_border_width().is_some() || self.window.has_ssd()
309+ pub fn draw_border_with_background(&self) -> bool {
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())
300318 }
301319
302320 fn render_inner<R: NiriRenderer>(
src/window/mapped.rsmodified+4 -0
@@ -184,4 +184,8 @@ impl LayoutElement for Mapped {
184184 fn refresh(&self) {
185185 self.window.refresh();
186186 }
187+
188+ fn rules(&self) -> &ResolvedWindowRules {
189+ &self.rules
190+ }
187191 }
src/window/mod.rsmodified+25 -2
@@ -13,7 +13,7 @@ pub mod unmapped;
1313 pub use unmapped::{InitialConfigureState, Unmapped};
1414
1515 /// Rules fully resolved for a window.
16-#[derive(Debug, Default, PartialEq)]
16+#[derive(Debug, PartialEq)]
1717 pub struct ResolvedWindowRules {
1818 /// Default width for this window.
1919 ///
@@ -39,13 +39,32 @@ pub struct ResolvedWindowRules {
3939 pub max_width: Option<u16>,
4040 /// Extra bound on the maximum window height.
4141 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>,
4247 }
4348
4449 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+
4564 pub fn compute(rules: &[WindowRule], toplevel: &ToplevelSurface) -> Self {
4665 let _span = tracy_client::span!("ResolvedWindowRules::compute");
4766
48- let mut resolved = ResolvedWindowRules::default();
67+ let mut resolved = ResolvedWindowRules::empty();
4968
5069 with_states(toplevel.wl_surface(), |states| {
5170 let role = states
@@ -100,6 +119,10 @@ impl ResolvedWindowRules {
100119 if let Some(x) = rule.max_height {
101120 resolved.max_height = Some(x);
102121 }
122+
123+ if let Some(x) = rule.draw_border_with_background {
124+ resolved.draw_border_with_background = Some(x);
125+ }
103126 }
104127
105128 resolved.open_on_output = open_on_output.map(|x| x.to_owned());