* dwmstatus for OpenBSD
       
   URI git clone git://git.codevoid.de/dwmstatus-sdk
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
   DIR commit c891fa7936514f8933b0bd23dadac36149d67f19
   DIR parent 284e83b7a08209da3b1c70fce10f9a7821f00044
   URI Author: Stefan Hagen <github@textmail.me>
       Date:   Sun, 20 May 2018 22:26:54 +0200
       
       sysctl interface - first version
       
       Diffstat:
         M dwmstatus.c                         |      76 +++++++++++++++++--------------
       
       1 file changed, 42 insertions(+), 34 deletions(-)
       ---
   DIR diff --git a/dwmstatus.c b/dwmstatus.c
       @@ -13,16 +13,20 @@
        #include <sys/time.h>
        #include <time.h>
        #include <sys/types.h>
       +#include <sys/sysctl.h>
        #include <sys/wait.h>
        
        #include <X11/Xlib.h>
        
       -char *tzargentina = "America/Buenos_Aires";
       -char *tzutc = "UTC";
       +#define ZEROC 2731
       +#define CONVC(x) ((x)-ZEROC) / 10
       +
       +
        char *tzberlin = "Europe/Berlin";
        
        static Display *dpy;
        
       +
        char *
        smprintf(char *fmt, ...)
        {
       @@ -44,7 +48,28 @@ smprintf(char *fmt, ...)
                vsnprintf(ret, len, fmt, fmtargs);
                va_end(fmtargs);
        
       -        return ret;
       +        return ret;
       +}
       +
       +char *
       +getsysctl(char *input_str) {
       +    char   *ret_val;
       +    size_t ret_size;
       +
       +    sysctlbyname(input_str, NULL, &ret_size, NULL, 0);
       +    ret_val = malloc(ret_size);
       +
       +    // call to get size
       +    sysctlbyname(input_str, NULL, &ret_size, NULL, 0);
       +
       +    // allocate memory
       +    ret_val = malloc(ret_size);
       +
       +    // retrieve value
       +    sysctlbyname(input_str, &ret_val, &ret_size, NULL, 0);
       +
       +    // caller must know how to interpret this (s or i)
       +    return ret_val;
        }
        
        void
       @@ -179,13 +204,9 @@ int
        main(void)
        {
                char *status;
       -        char *avgs;
       -        char *bat;
       -        char *bat1;
       -        char *tmar;
       -        char *tmutc;
       -        char *tmbln;
       -        char *t0, *t1, *t2, *t3;
       +        char *datetime;
       +        char *cputemp;
       +        char *battery;
        
                if (!(dpy = XOpenDisplay(NULL))) {
                        fprintf(stderr, "dwmstatus: cannot open display.\n");
       @@ -193,32 +214,19 @@ main(void)
                }
        
                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/hwmon1", "temp1_input");
       -                t1 = gettemperature("/sys/devices/platform/coretemp.0/hwmon/hwmon3", "temp1_input");
       -                t2 = gettemperature("/sys/devices/platform/coretemp.0/hwmon/hwmon3", "temp2_input");
       -                t3 = gettemperature("/sys/devices/platform/coretemp.0/hwmon/hwmon3", "temp3_input");
       -
       -                status = smprintf("T:%s|%s|%s|%s L:%s B:%s|%s A:%s U:%s %s",
       -                                t0, t1, t2, t3, avgs, bat, bat1, tmar, tmutc,
       -                                tmbln);
       +                datetime = mktimes("%d.%m.%Y %H:%M", tzberlin);
       +
       +                cputemp  = smprintf("%i", CONVC((int)getsysctl("hw.acpi.thermal.tz0.temperature")));
       +                battery  = smprintf("%i", (int)getsysctl("hw.acpi.battery.life"));
       +
       +                status   = smprintf(" CPU:%s°C BAT:%s%% | %s %s",
       +                                cputemp, battery, datetime);
       +
                        setstatus(status);
        
       -                free(t0);
       -                free(t1);
       -                free(t2);
       -                free(t3);
       -                free(avgs);
       -                free(bat);
       -                free(bat1);
       -                free(tmar);
       -                free(tmutc);
       -                free(tmbln);
       +                free(battery);
       +                free(cputemp);
       +                free(datetime);
                        free(status);
                }