Fix battery reporting on Dells

This commit is contained in:
Přemysl Eric Janouch 2017-01-01 05:01:57 +01:00
parent ae0c29559c
commit 047db4eb8c
Signed by: p
GPG Key ID: B715679E3A361BE6
1 changed files with 6 additions and 2 deletions

View File

@ -1315,8 +1315,12 @@ read_battery_status (int dir, struct error **e)
|| (charge_full = read_number (dir, "charge_full", &error), error))
error_propagate (e, error);
else
result = xstrdup_printf ("%s (%u%%)",
status, (unsigned) (charge_now / charge_full * 100 + 0.5));
{
// Dell is being unreasonable and seems to set charge_now
// to charge_full_design when the battery is fully charged
unsigned percentage = charge_now / charge_full * 100 + 0.5;
result = xstrdup_printf ("%s (%u%%)", status, MIN (percentage, 100));
}
free (status);
return result;