i3 - improved tiling WM


Fix battery indicator on systems without POWER_SUPPLY_VOLTAGE_NOW.

Patch status: merged

Patch by Klemen KoŇ°ir

Long description:

In my case, the voltage variable would stay initialized as -1,
which caused the calculation of battery charge percentage to be
incorrect (I would get the message that there is no battery present
or even -0% charge).

I have no idea how this would affect other systems, since I don't
have a chance to test this.

To apply this patch, use:
curl http://cr.i3wm.org/patch/638/raw.patch | git am

b/src/print_battery_info.c

21
@@ -124,8 +124,11 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
22
          * ampere to watt */
23
         if (!watt_as_unit) {
24
             present_rate = (((float)voltage / 1000.0) * ((float)present_rate / 1000.0));
25
-            remaining = (((float)voltage / 1000.0) * ((float)remaining / 1000.0));
26
-            full_design = (((float)voltage / 1000.0) * ((float)full_design / 1000.0));
27
+
28
+            if (voltage != -1) {
29
+                remaining = (((float)voltage / 1000.0) * ((float)remaining / 1000.0));
30
+                full_design = (((float)voltage / 1000.0) * ((float)full_design / 1000.0));
31
+            }
32
         }
33
 
34
         if ((full_design == -1) || (remaining == -1)) {