diff options
Diffstat (limited to 'bin/backlight.c')
| -rw-r--r-- | bin/backlight.c | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/bin/backlight.c b/bin/backlight.c index 5894cd8..e3d6f6a 100644 --- a/bin/backlight.c +++ b/bin/backlight.c @@ -6,11 +6,10 @@ #include <stdlib.h> #include <limits.h> #include <errno.h> +#include <sys/types.h> +#include <dirent.h> -const char *backlight_f[] = { - "/sys/class/backlight/intel_backlight/", - "/sys/class/backlight/amdgpu_bl0/", -}; +#define BACKLIGHT_DIR "/sys/class/backlight" void die(const char *msg) @@ -134,11 +133,29 @@ main(int argc, char **argv) if (percent < 0 || percent > 100) die("percent must be between 0 and 100"); + DIR *d = opendir(BACKLIGHT_DIR); + if (!d) + err("opendir"); + + errno = 0; + for (;;) { + struct dirent *dent = readdir(d); + if(!dent&&errno!=0) + err("readdir"); + + if (!dent) + break; + + if (strcmp("..", dent->d_name)==0 || strcmp(".", dent->d_name)==0) + continue; + + char *prefix = appendStr(1024, BACKLIGHT_DIR"/", dent->d_name); + + printf("found backlight: %s\n", prefix); - for (int i=0; i < sizeof(backlight_f)/sizeof(backlight_f[0]); i++) { int ret; long max = 0; - ret = maxBrightness(backlight_f[i], &max); + ret = maxBrightness(prefix, &max); if (ret != 0) { const char *msg = strerror(ret); continue; @@ -146,13 +163,9 @@ main(int argc, char **argv) float p = (double)max*((double)percent/100.0); - ret = setBacklight(backlight_f[i], (int)p); + ret = setBacklight(prefix, (int)p); if (ret != 0) { perror("setBacklight"); } } - - - - } |
