From d0728523da95e687d81d7071dbf855cc6415d585 Mon Sep 17 00:00:00 2001 From: rajhansgithub Date: Thu, 3 Dec 2026 02:15:05 +0530 Subject: [PATCH] 2.35.2: earbud parts coloured by their own level --- Cargo.lock | 2 +- Cargo.toml | 2 +- res/resmon.manifest | 2 +- setup.iss | 2 +- src/liquid.rs | 51 +++++++++++++++++++++++++++++++++++++++++-- src/monitor/btpage.rs | 32 ++++++++++++++++++++++++++- src/monitor/hover.rs | 2 +- 7 files changed, 85 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index acbe579..74bcc7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,7 +92,7 @@ dependencies = [ [[package]] name = "resmon" -version = "2.35.1" +version = "2.35.2" dependencies = [ "embed-resource", "windows", diff --git a/Cargo.toml b/Cargo.toml index afd53b4..362fe31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "resmon" -version = "2.35.1" +version = "2.35.2" edition = "2021" authors = ["Emulsion Labs"] description = "Ultra-light taskbar resource monitor for Windows 10/11" diff --git a/res/resmon.manifest b/res/resmon.manifest index ed83c46..1392a5b 100644 --- a/res/resmon.manifest +++ b/res/resmon.manifest @@ -1,6 +1,6 @@ - + diff --git a/setup.iss b/setup.iss index b37dd77..13680c5 100644 --- a/setup.iss +++ b/setup.iss @@ -1,6 +1,6 @@ ; Inno Setup script. Build the exe first: cargo build --release #define MyAppName "Resource Monitor" -#define MyAppVersion "2.35.1" +#define MyAppVersion "2.35.2" #define MyAppPublisher "Emulsion Labs" #define MyAppURL "https://github.com/rajhansgithub/Windows_Resource_Monitoring_Tool" #define MyAppExeName "ResourceMonitor.exe" diff --git a/src/liquid.rs b/src/liquid.rs index 0731897..e242212 100644 --- a/src/liquid.rs +++ b/src/liquid.rs @@ -45,6 +45,9 @@ pub enum St { Low, } +/// At or below this a part of a low device is drawn low. +pub const LOW: f32 = 20.0; + impl St { /// Something moves: the caller keeps repainting only while this is true. pub fn moves(self) -> bool { @@ -993,6 +996,16 @@ impl Pen<'_> { } } +/// The state one part of `d` is drawn in at level `v` (0..100). A low device's parts go by their +/// own level: a full case is not red because the buds are low. +pub fn part_state(d: Dev, st: St, v: f32) -> St { + if d.three() && st == St::Low && v > LOW { + St::Normal + } else { + st + } +} + /// The scale a cached mask was built at (sizes snap to 1/16 px per unit). fn mask_k(k: f32) -> f32 { (k * 16.0).round().max(1.0) / 16.0 @@ -1012,9 +1025,10 @@ pub fn draw(cv: &mut Canvas, d: Dev, x: f32, y: f32, k: f32, vals: [f32; 3], st: let regs = regions_of(d); for (i, r) in regs.iter().enumerate() { let v = if d.three() { vals[r.vi] } else { vals[0] }; - p.region(d, i, r, (v / 100.0).clamp(0.0, 1.0), st); + p.region(d, i, r, (v / 100.0).clamp(0.0, 1.0), part_state(d, st, v)); } - p.deco(d, st, vals); + // Earbuds: the parts that are not fills (the case's light) belong to the case. + p.deco(d, if d.three() { part_state(d, st, vals[1]) } else { st }, vals); } #[cfg(test)] @@ -1077,6 +1091,39 @@ mod tests { assert_eq!(rows.len(), 4); } + /// Buds at 10 %, case at 100 %: the buds are red, the case is not, in every look. + #[test] + fn each_part_has_its_own_colour() { + for look in crate::look::Look::ALL { + for dark in [true, false] { + let tk = crate::look::tokens_for(look, dark); + for d in [Dev::Earbuds, Dev::Pods] { + // How many pixels of a part differ between two states. + let shot = |vals: [f32; 3], st: St| { + let mut cv = Canvas::new(); + cv.resize(400, 400); + cv.clear(tk.panel); + draw(&mut cv, d, 0.0, 0.0, 4.0, vals, st, 0.4, &tk, 1.7); + cv.pixels().to_vec() + }; + let (low, calm) = (shot([10.0, 100.0, 10.0], St::Low), shot([10.0, 100.0, 10.0], St::Normal)); + let diff = |x0: usize, x1: usize| (0..400).flat_map(|y| (x0..x1).map(move |x| y * 400 + x)).filter(|&i| low[i] != calm[i]).count(); + // The case is the middle of the drawing (units 31..69), the buds its sides. + assert_eq!(diff(31 * 4, 69 * 4), 0, "{look:?} {d:?}: the full case changed with the low buds"); + assert!(diff(0, 31 * 4) > 0, "{look:?} {d:?}: the low bud is not marked"); + // A low case beside full buds: the other way round. + let (low, calm) = (shot([90.0, 10.0, 90.0], St::Low), shot([90.0, 10.0, 90.0], St::Normal)); + let side = (0..400).flat_map(|y| (0..28 * 4).map(move |x| y * 400 + x)).filter(|&i| low[i] != calm[i]).count(); + assert_eq!(side, 0, "{look:?} {d:?}: a full bud changed with the low case"); + } + } + } + assert_eq!(part_state(Dev::Earbuds, St::Low, 20.0), St::Low); + assert_eq!(part_state(Dev::Earbuds, St::Low, 21.0), St::Normal); + assert_eq!(part_state(Dev::Earbuds, St::Charging, 90.0), St::Charging); + assert_eq!(part_state(Dev::Mouse, St::Low, 90.0), St::Low, "a device with one level is as it was"); + } + #[test] fn only_activity_moves() { assert!(!St::Normal.moves()); diff --git a/src/monitor/btpage.rs b/src/monitor/btpage.rs index 594f2ea..908e886 100644 --- a/src/monitor/btpage.rs +++ b/src/monitor/btpage.rs @@ -63,6 +63,11 @@ fn is_low(d: &BtDevice) -> bool { fresh(d) && level(d).is_some_and(|l| l <= LOW_PCT) } +/// A part with charge of its own on a device that is low. +fn part_calm(d: &BtDevice, v: Option) -> bool { + is_low(d) && v.is_some_and(|v| v > LOW_PCT) +} + fn kind_label(k: Kind) -> &'static str { match k { Kind::Earbuds => "EARBUDS", @@ -564,6 +569,17 @@ impl Draw<'_> { } } + /// Colour of one part's level (left, right or case): a low device's other parts are not red. + fn part_col(&self, d: &BtDevice, v: Option) -> Rgba { + if !part_calm(d, v) { + self.bt_col(d) + } else if d.charging == Some(true) { + self.col.good + } else { + self.col.accent + } + } + pub(super) fn draw_bt(&self, cv: &mut Canvas, vis: &dyn Fn(Rect) -> bool) { let m = self.m; let lay = &m.dp.bt; @@ -642,7 +658,7 @@ impl Draw<'_> { for (j, (lab, v)) in [("L", d.left), ("R", d.right), ("C", d.case)].iter().enumerate() { let bt = cy - self.s(13) + j as i32 * self.s(9); cv.text(self.f.tiny, lab, bl, bt - self.s(5), self.col.dim); - self.segs(cv, Rect { l: bl + self.s(12), t: bt, r: br, b: bt + bh }, *v, c); + self.segs(cv, Rect { l: bl + self.s(12), t: bt, r: br, b: bt + bh }, *v, self.part_col(d, *v)); } } else { self.segs(cv, Rect { l: bl, t: cy - self.s(5), r: br, b: cy + self.s(5) }, level(d), c); @@ -983,6 +999,20 @@ mod tests { assert_eq!(state(&n), "Nearby \u{00B7} not paired"); } + /// Buds at 10 %, case at 100 %: only the buds take the low colour. + #[test] + fn a_full_case_is_not_low() { + let mut d = dev(None, Some(10), Some(10)); + d.case = Some(100); + assert!(is_low(&d)); + assert!(part_calm(&d, d.case)); + assert!(!part_calm(&d, d.left) && !part_calm(&d, None)); + d.left = Some(90); + d.right = Some(90); + assert!(!part_calm(&d, d.case), "nothing is low: as before"); + assert_eq!(f32::from(LOW_PCT), crate::liquid::LOW); + } + #[test] fn low_only_when_connected() { let mut d = dev(Some(15), None, None); diff --git a/src/monitor/hover.rs b/src/monitor/hover.rs index a1090af..8faac07 100644 --- a/src/monitor/hover.rs +++ b/src/monitor/hover.rs @@ -1237,7 +1237,7 @@ mod tests { b.m = machine(); b.m.in_hover = true; let mut bt = (*b.m.det.deep.bt).clone(); - bt.push(BtDevice { id: "{buds}~".into(), name: "WF-C710N".into(), left: Some(100), right: Some(100), case: Some(100), ..bt[0].clone() }); + bt.push(BtDevice { id: "{buds}~".into(), name: "WF-C710N".into(), left: Some(10), right: Some(10), case: Some(100), ..bt[0].clone() }); b.m.det.deep.bt = Arc::new(bt); cv.resize(w, 2500); cv.clear(crate::look::tokens(true).bg);