From 2e4a2e13b175fcbb0fef58214f7de5b60775214a Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sun, 5 May 2024 12:39:20 +0400 Subject: Make missing scale = automatic selection That was the intention, but I missed it before. --- niri-ipc/src/lib.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'niri-ipc/src/lib.rs') diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs index c721ac9b..db2d7a0f 100644 --- a/niri-ipc/src/lib.rs +++ b/niri-ipc/src/lib.rs @@ -278,9 +278,9 @@ pub enum OutputAction { }, /// Set the output scale. Scale { - /// Scale factor to set. + /// Scale factor to set, or "auto" for automatic selection. #[cfg_attr(feature = "clap", arg())] - scale: f64, + scale: ScaleToSet, }, /// Set the output transform. Transform { @@ -329,6 +329,15 @@ pub struct ConfiguredMode { pub refresh: Option, } +/// Output scale to set. +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] +pub enum ScaleToSet { + /// Niri will pick the scale automatically. + Automatic, + /// Specific scale. + Specific(f64), +} + /// Output position to set. #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "clap", derive(clap::Subcommand))] @@ -560,3 +569,16 @@ impl FromStr for ConfiguredMode { }) } } + +impl FromStr for ScaleToSet { + type Err = &'static str; + + fn from_str(s: &str) -> Result { + if s.eq_ignore_ascii_case("auto") { + return Ok(Self::Automatic); + } + + let scale = s.parse().map_err(|_| "error parsing scale")?; + Ok(Self::Specific(scale)) + } +} -- cgit