spoon

set dwm status
git clone git://git.2f30.org/spoon
Log | Files | Refs | LICENSE

commit 9d849c4df8f4f2a648387b7118c251b35a438ba6
parent 44c65688aa9526fbd1e075a6f5af3a74391722d0
Author: sin <sin@2f30.org>
Date:   Thu, 15 Mar 2018 14:01:53 +0000

Add screen brightness sensor implementation for Linux

In the future we might drop the dependency on xbacklight(1).

Diffstat:
Mbrightness.c | 19++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/brightness.c b/brightness.c @@ -30,9 +30,26 @@ brightnessread(void *arg, char *buf, size_t len) return 0; } #elif __linux__ +#include <sys/wait.h> int brightnessread(void *arg, char *buf, size_t len) { - return -1; + FILE *fp; + int brightness; + + fp = popen("xbacklight", "r"); + if (fp == NULL) + return -1; + if (fscanf(fp, "%d", &brightness) == EOF) { + if (ferror(fp)) { + pclose(fp); + return -1; + } + } + /* This system does not have a backlight so report it as 100% */ + if (WEXITSTATUS(pclose(fp)) == 1) + brightness = 100; + snprintf(buf, len, "%3d%%", brightness); + return 0; } #endif