From 8fc9a6b912ef68e19c4947f9d279d90d8d99791e Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 30 Jan 2025 15:44:33 +0100 Subject: ... --- overlays/swayosd.nix | 27 ------------------ overlays/swayosd/default.nix | 30 ++++++++++++++++++++ overlays/swayosd/exponential.patch | 57 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 27 deletions(-) delete mode 100644 overlays/swayosd.nix create mode 100644 overlays/swayosd/default.nix create mode 100644 overlays/swayosd/exponential.patch (limited to 'overlays') diff --git a/overlays/swayosd.nix b/overlays/swayosd.nix deleted file mode 100644 index 61c865e7..00000000 --- a/overlays/swayosd.nix +++ /dev/null @@ -1,27 +0,0 @@ -{ final, prev, sources, ... }: { - swayosd = prev.swayosd.overrideAttrs (oldAttrs: rec { - inherit (sources.swayosd) version src; - cargoDeps = prev.rustPlatform.fetchCargoTarball { - inherit (oldAttrs) pname; - inherit version src; - hash = "sha256-Anrk8p76HKZcNavYdi9l1oYahduLrb7Lf7knQK7Hy5E="; - }; - nativeBuildInputs = with final; [ - wrapGAppsHook4 - pkg-config - meson - rustc - cargo - ninja - rustPlatform.cargoSetupHook - ]; - buildInputs = with final; [ - gtk4-layer-shell - libevdev - libinput - libpulseaudio - udev - sassc - ]; - }); -} diff --git a/overlays/swayosd/default.nix b/overlays/swayosd/default.nix new file mode 100644 index 00000000..28c8f1b9 --- /dev/null +++ b/overlays/swayosd/default.nix @@ -0,0 +1,30 @@ +{ final, prev, sources, ... }: { + swayosd = prev.swayosd.overrideAttrs (oldAttrs: rec { + inherit (sources.swayosd) version src; + cargoDeps = prev.rustPlatform.fetchCargoTarball { + inherit (oldAttrs) pname; + inherit version src; + hash = "sha256-Anrk8p76HKZcNavYdi9l1oYahduLrb7Lf7knQK7Hy5E="; + }; + nativeBuildInputs = with final; [ + wrapGAppsHook4 + pkg-config + meson + rustc + cargo + ninja + rustPlatform.cargoSetupHook + ]; + buildInputs = with final; [ + gtk4-layer-shell + libevdev + libinput + libpulseaudio + udev + sassc + ]; + patches = (oldAttrs.patches or []) ++ [ + ./exponential.patch + ]; + }); +} diff --git a/overlays/swayosd/exponential.patch b/overlays/swayosd/exponential.patch new file mode 100644 index 00000000..eb90d739 --- /dev/null +++ b/overlays/swayosd/exponential.patch @@ -0,0 +1,57 @@ +diff --git a/src/brightness_backend/brightnessctl.rs b/src/brightness_backend/brightnessctl.rs +index ccb0e11..740fdb6 100644 +--- a/src/brightness_backend/brightnessctl.rs ++++ b/src/brightness_backend/brightnessctl.rs +@@ -107,10 +107,21 @@ impl VirtualDevice { + } + } + +- fn set_percent(&mut self, mut val: u32) -> anyhow::Result<()> { +- val = val.clamp(0, 100); +- self.current = self.max.map(|max| val * max / 100); +- let _: String = self.run(("set", &*format!("{val}%")))?; ++ fn val_to_percent(&mut self, val: u32) -> u32 { ++ return ((val as f64 / self.get_max() as f64).powf(0.25) * 100_f64).round() as u32; ++ } ++ fn percent_to_val(&mut self, perc: u32) -> u32 { ++ return ((perc as f64 / 100_f64).powf(4_f64) * self.get_max() as f64).round() as u32; ++ } ++ ++ fn set_percent(&mut self, val: u32) -> anyhow::Result<()> { ++ let new = self.percent_to_val(val); ++ self.set_val(new) ++ } ++ fn set_val(&mut self, val: u32) -> anyhow::Result<()> { ++ let curr = val.clamp(0, self.get_max()); ++ self.current = Some(curr); ++ let _: String = self.run(("set", &*format!("{curr}")))?; + Ok(()) + } + } +@@ -134,20 +145,18 @@ impl BrightnessBackend for BrightnessCtl { + + fn lower(&mut self, by: u32) -> anyhow::Result<()> { + let curr = self.get_current(); +- let max = self.get_max(); +- +- let curr = curr * 100 / max; ++ let mut new = self.device.val_to_percent(curr).saturating_sub(by); ++ new = self.device.percent_to_val(new).min(curr.saturating_sub(1)); + +- self.device.set_percent(curr.saturating_sub(by)) ++ self.device.set_val(new) + } + + fn raise(&mut self, by: u32) -> anyhow::Result<()> { + let curr = self.get_current(); +- let max = self.get_max(); +- +- let curr = curr * 100 / max; ++ let mut new = self.device.val_to_percent(curr) + by; ++ new = self.device.percent_to_val(new).max(curr + 1); + +- self.device.set_percent(curr + by) ++ self.device.set_val(new) + } + + fn set(&mut self, val: u32) -> anyhow::Result<()> { -- cgit v1.2.3