]> git.sur5r.net Git - i3/i3status/blobdiff - src/print_battery_info.c
Merge pull request #58 from bsdjhb/freebsd_ethernet_media
[i3/i3status] / src / print_battery_info.c
index 1126f5712fe03586b3ccdccb18d51d9493228061..0853e18a862f92829233619e9d9a46e8ac6d8c3d 100644 (file)
@@ -137,6 +137,14 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
     (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
 
     float percentage_remaining = (((float)remaining / (float)full_design) * 100);
+    /* Some batteries report POWER_SUPPLY_CHARGE_NOW=<full_design> when fully
+     * charged, even though that’s plainly wrong. For people who chose to see
+     * the percentage calculated based on the last full capacity, we clamp the
+     * value to 100%, as that makes more sense.
+     * See http://bugs.debian.org/785398 */
+    if (last_full_capacity && percentage_remaining > 100) {
+        percentage_remaining = 100;
+    }
     if (integer_battery_capacity) {
         (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00f%%", percentage_remaining);
     } else {
@@ -245,7 +253,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
         minutes = remaining;
         hours = minutes / 60;
         minutes -= (hours * 60);
-        (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02dh%02d",
+        (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d",
                        max(hours, 0), max(minutes, 0));
         if (strcasecmp(threshold_type, "percentage") == 0 && present_rate < low_threshold) {
             START_COLOR("color_bad");
@@ -310,7 +318,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
 
     /* Can't give a meaningful value for remaining minutes if we're charging. */
     if (status != CS_CHARGING) {
-        (void)snprintf(remainingbuf, sizeof(remainingbuf), "%d", apm_info.minutes_left);
+        (void)snprintf(remainingbuf, sizeof(remainingbuf), "%02d:%02d", apm_info.minutes_left / 60, apm_info.minutes_left % 60);
     } else {
         (void)snprintf(remainingbuf, sizeof(remainingbuf), "%s", "(CHR)");
     }