]> git.sur5r.net Git - i3/i3status/commitdiff
Clamp the percentage at 100% when last_full_capacity is enabled.
authorMichael Stapelberg <michael@stapelberg.de>
Wed, 20 May 2015 17:17:23 +0000 (19:17 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 20 May 2015 17:17:23 +0000 (19:17 +0200)
src/print_battery_info.c

index 85b0a75a5d097d369d956162e80628bc5a3436ce..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 {