Skip to content

Commit

Permalink
Fix border getting default values for focus ring
Browse files Browse the repository at this point in the history
  • Loading branch information
YaLTeR committed Feb 12, 2024
1 parent 6e23073 commit 18f06a7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 20 deletions.
48 changes: 35 additions & 13 deletions niri-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ pub struct Mode {
pub struct Layout {
#[knuffel(child, default)]
pub focus_ring: FocusRing,
#[knuffel(child, default = FocusRing::default_border())]
pub border: FocusRing,
#[knuffel(child, default)]
pub border: Border,
#[knuffel(child, unwrap(children), default)]
pub preset_column_widths: Vec<PresetWidth>,
#[knuffel(child)]
Expand All @@ -305,11 +305,11 @@ pub struct SpawnAtStartup {
pub struct FocusRing {
#[knuffel(child)]
pub off: bool,
#[knuffel(child, unwrap(argument), default = 4)]
#[knuffel(child, unwrap(argument), default = Self::default().width)]
pub width: u16,
#[knuffel(child, default = Color::new(127, 200, 255, 255))]
#[knuffel(child, default = Self::default().active_color)]
pub active_color: Color,
#[knuffel(child, default = Color::new(80, 80, 80, 255))]
#[knuffel(child, default = Self::default().inactive_color)]
pub inactive_color: Color,
}

Expand All @@ -324,9 +324,21 @@ impl Default for FocusRing {
}
}

impl FocusRing {
pub const fn default_border() -> FocusRing {
FocusRing {
#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
pub struct Border {
#[knuffel(child)]
pub off: bool,
#[knuffel(child, unwrap(argument), default = Self::default().width)]
pub width: u16,
#[knuffel(child, default = Self::default().active_color)]
pub active_color: Color,
#[knuffel(child, default = Self::default().inactive_color)]
pub inactive_color: Color,
}

impl Default for Border {
fn default() -> Self {
Self {
off: true,
width: 4,
active_color: Color::new(255, 200, 127, 255),
Expand All @@ -335,6 +347,17 @@ impl FocusRing {
}
}

impl From<Border> for FocusRing {
fn from(value: Border) -> Self {
Self {
off: value.off,
width: value.width,
active_color: value.active_color,
inactive_color: value.inactive_color,
}
}
}

#[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct Color {
#[knuffel(argument)]
Expand Down Expand Up @@ -881,7 +904,6 @@ mod tests {
border {
width 3
active-color 0 100 200 255
inactive-color 255 200 100 0
}
Expand Down Expand Up @@ -1005,13 +1027,13 @@ mod tests {
a: 0,
},
},
border: FocusRing {
border: Border {
off: false,
width: 3,
active_color: Color {
r: 0,
g: 100,
b: 200,
r: 255,
g: 200,
b: 127,
a: 255,
},
inactive_color: Color {
Expand Down
2 changes: 1 addition & 1 deletion niri-visual-tests/src/cases/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Layout {
off: true,
..Default::default()
},
border: niri_config::FocusRing {
border: niri_config::Border {
off: false,
width: 4,
active_color: Color::new(255, 163, 72, 255),
Expand Down
2 changes: 1 addition & 1 deletion niri-visual-tests/src/cases/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Tile {
off: true,
..Default::default()
},
border: niri_config::FocusRing {
border: niri_config::Border {
off: false,
width: 32,
active_color: Color::new(255, 163, 72, 255),
Expand Down
19 changes: 16 additions & 3 deletions src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub struct Options {
/// Extra padding around the working area in logical pixels.
pub struts: Struts,
pub focus_ring: niri_config::FocusRing,
pub border: niri_config::FocusRing,
pub border: niri_config::Border,
pub center_focused_column: CenterFocusedColumn,
/// Column widths that `toggle_width()` switches between.
pub preset_widths: Vec<ColumnWidth>,
Expand All @@ -168,7 +168,7 @@ impl Default for Options {
gaps: 16,
struts: Default::default(),
focus_ring: Default::default(),
border: niri_config::FocusRing::default_border(),
border: Default::default(),
center_focused_column: Default::default(),
preset_widths: vec![
ColumnWidth::Proportion(1. / 3.),
Expand Down Expand Up @@ -2818,12 +2818,25 @@ mod tests {
}
}

prop_compose! {
fn arbitrary_border()(
off in any::<bool>(),
width in arbitrary_spacing(),
) -> niri_config::Border {
niri_config::Border {
off,
width,
..Default::default()
}
}
}

prop_compose! {
fn arbitrary_options()(
gaps in arbitrary_spacing(),
struts in arbitrary_struts(),
focus_ring in arbitrary_focus_ring(),
border in arbitrary_focus_ring(),
border in arbitrary_border(),
center_focused_column in arbitrary_center_focused_column(),
) -> Options {
Options {
Expand Down
4 changes: 2 additions & 2 deletions src/layout/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<W: LayoutElement> Tile<W> {
pub fn new(window: W, options: Rc<Options>) -> Self {
Self {
window,
border: FocusRing::new(options.border),
border: FocusRing::new(options.border.into()),
focus_ring: FocusRing::new(options.focus_ring),
is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size.
fullscreen_backdrop: SolidColorBuffer::new((0, 0), [0., 0., 0., 1.]),
Expand All @@ -73,7 +73,7 @@ impl<W: LayoutElement> Tile<W> {
}

pub fn update_config(&mut self, options: Rc<Options>) {
self.border.update_config(options.border);
self.border.update_config(options.border.into());
self.focus_ring.update_config(options.focus_ring);
self.options = options;
}
Expand Down

0 comments on commit 18f06a7

Please sign in to comment.