aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-01-06 13:04:21 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2024-01-06 13:04:21 +0400
commit4e0aa391137a53180783ab3d2d0ff0cc6311b23b (patch)
treec247452d66a09602fc2338980e8bc4582d5b7a07 /src
parentdcb80efc8803e9a7a90f26044867bf4fd7671310 (diff)
downloadniri-4e0aa391137a53180783ab3d2d0ff0cc6311b23b.tar.gz
niri-4e0aa391137a53180783ab3d2d0ff0cc6311b23b.tar.bz2
niri-4e0aa391137a53180783ab3d2d0ff0cc6311b23b.zip
[cfg-breaking] Move layout settings into their own scope
Diffstat (limited to 'src')
-rw-r--r--src/config.rs178
-rw-r--r--src/layout/mod.rs13
2 files changed, 102 insertions, 89 deletions
diff --git a/src/config.rs b/src/config.rs
index b6397a34..b1815459 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -17,21 +17,11 @@ pub struct Config {
#[knuffel(children(name = "spawn-at-startup"))]
pub spawn_at_startup: Vec<SpawnAtStartup>,
#[knuffel(child, default)]
- pub focus_ring: FocusRing,
- #[knuffel(child, default = default_border())]
- pub border: FocusRing,
+ pub layout: Layout,
#[knuffel(child, default)]
pub prefer_no_csd: bool,
#[knuffel(child, default)]
pub cursor: Cursor,
- #[knuffel(child, unwrap(children), default)]
- pub preset_column_widths: Vec<PresetWidth>,
- #[knuffel(child)]
- pub default_column_width: Option<DefaultColumnWidth>,
- #[knuffel(child, unwrap(argument), default = 16)]
- pub gaps: u16,
- #[knuffel(child, default)]
- pub struts: Struts,
#[knuffel(
child,
unwrap(argument),
@@ -165,6 +155,22 @@ pub struct Mode {
pub refresh: Option<f64>,
}
+#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)]
+pub struct Layout {
+ #[knuffel(child, default)]
+ pub focus_ring: FocusRing,
+ #[knuffel(child, default = default_border())]
+ pub border: FocusRing,
+ #[knuffel(child, unwrap(children), default)]
+ pub preset_column_widths: Vec<PresetWidth>,
+ #[knuffel(child)]
+ pub default_column_width: Option<DefaultColumnWidth>,
+ #[knuffel(child, unwrap(argument), default = 16)]
+ pub gaps: u16,
+ #[knuffel(child, default)]
+ pub struts: Struts,
+}
+
#[derive(knuffel::Decode, Debug, Clone, PartialEq, Eq)]
pub struct SpawnAtStartup {
#[knuffel(arguments)]
@@ -607,42 +613,44 @@ mod tests {
mode "1920x1080@144"
}
- spawn-at-startup "alacritty" "-e" "fish"
+ layout {
+ focus-ring {
+ width 5
+ active-color 0 100 200 255
+ inactive-color 255 200 100 0
+ }
- focus-ring {
- width 5
- active-color 0 100 200 255
- inactive-color 255 200 100 0
- }
+ border {
+ width 3
+ active-color 0 100 200 255
+ inactive-color 255 200 100 0
+ }
- border {
- width 3
- active-color 0 100 200 255
- inactive-color 255 200 100 0
- }
+ preset-column-widths {
+ proportion 0.25
+ proportion 0.5
+ fixed 960
+ fixed 1280
+ }
- prefer-no-csd
+ default-column-width { proportion 0.25; }
- cursor {
- xcursor-theme "breeze_cursors"
- xcursor-size 16
- }
+ gaps 8
- preset-column-widths {
- proportion 0.25
- proportion 0.5
- fixed 960
- fixed 1280
+ struts {
+ left 1
+ right 2
+ top 3
+ }
}
- default-column-width { proportion 0.25; }
+ spawn-at-startup "alacritty" "-e" "fish"
- gaps 8
+ prefer-no-csd
- struts {
- left 1
- right 2
- top 3
+ cursor {
+ xcursor-theme "breeze_cursors"
+ xcursor-size 16
}
screenshot-path "~/Screenshots/screenshot.png"
@@ -694,60 +702,64 @@ mod tests {
refresh: Some(144.),
}),
}],
- spawn_at_startup: vec![SpawnAtStartup {
- command: vec!["alacritty".to_owned(), "-e".to_owned(), "fish".to_owned()],
- }],
- focus_ring: FocusRing {
- off: false,
- width: 5,
- active_color: Color {
- r: 0,
- g: 100,
- b: 200,
- a: 255,
- },
- inactive_color: Color {
- r: 255,
- g: 200,
- b: 100,
- a: 0,
+ layout: Layout {
+ focus_ring: FocusRing {
+ off: false,
+ width: 5,
+ active_color: Color {
+ r: 0,
+ g: 100,
+ b: 200,
+ a: 255,
+ },
+ inactive_color: Color {
+ r: 255,
+ g: 200,
+ b: 100,
+ a: 0,
+ },
},
- },
- border: FocusRing {
- off: false,
- width: 3,
- active_color: Color {
- r: 0,
- g: 100,
- b: 200,
- a: 255,
+ border: FocusRing {
+ off: false,
+ width: 3,
+ active_color: Color {
+ r: 0,
+ g: 100,
+ b: 200,
+ a: 255,
+ },
+ inactive_color: Color {
+ r: 255,
+ g: 200,
+ b: 100,
+ a: 0,
+ },
},
- inactive_color: Color {
- r: 255,
- g: 200,
- b: 100,
- a: 0,
+ preset_column_widths: vec![
+ PresetWidth::Proportion(0.25),
+ PresetWidth::Proportion(0.5),
+ PresetWidth::Fixed(960),
+ PresetWidth::Fixed(1280),
+ ],
+ default_column_width: Some(DefaultColumnWidth(vec![PresetWidth::Proportion(
+ 0.25,
+ )])),
+ gaps: 8,
+ struts: Struts {
+ left: 1,
+ right: 2,
+ top: 3,
+ bottom: 0,
},
},
+ spawn_at_startup: vec![SpawnAtStartup {
+ command: vec!["alacritty".to_owned(), "-e".to_owned(), "fish".to_owned()],
+ }],
prefer_no_csd: true,
cursor: Cursor {
xcursor_theme: String::from("breeze_cursors"),
xcursor_size: 16,
},
- preset_column_widths: vec![
- PresetWidth::Proportion(0.25),
- PresetWidth::Proportion(0.5),
- PresetWidth::Fixed(960),
- PresetWidth::Fixed(1280),
- ],
- default_column_width: Some(DefaultColumnWidth(vec![PresetWidth::Proportion(0.25)])),
- gaps: 8,
- struts: Struts {
- left: 1,
- right: 2,
- top: 3,
- bottom: 0,
- },
screenshot_path: Some(String::from("~/Screenshots/screenshot.png")),
binds: Binds(vec![
Bind {
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 9c3fb66b..c7fce722 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -164,7 +164,8 @@ impl Default for Options {
impl Options {
fn from_config(config: &Config) -> Self {
- let preset_column_widths = &config.preset_column_widths;
+ let layout = &config.layout;
+ let preset_column_widths = &layout.preset_column_widths;
let preset_widths = if preset_column_widths.is_empty() {
Options::default().preset_widths
@@ -178,17 +179,17 @@ impl Options {
// Missing default_column_width maps to Some(ColumnWidth::Proportion(0.5)),
// while present, but empty, maps to None.
- let default_width = config
+ let default_width = layout
.default_column_width
.as_ref()
.map(|w| w.0.first().copied().map(ColumnWidth::from))
.unwrap_or(Some(ColumnWidth::Proportion(0.5)));
Self {
- gaps: config.gaps.into(),
- struts: config.struts,
- focus_ring: config.focus_ring,
- border: config.border,
+ gaps: layout.gaps.into(),
+ struts: layout.struts,
+ focus_ring: layout.focus_ring,
+ border: layout.border,
preset_widths,
default_width,
}