diff options
Diffstat (limited to 'dwmstatus.c')
-rw-r--r-- | dwmstatus.c | 135 |
1 files changed, 21 insertions, 114 deletions
diff --git a/dwmstatus.c b/dwmstatus.c index ce7914a..3a8dc1c 100644 --- a/dwmstatus.c +++ b/dwmstatus.c @@ -17,8 +17,6 @@ #include <X11/Xlib.h> -char *tzargentina = "America/Buenos_Aires"; -char *tzutc = "UTC"; char *tzberlin = "Europe/Berlin"; static Display *dpy; @@ -89,90 +87,7 @@ loadavg(void) if (getloadavg(avgs, 3) < 0) return smprintf(""); - return smprintf("%.2f %.2f %.2f", avgs[0], avgs[1], avgs[2]); -} - -char * -readfile(char *base, char *file) -{ - char *path, line[513]; - FILE *fd; - - memset(line, 0, sizeof(line)); - - path = smprintf("%s/%s", base, file); - fd = fopen(path, "r"); - free(path); - if (fd == NULL) - return NULL; - - if (fgets(line, sizeof(line)-1, fd) == NULL) - return NULL; - fclose(fd); - - return smprintf("%s", line); -} - -char * -getbattery(char *base) -{ - char *co, status; - int descap, remcap; - - descap = -1; - remcap = -1; - - co = readfile(base, "present"); - if (co == NULL) - return smprintf(""); - if (co[0] != '1') { - free(co); - return smprintf("not present"); - } - free(co); - - co = readfile(base, "charge_full_design"); - if (co == NULL) { - co = readfile(base, "energy_full_design"); - if (co == NULL) - return smprintf(""); - } - sscanf(co, "%d", &descap); - free(co); - - co = readfile(base, "charge_now"); - if (co == NULL) { - co = readfile(base, "energy_now"); - if (co == NULL) - return smprintf(""); - } - sscanf(co, "%d", &remcap); - free(co); - - co = readfile(base, "status"); - if (!strncmp(co, "Discharging", 11)) { - status = '-'; - } else if(!strncmp(co, "Charging", 8)) { - status = '+'; - } else { - status = '?'; - } - - if (remcap < 0 || descap < 0) - return smprintf("invalid"); - - return smprintf("%.0f%%%c", ((float)remcap / (float)descap) * 100, status); -} - -char * -gettemperature(char *base, char *sensor) -{ - char *co; - - co = readfile(base, sensor); - if (co == NULL) - return smprintf(""); - return smprintf("%02.0f°C", atof(co) / 1000); + return smprintf("%.2f", avgs[1]); } char * @@ -200,46 +115,38 @@ int main(void) { char *status; - char *avgs; - char *bat; - char *tmar; - char *tmutc; + char *avg; char *tmbln; - char *t0; - char *t1; - char *kbmap; + char *ips; + char *track; + char *temp; + char *partition; if (!(dpy = XOpenDisplay(NULL))) { fprintf(stderr, "dwmstatus: cannot open display.\n"); return 1; } - for (;;sleep(30)) { - avgs = loadavg(); - bat = getbattery("/sys/class/power_supply/BAT0"); - tmar = mktimes("%H:%M", tzargentina); - tmutc = mktimes("%H:%M", tzutc); - tmbln = mktimes("KW %W %a %d %b %H:%M %Z %Y", tzberlin); - kbmap = execscript("setxkbmap -query | grep layout | cut -d':' -f 2- | tr -d ' '"); - t0 = gettemperature("/sys/devices/virtual/thermal/thermal_zone0", "temp"); - t1 = gettemperature("/sys/devices/virtual/thermal/thermal_zone1", "temp"); - - status = smprintf("K:%s T:%s|%s L:%s B:%s A:%s U:%s %s", - kbmap, t0, t1, avgs, bat, tmar, tmutc, - tmbln); + for (;;sleep(1)) { + avg = loadavg(); + tmbln = mktimes("%a %d %b %H:%M", tzberlin); + ips = execscript("ip a | grep 'inet ' | grep -v 127.0.0.1 | tr -s ' ' |cut -f3 -d' '"); + temp = execscript("sensors amdgpu-pci-0400 | grep edge | cut -c 16-22"); + track = execscript("mpc -h core-a.lan | head -n 1 | grep -v volume || echo"); + partition = execscript("df -lh | grep cryptroot | tr -s ' ' | cut -d ' ' -f 4"); + + status = smprintf(" %s | %s | %s | %s | %s", + track, avg, temp, partition, tmbln); setstatus(status); - free(kbmap); - free(t0); - free(t1); - free(avgs); - free(bat); - free(tmar); - free(tmutc); + free(avg); free(tmbln); + free(ips); + free(track); + free(temp); + free(partition); free(status); } - XCloseDisplay(dpy); return 0; |