* dwmstatus for OpenBSD
       
   URI git clone git://git.codevoid.de/dwmstatus-sdk
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
   DIR commit e276c5ff75309f5a904bea54427f5bd871527f8b
   DIR parent 813aed994aac60d514a3387d3346b0d05c5a3257
   URI Author: Stefan Hagen <sh+git[at]codevoid[dot]de>
       Date:   Mon, 21 May 2018 11:02:31 +0200
       
       Adding USR1 signal handler to force update status
       
       Diffstat:
         M dwmstatus.c                         |      76 +++++++++++++++++++++----------
       
       1 file changed, 52 insertions(+), 24 deletions(-)
       ---
   DIR diff --git a/dwmstatus.c b/dwmstatus.c
       @@ -17,6 +17,7 @@
        #include <sys/types.h>
        #include <sys/sysctl.h>
        #include <sys/wait.h>
       +#include <signal.h>
        #include <fcntl.h>
        #include <sys/soundcard.h>
        
       @@ -86,7 +87,6 @@ getsysctl(char *input_str) {
        char *
        getvolume(char *mixerpath) {
            char defaultmixer[] = "/dev/mixer";
       -    char *ret_val;
            int mixfd, vol, devmask = 0;
        
            if (mixerpath == NULL)
       @@ -235,41 +235,69 @@ gettemperature(char *base, char *sensor)
            return smprintf("%02.0f°C", atof(co) / 1000);
        }
        
       -int
       -main(void)
       -{
       +
       +// update all values and print statusbar
       +void update() {
            char *status;
            char *datetime;
            char *cputemp;
            char *battery;
            char *volume;
        
       +    // cpu temperature
       +    cputemp  = smprintf("%i", ZEROCTOC((int)getsysctl("hw.acpi.thermal.tz0.temperature")));
       +
       +    // battery
       +    battery  = smprintf("%i", getsysctl("hw.acpi.battery.life"));
       +
       +    // audio volume
       +    volume = smprintf("%s", getvolume("/dev/mixer"));
       +
       +    // IP + (lan speed / wlan ssid)
       +    // TBD
       +
       +    // free disk space (root/home)
       +    // TBD
       +
       +    // date and time
       +    datetime = mktimes("%d.%m.%Y %H:%M", tzberlin);
       +
       +    // assemble and display
       +    status   = smprintf(" CPU:%s°C BAT:%s%% VOL:%s | %s ", cputemp, battery, volume, datetime);
       +    setstatus(status);
       +
       +    free(volume);
       +    free(battery);
       +    free(cputemp);
       +    free(datetime);
       +    free(status);
       +}
       +
       +
       +// A user might want to force update dwmstatus (for example after a
       +// changing the volume. This can be done by sending signal SIGUSR1.
       +void
       +sig_handler(int signo) {
       +    if (signo == SIGUSR1)
       +        update();
       +}
       +
       +int
       +main(void)
       +{
       +
            if (!(dpy = XOpenDisplay(NULL))) {
                fprintf(stderr, "dwmstatus: cannot open display.\n");
                return 1;
            }
        
       +    // register signal handler
       +    if (signal(SIGUSR1, sig_handler) == SIG_ERR)
       +        fprintf(stderr, "Err: can't register SIGUSR1\n");
       +
       +    // update status
            for (;;sleep(60)) {
       -        // cpu temperature
       -        cputemp  = smprintf("%i", ZEROCTOC((int)getsysctl("hw.acpi.thermal.tz0.temperature")));
       -        // battery
       -        battery  = smprintf("%i", getsysctl("hw.acpi.battery.life"));
       -        // audio volume
       -        volume = smprintf("%s", getvolume("/dev/mixer"));
       -        // IP + (lan speed / wlan ssid)
       -        // free disk space (root/home)
       -        // date and time: done
       -        datetime = mktimes("%d.%m.%Y %H:%M", tzberlin);
       -
       -        // assemble and display
       -        status   = smprintf(" CPU:%s°C BAT:%s%% VOL:%s | %s ", cputemp, battery, volume, datetime);
       -        setstatus(status);
       -
       -        free(volume);
       -        free(battery);
       -        free(cputemp);
       -        free(datetime);
       -        free(status);
       +        update();
            }
        
            XCloseDisplay(dpy);