forge
Explore
Log in

Don't you dare go Hollow

Implement border window rule

Browse files at this commit

3e598c565e6e8ad4c34e93aec9a49e60d51d730eIvan MolodetskikhParent: e261b64
niri-config/src/lib.rsmodified+80 -0
@@ -701,6 +701,8 @@ pub struct WindowRule {
701 #[knuffel(child, unwrap(argument))]701 #[knuffel(child, unwrap(argument))]
702 pub max_height: Option<u16>,702 pub max_height: Option<u16>,
703 703
704+ #[knuffel(child, default)]
705+ pub border: BorderRule,
704 #[knuffel(child, unwrap(argument))]706 #[knuffel(child, unwrap(argument))]
705 pub draw_border_with_background: Option<bool>,707 pub draw_border_with_background: Option<bool>,
706 #[knuffel(child, unwrap(argument))]708 #[knuffel(child, unwrap(argument))]
@@ -737,6 +739,24 @@ pub enum BlockOutFrom {
737 ScreenCapture,739 ScreenCapture,
738 }740 }
739 741
742+#[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq)]
743+pub struct BorderRule {
744+ #[knuffel(child)]
745+ pub off: bool,
746+ #[knuffel(child)]
747+ pub on: bool,
748+ #[knuffel(child, unwrap(argument))]
749+ pub width: Option<u16>,
750+ #[knuffel(child)]
751+ pub active_color: Option<Color>,
752+ #[knuffel(child)]
753+ pub inactive_color: Option<Color>,
754+ #[knuffel(child)]
755+ pub active_gradient: Option<Gradient>,
756+ #[knuffel(child)]
757+ pub inactive_gradient: Option<Gradient>,
758+}
759+
740 #[derive(Debug, Default, PartialEq)]760 #[derive(Debug, Default, PartialEq)]
741 pub struct Binds(pub Vec<Bind>);761 pub struct Binds(pub Vec<Bind>);
742 762
@@ -992,6 +1012,56 @@ impl Default for Config {
992 }1012 }
993 }1013 }
994 1014
1015+impl BorderRule {
1016+ pub fn merge_with(&mut self, other: &Self) {
1017+ self.off |= other.off;
1018+ self.on |= other.on;
1019+
1020+ if let Some(x) = other.width {
1021+ self.width = Some(x);
1022+ }
1023+ if let Some(x) = other.active_color {
1024+ self.active_color = Some(x);
1025+ }
1026+ if let Some(x) = other.inactive_color {
1027+ self.inactive_color = Some(x);
1028+ }
1029+ if let Some(x) = other.active_gradient {
1030+ self.active_gradient = Some(x);
1031+ }
1032+ if let Some(x) = other.inactive_gradient {
1033+ self.inactive_gradient = Some(x);
1034+ }
1035+ }
1036+
1037+ pub fn resolve_against(&self, mut config: Border) -> Border {
1038+ config.off |= self.off;
1039+ if self.on {
1040+ config.off = false;
1041+ }
1042+
1043+ if let Some(x) = self.width {
1044+ config.width = x;
1045+ }
1046+ if let Some(x) = self.active_color {
1047+ config.active_color = x;
1048+ config.active_gradient = None;
1049+ }
1050+ if let Some(x) = self.inactive_color {
1051+ config.inactive_color = x;
1052+ config.inactive_gradient = None;
1053+ }
1054+ if let Some(x) = self.active_gradient {
1055+ config.active_gradient = Some(x);
1056+ }
1057+ if let Some(x) = self.inactive_gradient {
1058+ config.inactive_gradient = Some(x);
1059+ }
1060+
1061+ config
1062+ }
1063+}
1064+
995 impl FromStr for Color {1065 impl FromStr for Color {
996 type Err = miette::Error;1066 type Err = miette::Error;
997 1067
@@ -1977,6 +2047,11 @@ mod tests {
1977 open-on-output "eDP-1"2047 open-on-output "eDP-1"
1978 open-maximized true2048 open-maximized true
1979 open-fullscreen false2049 open-fullscreen false
2050+
2051+ border {
2052+ on
2053+ width 8
2054+ }
1980 }2055 }
1981 2056
1982 binds {2057 binds {
@@ -2179,6 +2254,11 @@ mod tests {
2179 open_on_output: Some("eDP-1".to_owned()),2254 open_on_output: Some("eDP-1".to_owned()),
2180 open_maximized: Some(true),2255 open_maximized: Some(true),
2181 open_fullscreen: Some(false),2256 open_fullscreen: Some(false),
2257+ border: BorderRule {
2258+ on: true,
2259+ width: Some(8),
2260+ ..Default::default()
2261+ },
2182 ..Default::default()2262 ..Default::default()
2183 }],2263 }],
2184 binds: Binds(vec![2264 binds: Binds(vec![
niri-visual-tests/src/cases/layout.rsmodified+2 -2
@@ -147,7 +147,7 @@ impl Layout {
147 147
148 fn add_window(&mut self, mut window: TestWindow, width: Option<ColumnWidth>) {148 fn add_window(&mut self, mut window: TestWindow, width: Option<ColumnWidth>) {
149 let ws = self.layout.active_workspace().unwrap();149 let ws = self.layout.active_workspace().unwrap();
150- window.request_size(ws.new_window_size(width), false);150+ window.request_size(ws.new_window_size(width, window.rules()), false);
151 window.communicate();151 window.communicate();
152 152
153 self.layout.add_window(window.clone(), width, false);153 self.layout.add_window(window.clone(), width, false);
@@ -161,7 +161,7 @@ impl Layout {
161 width: Option<ColumnWidth>,161 width: Option<ColumnWidth>,
162 ) {162 ) {
163 let ws = self.layout.active_workspace().unwrap();163 let ws = self.layout.active_workspace().unwrap();
164- window.request_size(ws.new_window_size(width), false);164+ window.request_size(ws.new_window_size(width, window.rules()), false);
165 window.communicate();165 window.communicate();
166 166
167 self.layout167 self.layout
src/handlers/xdg_shell.rsmodified+5 -5
@@ -230,7 +230,7 @@ impl XdgShellHandler for State {
230 230
231 // The required configure will be the initial configure.231 // The required configure will be the initial configure.
232 }232 }
233- InitialConfigureState::Configured { output, .. } => {233+ InitialConfigureState::Configured { rules, output, .. } => {
234 // Figure out the monitor following a similar logic to initial configure.234 // Figure out the monitor following a similar logic to initial configure.
235 // FIXME: deduplicate.235 // FIXME: deduplicate.
236 let mon = requested_output236 let mon = requested_output
@@ -269,7 +269,7 @@ impl XdgShellHandler for State {
269 toplevel.with_pending_state(|state| {269 toplevel.with_pending_state(|state| {
270 state.states.set(xdg_toplevel::State::Fullscreen);270 state.states.set(xdg_toplevel::State::Fullscreen);
271 });271 });
272- ws.configure_new_window(&unmapped.window, None);272+ ws.configure_new_window(&unmapped.window, None, rules);
273 }273 }
274 274
275 // We already sent the initial configure, so we need to reconfigure.275 // We already sent the initial configure, so we need to reconfigure.
@@ -302,10 +302,10 @@ impl XdgShellHandler for State {
302 // The required configure will be the initial configure.302 // The required configure will be the initial configure.
303 }303 }
304 InitialConfigureState::Configured {304 InitialConfigureState::Configured {
305+ rules,
305 width,306 width,
306 is_full_width,307 is_full_width,
307 output,308 output,
308- ..
309 } => {309 } => {
310 // Figure out the monitor following a similar logic to initial configure.310 // Figure out the monitor following a similar logic to initial configure.
311 // FIXME: deduplicate.311 // FIXME: deduplicate.
@@ -349,7 +349,7 @@ impl XdgShellHandler for State {
349 } else {349 } else {
350 *width350 *width
351 };351 };
352- ws.configure_new_window(&unmapped.window, configure_width);352+ ws.configure_new_window(&unmapped.window, configure_width, rules);
353 }353 }
354 354
355 // We already sent the initial configure, so we need to reconfigure.355 // We already sent the initial configure, so we need to reconfigure.
@@ -580,7 +580,7 @@ impl State {
580 } else {580 } else {
581 width581 width
582 };582 };
583- ws.configure_new_window(window, configure_width);583+ ws.configure_new_window(window, configure_width, &rules);
584 }584 }
585 585
586 // If the user prefers no CSD, it's a reasonable assumption that they would prefer to get586 // If the user prefers no CSD, it's a reasonable assumption that they would prefer to get
src/layout/mod.rsmodified+12 -6
@@ -463,8 +463,10 @@ impl<W: LayoutElement> Layout<W> {
463 ) -> Option<&Output> {463 ) -> Option<&Output> {
464 let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));464 let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));
465 if let ColumnWidth::Fixed(w) = &mut width {465 if let ColumnWidth::Fixed(w) = &mut width {
466- if !self.options.border.off {466+ let rules = window.rules();
467- *w += self.options.border.width as i32 * 2;467+ let border_config = rules.border.resolve_against(self.options.border);
468+ if !border_config.off {
469+ *w += border_config.width as i32 * 2;
468 }470 }
469 }471 }
470 472
@@ -519,8 +521,10 @@ impl<W: LayoutElement> Layout<W> {
519 ) -> Option<&Output> {521 ) -> Option<&Output> {
520 let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));522 let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));
521 if let ColumnWidth::Fixed(w) = &mut width {523 if let ColumnWidth::Fixed(w) = &mut width {
522- if !self.options.border.off {524+ let rules = window.rules();
523- *w += self.options.border.width as i32 * 2;525+ let border_config = rules.border.resolve_against(self.options.border);
526+ if !border_config.off {
527+ *w += border_config.width as i32 * 2;
524 }528 }
525 }529 }
526 530
@@ -555,8 +559,10 @@ impl<W: LayoutElement> Layout<W> {
555 ) {559 ) {
556 let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));560 let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));
557 if let ColumnWidth::Fixed(w) = &mut width {561 if let ColumnWidth::Fixed(w) = &mut width {
558- if !self.options.border.off {562+ let rules = window.rules();
559- *w += self.options.border.width as i32 * 2;563+ let border_config = rules.border.resolve_against(self.options.border);
564+ if !border_config.off {
565+ *w += border_config.width as i32 * 2;
560 }566 }
561 }567 }
562 568
src/layout/tile.rsmodified+13 -2
@@ -107,9 +107,12 @@ struct MoveAnimation {
107 107
108 impl<W: LayoutElement> Tile<W> {108 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();
111+ let border_config = rules.border.resolve_against(options.border);
112+
110 Self {113 Self {
111 window,114 window,
112- border: FocusRing::new(options.border.into()),115+ border: FocusRing::new(border_config.into()),
113 focus_ring: FocusRing::new(options.focus_ring),116 focus_ring: FocusRing::new(options.focus_ring),
114 is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size.117 is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size.
115 fullscreen_backdrop: SolidColorBuffer::new((0, 0), [0., 0., 0., 1.]),118 fullscreen_backdrop: SolidColorBuffer::new((0, 0), [0., 0., 0., 1.]),
@@ -123,7 +126,11 @@ impl<W: LayoutElement> Tile<W> {
123 }126 }
124 127
125 pub fn update_config(&mut self, options: Rc<Options>) {128 pub fn update_config(&mut self, options: Rc<Options>) {
126- self.border.update_config(options.border.into());129+ let rules = self.window.rules();
130+
131+ let border_config = rules.border.resolve_against(self.options.border);
132+ self.border.update_config(border_config.into());
133+
127 self.focus_ring.update_config(options.focus_ring);134 self.focus_ring.update_config(options.focus_ring);
128 self.options = options;135 self.options = options;
129 }136 }
@@ -164,6 +171,10 @@ impl<W: LayoutElement> Tile<W> {
164 self.resize_animation = None;171 self.resize_animation = None;
165 }172 }
166 }173 }
174+
175+ let rules = self.window.rules();
176+ let border_config = rules.border.resolve_against(self.options.border);
177+ self.border.update_config(border_config.into());
167 }178 }
168 179
169 pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {180 pub fn advance_animations(&mut self, current_time: Duration, is_active: bool) {
src/layout/workspace.rsmodified+46 -20
@@ -23,6 +23,7 @@ use crate::render_helpers::RenderTarget;
23 use crate::swipe_tracker::SwipeTracker;23 use crate::swipe_tracker::SwipeTracker;
24 use crate::utils::id::IdCounter;24 use crate::utils::id::IdCounter;
25 use crate::utils::output_size;25 use crate::utils::output_size;
26+use crate::window::ResolvedWindowRules;
26 27
27 /// Amount of touchpad movement to scroll the view for the width of one working area.28 /// Amount of touchpad movement to scroll the view for the width of one working area.
28 const VIEW_GESTURE_WORKING_AREA_MOVEMENT: f64 = 1200.;29 const VIEW_GESTURE_WORKING_AREA_MOVEMENT: f64 = 1200.;
@@ -406,16 +407,9 @@ impl<W: LayoutElement> Workspace<W> {
406 }407 }
407 }408 }
408 409
409- fn toplevel_bounds(&self) -> Size<i32, Logical> {410+ fn toplevel_bounds(&self, rules: &ResolvedWindowRules) -> Size<i32, Logical> {
410- let mut border = 0;411+ let border_config = rules.border.resolve_against(self.options.border);
411- if !self.options.border.off {412+ compute_toplevel_bounds(border_config, self.working_area.size, self.options.gaps)
412- border = self.options.border.width as i32 * 2;
413- }
414-
415- Size::from((
416- max(self.working_area.size.w - self.options.gaps * 2 - border, 1),
417- max(self.working_area.size.h - self.options.gaps * 2 - border, 1),
418- ))
419 }413 }
420 414
421 pub fn resolve_default_width(415 pub fn resolve_default_width(
@@ -429,14 +423,20 @@ impl<W: LayoutElement> Workspace<W> {
429 }423 }
430 }424 }
431 425
432- pub fn new_window_size(&self, width: Option<ColumnWidth>) -> Size<i32, Logical> {426+ pub fn new_window_size(
427+ &self,
428+ width: Option<ColumnWidth>,
429+ rules: &ResolvedWindowRules,
430+ ) -> Size<i32, Logical> {
431+ let border = rules.border.resolve_against(self.options.border);
432+
433 let width = if let Some(width) = width {433 let width = if let Some(width) = width {
434 let is_fixed = matches!(width, ColumnWidth::Fixed(_));434 let is_fixed = matches!(width, ColumnWidth::Fixed(_));
435 435
436 let mut width = width.resolve(&self.options, self.working_area.size.w);436 let mut width = width.resolve(&self.options, self.working_area.size.w);
437 437
438- if !is_fixed && !self.options.border.off {438+ if !is_fixed && !border.off {
439- width -= self.options.border.width as i32 * 2;439+ width -= border.width as i32 * 2;
440 }440 }
441 441
442 max(1, width)442 max(1, width)
@@ -445,14 +445,19 @@ impl<W: LayoutElement> Workspace<W> {
445 };445 };
446 446
447 let mut height = self.working_area.size.h - self.options.gaps * 2;447 let mut height = self.working_area.size.h - self.options.gaps * 2;
448- if !self.options.border.off {448+ if !border.off {
449- height -= self.options.border.width as i32 * 2;449+ height -= border.width as i32 * 2;
450 }450 }
451 451
452 Size::from((width, max(height, 1)))452 Size::from((width, max(height, 1)))
453 }453 }
454 454
455- pub fn configure_new_window(&self, window: &Window, width: Option<ColumnWidth>) {455+ pub fn configure_new_window(
456+ &self,
457+ window: &Window,
458+ width: Option<ColumnWidth>,
459+ rules: &ResolvedWindowRules,
460+ ) {
456 if let Some(output) = self.output.as_ref() {461 if let Some(output) = self.output.as_ref() {
457 let scale = output.current_scale().integer_scale();462 let scale = output.current_scale().integer_scale();
458 let transform = output.current_transform();463 let transform = output.current_transform();
@@ -468,10 +473,10 @@ impl<W: LayoutElement> Workspace<W> {
468 if state.states.contains(xdg_toplevel::State::Fullscreen) {473 if state.states.contains(xdg_toplevel::State::Fullscreen) {
469 state.size = Some(self.view_size);474 state.size = Some(self.view_size);
470 } else {475 } else {
471- state.size = Some(self.new_window_size(width));476+ state.size = Some(self.new_window_size(width, rules));
472 }477 }
473 478
474- state.bounds = Some(self.toplevel_bounds());479+ state.bounds = Some(self.toplevel_bounds(rules));
475 });480 });
476 }481 }
477 482
@@ -2134,8 +2139,6 @@ impl<W: LayoutElement> Workspace<W> {
2134 }2139 }
2135 2140
2136 pub fn refresh(&mut self, is_active: bool) {2141 pub fn refresh(&mut self, is_active: bool) {
2137- let bounds = self.toplevel_bounds();
2138-
2139 for (col_idx, col) in self.columns.iter_mut().enumerate() {2142 for (col_idx, col) in self.columns.iter_mut().enumerate() {
2140 for (tile_idx, tile) in col.tiles.iter_mut().enumerate() {2143 for (tile_idx, tile) in col.tiles.iter_mut().enumerate() {
2141 let win = tile.window_mut();2144 let win = tile.window_mut();
@@ -2144,7 +2147,14 @@ impl<W: LayoutElement> Workspace<W> {
2144 && col.active_tile_idx == tile_idx;2147 && col.active_tile_idx == tile_idx;
2145 win.set_activated(active);2148 win.set_activated(active);
2146 2149
2150+ let border_config = win.rules().border.resolve_against(self.options.border);
2151+ let bounds = compute_toplevel_bounds(
2152+ border_config,
2153+ self.working_area.size,
2154+ self.options.gaps,
2155+ );
2147 win.set_bounds(bounds);2156 win.set_bounds(bounds);
2157+
2148 win.send_pending_configure();2158 win.send_pending_configure();
2149 win.refresh();2159 win.refresh();
2150 }2160 }
@@ -2824,3 +2834,19 @@ pub fn compute_working_area(output: &Output, struts: Struts) -> Rectangle<i32, L
2824 2834
2825 working_area2835 working_area
2826 }2836 }
2837+
2838+fn compute_toplevel_bounds(
2839+ border_config: niri_config::Border,
2840+ working_area_size: Size<i32, Logical>,
2841+ gaps: i32,
2842+) -> Size<i32, Logical> {
2843+ let mut border = 0;
2844+ if !border_config.off {
2845+ border = border_config.width as i32 * 2;
2846+ }
2847+
2848+ Size::from((
2849+ max(working_area_size.w - gaps * 2 - border, 1),
2850+ max(working_area_size.h - gaps * 2 - border, 1),
2851+ ))
2852+}
src/window/mod.rsmodified+15 -1
@@ -1,4 +1,4 @@
1-use niri_config::{BlockOutFrom, Match, WindowRule};1+use niri_config::{BlockOutFrom, BorderRule, Match, WindowRule};
2 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;2 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
3 use smithay::wayland::compositor::with_states;3 use smithay::wayland::compositor::with_states;
4 use smithay::wayland::shell::xdg::{4 use smithay::wayland::shell::xdg::{
@@ -48,6 +48,9 @@ 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+ /// Window border overrides.
52+ pub border: BorderRule,
53+
51 /// Whether or not to draw the border with a solid background.54 /// Whether or not to draw the border with a solid background.
52 ///55 ///
53 /// `None` means using the SSD heuristic.56 /// `None` means using the SSD heuristic.
@@ -87,6 +90,15 @@ impl ResolvedWindowRules {
87 min_height: None,90 min_height: None,
88 max_width: None,91 max_width: None,
89 max_height: None,92 max_height: None,
93+ border: BorderRule {
94+ off: false,
95+ on: false,
96+ width: None,
97+ active_color: None,
98+ inactive_color: None,
99+ active_gradient: None,
100+ inactive_gradient: None,
101+ },
90 draw_border_with_background: None,102 draw_border_with_background: None,
91 opacity: None,103 opacity: None,
92 block_out_from: None,104 block_out_from: None,
@@ -158,6 +170,8 @@ impl ResolvedWindowRules {
158 resolved.max_height = Some(x);170 resolved.max_height = Some(x);
159 }171 }
160 172
173+ resolved.border.merge_with(&rule.border);
174+
161 if let Some(x) = rule.draw_border_with_background {175 if let Some(x) = rule.draw_border_with_background {
162 resolved.draw_border_with_background = Some(x);176 resolved.draw_border_with_background = Some(x);
163 }177 }
wiki/Configuration:-Window-Rules.mdmodified+30 -0
@@ -45,6 +45,16 @@ 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 {
49+ // off
50+ on
51+ width 4
52+ active-color "#ffc87f"
53+ inactive-color "#505050"
54+ active-gradient from="#ffbb66" to="#ffc880" angle=45 relative-to="workspace-view"
55+ inactive-gradient from="#505050" to="#808080" angle=45 relative-to="workspace-view"
56+ }
57+
48 min-width 10058 min-width 100
49 max-width 20059 max-width 200
50 min-height 30060 min-height 300
@@ -337,6 +347,26 @@ window-rule {
337 }347 }
338 ```348 ```
339 349
350+#### `border`
351+
352+<sup>Since: 0.1.6</sup>
353+
354+Override the border options for the window.
355+
356+This rule has the same options as the normal border config in the [layout](./Configuration:-Layout.md) section, so check the documentation there.
357+
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.
359+The `on` flag has precedence over the `off` flag, in case both are set.
360+
361+```
362+window-rule {
363+ border {
364+ on
365+ width 8
366+ }
367+}
368+```
369+
340 #### Size Overrides370 #### Size Overrides
341 371
342 You can amend the window's minimum and maximum size in logical pixels.372 You can amend the window's minimum and maximum size in logical pixels.