* dwmstatus for OpenBSD
       
   URI git clone git://git.codevoid.de/dwmstatus-sdk
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
   DIR commit ab069199882de382939ef724b19563a3b0eac86c
   DIR parent a7ed94764ae00edced4ca65047ca006b655569a0
   URI Author: Stefan Hagen <sh+git[at]codevoid[dot]de>
       Date:   Sun,  3 Nov 2019 19:21:20 +0100
       
       ugly disk space display
       
       Diffstat:
         M config.mk                           |       2 +-
         M dwmstatus.c                         |      57 ++++++++++++++++++-------------
       
       2 files changed, 34 insertions(+), 25 deletions(-)
       ---
   DIR diff --git a/config.mk b/config.mk
       @@ -20,7 +20,7 @@ LIBS = -L/usr/local/lib -lc -L${X11LIB} -lX11
        
        # flags
        CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE
       -CFLAGS = -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
       +CFLAGS = -std=c99 -pedantic -Wall -g -O0 ${INCS} ${CPPFLAGS}
        #CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
        LDFLAGS = ${LIBS}
        #LDFLAGS = -s ${LIBS}
   DIR diff --git a/dwmstatus.c b/dwmstatus.c
       @@ -12,6 +12,9 @@
        #include <sys/sensors.h>
        #include <sys/ioctl.h>
        #include <sys/audioio.h>
       +#include <sys/types.h>
       +#include <sys/socket.h>
       +#include <ifaddrs.h>
        #include <machine/apmvar.h>
        #include <fcntl.h>
        #include <X11/Xlib.h>
       @@ -20,8 +23,6 @@
        
        // configuration
        #define UPDATE_INTERVAL 10
       -#define LOW_DISKSPACE_HOME 10240
       -#define LOW_DISKSPACE_ROOT 512
        
        // conversation presets
        #define ZEROCTOC(x) ((x)-2731) / 10
       @@ -146,13 +147,14 @@ void setstatus(char *str) {
            XSync(dpy, False);
        }
        
       -char * loadavg(void) {
       +char * loadavg(int i) {
            double avgs[3];
        
            if (getloadavg(avgs, 3) < 0)
                return smprintf("");
        
       -    return smprintf("%.2f|%.2f|%.2f", avgs[0], avgs[1], avgs[2]);
       +    //return smprintf("%.2f|%.2f|%.2f", avgs[0], avgs[1], avgs[2]);
       +    return smprintf("%.2f", avgs[i]);
        }
        
        char * readfile(char *base, char *file) {
       @@ -191,45 +193,52 @@ char * getbattery()
                return smprintf("%i", pi.battery_life);
        }
        
       +char * getifaddr(char * intf)
       +{
       +    struct ifaddrs *addrs;
       +    getifaddrs(&addrs);
       +
       +    while (addrs)
       +    {
       +        if (addrs->ifa_addr && strcmp(addrs->ifa_name,intf)
       +                && addrs->ifa_addr->sa_family == AF_INET)
       +        {
       +            struct sockaddr * myaddr = addrs->ifa_addr;
       +            return smprintf("%x", myaddr);
       +        }
       +        addrs = addrs->ifa_next;
       +    }
       +    freeifaddrs(addrs);
       +    return smprintf("n/a");
       +}
        
        // update all values and print statusbar
        void update() {
        
            // date and time (local)
            char *time = mktimes("%H:%M", tzlocal);
       -    char *date = mktimes("%d.%m.%Y", tzlocal);
       +    char *date = mktimes("%a %Y-%m-%d", tzlocal);
        
       -    // date and time (UTC)
       -    char *time_utc = mktimes("%H:%M", "UTC");
       -    char *date_utc = mktimes("%d.%m.%Y", "UTC");
       -
       -    // free disk space (root/home)
       +    // free disk space
            char *freehomespace = getfreespace("/home");
       +    char *freedataspace = getfreespace("/data");
            char *freerootspace = getfreespace("/");
        
       -    // low disk space warning
       -    char *warn = "\0";
       -    if(atoi(freehomespace) < LOW_DISKSPACE_HOME)
       -        warn = "     !!! LOW DISK SPACE WARNING @ HOME !!!    |";
       -    if(atoi(freerootspace) < LOW_DISKSPACE_ROOT)
       -        warn = "     !!! LOW DISK SPACE WARNING @ ROOT !!!    |";
       -
            // display status
       -    setstatus(smprintf("Bat: %s%% | Vol: %s%% | Temp: %sĀ°C (%sRPM) | Load: %s | %s | %s;"
       -                       "Network: %s | Address: %s |%s /home: %sMB | /: %sMB",
       -                       getbattery(), getvolume(), getcputemp(), getfan(), loadavg(), date, time,
       -                       "PowerMate 2.4GHz", "192.168.2.235", warn, freehomespace, freerootspace));
       +    setstatus(smprintf(
       +                "H:%.2fGB D:%.2fGB šŸ”Œ %s%% šŸ”Š %s%% šŸ”„ %sĀ°C šŸ”ƒ %sRPM šŸ“ˆ %s šŸ“† %s @ %s",
       +                (float)atoi(freehomespace) / 1024, (float)atoi(freedataspace) / 1024,
       +                getbattery(), getvolume(), getcputemp(), getfan(), loadavg(0), date,
       +                time));
        
            // free everything up
            free(time);
       -    free(time_utc);
            free(date);
       -    free(date_utc);
            free(freehomespace);
            free(freerootspace);
       +    free(freedataspace);
        }
        
       -
        void sig_handler(int signo) {
            if (signo == SIGUSR1)
                update();