diff --git a/src/cli/randr.rs b/src/cli/randr.rs index df63d735..b5b976ce 100644 --- a/src/cli/randr.rs +++ b/src/cli/randr.rs @@ -292,6 +292,11 @@ pub struct ModeArgs { #[derive(Args, Debug, Clone)] pub struct ScaleArgs { + /// Rounds the scale to a value that can be stored in a floating-point number. This + /// might be useful because some applications store scales as floating-point numbers + /// and can become blurry if the scale cannot be represented exactly. + #[arg(long)] + pub round_to_float: bool, /// The new scale. pub scale: f64, } @@ -583,7 +588,10 @@ impl Randr { self.handle_error(randr, |msg| { eprintln!("Could not modify the scale: {}", msg); }); - let scale = Scale::from_f64(t.scale); + let scale = match t.round_to_float { + true => Scale::from_f64_as_float(t.scale), + false => Scale::from_f64(t.scale), + }; tc.send(jay_randr::SetScale { self_id: randr, output: &args.output, diff --git a/src/scale.rs b/src/scale.rs index 63f06f81..2e93dd96 100644 --- a/src/scale.rs +++ b/src/scale.rs @@ -23,6 +23,10 @@ impl Scale { Self((f * BASEF).round() as u32) } + pub fn from_f64_as_float(f: f64) -> Self { + Self(((f * (BASEF / 15.0)).round() as u32).saturating_mul(15)) + } + pub fn to_f64(self) -> f64 { self.0 as f64 / BASEF }