diff options
author | David Phillips <dbphillipsnz@gmail.com> | 2016-09-20 11:23:49 +1200 |
---|---|---|
committer | David Phillips <dbphillipsnz@gmail.com> | 2016-09-20 11:23:49 +1200 |
commit | a5d03ca5ffab3a5ba57f4ff04a7d0dd139c08856 (patch) | |
tree | 1cbf7419c9285e242d02731962a36b7d6ebe1cd9 /bat_tray.c | |
parent | 7b364cd870e5db98197b7f377f36553178c79ffc (diff) | |
download | paramano-a5d03ca5ffab3a5ba57f4ff04a7d0dd139c08856.tar.xz |
Ensure valid battery icon is selected when charge value out of bounds
Diffstat (limited to 'bat_tray.c')
-rw-r--r-- | bat_tray.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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: |