From 047db4eb8c83e1d70f92dfe240197a1bd88051c6 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Sun, 1 Jan 2017 05:01:57 +0100
Subject: Fix battery reporting on Dells
---
wmstatus.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/wmstatus.c b/wmstatus.c
index 4f1c434..23521b5 100644
--- a/wmstatus.c
+++ b/wmstatus.c
@@ -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;
--
cgit v1.2.3-70-g09d2