From 964275e14d63dbce8805b04c62692a14affbdc22 Mon Sep 17 00:00:00 2001 From: Dijo Date: Mon, 19 Oct 2026 13:46:19 +0530 Subject: [PATCH] Add serde defaults to optional IPC fields (#4698) * [ ipc ] : add serde defaults for optional action fields * [ ipc ] : default omitted VRR on demand flag false * [ ipc ] : remove serde tests --- niri-ipc/src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs index ec851349..c314d453 100644 --- a/niri-ipc/src/lib.rs +++ b/niri-ipc/src/lib.rs @@ -195,6 +195,7 @@ pub enum Action { /// Exit niri. Quit { /// Skip the "Press Enter to confirm" prompt. + #[serde(default)] #[cfg_attr(feature = "clap", arg(short, long))] skip_confirmation: bool, }, @@ -223,6 +224,7 @@ pub enum Action { /// Open the screenshot UI. Screenshot { /// Whether to show the mouse pointer by default in the screenshot UI. + #[serde(default = "default_true")] #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))] show_pointer: bool, @@ -239,10 +241,12 @@ pub enum Action { /// Write the screenshot to disk in addition to putting it in your clipboard. /// /// The screenshot is saved according to the `screenshot-path` config setting. + #[serde(default = "default_true")] #[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))] write_to_disk: bool, /// Whether to include the mouse pointer in the screenshot. + #[serde(default = "default_true")] #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))] show_pointer: bool, @@ -265,6 +269,7 @@ pub enum Action { /// Write the screenshot to disk in addition to putting it in your clipboard. /// /// The screenshot is saved according to the `screenshot-path` config setting. + #[serde(default = "default_true")] #[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))] write_to_disk: bool, @@ -272,6 +277,7 @@ pub enum Action { /// /// The pointer will be included only if the window is currently receiving pointer input /// (usually this means the pointer is on top of the window). + #[serde(default)] #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = false))] show_pointer: bool, @@ -488,6 +494,7 @@ pub enum Action { /// /// If `true` (the default), the focus will follow the window to the new workspace. If /// `false`, the focus will remain on the original workspace. + #[serde(default = "default_true")] #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] focus: bool, }, @@ -497,6 +504,7 @@ pub enum Action { /// /// If `true` (the default), the focus will follow the window to the new workspace. If /// `false`, the focus will remain on the original workspace. + #[serde(default = "default_true")] #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] focus: bool, }, @@ -521,6 +529,7 @@ pub enum Action { /// If `true` (the default) and the window to move is focused, the focus will follow the /// window to the new workspace. If `false`, the focus will remain on the original /// workspace. + #[serde(default = "default_true")] #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] focus: bool, }, @@ -530,6 +539,7 @@ pub enum Action { /// /// If `true` (the default), the focus will follow the column to the new workspace. If /// `false`, the focus will remain on the original workspace. + #[serde(default = "default_true")] #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] focus: bool, }, @@ -539,6 +549,7 @@ pub enum Action { /// /// If `true` (the default), the focus will follow the column to the new workspace. If /// `false`, the focus will remain on the original workspace. + #[serde(default = "default_true")] #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] focus: bool, }, @@ -552,6 +563,7 @@ pub enum Action { /// /// If `true` (the default), the focus will follow the column to the new workspace. If /// `false`, the focus will remain on the original workspace. + #[serde(default = "default_true")] #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] focus: bool, }, @@ -849,6 +861,7 @@ pub enum Action { id: Option, /// How to change the X position. + #[serde(default = "default_position_change")] #[cfg_attr( feature = "clap", arg(short, long, default_value = "+0", allow_hyphen_values = true) @@ -856,6 +869,7 @@ pub enum Action { x: PositionChange, /// How to change the Y position. + #[serde(default = "default_position_change")] #[cfg_attr( feature = "clap", arg(short, long, default_value = "+0", allow_hyphen_values = true) @@ -1202,6 +1216,7 @@ pub struct VrrToSet { )] pub vrr: bool, /// Only enable when the output shows a window matching the variable-refresh-rate window rule. + #[serde(default)] #[cfg_attr(feature = "clap", arg(long))] pub on_demand: bool, } @@ -2116,6 +2131,14 @@ impl OutputAction { } } +fn default_true() -> bool { + true +} + +fn default_position_change() -> PositionChange { + PositionChange::AdjustFixed(0.) +} + #[cfg(test)] mod tests { use super::*;