Fix border getting default values for focus ring

This commit is contained in:
Ivan Molodetskikh
2024-02-12 09:34:54 +04:00
parent 6e23073019
commit 18f06a7acd
5 changed files with 55 additions and 20 deletions

View File

@@ -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)]
@@ -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,
}
@@ -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),
@@ -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)]
@@ -881,7 +904,6 @@ mod tests {
border {
width 3
active-color 0 100 200 255
inactive-color 255 200 100 0
}
@@ -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 {

View File

@@ -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),

View File

@@ -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),

View File

@@ -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>,
@@ -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.),
@@ -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 {

View File

@@ -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.]),
@@ -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;
}