forge
Explore
Log in

Don't you dare go Hollow

[cfg-breaking] Move layout settings into their own scope

Browse files at this commit

4e0aa391137a53180783ab3d2d0ff0cc6311b23bIvan MolodetskikhParent: dcb80ef
resources/default-config.kdlmodified+58 -56
@@ -75,37 +75,72 @@ input {
7575 position x=1280 y=0
7676 }
7777
78-// Add lines like this to spawn processes at startup.
79-// Note that running niri as a session supports xdg-desktop-autostart,
80-// which may be more convenient to use.
81-// spawn-at-startup "alacritty" "-e" "fish"
78+layout {
79+ // You can change how the focus ring looks.
80+ focus-ring {
81+ // Uncomment this line to disable the focus ring.
82+ // off
8283
83-// You can change how the focus ring looks.
84-focus-ring {
85- // Uncomment this line to disable the focus ring.
86- // off
84+ // How many logical pixels the ring extends out from the windows.
85+ width 4
8786
88- // How many logical pixels the ring extends out from the windows.
89- width 4
87+ // Color of the ring on the active monitor: red, green, blue, alpha.
88+ active-color 127 200 255 255
9089
91- // Color of the ring on the active monitor: red, green, blue, alpha.
92- active-color 127 200 255 255
90+ // Color of the ring on inactive monitors: red, green, blue, alpha.
91+ inactive-color 80 80 80 255
92+ }
9393
94- // Color of the ring on inactive monitors: red, green, blue, alpha.
95- inactive-color 80 80 80 255
96-}
94+ // You can also add a border. It's similar to the focus ring, but always visible.
95+ border {
96+ // The settings are the same as for the focus ring.
97+ // If you enable the border, you probably want to disable the focus ring.
98+ off
9799
98-// You can also add a border. It's similar to the focus ring, but always visible.
99-border {
100- // The settings are the same as for the focus ring.
101- // If you enable the border, you probably want to disable the focus ring.
102- off
100+ width 4
101+ active-color 255 200 127 255
102+ inactive-color 80 80 80 255
103+ }
104+
105+ // You can customize the widths that "switch-preset-column-width" (Mod+R) toggles between.
106+ preset-column-widths {
107+ // Proportion sets the width as a fraction of the output width, taking gaps into account.
108+ // For example, you can perfectly fit four windows sized "proportion 0.25" on an output.
109+ // The default preset widths are 1/3, 1/2 and 2/3 of the output.
110+ proportion 0.333
111+ proportion 0.5
112+ proportion 0.667
113+
114+ // Fixed sets the width in logical pixels exactly.
115+ // fixed 1920
116+ }
103117
104- width 4
105- active-color 255 200 127 255
106- inactive-color 80 80 80 255
118+ // You can change the default width of the new windows.
119+ default-column-width { proportion 0.5; }
120+ // If you leave the brackets empty, the windows themselves will decide their initial width.
121+ // default-column-width {}
122+
123+ // Set gaps around windows in logical pixels.
124+ gaps 16
125+
126+ // Struts shrink the area occupied by windows, similarly to layer-shell panels.
127+ // You can think of them as a kind of outer gaps. They are set in logical pixels.
128+ // Left and right struts will cause the next window to the side to always be visible.
129+ // Top and bottom struts will simply add outer gaps in addition to the area occupied by
130+ // layer-shell panels and regular gaps.
131+ struts {
132+ // left 64
133+ // right 64
134+ // top 64
135+ // bottom 64
136+ }
107137 }
108138
139+// Add lines like this to spawn processes at startup.
140+// Note that running niri as a session supports xdg-desktop-autostart,
141+// which may be more convenient to use.
142+// spawn-at-startup "alacritty" "-e" "fish"
143+
109144 cursor {
110145 // Change the theme and size of the cursor as well as set the
111146 // `XCURSOR_THEME` and `XCURSOR_SIZE` env variables.
@@ -118,39 +153,6 @@ cursor {
118153 // Additionally, clients will be informed that they are tiled, removing some rounded corners.
119154 // prefer-no-csd
120155
121-// You can customize the widths that "switch-preset-column-width" (Mod+R) toggles between.
122-preset-column-widths {
123- // Proportion sets the width as a fraction of the output width, taking gaps into account.
124- // For example, you can perfectly fit four windows sized "proportion 0.25" on an output.
125- // The default preset widths are 1/3, 1/2 and 2/3 of the output.
126- proportion 0.333
127- proportion 0.5
128- proportion 0.667
129-
130- // Fixed sets the width in logical pixels exactly.
131- // fixed 1920
132-}
133-
134-// You can change the default width of the new windows.
135-default-column-width { proportion 0.5; }
136-// If you leave the brackets empty, the windows themselves will decide their initial width.
137-// default-column-width {}
138-
139-// Set gaps around windows in logical pixels.
140-gaps 16
141-
142-// Struts shrink the area occupied by windows, similarly to layer-shell panels.
143-// You can think of them as a kind of outer gaps. They are set in logical pixels.
144-// Left and right struts will cause the next window to the side to always be visible.
145-// Top and bottom struts will simply add outer gaps in addition to the area occupied by
146-// layer-shell panels and regular gaps.
147-struts {
148- // left 64
149- // right 64
150- // top 64
151- // bottom 64
152-}
153-
154156 // You can change the path where screenshots are saved.
155157 // A ~ at the front will be expanded to the home directory.
156158 // The path is formatted with strftime(3) to give you the screenshot date and time.
src/config.rsmodified+95 -83
@@ -17,21 +17,11 @@ pub struct Config {
1717 #[knuffel(children(name = "spawn-at-startup"))]
1818 pub spawn_at_startup: Vec<SpawnAtStartup>,
1919 #[knuffel(child, default)]
20- pub focus_ring: FocusRing,
21- #[knuffel(child, default = default_border())]
22- pub border: FocusRing,
20+ pub layout: Layout,
2321 #[knuffel(child, default)]
2422 pub prefer_no_csd: bool,
2523 #[knuffel(child, default)]
2624 pub cursor: Cursor,
27- #[knuffel(child, unwrap(children), default)]
28- pub preset_column_widths: Vec<PresetWidth>,
29- #[knuffel(child)]
30- pub default_column_width: Option<DefaultColumnWidth>,
31- #[knuffel(child, unwrap(argument), default = 16)]
32- pub gaps: u16,
33- #[knuffel(child, default)]
34- pub struts: Struts,
3525 #[knuffel(
3626 child,
3727 unwrap(argument),
@@ -165,6 +155,22 @@ pub struct Mode {
165155 pub refresh: Option<f64>,
166156 }
167157
158+#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)]
159+pub struct Layout {
160+ #[knuffel(child, default)]
161+ pub focus_ring: FocusRing,
162+ #[knuffel(child, default = default_border())]
163+ pub border: FocusRing,
164+ #[knuffel(child, unwrap(children), default)]
165+ pub preset_column_widths: Vec<PresetWidth>,
166+ #[knuffel(child)]
167+ pub default_column_width: Option<DefaultColumnWidth>,
168+ #[knuffel(child, unwrap(argument), default = 16)]
169+ pub gaps: u16,
170+ #[knuffel(child, default)]
171+ pub struts: Struts,
172+}
173+
168174 #[derive(knuffel::Decode, Debug, Clone, PartialEq, Eq)]
169175 pub struct SpawnAtStartup {
170176 #[knuffel(arguments)]
@@ -607,42 +613,44 @@ mod tests {
607613 mode "1920x1080@144"
608614 }
609615
610- spawn-at-startup "alacritty" "-e" "fish"
616+ layout {
617+ focus-ring {
618+ width 5
619+ active-color 0 100 200 255
620+ inactive-color 255 200 100 0
621+ }
611622
612- focus-ring {
613- width 5
614- active-color 0 100 200 255
615- inactive-color 255 200 100 0
616- }
623+ border {
624+ width 3
625+ active-color 0 100 200 255
626+ inactive-color 255 200 100 0
627+ }
617628
618- border {
619- width 3
620- active-color 0 100 200 255
621- inactive-color 255 200 100 0
622- }
629+ preset-column-widths {
630+ proportion 0.25
631+ proportion 0.5
632+ fixed 960
633+ fixed 1280
634+ }
623635
624- prefer-no-csd
636+ default-column-width { proportion 0.25; }
625637
626- cursor {
627- xcursor-theme "breeze_cursors"
628- xcursor-size 16
629- }
638+ gaps 8
630639
631- preset-column-widths {
632- proportion 0.25
633- proportion 0.5
634- fixed 960
635- fixed 1280
640+ struts {
641+ left 1
642+ right 2
643+ top 3
644+ }
636645 }
637646
638- default-column-width { proportion 0.25; }
647+ spawn-at-startup "alacritty" "-e" "fish"
639648
640- gaps 8
649+ prefer-no-csd
641650
642- struts {
643- left 1
644- right 2
645- top 3
651+ cursor {
652+ xcursor-theme "breeze_cursors"
653+ xcursor-size 16
646654 }
647655
648656 screenshot-path "~/Screenshots/screenshot.png"
@@ -694,60 +702,64 @@ mod tests {
694702 refresh: Some(144.),
695703 }),
696704 }],
697- spawn_at_startup: vec![SpawnAtStartup {
698- command: vec!["alacritty".to_owned(), "-e".to_owned(), "fish".to_owned()],
699- }],
700- focus_ring: FocusRing {
701- off: false,
702- width: 5,
703- active_color: Color {
704- r: 0,
705- g: 100,
706- b: 200,
707- a: 255,
708- },
709- inactive_color: Color {
710- r: 255,
711- g: 200,
712- b: 100,
713- a: 0,
705+ layout: Layout {
706+ focus_ring: FocusRing {
707+ off: false,
708+ width: 5,
709+ active_color: Color {
710+ r: 0,
711+ g: 100,
712+ b: 200,
713+ a: 255,
714+ },
715+ inactive_color: Color {
716+ r: 255,
717+ g: 200,
718+ b: 100,
719+ a: 0,
720+ },
714721 },
715- },
716- border: FocusRing {
717- off: false,
718- width: 3,
719- active_color: Color {
720- r: 0,
721- g: 100,
722- b: 200,
723- a: 255,
722+ border: FocusRing {
723+ off: false,
724+ width: 3,
725+ active_color: Color {
726+ r: 0,
727+ g: 100,
728+ b: 200,
729+ a: 255,
730+ },
731+ inactive_color: Color {
732+ r: 255,
733+ g: 200,
734+ b: 100,
735+ a: 0,
736+ },
724737 },
725- inactive_color: Color {
726- r: 255,
727- g: 200,
728- b: 100,
729- a: 0,
738+ preset_column_widths: vec![
739+ PresetWidth::Proportion(0.25),
740+ PresetWidth::Proportion(0.5),
741+ PresetWidth::Fixed(960),
742+ PresetWidth::Fixed(1280),
743+ ],
744+ default_column_width: Some(DefaultColumnWidth(vec![PresetWidth::Proportion(
745+ 0.25,
746+ )])),
747+ gaps: 8,
748+ struts: Struts {
749+ left: 1,
750+ right: 2,
751+ top: 3,
752+ bottom: 0,
730753 },
731754 },
755+ spawn_at_startup: vec![SpawnAtStartup {
756+ command: vec!["alacritty".to_owned(), "-e".to_owned(), "fish".to_owned()],
757+ }],
732758 prefer_no_csd: true,
733759 cursor: Cursor {
734760 xcursor_theme: String::from("breeze_cursors"),
735761 xcursor_size: 16,
736762 },
737- preset_column_widths: vec![
738- PresetWidth::Proportion(0.25),
739- PresetWidth::Proportion(0.5),
740- PresetWidth::Fixed(960),
741- PresetWidth::Fixed(1280),
742- ],
743- default_column_width: Some(DefaultColumnWidth(vec![PresetWidth::Proportion(0.25)])),
744- gaps: 8,
745- struts: Struts {
746- left: 1,
747- right: 2,
748- top: 3,
749- bottom: 0,
750- },
751763 screenshot_path: Some(String::from("~/Screenshots/screenshot.png")),
752764 binds: Binds(vec![
753765 Bind {
src/layout/mod.rsmodified+7 -6
@@ -164,7 +164,8 @@ impl Default for Options {
164164
165165 impl Options {
166166 fn from_config(config: &Config) -> Self {
167- let preset_column_widths = &config.preset_column_widths;
167+ let layout = &config.layout;
168+ let preset_column_widths = &layout.preset_column_widths;
168169
169170 let preset_widths = if preset_column_widths.is_empty() {
170171 Options::default().preset_widths
@@ -178,17 +179,17 @@ impl Options {
178179
179180 // Missing default_column_width maps to Some(ColumnWidth::Proportion(0.5)),
180181 // while present, but empty, maps to None.
181- let default_width = config
182+ let default_width = layout
182183 .default_column_width
183184 .as_ref()
184185 .map(|w| w.0.first().copied().map(ColumnWidth::from))
185186 .unwrap_or(Some(ColumnWidth::Proportion(0.5)));
186187
187188 Self {
188- gaps: config.gaps.into(),
189- struts: config.struts,
190- focus_ring: config.focus_ring,
191- border: config.border,
189+ gaps: layout.gaps.into(),
190+ struts: layout.struts,
191+ focus_ring: layout.focus_ring,
192+ border: layout.border,
192193 preset_widths,
193194 default_width,
194195 }