tAdd screen brightness sensor - spoon - dwm status utility (2f30 fork)
 (HTM) git clone git://src.adamsgaard.dk/spoon
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit 9a248ae02783160a7d78adc151d065f3276055c1
 (DIR) parent ab74543a5e74287d11500dfbd7483dc88069e2b3
 (HTM) Author: Lucas Gabriel Vuotto <lgv@nanashi.co>
       Date:   Sat, 14 Oct 2017 14:04:10 -0300
       
       Add screen brightness sensor
       
       Signed-off-by: Lucas Gabriel Vuotto <lgv@nanashi.co>
       
       Diffstat:
         M Makefile                            |       4 ++--
         A brightness.c                        |      38 +++++++++++++++++++++++++++++++
         M spoon.c                             |       1 +
         M stub.c                              |       7 +++++++
       
       4 files changed, 48 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/Makefile b/Makefile
       t@@ -1,9 +1,9 @@
        VERSION = 0.5
        PREFIX = /usr/local
        SRC = spoon.c batt.c wifi.c cpu.c temp.c date.c load.c file.c key.c\
       -      netspeed.c strlcpy.c strlcat.c stub.c mix.c xkblayout.c mpd.c
       +      netspeed.c strlcpy.c strlcat.c stub.c mix.c xkblayout.c mpd.c brightness.c
        OBJ = spoon.o batt.o wifi.o cpu.o temp.o date.o load.o file.o key.o\
       -      netspeed.o strlcpy.o strlcat.o stub.o
       +      netspeed.o strlcpy.o strlcat.o stub.o brightness.o
        BIN = spoon
        DISTFILES = $(SRC) types.h util.h config.def.h Makefile LICENSE configure
        
 (DIR) diff --git a/brightness.c b/brightness.c
       t@@ -0,0 +1,38 @@
       +#include <err.h>
       +#include <stdio.h>
       +
       +#ifdef __OpenBSD__
       +#include <sys/ioctl.h>
       +#include <fcntl.h>
       +#include <time.h>
       +#include <unistd.h>
       +#include <dev/wscons/wsconsio.h>
       +
       +int
       +brightnessread(void *arg, char *buf, size_t len)
       +{
       +        struct wsdisplay_param dpyp;
       +        int fd;
       +
       +        if ((fd = open("/dev/ttyC0", O_RDONLY)) == -1) {
       +                warn("couldn't open /dev/ttyC0");
       +                return -1;
       +        }
       +        dpyp.param = WSDISPLAYIO_PARAM_BRIGHTNESS;
       +        if (ioctl(fd, WSDISPLAYIO_GETPARAM, &dpyp) == -1) {
       +                warn("WSDISPLAYIO_PARAM_BRIGHTNESS ioctl");
       +                return -1;
       +        }
       +        close(fd);
       +        snprintf(buf, len, "%3d%%",
       +            100 * (dpyp.curval - dpyp.min) / (dpyp.max - dpyp.min));
       +
       +        return 0;
       +}
       +#elif __linux__
       +int
       +brightnessread(void *arg, char *buf, size_t len)
       +{
       +        return -1;
       +}
       +#endif
 (DIR) diff --git a/spoon.c b/spoon.c
       t@@ -21,6 +21,7 @@ int xkblayoutread(void *, char *, size_t);
        int fileread(void *, char *, size_t);
        int keyread(void *, char *, size_t);
        int netspeedread(void *, char *, size_t);
       +int brightnessread(void *, char *, size_t);
        
        struct ent {
                char *fmt;
 (DIR) diff --git a/stub.c b/stub.c
       t@@ -69,3 +69,10 @@ netspeedread(void *arg, char *buf, size_t len)
        {
                return -1;
        }
       +
       +#pragma weak brightnessread
       +int
       +brightnessread(void *arg, char *buf, size_t len)
       +{
       +        return -1;
       +}