summaryrefslogtreecommitdiff
path: root/overlays
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2025-01-30 15:44:33 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2025-01-30 15:44:33 +0100
commit8fc9a6b912ef68e19c4947f9d279d90d8d99791e (patch)
tree7aa3c8c57be857585915b6134eac681b7a8567b5 /overlays
parent20168a40bc72096b2abd2b5fceae4a5f8a318cc9 (diff)
downloadnixos-8fc9a6b912ef68e19c4947f9d279d90d8d99791e.tar
nixos-8fc9a6b912ef68e19c4947f9d279d90d8d99791e.tar.gz
nixos-8fc9a6b912ef68e19c4947f9d279d90d8d99791e.tar.bz2
nixos-8fc9a6b912ef68e19c4947f9d279d90d8d99791e.tar.xz
nixos-8fc9a6b912ef68e19c4947f9d279d90d8d99791e.zip
Diffstat (limited to 'overlays')
-rw-r--r--overlays/swayosd/default.nix (renamed from overlays/swayosd.nix)3
-rw-r--r--overlays/swayosd/exponential.patch57
2 files changed, 60 insertions, 0 deletions
diff --git a/overlays/swayosd.nix b/overlays/swayosd/default.nix
index 61c865e7..28c8f1b9 100644
--- a/overlays/swayosd.nix
+++ b/overlays/swayosd/default.nix
@@ -23,5 +23,8 @@
23 udev 23 udev
24 sassc 24 sassc
25 ]; 25 ];
26 patches = (oldAttrs.patches or []) ++ [
27 ./exponential.patch
28 ];
26 }); 29 });
27} 30}
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 @@
1diff --git a/src/brightness_backend/brightnessctl.rs b/src/brightness_backend/brightnessctl.rs
2index ccb0e11..740fdb6 100644
3--- a/src/brightness_backend/brightnessctl.rs
4+++ b/src/brightness_backend/brightnessctl.rs
5@@ -107,10 +107,21 @@ impl VirtualDevice {
6 }
7 }
8
9- fn set_percent(&mut self, mut val: u32) -> anyhow::Result<()> {
10- val = val.clamp(0, 100);
11- self.current = self.max.map(|max| val * max / 100);
12- let _: String = self.run(("set", &*format!("{val}%")))?;
13+ fn val_to_percent(&mut self, val: u32) -> u32 {
14+ return ((val as f64 / self.get_max() as f64).powf(0.25) * 100_f64).round() as u32;
15+ }
16+ fn percent_to_val(&mut self, perc: u32) -> u32 {
17+ return ((perc as f64 / 100_f64).powf(4_f64) * self.get_max() as f64).round() as u32;
18+ }
19+
20+ fn set_percent(&mut self, val: u32) -> anyhow::Result<()> {
21+ let new = self.percent_to_val(val);
22+ self.set_val(new)
23+ }
24+ fn set_val(&mut self, val: u32) -> anyhow::Result<()> {
25+ let curr = val.clamp(0, self.get_max());
26+ self.current = Some(curr);
27+ let _: String = self.run(("set", &*format!("{curr}")))?;
28 Ok(())
29 }
30 }
31@@ -134,20 +145,18 @@ impl BrightnessBackend for BrightnessCtl {
32
33 fn lower(&mut self, by: u32) -> anyhow::Result<()> {
34 let curr = self.get_current();
35- let max = self.get_max();
36-
37- let curr = curr * 100 / max;
38+ let mut new = self.device.val_to_percent(curr).saturating_sub(by);
39+ new = self.device.percent_to_val(new).min(curr.saturating_sub(1));
40
41- self.device.set_percent(curr.saturating_sub(by))
42+ self.device.set_val(new)
43 }
44
45 fn raise(&mut self, by: u32) -> anyhow::Result<()> {
46 let curr = self.get_current();
47- let max = self.get_max();
48-
49- let curr = curr * 100 / max;
50+ let mut new = self.device.val_to_percent(curr) + by;
51+ new = self.device.percent_to_val(new).max(curr + 1);
52
53- self.device.set_percent(curr + by)
54+ self.device.set_val(new)
55 }
56
57 fn set(&mut self, val: u32) -> anyhow::Result<()> {