X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/98e7324010626c5ba05d199190d9416359cf801e..74b6e340f2be27f82b4dcfc95fab47cbc0a5843b:/slstatus.c?ds=sidebyside diff --git a/slstatus.c b/slstatus.c index 991334a..f61e987 100644 --- a/slstatus.c +++ b/slstatus.c @@ -98,33 +98,18 @@ smprintf(const char *fmt, ...) static char * battery_perc(const char *battery) { - int now, full, perc; + int perc; FILE *fp; - ccat(4, BATTERY_PATH, battery, "/", BATTERY_NOW); - + ccat(3, "/sys/class/power_supply/", battery, "/capacity"); fp = fopen(concat, "r"); if (fp == NULL) { warn("Error opening battery file: %s", concat); return smprintf(UNKNOWN_STR); } - - fscanf(fp, "%i", &now); + fscanf(fp, "%i", &perc); fclose(fp); - ccat(4, BATTERY_PATH, battery, "/", BATTERY_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); - - perc = now / (full / 100); - return smprintf("%d%%", perc); }