config: Add merging for misc sections
Browse files at this commit2de34e8798d18321cc36bde97960ef1a9958bca0Parent: ceaf9404 changed files +149 -48
- niri-config/src/appearance.rs +35 -12
- niri-config/src/lib.rs +9 -15
- niri-config/src/misc.rs +104 -20
- src/layout/mod.rs +1 -1
niri-config/src/appearance.rsmodified+35 -12
| @@ -383,17 +383,12 @@ pub struct ShadowOffset { | ||
| 383 | 383 | pub y: FloatOrInt<-65535, 65535>, |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | -#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] | |
| 386 | +#[derive(Debug, Clone, Copy, PartialEq)] | |
| 387 | 387 | pub struct WorkspaceShadow { |
| 388 | - #[knuffel(child)] | |
| 389 | 388 | pub off: bool, |
| 390 | - #[knuffel(child, default = Self::default().offset)] | |
| 391 | 389 | 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, | |
| 397 | 392 | pub color: Color, |
| 398 | 393 | } |
| 399 | 394 | |
| @@ -405,8 +400,8 @@ impl Default for WorkspaceShadow { | ||
| 405 | 400 | x: FloatOrInt(0.), |
| 406 | 401 | y: FloatOrInt(10.), |
| 407 | 402 | }, |
| 408 | - softness: FloatOrInt(40.), | |
| 409 | - spread: FloatOrInt(10.), | |
| 403 | + softness: 40., | |
| 404 | + spread: 10., | |
| 410 | 405 | color: Color::from_rgba8_unpremul(0, 0, 0, 0x50), |
| 411 | 406 | } |
| 412 | 407 | } |
| @@ -417,8 +412,8 @@ impl From<WorkspaceShadow> for Shadow { | ||
| 417 | 412 | Self { |
| 418 | 413 | on: !value.off, |
| 419 | 414 | offset: value.offset, |
| 420 | - softness: value.softness.0, | |
| 421 | - spread: value.spread.0, | |
| 415 | + softness: value.softness, | |
| 416 | + spread: value.spread, | |
| 422 | 417 | draw_behind_window: false, |
| 423 | 418 | color: value.color, |
| 424 | 419 | inactive_color: None, |
| @@ -426,6 +421,34 @@ impl From<WorkspaceShadow> for Shadow { | ||
| 426 | 421 | } |
| 427 | 422 | } |
| 428 | 423 | |
| 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 | + | |
| 429 | 452 | #[derive(Debug, Clone, Copy, PartialEq)] |
| 430 | 453 | pub struct TabIndicator { |
| 431 | 454 | pub off: bool, |
niri-config/src/lib.rsmodified+9 -15
| @@ -187,14 +187,14 @@ where | ||
| 187 | 187 | match name { |
| 188 | 188 | // TODO: most (all?) of these need to be merged instead |
| 189 | 189 | "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), | |
| 194 | 194 | "animations" => m_replace!(animations), |
| 195 | 195 | "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), | |
| 198 | 198 | "switch-events" => m_merge!(switch_events), |
| 199 | 199 | "debug" => m_merge!(debug), |
| 200 | 200 | |
| @@ -1459,9 +1459,7 @@ mod tests { | ||
| 1459 | 1459 | }, |
| 1460 | 1460 | }, |
| 1461 | 1461 | overview: Overview { |
| 1462 | - zoom: FloatOrInt( | |
| 1463 | - 0.5, | |
| 1464 | - ), | |
| 1462 | + zoom: 0.5, | |
| 1465 | 1463 | backdrop_color: Color { |
| 1466 | 1464 | r: 0.15, |
| 1467 | 1465 | g: 0.15, |
| @@ -1478,12 +1476,8 @@ mod tests { | ||
| 1478 | 1476 | 10.0, |
| 1479 | 1477 | ), |
| 1480 | 1478 | }, |
| 1481 | - softness: FloatOrInt( | |
| 1482 | - 40.0, | |
| 1483 | - ), | |
| 1484 | - spread: FloatOrInt( | |
| 1485 | - 10.0, | |
| 1486 | - ), | |
| 1479 | + softness: 40.0, | |
| 1480 | + spread: 10.0, | |
| 1487 | 1481 | color: Color { |
| 1488 | 1482 | r: 0.0, |
| 1489 | 1483 | 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}; | |
| 2 | 3 | use crate::FloatOrInt; |
| 3 | 4 | |
| 4 | 5 | #[derive(knuffel::Decode, Debug, Clone, PartialEq, Eq)] |
| @@ -13,15 +14,11 @@ pub struct SpawnShAtStartup { | ||
| 13 | 14 | pub command: String, |
| 14 | 15 | } |
| 15 | 16 | |
| 16 | -#[derive(knuffel::Decode, Debug, PartialEq)] | |
| 17 | +#[derive(Debug, PartialEq)] | |
| 17 | 18 | pub struct Cursor { |
| 18 | - #[knuffel(child, unwrap(argument), default = String::from("default"))] | |
| 19 | 19 | pub xcursor_theme: String, |
| 20 | - #[knuffel(child, unwrap(argument), default = 24)] | |
| 21 | 20 | pub xcursor_size: u8, |
| 22 | - #[knuffel(child)] | |
| 23 | 21 | pub hide_when_typing: bool, |
| 24 | - #[knuffel(child, unwrap(argument))] | |
| 25 | 22 | pub hide_after_inactive_ms: Option<u32>, |
| 26 | 23 | } |
| 27 | 24 | |
| @@ -36,6 +33,26 @@ impl Default for Cursor { | ||
| 36 | 33 | } |
| 37 | 34 | } |
| 38 | 35 | |
| 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 | + | |
| 39 | 56 | #[derive(knuffel::Decode, Debug, Clone, PartialEq)] |
| 40 | 57 | pub struct ScreenshotPath(#[knuffel(argument)] pub Option<String>); |
| 41 | 58 | |
| @@ -47,46 +64,94 @@ impl Default for ScreenshotPath { | ||
| 47 | 64 | } |
| 48 | 65 | } |
| 49 | 66 | |
| 50 | -#[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)] | |
| 67 | +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] | |
| 51 | 68 | pub struct HotkeyOverlay { |
| 52 | - #[knuffel(child)] | |
| 53 | 69 | pub skip_at_startup: bool, |
| 54 | - #[knuffel(child)] | |
| 55 | 70 | pub hide_not_bound: bool, |
| 56 | 71 | } |
| 57 | 72 | |
| 58 | 73 | #[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)] |
| 59 | -pub struct ConfigNotification { | |
| 74 | +pub struct HotkeyOverlayPart { | |
| 60 | 75 | #[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 { | |
| 61 | 89 | pub disable_failed: bool, |
| 62 | 90 | } |
| 63 | 91 | |
| 64 | 92 | #[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)] |
| 65 | -pub struct Clipboard { | |
| 93 | +pub struct ConfigNotificationPart { | |
| 66 | 94 | #[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 { | |
| 67 | 106 | pub disable_primary: bool, |
| 68 | 107 | } |
| 69 | 108 | |
| 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)] | |
| 71 | 122 | 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, | |
| 75 | 124 | pub backdrop_color: Color, |
| 76 | - #[knuffel(child, default)] | |
| 77 | 125 | pub workspace_shadow: WorkspaceShadow, |
| 78 | 126 | } |
| 79 | 127 | |
| 80 | 128 | impl Default for Overview { |
| 81 | 129 | fn default() -> Self { |
| 82 | 130 | Self { |
| 83 | - zoom: FloatOrInt(0.5), | |
| 131 | + zoom: 0.5, | |
| 84 | 132 | backdrop_color: DEFAULT_BACKDROP_COLOR, |
| 85 | 133 | workspace_shadow: WorkspaceShadow::default(), |
| 86 | 134 | } |
| 87 | 135 | } |
| 88 | 136 | } |
| 89 | 137 | |
| 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 | + | |
| 90 | 155 | #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq, Eq)] |
| 91 | 156 | pub struct Environment(#[knuffel(children)] pub Vec<EnvironmentVariable>); |
| 92 | 157 | |
| @@ -98,11 +163,9 @@ pub struct EnvironmentVariable { | ||
| 98 | 163 | pub value: Option<String>, |
| 99 | 164 | } |
| 100 | 165 | |
| 101 | -#[derive(knuffel::Decode, Debug, Clone, PartialEq, Eq)] | |
| 166 | +#[derive(Debug, Clone, PartialEq, Eq)] | |
| 102 | 167 | pub struct XwaylandSatellite { |
| 103 | - #[knuffel(child)] | |
| 104 | 168 | pub off: bool, |
| 105 | - #[knuffel(child, unwrap(argument), default = Self::default().path)] | |
| 106 | 169 | pub path: String, |
| 107 | 170 | } |
| 108 | 171 | |
| @@ -114,3 +177,24 @@ impl Default for XwaylandSatellite { | ||
| 114 | 177 | } |
| 115 | 178 | } |
| 116 | 179 | } |
| 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> { | ||
| 4916 | 4916 | |
| 4917 | 4917 | fn compute_overview_zoom(options: &Options, overview_progress: Option<f64>) -> f64 { |
| 4918 | 4918 | // 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); | |
| 4920 | 4920 | |
| 4921 | 4921 | if let Some(p) = overview_progress { |
| 4922 | 4922 | (1. - p * (1. - zoom)).max(0.0001) |