battery: fixed remaining time on connected AC
authorTobias Tschinkowitz <he4d@posteo.de>
Fri, 18 May 2018 14:33:51 +0000 (16:33 +0200)
committerAaron Marcher <me@drkhsh.at>
Fri, 18 May 2018 14:35:32 +0000 (16:35 +0200)
when an AC is connected apm_info shows a non-valid value for remaining
minutes. it was decided that in that case the function should return an
empty string.

components/battery.c

index 53d94b5bd6f827bd714fc8ac7f5cd31c2277037c..84b2c116985d82ac5f3877cbf667585e4873c2e9 100644 (file)
                struct apm_power_info apm_info;
 
                if (load_apm_power_info(&apm_info)) {
-                       return bprintf("%u:%02u", apm_info.minutes_left / 60,
-                                      apm_info.minutes_left % 60);
+                       if (apm_info.ac_state != APM_AC_ON) {
+                               return bprintf("%u:%02u", apm_info.minutes_left / 60,
+                                              apm_info.minutes_left % 60);
+                       } else {
+                               return strdup("");
+                       }
                }
 
                return NULL;