From a5d03ca5ffab3a5ba57f4ff04a7d0dd139c08856 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Tue, 20 Sep 2016 11:23:49 +1200 Subject: Ensure valid battery icon is selected when charge value out of bounds --- bat_tray.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bat_tray.c b/bat_tray.c index f9bb1bf..c6e9f45 100644 --- a/bat_tray.c +++ b/bat_tray.c @@ -138,11 +138,18 @@ static void update_tooltip_cache() static gboolean update() { char icon_file[1024]; - unsigned int rounded = 0; + int rounded = 0; /* Round percentage to 0, 20, 40, 60, 80 or 100 */ rounded = 20 * (int)((get_bat_percent() + 10) / 20); + /* cap rounded value to safe bounds */ + if (rounded < 0) + rounded = 0; + + if (rounded > 100) + rounded = 100; + switch (get_battery_state()) { case STATE_DISCHARGING: -- cgit v1.1