diff options
author | Michael Stapelberg <michael+x200@stapelberg.de> | 2009-05-01 15:32:51 +0200 |
---|---|---|
committer | Michael Stapelberg <michael+x200@stapelberg.de> | 2009-05-01 15:32:51 +0200 |
commit | ac39765685d9a28cd86a233d171f7278f331ef09 (patch) | |
tree | 44ef386d67a8ec2c27ac991cfc9f5a33d90fdfa4 | |
parent | b844bd0eb3e4c97bf3264cc84db9a86ccab459fa (diff) |
Display 0 instead of negative values for remaining time
This could happen with new batteries which are charged further than
their design capacity is
-rw-r--r-- | i3status.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -93,6 +93,10 @@ static const char **run_watches; static unsigned int num_run_watches; static unsigned int interval = 1; +static int max(int a, int b) { + return (a > b ? a : b); +} + /* * This function just concats two strings in place, it should only be used * for concatting order to the name of a file or concatting color codes. @@ -340,7 +344,7 @@ static char *get_battery_info(const char *path) { (status == CS_CHARGING ? "CHR" : (status == CS_DISCHARGING ? "BAT" : "FULL")), (((float)remaining / (float)full_design) * 100), - hours, minutes, seconds); + max(hours, 0), max(minutes, 0), max(seconds, 0)); } else { (void)snprintf(part, sizeof(part), "%s %.02f%%", (status == CS_CHARGING ? "CHR" : |