aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <dbphillipsnz@gmail.com>2016-09-20 11:23:49 +1200
committerDavid Phillips <dbphillipsnz@gmail.com>2016-09-20 11:23:49 +1200
commita5d03ca5ffab3a5ba57f4ff04a7d0dd139c08856 (patch)
tree1cbf7419c9285e242d02731962a36b7d6ebe1cd9
parent7b364cd870e5db98197b7f377f36553178c79ffc (diff)
downloadparamano-a5d03ca5ffab3a5ba57f4ff04a7d0dd139c08856.tar.xz
Ensure valid battery icon is selected when charge value out of bounds
-rw-r--r--bat_tray.c9
1 files changed, 8 insertions, 1 deletions
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: