* dwmstatus for OpenBSD
       
   URI git clone git://git.codevoid.de/dwmstatus-sdk
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
   DIR commit 7bf763a0426f1124a7eca8f21255e496e9747ea2
   DIR parent e591bf9a6df8ae266b612bacec9e407fc9c4c1f7
   URI Author: Stefan Hagen <sh+git[at]codevoid[dot]de>
       Date:   Sat, 24 Nov 2018 19:50:00 +0100
       
       Update 2018-11-24 19:50 OpenBSD/amd64
       
       Diffstat:
         M dwmstatus.c                         |      75 +++++++++----------------------
       
       1 file changed, 22 insertions(+), 53 deletions(-)
       ---
   DIR diff --git a/dwmstatus.c b/dwmstatus.c
       @@ -15,6 +15,7 @@
        #include <sys/ioctl.h>
        #include <sys/audioio.h>
        #include <sys/socket.h>
       +#include <machine/apmvar.h>
        #include <sys/wait.h>
        #include <signal.h>
        #include <fcntl.h>
       @@ -171,55 +172,6 @@ char * readfile(char *base, char *file) {
            return smprintf("%s", line);
        }
        
       -char * getbattery(char *base) {
       -    char *co, status;
       -    int descap, remcap;
       -
       -    descap = -1;
       -    remcap = -1;
       -
       -    co = readfile(base, "present");
       -    if (co == NULL)
       -        return smprintf("");
       -    if (co[0] != '1') {
       -        free(co);
       -        return smprintf("not present");
       -    }
       -    free(co);
       -
       -    co = readfile(base, "charge_full_design");
       -    if (co == NULL) {
       -        co = readfile(base, "energy_full_design");
       -        if (co == NULL)
       -            return smprintf("");
       -    }
       -    sscanf(co, "%d", &descap);
       -    free(co);
       -
       -    co = readfile(base, "charge_now");
       -    if (co == NULL) {
       -        co = readfile(base, "energy_now");
       -        if (co == NULL)
       -            return smprintf("");
       -    }
       -    sscanf(co, "%d", &remcap);
       -    free(co);
       -
       -    co = readfile(base, "status");
       -    if (!strncmp(co, "Discharging", 11)) {
       -        status = '-';
       -    } else if(!strncmp(co, "Charging", 8)) {
       -        status = '+';
       -    } else {
       -        status = '?';
       -    }
       -
       -    if (remcap < 0 || descap < 0)
       -        return smprintf("invalid");
       -
       -    return smprintf("%.0f%%%c", ((float)remcap / (float)descap) * 100, status);
       -}
       -
        char * gettemperature(char *base, char *sensor) {
            char *co;
            co = readfile(base, sensor);
       @@ -228,6 +180,23 @@ char * gettemperature(char *base, char *sensor) {
            return smprintf("%02.0f°C", atof(co) / 1000);
        }
        
       +char * getbattery()
       +{
       +        int        fd;
       +        struct apm_power_info pi;
       +
       +        if ((fd = open("/dev/apm", O_RDONLY)) == -1 ||
       +            ioctl(fd, APM_IOC_GETPOWER, &pi) == -1 ||
       +            close(fd) == -1)
       +            return smprintf("battery");
       +
       +        if (pi.battery_state == APM_BATT_UNKNOWN ||
       +            pi.battery_state == APM_BATTERY_ABSENT)
       +            return smprintf("no battery");
       +
       +        return smprintf("%i", pi.battery_life);
       +}
       +
        
        // update all values and print statusbar
        void update() {
       @@ -248,8 +217,8 @@ void update() {
            // cpufreq  = smprintf("%i", getsysctl("dev.cpu.0.freq"));
        
            // battery
       -    // battery  = smprintf("%i", getsysctl("hw.acpi.battery.life"));
       -
       +    // battery  = smprintf("%i", ge      tsysctl("hw.acpi.battery.life"));
       +                                         
            // audio volume
            char *volume = getvolume();
        
       @@ -265,9 +234,9 @@ void update() {
                warn = "     !!! LOW DISK SPACE WARNING @ ROOT !!!    |";
        
            // display status
       -    setstatus(smprintf("Volume: %s | Load: %s | %s | %s;"
       +    setstatus(smprintf("Battery: %s%% | Volume: %s%% | Load: %s | %s | %s;"
                               "Network: %s | Address: %s |%s /home: %sMB | /: %sMB",
       -                       volume, loadavg(), date, time,
       +                       getbattery(), volume, loadavg(), date, time,
                               "PowerMate 2.4GHz", "192.168.2.235", warn, freehomespace, freerootspace));
        
            // free everything up