diff --git a/brightness-adjust b/brightness-adjust new file mode 100755 index 0000000..7f11e09 Binary files /dev/null and b/brightness-adjust differ diff --git a/brightness-adjust.c b/brightness-adjust.c new file mode 100644 index 0000000..76fc020 --- /dev/null +++ b/brightness-adjust.c @@ -0,0 +1,56 @@ +#include +#include + +#define ROOT_DIR "/sys/class/backlight/intel_backlight/" +#define BRIGHTNESS_STEP 750 + + +int main(int argc, char** argv) { + FILE* brightness = fopen(ROOT_DIR "brightness", "r+"); + if(brightness == NULL) { + perror("fopen"); + exit(EXIT_FAILURE); + } + + int current_brightness; + + int res = fscanf(brightness, "%d", ¤t_brightness); + if(res != 1) { + perror("fscanf"); + exit(EXIT_FAILURE); + } + + + if(argc != 2) { + fprintf(stderr, "Exactly one argument is required. Got %d arguments.\n", argc); + exit(EXIT_FAILURE); + } + + if(*argv[1] == '+') { + current_brightness+=BRIGHTNESS_STEP; + } else if(*argv[1] == '-') { + current_brightness-=BRIGHTNESS_STEP; + } else { + fprintf(stderr, "Argument must be '+' or '-', got %s.\n", argv[1]); + exit(EXIT_FAILURE); + } + + if(current_brightness < 0) + current_brightness = 0; + + rewind(brightness); + + if(!fprintf(brightness, "%d", current_brightness)) { + perror("fprintf"); + exit(EXIT_FAILURE); + } + + + if(fclose(brightness)) { + perror("fclose"); + exit(EXIT_FAILURE); + } + + return 0; + +} diff --git a/xmonad.hs b/xmonad.hs index 8f80d96..354946a 100644 --- a/xmonad.hs +++ b/xmonad.hs @@ -123,6 +123,9 @@ main = do , ((0, 0x1008ff15), spawn "clementine --stop") , ((0, 0x1008ff16), spawn "clementine --restart-or-previous") , ((0, 0x1008ff17), spawn "clementine --next") + -- Brightness buttons + , ((0, 0x1008ff02), spawn "~/.xmonad/brightness-adjust +") + , ((0, 0x1008ff03), spawn "~/.xmonad/brightness-adjust -") ] `additionalKeys` --