Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion res/resmon.manifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity type="win32" name="ResourceMonitor" version="2.35.1.0"/>
<assemblyIdentity type="win32" name="ResourceMonitor" version="2.35.2.0"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security><requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
Expand Down
2 changes: 1 addition & 1 deletion setup.iss
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
51 changes: 49 additions & 2 deletions src/liquid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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)]
Expand Down Expand Up @@ -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());
Expand Down
32 changes: 31 additions & 1 deletion src/monitor/btpage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>) -> bool {
is_low(d) && v.is_some_and(|v| v > LOW_PCT)
}

fn kind_label(k: Kind) -> &'static str {
match k {
Kind::Earbuds => "EARBUDS",
Expand Down Expand Up @@ -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<u8>) -> 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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/monitor/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading