Compile the following C program as changebr
. You may have to change line 17 depending on your chipset (look in ls /sys/class/backlight/
).
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc < 2) {
fprintf(stderr, "Usage: %s <relative brightness>\n", argv[0]);
return 1;
} else {
size_t curbrend;
char curbr[17];
int curbri, relnum;
FILE *control;
relnum = atoi(argv[1]);
if ((control = fopen("/sys/class/backlight/intel_backlight/brightness", "r+")) == NULL) {
perror("fopen");
return 2;
}
curbrend = fread(curbr, sizeof(char), 16, control);
curbr[curbrend] = '\0';
curbri = atoi(curbr);
sprintf(curbr, "%d", curbri + relnum);
rewind(control);
fwrite(curbr, sizeof(char), 17, control);
fclose(control);
return 0;
}
}
Place it in /usr/local/bin/
and chown root:root /usr/local/bin/changebr
. Then make it setuid using chmod u+s /usr/local/bin/changebr
. Switch to your normal account and check if you can change the brightness by running changebr -1000
.
Install Xbindkeys and put the following in your ~/.xbindkeysrc
:
"changebr -1000"
XF86MonBrightnessDown
"changebr 1000"
XF86MonBrightnessUp
Reload the file using xbindkeys --poll-rc
and your brightness keys should work.