#include #include #define PATH "/sys/devices/pci0000:00/0000:00:02.0/config" #define STEP 24 /* Written by Krzysztof Sielużycki, KSieluzycki@gmail.com !!! Use at your own risk !!! How to install: 1) adjust PATH. You can check your device address by running lspci 2) compile: gcc bright.c -o b of course you can use any desired name instead of b ;) 3) change owner to root: chown root:root b 4) set suid (app require root privileges): chmod +s b 5) move to /usr/bin: mv b /usr/bin/b 6) adjust key shortcuts in your window manager. For example, in gnome, it's in start->system->preferences. Create one shortcut for /usr/bin/d u, and another one for /usr/bin/b d Usage: b u - increase brightness by STEP value b d - decrease by STEP value b s - show brightness level b x - set brightness to value x, where x is a integer between 0 and 255. 0 means backlight off. */ signed int check_level() { int current_level; FILE * cfg; cfg=fopen(PATH,"rb"); if(cfg) { fseek(cfg,244,0); current_level=fgetc(cfg); fclose(cfg); return current_level; } else {return -1;} } signed int set_level(int value) { if(value<0 || value>255) { printf("Error\n"); return -1; } FILE * cfg; cfg=fopen(PATH,"r+b"); if(cfg) { fseek(cfg,244,0); fputc(value,cfg); fclose(cfg); return 0; } else {return -1;} } int main(int argc, char * argv[]) { int current_level=3; if(argc!=1) { if((current_level=check_level())!=-1) { if(*argv[1]=='u') { if(current_level<255-STEP) { if(set_level(current_level+STEP)==-1) { printf("Error setting level.\n"); } } else {printf("%s\n","Maximum reached");} } else if(*argv[1]=='d') { if(current_level>0+STEP) { if(set_level(current_level-STEP)==-1) { printf("Error setting level.\n"); } } else {printf("%s\n","Minimum reached");} } else if(*argv[1]=='s') { printf("%s%d\n","Current brightness level: ",current_level); } else if(*argv[1]=='x' && argc>2) { set_level(atoi(argv[2])); } else {printf("Invalid argument\n");} } else { printf("%s\n","Error checking brightness level."); } } else { printf("%s\n","Usage: b [u|d|s|x]"); } return 0; }