You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.0 KiB
57 lines
1.0 KiB
8 years ago
|
#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;
|
||
|
|
||
|
}
|