forge
Explore
Log in

Don't you dare go Hollow

Add serde defaults to optional IPC fields (#4698)

Browse files at this commit

964275e14d63dbce8805b04c62692a14affbdc22UnverifiedDijoParent: 36e9160
* [ ipc ] :  add serde defaults for optional action fields

* [ ipc ] : default omitted VRR on demand flag false

* [ ipc ] : remove serde tests
niri-ipc/src/lib.rsmodified+23 -0
@@ -195,6 +195,7 @@ pub enum Action {
195195 /// Exit niri.
196196 Quit {
197197 /// Skip the "Press Enter to confirm" prompt.
198+ #[serde(default)]
198199 #[cfg_attr(feature = "clap", arg(short, long))]
199200 skip_confirmation: bool,
200201 },
@@ -223,6 +224,7 @@ pub enum Action {
223224 /// Open the screenshot UI.
224225 Screenshot {
225226 /// Whether to show the mouse pointer by default in the screenshot UI.
227+ #[serde(default = "default_true")]
226228 #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))]
227229 show_pointer: bool,
228230
@@ -239,10 +241,12 @@ pub enum Action {
239241 /// Write the screenshot to disk in addition to putting it in your clipboard.
240242 ///
241243 /// The screenshot is saved according to the `screenshot-path` config setting.
244+ #[serde(default = "default_true")]
242245 #[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))]
243246 write_to_disk: bool,
244247
245248 /// Whether to include the mouse pointer in the screenshot.
249+ #[serde(default = "default_true")]
246250 #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))]
247251 show_pointer: bool,
248252
@@ -265,6 +269,7 @@ pub enum Action {
265269 /// Write the screenshot to disk in addition to putting it in your clipboard.
266270 ///
267271 /// The screenshot is saved according to the `screenshot-path` config setting.
272+ #[serde(default = "default_true")]
268273 #[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))]
269274 write_to_disk: bool,
270275
@@ -272,6 +277,7 @@ pub enum Action {
272277 ///
273278 /// The pointer will be included only if the window is currently receiving pointer input
274279 /// (usually this means the pointer is on top of the window).
280+ #[serde(default)]
275281 #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = false))]
276282 show_pointer: bool,
277283
@@ -488,6 +494,7 @@ pub enum Action {
488494 ///
489495 /// If `true` (the default), the focus will follow the window to the new workspace. If
490496 /// `false`, the focus will remain on the original workspace.
497+ #[serde(default = "default_true")]
491498 #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))]
492499 focus: bool,
493500 },
@@ -497,6 +504,7 @@ pub enum Action {
497504 ///
498505 /// If `true` (the default), the focus will follow the window to the new workspace. If
499506 /// `false`, the focus will remain on the original workspace.
507+ #[serde(default = "default_true")]
500508 #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))]
501509 focus: bool,
502510 },
@@ -521,6 +529,7 @@ pub enum Action {
521529 /// If `true` (the default) and the window to move is focused, the focus will follow the
522530 /// window to the new workspace. If `false`, the focus will remain on the original
523531 /// workspace.
532+ #[serde(default = "default_true")]
524533 #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))]
525534 focus: bool,
526535 },
@@ -530,6 +539,7 @@ pub enum Action {
530539 ///
531540 /// If `true` (the default), the focus will follow the column to the new workspace. If
532541 /// `false`, the focus will remain on the original workspace.
542+ #[serde(default = "default_true")]
533543 #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))]
534544 focus: bool,
535545 },
@@ -539,6 +549,7 @@ pub enum Action {
539549 ///
540550 /// If `true` (the default), the focus will follow the column to the new workspace. If
541551 /// `false`, the focus will remain on the original workspace.
552+ #[serde(default = "default_true")]
542553 #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))]
543554 focus: bool,
544555 },
@@ -552,6 +563,7 @@ pub enum Action {
552563 ///
553564 /// If `true` (the default), the focus will follow the column to the new workspace. If
554565 /// `false`, the focus will remain on the original workspace.
566+ #[serde(default = "default_true")]
555567 #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))]
556568 focus: bool,
557569 },
@@ -849,6 +861,7 @@ pub enum Action {
849861 id: Option<u64>,
850862
851863 /// How to change the X position.
864+ #[serde(default = "default_position_change")]
852865 #[cfg_attr(
853866 feature = "clap",
854867 arg(short, long, default_value = "+0", allow_hyphen_values = true)
@@ -856,6 +869,7 @@ pub enum Action {
856869 x: PositionChange,
857870
858871 /// How to change the Y position.
872+ #[serde(default = "default_position_change")]
859873 #[cfg_attr(
860874 feature = "clap",
861875 arg(short, long, default_value = "+0", allow_hyphen_values = true)
@@ -1202,6 +1216,7 @@ pub struct VrrToSet {
12021216 )]
12031217 pub vrr: bool,
12041218 /// Only enable when the output shows a window matching the variable-refresh-rate window rule.
1219+ #[serde(default)]
12051220 #[cfg_attr(feature = "clap", arg(long))]
12061221 pub on_demand: bool,
12071222 }
@@ -2116,6 +2131,14 @@ impl OutputAction {
21162131 }
21172132 }
21182133
2134+fn default_true() -> bool {
2135+ true
2136+}
2137+
2138+fn default_position_change() -> PositionChange {
2139+ PositionChange::AdjustFixed(0.)
2140+}
2141+
21192142 #[cfg(test)]
21202143 mod tests {
21212144 use super::*;