diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2022-12-31 20:50:24 -0500 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2022-12-31 20:50:24 -0500 |
| commit | d5142521687097211683e15e178d120ccf26d66b (patch) | |
| tree | 4dd243b6e50c3067cfd8e15bc5eb6e655c637f00 | |
| parent | 545814f3792c9d7e5702cb6112ef949e2a1fd263 (diff) | |
| download | dotfiles-d5142521687097211683e15e178d120ccf26d66b.tar.gz dotfiles-d5142521687097211683e15e178d120ccf26d66b.tar.xz | |
Go and find backlights... don't rely on pre-compiled information
| -rw-r--r-- | bin/Makefile | 9 | ||||
| -rw-r--r-- | bin/backlight.c | 35 |
2 files changed, 29 insertions, 15 deletions
diff --git a/bin/Makefile b/bin/Makefile index b0a8dd1..34d2d70 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -1,13 +1,14 @@ +WHEEL ?= wheel default: install install-zzz: zzz - install -D -o root -g root -m 755 zzz /sbin/ - chmod 6755 /sbin/zzz + install -D -o root -g $(WHEEL) -m 755 zzz /sbin/ + chmod 6750 /sbin/zzz install-linux: backlight - install -D -o root -g root -m 755 backlight /sbin/ - chmod 6755 /sbin/backlight + install -D -o root -g $(WHEEL) -m 755 backlight /sbin/ + chmod 6750 /sbin/backlight linux: install wpa $(HOME)/bin 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"); } } - - - - } |
