forge
Explore
Log in

Don't you dare go Hollow

Fix border getting default values for focus ring

Browse files at this commit

18f06a7acd79feb16dc667b68a1ffd0d59e234c8Ivan MolodetskikhParent: 6e23073
niri-config/src/lib.rsmodified+35 -13
@@ -281,8 +281,8 @@ pub struct Mode {
281 pub struct Layout {281 pub struct Layout {
282 #[knuffel(child, default)]282 #[knuffel(child, default)]
283 pub focus_ring: FocusRing,283 pub focus_ring: FocusRing,
284- #[knuffel(child, default = FocusRing::default_border())]284+ #[knuffel(child, default)]
285- pub border: FocusRing,285+ pub border: Border,
286 #[knuffel(child, unwrap(children), default)]286 #[knuffel(child, unwrap(children), default)]
287 pub preset_column_widths: Vec<PresetWidth>,287 pub preset_column_widths: Vec<PresetWidth>,
288 #[knuffel(child)]288 #[knuffel(child)]
@@ -305,11 +305,11 @@ pub struct SpawnAtStartup {
305 pub struct FocusRing {305 pub struct FocusRing {
306 #[knuffel(child)]306 #[knuffel(child)]
307 pub off: bool,307 pub off: bool,
308- #[knuffel(child, unwrap(argument), default = 4)]308+ #[knuffel(child, unwrap(argument), default = Self::default().width)]
309 pub width: u16,309 pub width: u16,
310- #[knuffel(child, default = Color::new(127, 200, 255, 255))]310+ #[knuffel(child, default = Self::default().active_color)]
311 pub active_color: Color,311 pub active_color: Color,
312- #[knuffel(child, default = Color::new(80, 80, 80, 255))]312+ #[knuffel(child, default = Self::default().inactive_color)]
313 pub inactive_color: Color,313 pub inactive_color: Color,
314 }314 }
315 315
@@ -324,9 +324,21 @@ impl Default for FocusRing {
324 }324 }
325 }325 }
326 326
327-impl FocusRing {327+#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
328- pub const fn default_border() -> FocusRing {328+pub struct Border {
329- FocusRing {329+ #[knuffel(child)]
330+ pub off: bool,
331+ #[knuffel(child, unwrap(argument), default = Self::default().width)]
332+ pub width: u16,
333+ #[knuffel(child, default = Self::default().active_color)]
334+ pub active_color: Color,
335+ #[knuffel(child, default = Self::default().inactive_color)]
336+ pub inactive_color: Color,
337+}
338+
339+impl Default for Border {
340+ fn default() -> Self {
341+ Self {
330 off: true,342 off: true,
331 width: 4,343 width: 4,
332 active_color: Color::new(255, 200, 127, 255),344 active_color: Color::new(255, 200, 127, 255),
@@ -335,6 +347,17 @@ impl FocusRing {
335 }347 }
336 }348 }
337 349
350+impl From<Border> for FocusRing {
351+ fn from(value: Border) -> Self {
352+ Self {
353+ off: value.off,
354+ width: value.width,
355+ active_color: value.active_color,
356+ inactive_color: value.inactive_color,
357+ }
358+ }
359+}
360+
338 #[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)]361 #[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)]
339 pub struct Color {362 pub struct Color {
340 #[knuffel(argument)]363 #[knuffel(argument)]
@@ -881,7 +904,6 @@ mod tests {
881 904
882 border {905 border {
883 width 3906 width 3
884- active-color 0 100 200 255
885 inactive-color 255 200 100 0907 inactive-color 255 200 100 0
886 }908 }
887 909
@@ -1005,13 +1027,13 @@ mod tests {
1005 a: 0,1027 a: 0,
1006 },1028 },
1007 },1029 },
1008- border: FocusRing {1030+ border: Border {
1009 off: false,1031 off: false,
1010 width: 3,1032 width: 3,
1011 active_color: Color {1033 active_color: Color {
1012- r: 0,1034+ r: 255,
1013- g: 100,1035+ g: 200,
1014- b: 200,1036+ b: 127,
1015 a: 255,1037 a: 255,
1016 },1038 },
1017 inactive_color: Color {1039 inactive_color: Color {
niri-visual-tests/src/cases/layout.rsmodified+1 -1
@@ -46,7 +46,7 @@ impl Layout {
46 off: true,46 off: true,
47 ..Default::default()47 ..Default::default()
48 },48 },
49- border: niri_config::FocusRing {49+ border: niri_config::Border {
50 off: false,50 off: false,
51 width: 4,51 width: 4,
52 active_color: Color::new(255, 163, 72, 255),52 active_color: Color::new(255, 163, 72, 255),
niri-visual-tests/src/cases/tile.rsmodified+1 -1
@@ -68,7 +68,7 @@ impl Tile {
68 off: true,68 off: true,
69 ..Default::default()69 ..Default::default()
70 },70 },
71- border: niri_config::FocusRing {71+ border: niri_config::Border {
72 off: false,72 off: false,
73 width: 32,73 width: 32,
74 active_color: Color::new(255, 163, 72, 255),74 active_color: Color::new(255, 163, 72, 255),
src/layout/mod.rsmodified+16 -3
@@ -153,7 +153,7 @@ pub struct Options {
153 /// Extra padding around the working area in logical pixels.153 /// Extra padding around the working area in logical pixels.
154 pub struts: Struts,154 pub struts: Struts,
155 pub focus_ring: niri_config::FocusRing,155 pub focus_ring: niri_config::FocusRing,
156- pub border: niri_config::FocusRing,156+ pub border: niri_config::Border,
157 pub center_focused_column: CenterFocusedColumn,157 pub center_focused_column: CenterFocusedColumn,
158 /// Column widths that `toggle_width()` switches between.158 /// Column widths that `toggle_width()` switches between.
159 pub preset_widths: Vec<ColumnWidth>,159 pub preset_widths: Vec<ColumnWidth>,
@@ -168,7 +168,7 @@ impl Default for Options {
168 gaps: 16,168 gaps: 16,
169 struts: Default::default(),169 struts: Default::default(),
170 focus_ring: Default::default(),170 focus_ring: Default::default(),
171- border: niri_config::FocusRing::default_border(),171+ border: Default::default(),
172 center_focused_column: Default::default(),172 center_focused_column: Default::default(),
173 preset_widths: vec![173 preset_widths: vec![
174 ColumnWidth::Proportion(1. / 3.),174 ColumnWidth::Proportion(1. / 3.),
@@ -2818,12 +2818,25 @@ mod tests {
2818 }2818 }
2819 }2819 }
2820 2820
2821+ prop_compose! {
2822+ fn arbitrary_border()(
2823+ off in any::<bool>(),
2824+ width in arbitrary_spacing(),
2825+ ) -> niri_config::Border {
2826+ niri_config::Border {
2827+ off,
2828+ width,
2829+ ..Default::default()
2830+ }
2831+ }
2832+ }
2833+
2821 prop_compose! {2834 prop_compose! {
2822 fn arbitrary_options()(2835 fn arbitrary_options()(
2823 gaps in arbitrary_spacing(),2836 gaps in arbitrary_spacing(),
2824 struts in arbitrary_struts(),2837 struts in arbitrary_struts(),
2825 focus_ring in arbitrary_focus_ring(),2838 focus_ring in arbitrary_focus_ring(),
2826- border in arbitrary_focus_ring(),2839+ border in arbitrary_border(),
2827 center_focused_column in arbitrary_center_focused_column(),2840 center_focused_column in arbitrary_center_focused_column(),
2828 ) -> Options {2841 ) -> Options {
2829 Options {2842 Options {
src/layout/tile.rsmodified+2 -2
@@ -62,7 +62,7 @@ impl<W: LayoutElement> Tile<W> {
62 pub fn new(window: W, options: Rc<Options>) -> Self {62 pub fn new(window: W, options: Rc<Options>) -> Self {
63 Self {63 Self {
64 window,64 window,
65- border: FocusRing::new(options.border),65+ border: FocusRing::new(options.border.into()),
66 focus_ring: FocusRing::new(options.focus_ring),66 focus_ring: FocusRing::new(options.focus_ring),
67 is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size.67 is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size.
68 fullscreen_backdrop: SolidColorBuffer::new((0, 0), [0., 0., 0., 1.]),68 fullscreen_backdrop: SolidColorBuffer::new((0, 0), [0., 0., 0., 1.]),
@@ -73,7 +73,7 @@ impl<W: LayoutElement> Tile<W> {
73 }73 }
74 74
75 pub fn update_config(&mut self, options: Rc<Options>) {75 pub fn update_config(&mut self, options: Rc<Options>) {
76- self.border.update_config(options.border);76+ self.border.update_config(options.border.into());
77 self.focus_ring.update_config(options.focus_ring);77 self.focus_ring.update_config(options.focus_ring);
78 self.options = options;78 self.options = options;
79 }79 }