parent
cb9da78ece
commit
b3fcc5c1ab
Binary file not shown.
@ -0,0 +1,56 @@ |
|||||||
|
#include <stdio.h> |
||||||
|
#include <stdlib.h> |
||||||
|
|
||||||
|
#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; |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue