forge
Explore
Log in

Don't you dare go Hollow

config: Add merging for misc sections

Browse files at this commit

2de34e8798d18321cc36bde97960ef1a9958bca0Ivan MolodetskikhParent: ceaf940
niri-config/src/appearance.rsmodified+35 -12
@@ -383,17 +383,12 @@ pub struct ShadowOffset {
383383 pub y: FloatOrInt<-65535, 65535>,
384384 }
385385
386-#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
386+#[derive(Debug, Clone, Copy, PartialEq)]
387387 pub struct WorkspaceShadow {
388- #[knuffel(child)]
389388 pub off: bool,
390- #[knuffel(child, default = Self::default().offset)]
391389 pub offset: ShadowOffset,
392- #[knuffel(child, unwrap(argument), default = Self::default().softness)]
393- pub softness: FloatOrInt<0, 1024>,
394- #[knuffel(child, unwrap(argument), default = Self::default().spread)]
395- pub spread: FloatOrInt<-1024, 1024>,
396- #[knuffel(child, default = Self::default().color)]
390+ pub softness: f64,
391+ pub spread: f64,
397392 pub color: Color,
398393 }
399394
@@ -405,8 +400,8 @@ impl Default for WorkspaceShadow {
405400 x: FloatOrInt(0.),
406401 y: FloatOrInt(10.),
407402 },
408- softness: FloatOrInt(40.),
409- spread: FloatOrInt(10.),
403+ softness: 40.,
404+ spread: 10.,
410405 color: Color::from_rgba8_unpremul(0, 0, 0, 0x50),
411406 }
412407 }
@@ -417,8 +412,8 @@ impl From<WorkspaceShadow> for Shadow {
417412 Self {
418413 on: !value.off,
419414 offset: value.offset,
420- softness: value.softness.0,
421- spread: value.spread.0,
415+ softness: value.softness,
416+ spread: value.spread,
422417 draw_behind_window: false,
423418 color: value.color,
424419 inactive_color: None,
@@ -426,6 +421,34 @@ impl From<WorkspaceShadow> for Shadow {
426421 }
427422 }
428423
424+#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
425+pub struct WorkspaceShadowPart {
426+ #[knuffel(child)]
427+ pub off: bool,
428+ #[knuffel(child)]
429+ pub on: bool,
430+ #[knuffel(child)]
431+ pub offset: Option<ShadowOffset>,
432+ #[knuffel(child, unwrap(argument))]
433+ pub softness: Option<FloatOrInt<0, 1024>>,
434+ #[knuffel(child, unwrap(argument))]
435+ pub spread: Option<FloatOrInt<-1024, 1024>>,
436+ #[knuffel(child)]
437+ pub color: Option<Color>,
438+}
439+
440+impl MergeWith<WorkspaceShadowPart> for WorkspaceShadow {
441+ fn merge_with(&mut self, part: &WorkspaceShadowPart) {
442+ self.off |= part.off;
443+ if part.on {
444+ self.off = false;
445+ }
446+
447+ merge_clone!((self, part), offset, color);
448+ merge!((self, part), softness, spread);
449+ }
450+}
451+
429452 #[derive(Debug, Clone, Copy, PartialEq)]
430453 pub struct TabIndicator {
431454 pub off: bool,
niri-config/src/lib.rsmodified+9 -15
@@ -187,14 +187,14 @@ where
187187 match name {
188188 // TODO: most (all?) of these need to be merged instead
189189 "input" => m_replace!(input),
190- "cursor" => m_replace!(cursor),
191- "clipboard" => m_replace!(clipboard),
192- "hotkey-overlay" => m_replace!(hotkey_overlay),
193- "config-notification" => m_replace!(config_notification),
190+ "cursor" => m_merge!(cursor),
191+ "clipboard" => m_merge!(clipboard),
192+ "hotkey-overlay" => m_merge!(hotkey_overlay),
193+ "config-notification" => m_merge!(config_notification),
194194 "animations" => m_replace!(animations),
195195 "gestures" => m_replace!(gestures),
196- "overview" => m_replace!(overview),
197- "xwayland-satellite" => m_replace!(xwayland_satellite),
196+ "overview" => m_merge!(overview),
197+ "xwayland-satellite" => m_merge!(xwayland_satellite),
198198 "switch-events" => m_merge!(switch_events),
199199 "debug" => m_merge!(debug),
200200
@@ -1459,9 +1459,7 @@ mod tests {
14591459 },
14601460 },
14611461 overview: Overview {
1462- zoom: FloatOrInt(
1463- 0.5,
1464- ),
1462+ zoom: 0.5,
14651463 backdrop_color: Color {
14661464 r: 0.15,
14671465 g: 0.15,
@@ -1478,12 +1476,8 @@ mod tests {
14781476 10.0,
14791477 ),
14801478 },
1481- softness: FloatOrInt(
1482- 40.0,
1483- ),
1484- spread: FloatOrInt(
1485- 10.0,
1486- ),
1479+ softness: 40.0,
1480+ spread: 10.0,
14871481 color: Color {
14881482 r: 0.0,
14891483 g: 0.0,
niri-config/src/misc.rsmodified+104 -20
@@ -1,4 +1,5 @@
1-use crate::appearance::{Color, WorkspaceShadow, DEFAULT_BACKDROP_COLOR};
1+use crate::appearance::{Color, WorkspaceShadow, WorkspaceShadowPart, DEFAULT_BACKDROP_COLOR};
2+use crate::utils::{Flag, MergeWith};
23 use crate::FloatOrInt;
34
45 #[derive(knuffel::Decode, Debug, Clone, PartialEq, Eq)]
@@ -13,15 +14,11 @@ pub struct SpawnShAtStartup {
1314 pub command: String,
1415 }
1516
16-#[derive(knuffel::Decode, Debug, PartialEq)]
17+#[derive(Debug, PartialEq)]
1718 pub struct Cursor {
18- #[knuffel(child, unwrap(argument), default = String::from("default"))]
1919 pub xcursor_theme: String,
20- #[knuffel(child, unwrap(argument), default = 24)]
2120 pub xcursor_size: u8,
22- #[knuffel(child)]
2321 pub hide_when_typing: bool,
24- #[knuffel(child, unwrap(argument))]
2522 pub hide_after_inactive_ms: Option<u32>,
2623 }
2724
@@ -36,6 +33,26 @@ impl Default for Cursor {
3633 }
3734 }
3835
36+#[derive(knuffel::Decode, Debug, PartialEq)]
37+pub struct CursorPart {
38+ #[knuffel(child, unwrap(argument))]
39+ pub xcursor_theme: Option<String>,
40+ #[knuffel(child, unwrap(argument))]
41+ pub xcursor_size: Option<u8>,
42+ #[knuffel(child)]
43+ pub hide_when_typing: Option<Flag>,
44+ #[knuffel(child, unwrap(argument))]
45+ pub hide_after_inactive_ms: Option<u32>,
46+}
47+
48+impl MergeWith<CursorPart> for Cursor {
49+ fn merge_with(&mut self, part: &CursorPart) {
50+ merge_clone!((self, part), xcursor_theme, xcursor_size);
51+ merge!((self, part), hide_when_typing);
52+ merge_clone_opt!((self, part), hide_after_inactive_ms);
53+ }
54+}
55+
3956 #[derive(knuffel::Decode, Debug, Clone, PartialEq)]
4057 pub struct ScreenshotPath(#[knuffel(argument)] pub Option<String>);
4158
@@ -47,46 +64,94 @@ impl Default for ScreenshotPath {
4764 }
4865 }
4966
50-#[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)]
67+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
5168 pub struct HotkeyOverlay {
52- #[knuffel(child)]
5369 pub skip_at_startup: bool,
54- #[knuffel(child)]
5570 pub hide_not_bound: bool,
5671 }
5772
5873 #[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)]
59-pub struct ConfigNotification {
74+pub struct HotkeyOverlayPart {
6075 #[knuffel(child)]
76+ pub skip_at_startup: Option<Flag>,
77+ #[knuffel(child)]
78+ pub hide_not_bound: Option<Flag>,
79+}
80+
81+impl MergeWith<HotkeyOverlayPart> for HotkeyOverlay {
82+ fn merge_with(&mut self, part: &HotkeyOverlayPart) {
83+ merge!((self, part), skip_at_startup, hide_not_bound);
84+ }
85+}
86+
87+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
88+pub struct ConfigNotification {
6189 pub disable_failed: bool,
6290 }
6391
6492 #[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)]
65-pub struct Clipboard {
93+pub struct ConfigNotificationPart {
6694 #[knuffel(child)]
95+ pub disable_failed: Option<Flag>,
96+}
97+
98+impl MergeWith<ConfigNotificationPart> for ConfigNotification {
99+ fn merge_with(&mut self, part: &ConfigNotificationPart) {
100+ merge!((self, part), disable_failed);
101+ }
102+}
103+
104+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
105+pub struct Clipboard {
67106 pub disable_primary: bool,
68107 }
69108
70-#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
109+#[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)]
110+pub struct ClipboardPart {
111+ #[knuffel(child)]
112+ pub disable_primary: Option<Flag>,
113+}
114+
115+impl MergeWith<ClipboardPart> for Clipboard {
116+ fn merge_with(&mut self, part: &ClipboardPart) {
117+ merge!((self, part), disable_primary);
118+ }
119+}
120+
121+#[derive(Debug, Clone, Copy, PartialEq)]
71122 pub struct Overview {
72- #[knuffel(child, unwrap(argument), default = Self::default().zoom)]
73- pub zoom: FloatOrInt<0, 1>,
74- #[knuffel(child, default = Self::default().backdrop_color)]
123+ pub zoom: f64,
75124 pub backdrop_color: Color,
76- #[knuffel(child, default)]
77125 pub workspace_shadow: WorkspaceShadow,
78126 }
79127
80128 impl Default for Overview {
81129 fn default() -> Self {
82130 Self {
83- zoom: FloatOrInt(0.5),
131+ zoom: 0.5,
84132 backdrop_color: DEFAULT_BACKDROP_COLOR,
85133 workspace_shadow: WorkspaceShadow::default(),
86134 }
87135 }
88136 }
89137
138+#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
139+pub struct OverviewPart {
140+ #[knuffel(child, unwrap(argument))]
141+ pub zoom: Option<FloatOrInt<0, 1>>,
142+ #[knuffel(child)]
143+ pub backdrop_color: Option<Color>,
144+ #[knuffel(child)]
145+ pub workspace_shadow: Option<WorkspaceShadowPart>,
146+}
147+
148+impl MergeWith<OverviewPart> for Overview {
149+ fn merge_with(&mut self, part: &OverviewPart) {
150+ merge!((self, part), zoom, workspace_shadow);
151+ merge_clone!((self, part), backdrop_color);
152+ }
153+}
154+
90155 #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq, Eq)]
91156 pub struct Environment(#[knuffel(children)] pub Vec<EnvironmentVariable>);
92157
@@ -98,11 +163,9 @@ pub struct EnvironmentVariable {
98163 pub value: Option<String>,
99164 }
100165
101-#[derive(knuffel::Decode, Debug, Clone, PartialEq, Eq)]
166+#[derive(Debug, Clone, PartialEq, Eq)]
102167 pub struct XwaylandSatellite {
103- #[knuffel(child)]
104168 pub off: bool,
105- #[knuffel(child, unwrap(argument), default = Self::default().path)]
106169 pub path: String,
107170 }
108171
@@ -114,3 +177,24 @@ impl Default for XwaylandSatellite {
114177 }
115178 }
116179 }
180+
181+#[derive(knuffel::Decode, Debug, Clone, PartialEq, Eq)]
182+pub struct XwaylandSatellitePart {
183+ #[knuffel(child)]
184+ pub off: bool,
185+ #[knuffel(child)]
186+ pub on: bool,
187+ #[knuffel(child, unwrap(argument))]
188+ pub path: Option<String>,
189+}
190+
191+impl MergeWith<XwaylandSatellitePart> for XwaylandSatellite {
192+ fn merge_with(&mut self, part: &XwaylandSatellitePart) {
193+ self.off |= part.off;
194+ if part.on {
195+ self.off = false;
196+ }
197+
198+ merge_clone!((self, part), path);
199+ }
200+}
src/layout/mod.rsmodified+1 -1
@@ -4916,7 +4916,7 @@ impl<W: LayoutElement> Default for MonitorSet<W> {
49164916
49174917 fn compute_overview_zoom(options: &Options, overview_progress: Option<f64>) -> f64 {
49184918 // Clamp to some sane values.
4919- let zoom = options.overview.zoom.0.clamp(0.0001, 0.75);
4919+ let zoom = options.overview.zoom.clamp(0.0001, 0.75);
49204920
49214921 if let Some(p) = overview_progress {
49224922 (1. - p * (1. - zoom)).max(0.0001)