diff options
Diffstat (limited to 'overlays/swayosd/exponential.patch')
-rw-r--r-- | overlays/swayosd/exponential.patch | 57 |
1 files changed, 57 insertions, 0 deletions
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 @@ | |||
1 | diff --git a/src/brightness_backend/brightnessctl.rs b/src/brightness_backend/brightnessctl.rs | ||
2 | index 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<()> { | ||