dwmstatus

dwmstatus fork with some Raspberry Pi workaround additions.
git clone git://bsandro.tech/dwmstatus
Log | Files | Refs | LICENSE

commit fcba7d6205b16c3099c3a30cf5bc0ef9dadd188b
parent 51bc02f6ea93e54c976aa76f5a43dd032e637f51
Author: bsandro <brian.drosan@gmail.com>
Date:   Sun,  1 Aug 2021 19:44:22 +0300

init rpi400-openbsd branch

Diffstat:
Mconfig.mk | 12++++++------
Mdwmstatus.c | 93+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
2 files changed, 66 insertions(+), 39 deletions(-)

diff --git a/config.mk b/config.mk @@ -4,7 +4,7 @@ VERSION = 1.0 # Customize below to fit your system # paths -PREFIX = /usr +PREFIX = /usr/local MANPREFIX = ${PREFIX}/share/man X11INC = /usr/X11R6/include @@ -16,15 +16,15 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 # flags CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS} -#CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} -LDFLAGS = -g ${LIBS} -#LDFLAGS = -s ${LIBS} +#CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS} +CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} +#LDFLAGS = -g ${LIBS} +LDFLAGS = -s ${LIBS} # Solaris #CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" #LDFLAGS = ${LIBS} # compiler and linker -CC = cc +CC = clang diff --git a/dwmstatus.c b/dwmstatus.c @@ -17,9 +17,8 @@ #include <X11/Xlib.h> -char *tzargentina = "America/Buenos_Aires"; -char *tzutc = "UTC"; -char *tzberlin = "Europe/Berlin"; +char *tzcyprus = "Asia/Nicosia"; +char *tzmoscow = "Europe/Moscow"; static Display *dpy; @@ -114,6 +113,47 @@ readfile(char *base, char *file) } char * +execproc(char *cmdname) +{ + const size_t buf_size = 256; + FILE *cmd = popen(cmdname, "r"); + if (!cmd) + return NULL; + + char *cmd_out = malloc(buf_size); + if (cmd_out == NULL) { + perror("malloc"); + exit(1); + } + bzero(cmd_out, buf_size); + fgets(cmd_out, buf_size, cmd); + // replacing newlines with 0 + cmd_out[strcspn(cmd_out, "\r\n")] = 0; + pclose(cmd); + return cmd_out; +} + +int +cpufreq(void) +{ + int freq = 0; + char *cmd_out = execproc("vcgencmd measure_clock arm"); + if (cmd_out == NULL) + return freq; + + // we need 2nd element from that string split by '=' + char *part = strtok(cmd_out, "="); + if (part != NULL) + part = strtok(NULL, "="); + + if (part != NULL) + freq = atol(part) / 1000000; + + free(cmd_out); + return freq; +} + +char * getbattery(char *base) { char *co, status; @@ -179,44 +219,31 @@ int main(void) { char *status; - char *avgs; - char *bat; - char *bat1; - char *tmar; - char *tmutc; - char *tmbln; - char *t0, *t1, *t2; + //char *avgs; + char *tmmoscow; + char *tmcyprus; + char *cpu_temp; + int cpu_clock; if (!(dpy = XOpenDisplay(NULL))) { fprintf(stderr, "dwmstatus: cannot open display.\n"); return 1; } - for (;;sleep(60)) { - avgs = loadavg(); - bat = getbattery("/sys/class/power_supply/BAT0"); - bat1 = getbattery("/sys/class/power_supply/BAT1"); - tmar = mktimes("%H:%M", tzargentina); - tmutc = mktimes("%H:%M", tzutc); - tmbln = mktimes("KW %W %a %d %b %H:%M %Z %Y", tzberlin); - t0 = gettemperature("/sys/devices/virtual/hwmon/hwmon0", "temp1_input"); - t1 = gettemperature("/sys/devices/virtual/hwmon/hwmon2", "temp1_input"); - t2 = gettemperature("/sys/devices/virtual/hwmon/hwmon4", "temp1_input"); - - status = smprintf("T:%s|%s|%s L:%s B:%s|%s A:%s U:%s %s", - t0, t1, t2, avgs, bat, bat1, tmar, tmutc, - tmbln); + for (;;sleep(5)) { + //avgs = loadavg(); + tmmoscow = mktimes("%H:%M", tzmoscow); + tmcyprus = mktimes("%a %F %R", tzcyprus); + //cpu_temp = execproc("vcgencmd measure_temp"); + //cpu_clock = cpufreq(); + status = smprintf("MSK(%s) %s", + /*cpu_temp, cpu_clock,*/ tmmoscow, tmcyprus); setstatus(status); - free(t0); - free(t1); - free(t2); - free(avgs); - free(bat); - free(bat1); - free(tmar); - free(tmutc); - free(tmbln); + //free(cpu_temp); + //free(avgs); + free(tmmoscow); + free(tmcyprus); free(status); }