* dwmstatus for OpenBSD
       
   URI git clone git://git.codevoid.de/dwmstatus-sdk
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
   DIR commit e591bf9a6df8ae266b612bacec9e407fc9c4c1f7
   DIR parent dd54568f6cfe3ee35e7b62546ee886ad49136083
   URI Author: Stefan Hagen <sh+git[at]codevoid[dot]de>
       Date:   Fri, 23 Nov 2018 20:24:38 +0100
       
       Update 2018-11-23 20:24 OpenBSD/amd64
       
       Diffstat:
         M dwmstatus.c                         |      60 ++++++++++++++++++++++++++------
       
       1 file changed, 50 insertions(+), 10 deletions(-)
       ---
   DIR diff --git a/dwmstatus.c b/dwmstatus.c
       @@ -12,6 +12,9 @@
        #include <time.h>
        #include <sys/types.h>
        #include <sys/sysctl.h>
       +#include <sys/ioctl.h>
       +#include <sys/audioio.h>
       +#include <sys/socket.h>
        #include <sys/wait.h>
        #include <signal.h>
        #include <fcntl.h>
       @@ -63,17 +66,54 @@ char * getfreespace(const char *path) {
            return smprintf("%ld", (vfs.f_bavail * vfs.f_bsize) / 1024 / 1024);
        }
        
       -char * getsysctl(char *input_str) {
       -    char   *ret_val;
       -    size_t ret_size;
       -
       -    return "not implemented";
       +//char * getsysctl(char *input_str) {
       +//    char   *ret_val;
       +//    size_t ret_size;
       +//
       +//    return "not implemented";
       +//}
       +
       +char * getvolume() {
       +
       +        static int                        cls = -1, fd, v;
       +        static struct mixer_devinfo        mdi;
       +        static struct mixer_ctrl        mc;
       +
       +        if ((fd = open("/dev/mixer", O_RDONLY)) == -1)
       +            return smprintf("NOMIXER");
       +
       +        for (mdi.index = 0; cls == -1; ++mdi.index) {
       +                if (ioctl(fd, AUDIO_MIXER_DEVINFO, &mdi) == -1)
       +                        goto fail;
       +                if (mdi.type == AUDIO_MIXER_CLASS &&
       +                    strcmp(mdi.label.name, AudioCoutputs) == 0)
       +                        cls = mdi.index;
       +        }
       +        for (mdi.index = 0, v = -1; v == -1; ++mdi.index) {
       +                if (ioctl(fd, AUDIO_MIXER_DEVINFO, &mdi) == -1)
       +                        goto fail;
       +                if (mdi.type == AUDIO_MIXER_VALUE &&
       +                    mdi.prev == AUDIO_MIXER_LAST &&
       +                    mdi.mixer_class == cls &&
       +                    strcmp(mdi.label.name, AudioNmaster) == 0) {
       +                        mc.dev = mdi.index;
       +                        if (ioctl(fd, AUDIO_MIXER_READ, &mc) == -1)
       +                                goto fail;
       +                        v = MAX(mc.un.value.level[AUDIO_MIXER_LEVEL_MONO],
       +                                mc.un.value.level[AUDIO_MIXER_LEVEL_RIGHT]);
       +                }
       +        }
       +
       +        if (v == -1 || close(fd) == -1)
       +            return smprintf("NOCHAN");
       +
       +        return smprintf("%i", v * 100 / 255);
       +
       +fail:
       +        (void)close(fd);
       +        return smprintf("FAILED");
        }
        
       -char * getvolume(char *mixerpath) {
       -    return smprintf("N/A");
       -} 
       -
        void settz(char *tzname) {
            setenv("TZ", tzname, 1);
        }
       @@ -211,7 +251,7 @@ void update() {
            // battery  = smprintf("%i", getsysctl("hw.acpi.battery.life"));
        
            // audio volume
       -    char *volume = getvolume("/dev/mixer");
       +    char *volume = getvolume();
        
            // free disk space (root/home)
            char *freehomespace = getfreespace("/home");