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
+35 -13
View File
@@ -281,8 +281,8 @@ pub struct Mode {
pub struct Layout { pub struct Layout {
#[knuffel(child, default)] #[knuffel(child, default)]
pub focus_ring: FocusRing, pub focus_ring: FocusRing,
#[knuffel(child, default = FocusRing::default_border())] #[knuffel(child, default)]
pub border: FocusRing, pub border: Border,
#[knuffel(child, unwrap(children), default)] #[knuffel(child, unwrap(children), default)]
pub preset_column_widths: Vec<PresetWidth>, pub preset_column_widths: Vec<PresetWidth>,
#[knuffel(child)] #[knuffel(child)]
@@ -305,11 +305,11 @@ pub struct SpawnAtStartup {
pub struct FocusRing { pub struct FocusRing {
#[knuffel(child)] #[knuffel(child)]
pub off: bool, pub off: bool,
#[knuffel(child, unwrap(argument), default = 4)] #[knuffel(child, unwrap(argument), default = Self::default().width)]
pub width: u16, pub width: u16,
#[knuffel(child, default = Color::new(127, 200, 255, 255))] #[knuffel(child, default = Self::default().active_color)]
pub active_color: 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, pub inactive_color: Color,
} }
@@ -324,9 +324,21 @@ impl Default for FocusRing {
} }
} }
impl FocusRing { #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
pub const fn default_border() -> FocusRing { pub struct Border {
FocusRing { #[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, off: true,
width: 4, width: 4,
active_color: Color::new(255, 200, 127, 255), 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)] #[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct Color { pub struct Color {
#[knuffel(argument)] #[knuffel(argument)]
@@ -881,7 +904,6 @@ mod tests {
border { border {
width 3 width 3
active-color 0 100 200 255
inactive-color 255 200 100 0 inactive-color 255 200 100 0
} }
@@ -1005,13 +1027,13 @@ mod tests {
a: 0, a: 0,
}, },
}, },
border: FocusRing { border: Border {
off: false, off: false,
width: 3, width: 3,
active_color: Color { active_color: Color {
r: 0, r: 255,
g: 100, g: 200,
b: 200, b: 127,
a: 255, a: 255,
}, },
inactive_color: Color { inactive_color: Color {
+1 -1
View File
@@ -46,7 +46,7 @@ impl Layout {
off: true, off: true,
..Default::default() ..Default::default()
}, },
border: niri_config::FocusRing { border: niri_config::Border {
off: false, off: false,
width: 4, width: 4,
active_color: Color::new(255, 163, 72, 255), active_color: Color::new(255, 163, 72, 255),
+1 -1
View File
@@ -68,7 +68,7 @@ impl Tile {
off: true, off: true,
..Default::default() ..Default::default()
}, },
border: niri_config::FocusRing { border: niri_config::Border {
off: false, off: false,
width: 32, width: 32,
active_color: Color::new(255, 163, 72, 255), active_color: Color::new(255, 163, 72, 255),
+16 -3
View File
@@ -153,7 +153,7 @@ pub struct Options {
/// Extra padding around the working area in logical pixels. /// Extra padding around the working area in logical pixels.
pub struts: Struts, pub struts: Struts,
pub focus_ring: niri_config::FocusRing, pub focus_ring: niri_config::FocusRing,
pub border: niri_config::FocusRing, pub border: niri_config::Border,
pub center_focused_column: CenterFocusedColumn, pub center_focused_column: CenterFocusedColumn,
/// Column widths that `toggle_width()` switches between. /// Column widths that `toggle_width()` switches between.
pub preset_widths: Vec<ColumnWidth>, pub preset_widths: Vec<ColumnWidth>,
@@ -168,7 +168,7 @@ impl Default for Options {
gaps: 16, gaps: 16,
struts: Default::default(), struts: Default::default(),
focus_ring: Default::default(), focus_ring: Default::default(),
border: niri_config::FocusRing::default_border(), border: Default::default(),
center_focused_column: Default::default(), center_focused_column: Default::default(),
preset_widths: vec![ preset_widths: vec![
ColumnWidth::Proportion(1. / 3.), 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! { prop_compose! {
fn arbitrary_options()( fn arbitrary_options()(
gaps in arbitrary_spacing(), gaps in arbitrary_spacing(),
struts in arbitrary_struts(), struts in arbitrary_struts(),
focus_ring in arbitrary_focus_ring(), focus_ring in arbitrary_focus_ring(),
border in arbitrary_focus_ring(), border in arbitrary_border(),
center_focused_column in arbitrary_center_focused_column(), center_focused_column in arbitrary_center_focused_column(),
) -> Options { ) -> Options {
Options { Options {
+2 -2
View File
@@ -62,7 +62,7 @@ impl<W: LayoutElement> Tile<W> {
pub fn new(window: W, options: Rc<Options>) -> Self { pub fn new(window: W, options: Rc<Options>) -> Self {
Self { Self {
window, window,
border: FocusRing::new(options.border), border: FocusRing::new(options.border.into()),
focus_ring: FocusRing::new(options.focus_ring), focus_ring: FocusRing::new(options.focus_ring),
is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size. is_fullscreen: false, // FIXME: up-to-date fullscreen right away, but we need size.
fullscreen_backdrop: SolidColorBuffer::new((0, 0), [0., 0., 0., 1.]), 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>) { 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.focus_ring.update_config(options.focus_ring);
self.options = options; self.options = options;
} }