aboutsummaryrefslogtreecommitdiff
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
parentdcb80efc8803e9a7a90f26044867bf4fd7671310 (diff)
downloadniri-4e0aa391137a53180783ab3d2d0ff0cc6311b23b.tar.gz
niri-4e0aa391137a53180783ab3d2d0ff0cc6311b23b.tar.bz2
niri-4e0aa391137a53180783ab3d2d0ff0cc6311b23b.zip
[cfg-breaking] Move layout settings into their own scope
-rw-r--r--resources/default-config.kdl114
-rw-r--r--src/config.rs178
-rw-r--r--src/layout/mod.rs13
3 files changed, 160 insertions, 145 deletions
diff --git a/resources/default-config.kdl b/resources/default-config.kdl
index 4ea3b5d0..5babfb41 100644
--- a/resources/default-config.kdl
+++ b/resources/default-config.kdl
@@ -75,37 +75,72 @@ input {
position x=1280 y=0
}
-// Add lines like this to spawn processes at startup.
-// Note that running niri as a session supports xdg-desktop-autostart,
-// which may be more convenient to use.
-// spawn-at-startup "alacritty" "-e" "fish"
+layout {
+ // You can change how the focus ring looks.
+ focus-ring {
+ // Uncomment this line to disable the focus ring.
+ // off
-// You can change how the focus ring looks.
-focus-ring {
- // Uncomment this line to disable the focus ring.
- // off
+ // How many logical pixels the ring extends out from the windows.
+ width 4
- // How many logical pixels the ring extends out from the windows.
- width 4
+ // Color of the ring on the active monitor: red, green, blue, alpha.
+ active-color 127 200 255 255
- // Color of the ring on the active monitor: red, green, blue, alpha.
- active-color 127 200 255 255
+ // Color of the ring on inactive monitors: red, green, blue, alpha.
+ inactive-color 80 80 80 255
+ }
- // Color of the ring on inactive monitors: red, green, blue, alpha.
- inactive-color 80 80 80 255
-}
+ // You can also add a border. It's similar to the focus ring, but always visible.
+ border {
+ // The settings are the same as for the focus ring.
+ // If you enable the border, you probably want to disable the focus ring.
+ off
-// You can also add a border. It's similar to the focus ring, but always visible.
-border {
- // The settings are the same as for the focus ring.
- // If you enable the border, you probably want to disable the focus ring.
- off
+ width 4
+ active-color 255 200 127 255
+ inactive-color 80 80 80 255
+ }
+
+ // You can customize the widths that "switch-preset-column-width" (Mod+R) toggles between.
+ preset-column-widths {
+ // Proportion sets the width as a fraction of the output width, taking gaps into account.
+ // For example, you can perfectly fit four windows sized "proportion 0.25" on an output.
+ // The default preset widths are 1/3, 1/2 and 2/3 of the output.
+ proportion 0.333
+ proportion 0.5
+ proportion 0.667
+
+ // Fixed sets the width in logical pixels exactly.
+ // fixed 1920
+ }
- width 4
- active-color 255 200 127 255
- inactive-color 80 80 80 255
+ // You can change the default width of the new windows.
+ default-column-width { proportion 0.5; }
+ // If you leave the brackets empty, the windows themselves will decide their initial width.
+ // default-column-width {}
+
+ // Set gaps around windows in logical pixels.
+ gaps 16
+
+ // Struts shrink the area occupied by windows, similarly to layer-shell panels.
+ // You can think of them as a kind of outer gaps. They are set in logical pixels.
+ // Left and right struts will cause the next window to the side to always be visible.
+ // Top and bottom struts will simply add outer gaps in addition to the area occupied by
+ // layer-shell panels and regular gaps.
+ struts {
+ // left 64
+ // right 64
+ // top 64
+ // bottom 64
+ }
}
+// Add lines like this to spawn processes at startup.
+// Note that running niri as a session supports xdg-desktop-autostart,
+// which may be more convenient to use.
+// spawn-at-startup "alacritty" "-e" "fish"
+
cursor {
// Change the theme and size of the cursor as well as set the
// `XCURSOR_THEME` and `XCURSOR_SIZE` env variables.
@@ -118,39 +153,6 @@ cursor {
// Additionally, clients will be informed that they are tiled, removing some rounded corners.
// prefer-no-csd
-// You can customize the widths that "switch-preset-column-width" (Mod+R) toggles between.
-preset-column-widths {
- // Proportion sets the width as a fraction of the output width, taking gaps into account.
- // For example, you can perfectly fit four windows sized "proportion 0.25" on an output.
- // The default preset widths are 1/3, 1/2 and 2/3 of the output.
- proportion 0.333
- proportion 0.5
- proportion 0.667
-
- // Fixed sets the width in logical pixels exactly.
- // fixed 1920
-}
-
-// You can change the default width of the new windows.
-default-column-width { proportion 0.5; }
-// If you leave the brackets empty, the windows themselves will decide their initial width.
-// default-column-width {}
-
-// Set gaps around windows in logical pixels.
-gaps 16
-
-// Struts shrink the area occupied by windows, similarly to layer-shell panels.
-// You can think of them as a kind of outer gaps. They are set in logical pixels.
-// Left and right struts will cause the next window to the side to always be visible.
-// Top and bottom struts will simply add outer gaps in addition to the area occupied by
-// layer-shell panels and regular gaps.
-struts {
- // left 64
- // right 64
- // top 64
- // bottom 64
-}
-
// You can change the path where screenshots are saved.
// A ~ at the front will be expanded to the home directory.
// The path is formatted with strftime(3) to give you the screenshot date and time.
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,
}