[hackers] [dwmstatus] added battery capacity info || Anselm R Garbe
commit 76e1a233e088b3cffb00fde44fcc7c37a0eac038
Author: Anselm R Garbe <anselm_AT_garbe.us>
AuthorDate: Sun Jul 19 20:18:25 2015 +0200
Commit: Anselm R Garbe <anselm_AT_garbe.us>
CommitDate: Sun Jul 19 20:18:25 2015 +0200
added battery capacity info
diff --git a/dwmstatus.c b/dwmstatus.c
index 236bca6..3d03dd8 100644
--- a/dwmstatus.c
+++ b/dwmstatus.c
_AT_@ -12,7 +12,9 @@
#include <X11/Xlib.h>
-char *tzargentina = "America/Buenos_Aires";
+char *sysbat = "/sys/class/power_supply/BAT0/capacity";
+char *tzsf = "US/Pacific";
+char *tztokyo= "Japan";
char *tzutc = "UTC";
char *tzberlin = "Europe/Berlin";
_AT_@ -80,6 +82,22 @@ setstatus(char *str)
}
char *
+batcap(void)
+{
+ char cap[16], *r = NULL;
+ FILE *f = fopen(sysbat, "r");
+
+ memset(cap, 1, sizeof cap);
+ if (f) {
+ r = fgets(cap, sizeof cap, f);
+ if (r == cap)
+ cap[strlen(cap)-1] = '\0';
+ fclose(f);
+ }
+ return smprintf("%s%%", r != NULL ? r : "?");
+}
+
+char *
loadavg(void)
{
double avgs[3];
_AT_@ -95,9 +113,11 @@ loadavg(void)
int
main(void)
{
+ char *cap;
char *status;
char *avgs;
- char *tmar;
+ char *tmsf;
+ char *tmtokyo;
char *tmutc;
char *tmbln;
_AT_@ -107,16 +127,19 @@ main(void)
}
for (;;sleep(90)) {
+ cap = batcap();
avgs = loadavg();
- tmar = mktimes("%H:%M", tzargentina);
+ tmsf = mktimes("%H:%M", tzsf);
+ tmtokyo = mktimes("%H:%M", tztokyo);
tmutc = mktimes("%H:%M", tzutc);
tmbln = mktimes("KW %W %a %d %b %H:%M %Z %Y", tzberlin);
- status = smprintf("L:%s A:%s U:%s %s",
- avgs, tmar, tmutc, tmbln);
+ status = smprintf("B:%s L:%s SF:%s JP:%s U:%s %s",
+ cap, avgs, tmsf, tmtokyo, tmutc, tmbln);
setstatus(status);
free(avgs);
- free(tmar);
+ free(tmsf);
+ free(tmtokyo);
free(tmutc);
free(tmbln);
free(status);
Received on Sun Jul 19 2015 - 20:18:51 CEST
This archive was generated by hypermail 2.3.0
: Sun Jul 19 2015 - 20:24:12 CEST