lol, battery_perc() is even simpler, fuck this shit :D
Aaron Marcher info@nulltime.net
Tue, 13 Sep 2016 21:05:49 +0200
1 files changed,
6 insertions(+),
23 deletions(-)
jump to
M
slstatus.c
→
slstatus.c
@@ -98,36 +98,19 @@
static char * battery_perc(const char *battery) { - int now, full; + int perc; FILE *fp; - ccat(3, "/sys/class/power_supply/", battery, "/energy_now"); + ccat(3, "/sys/class/power_supply/", battery, "/capacity"); fp = fopen(concat, "r"); if (fp == NULL) { - ccat(4, "/sys/class/power_supply/", battery, "/charge_now"); - fp = fopen(concat, "r"); - if (fp == NULL) { - warn("Error opening battery file: %s", concat); - return smprintf(UNKNOWN_STR); - } + warn("Error opening battery file: %s", concat); + return smprintf(UNKNOWN_STR); } - fscanf(fp, "%i", &now); + fscanf(fp, "%i", &perc); fclose(fp); - ccat(3, "/sys/class/power_supply/", battery, "/energy_full"); - fp = fopen(concat, "r"); - if (fp == NULL) { - ccat(4, "/sys/class/power_supply/", battery, "/charge_full"); - fp = fopen(concat, "r"); - if (fp == NULL) { - warn("Error opening battery file: %s", concat); - return smprintf(UNKNOWN_STR); - } - } - fscanf(fp, "%i", &full); - fclose(fp); - - return smprintf("%d%%", now / (full / 100)); + return smprintf("%d%%", perc); } static char *