Add serde defaults to optional IPC fields (#4698)
Browse files at this commit1 changed file +23 -0
- niri-ipc/src/lib.rs +23 -0
niri-ipc/src/lib.rsmodified+23 -0
| @@ -195,6 +195,7 @@ pub enum Action { | |||
| 195 | /// Exit niri. | 195 | /// Exit niri. |
| 196 | Quit { | 196 | Quit { |
| 197 | /// Skip the "Press Enter to confirm" prompt. | 197 | /// Skip the "Press Enter to confirm" prompt. |
| 198 | + #[serde(default)] | ||
| 198 | #[cfg_attr(feature = "clap", arg(short, long))] | 199 | #[cfg_attr(feature = "clap", arg(short, long))] |
| 199 | skip_confirmation: bool, | 200 | skip_confirmation: bool, |
| 200 | }, | 201 | }, |
| @@ -223,6 +224,7 @@ pub enum Action { | |||
| 223 | /// Open the screenshot UI. | 224 | /// Open the screenshot UI. |
| 224 | Screenshot { | 225 | Screenshot { |
| 225 | /// Whether to show the mouse pointer by default in the screenshot UI. | 226 | /// Whether to show the mouse pointer by default in the screenshot UI. |
| 227 | + #[serde(default = "default_true")] | ||
| 226 | #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))] | 228 | #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))] |
| 227 | show_pointer: bool, | 229 | show_pointer: bool, |
| 228 | 230 | ||
| @@ -239,10 +241,12 @@ pub enum Action { | |||
| 239 | /// Write the screenshot to disk in addition to putting it in your clipboard. | 241 | /// Write the screenshot to disk in addition to putting it in your clipboard. |
| 240 | /// | 242 | /// |
| 241 | /// The screenshot is saved according to the `screenshot-path` config setting. | 243 | /// The screenshot is saved according to the `screenshot-path` config setting. |
| 244 | + #[serde(default = "default_true")] | ||
| 242 | #[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))] | 245 | #[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))] |
| 243 | write_to_disk: bool, | 246 | write_to_disk: bool, |
| 244 | 247 | ||
| 245 | /// Whether to include the mouse pointer in the screenshot. | 248 | /// Whether to include the mouse pointer in the screenshot. |
| 249 | + #[serde(default = "default_true")] | ||
| 246 | #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))] | 250 | #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))] |
| 247 | show_pointer: bool, | 251 | show_pointer: bool, |
| 248 | 252 | ||
| @@ -265,6 +269,7 @@ pub enum Action { | |||
| 265 | /// Write the screenshot to disk in addition to putting it in your clipboard. | 269 | /// Write the screenshot to disk in addition to putting it in your clipboard. |
| 266 | /// | 270 | /// |
| 267 | /// The screenshot is saved according to the `screenshot-path` config setting. | 271 | /// The screenshot is saved according to the `screenshot-path` config setting. |
| 272 | + #[serde(default = "default_true")] | ||
| 268 | #[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))] | 273 | #[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))] |
| 269 | write_to_disk: bool, | 274 | write_to_disk: bool, |
| 270 | 275 | ||
| @@ -272,6 +277,7 @@ pub enum Action { | |||
| 272 | /// | 277 | /// |
| 273 | /// The pointer will be included only if the window is currently receiving pointer input | 278 | /// The pointer will be included only if the window is currently receiving pointer input |
| 274 | /// (usually this means the pointer is on top of the window). | 279 | /// (usually this means the pointer is on top of the window). |
| 280 | + #[serde(default)] | ||
| 275 | #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = false))] | 281 | #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = false))] |
| 276 | show_pointer: bool, | 282 | show_pointer: bool, |
| 277 | 283 | ||
| @@ -488,6 +494,7 @@ pub enum Action { | |||
| 488 | /// | 494 | /// |
| 489 | /// If `true` (the default), the focus will follow the window to the new workspace. If | 495 | /// If `true` (the default), the focus will follow the window to the new workspace. If |
| 490 | /// `false`, the focus will remain on the original workspace. | 496 | /// `false`, the focus will remain on the original workspace. |
| 497 | + #[serde(default = "default_true")] | ||
| 491 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] | 498 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] |
| 492 | focus: bool, | 499 | focus: bool, |
| 493 | }, | 500 | }, |
| @@ -497,6 +504,7 @@ pub enum Action { | |||
| 497 | /// | 504 | /// |
| 498 | /// If `true` (the default), the focus will follow the window to the new workspace. If | 505 | /// If `true` (the default), the focus will follow the window to the new workspace. If |
| 499 | /// `false`, the focus will remain on the original workspace. | 506 | /// `false`, the focus will remain on the original workspace. |
| 507 | + #[serde(default = "default_true")] | ||
| 500 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] | 508 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] |
| 501 | focus: bool, | 509 | focus: bool, |
| 502 | }, | 510 | }, |
| @@ -521,6 +529,7 @@ pub enum Action { | |||
| 521 | /// If `true` (the default) and the window to move is focused, the focus will follow the | 529 | /// If `true` (the default) and the window to move is focused, the focus will follow the |
| 522 | /// window to the new workspace. If `false`, the focus will remain on the original | 530 | /// window to the new workspace. If `false`, the focus will remain on the original |
| 523 | /// workspace. | 531 | /// workspace. |
| 532 | + #[serde(default = "default_true")] | ||
| 524 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] | 533 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] |
| 525 | focus: bool, | 534 | focus: bool, |
| 526 | }, | 535 | }, |
| @@ -530,6 +539,7 @@ pub enum Action { | |||
| 530 | /// | 539 | /// |
| 531 | /// If `true` (the default), the focus will follow the column to the new workspace. If | 540 | /// If `true` (the default), the focus will follow the column to the new workspace. If |
| 532 | /// `false`, the focus will remain on the original workspace. | 541 | /// `false`, the focus will remain on the original workspace. |
| 542 | + #[serde(default = "default_true")] | ||
| 533 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] | 543 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] |
| 534 | focus: bool, | 544 | focus: bool, |
| 535 | }, | 545 | }, |
| @@ -539,6 +549,7 @@ pub enum Action { | |||
| 539 | /// | 549 | /// |
| 540 | /// If `true` (the default), the focus will follow the column to the new workspace. If | 550 | /// If `true` (the default), the focus will follow the column to the new workspace. If |
| 541 | /// `false`, the focus will remain on the original workspace. | 551 | /// `false`, the focus will remain on the original workspace. |
| 552 | + #[serde(default = "default_true")] | ||
| 542 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] | 553 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] |
| 543 | focus: bool, | 554 | focus: bool, |
| 544 | }, | 555 | }, |
| @@ -552,6 +563,7 @@ pub enum Action { | |||
| 552 | /// | 563 | /// |
| 553 | /// If `true` (the default), the focus will follow the column to the new workspace. If | 564 | /// If `true` (the default), the focus will follow the column to the new workspace. If |
| 554 | /// `false`, the focus will remain on the original workspace. | 565 | /// `false`, the focus will remain on the original workspace. |
| 566 | + #[serde(default = "default_true")] | ||
| 555 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] | 567 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] |
| 556 | focus: bool, | 568 | focus: bool, |
| 557 | }, | 569 | }, |
| @@ -849,6 +861,7 @@ pub enum Action { | |||
| 849 | id: Option<u64>, | 861 | id: Option<u64>, |
| 850 | 862 | ||
| 851 | /// How to change the X position. | 863 | /// How to change the X position. |
| 864 | + #[serde(default = "default_position_change")] | ||
| 852 | #[cfg_attr( | 865 | #[cfg_attr( |
| 853 | feature = "clap", | 866 | feature = "clap", |
| 854 | arg(short, long, default_value = "+0", allow_hyphen_values = true) | 867 | arg(short, long, default_value = "+0", allow_hyphen_values = true) |
| @@ -856,6 +869,7 @@ pub enum Action { | |||
| 856 | x: PositionChange, | 869 | x: PositionChange, |
| 857 | 870 | ||
| 858 | /// How to change the Y position. | 871 | /// How to change the Y position. |
| 872 | + #[serde(default = "default_position_change")] | ||
| 859 | #[cfg_attr( | 873 | #[cfg_attr( |
| 860 | feature = "clap", | 874 | feature = "clap", |
| 861 | arg(short, long, default_value = "+0", allow_hyphen_values = true) | 875 | arg(short, long, default_value = "+0", allow_hyphen_values = true) |
| @@ -1202,6 +1216,7 @@ pub struct VrrToSet { | |||
| 1202 | )] | 1216 | )] |
| 1203 | pub vrr: bool, | 1217 | pub vrr: bool, |
| 1204 | /// Only enable when the output shows a window matching the variable-refresh-rate window rule. | 1218 | /// Only enable when the output shows a window matching the variable-refresh-rate window rule. |
| 1219 | + #[serde(default)] | ||
| 1205 | #[cfg_attr(feature = "clap", arg(long))] | 1220 | #[cfg_attr(feature = "clap", arg(long))] |
| 1206 | pub on_demand: bool, | 1221 | pub on_demand: bool, |
| 1207 | } | 1222 | } |
| @@ -2116,6 +2131,14 @@ impl OutputAction { | |||
| 2116 | } | 2131 | } |
| 2117 | } | 2132 | } |
| 2118 | 2133 | ||
| 2134 | +fn default_true() -> bool { | ||
| 2135 | + true | ||
| 2136 | +} | ||
| 2137 | + | ||
| 2138 | +fn default_position_change() -> PositionChange { | ||
| 2139 | + PositionChange::AdjustFixed(0.) | ||
| 2140 | +} | ||
| 2141 | + | ||
| 2119 | #[cfg(test)] | 2142 | #[cfg(test)] |
| 2120 | mod tests { | 2143 | mod tests { |
| 2121 | use super::*; | 2144 | use super::*; |