tAdd screen brightness sensor implementation for Linux - spoon - dwm status uti… | |
git clone git://src.adamsgaard.dk/spoon | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit 9d849c4df8f4f2a648387b7118c251b35a438ba6 | |
parent 44c65688aa9526fbd1e075a6f5af3a74391722d0 | |
Author: sin <[email protected]> | |
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: | |
M brightness.c | 19 ++++++++++++++++++- | |
1 file changed, 18 insertions(+), 1 deletion(-) | |
--- | |
diff --git a/brightness.c b/brightness.c | |
t@@ -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 |