(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);
+ (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00f%s", percentage_remaining, pct_mark);
} else {
- (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%", percentage_remaining);
+ (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%s", percentage_remaining, pct_mark);
}
if (present_rate > 0) {
(void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
- (void)snprintf(percentagebuf, sizeof(percentagebuf), "%02d%%",
- present_rate);
+ (void)snprintf(percentagebuf, sizeof(percentagebuf), "%02d%s",
+ present_rate, pct_mark);
if (state == 1) {
int hours, minutes;
(void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
/* integer_battery_capacity is implied as battery_life is already in whole numbers. */
- (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00d%%", apm_info.battery_life);
+ (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00d%s", apm_info.battery_life, pct_mark);
if (status == CS_DISCHARGING && low_threshold > 0) {
if (strcasecmp(threshold_type, "percentage") == 0 && apm_info.battery_life < low_threshold) {
if (integer_battery_capacity)
(void)snprintf(percentagebuf,
sizeof(percentagebuf),
- "%d%%",
- (int)percentage_remaining);
+ "%d%s",
+ (int)percentage_remaining, pct_mark);
else
(void)snprintf(percentagebuf,
sizeof(percentagebuf),
- "%.02f%%",
- percentage_remaining);
+ "%.02f%s",
+ percentage_remaining, pct_mark);
/*
* Handle percentage low_threshold here, and time low_threshold when