--- /dev/null
+#include <math.h>
+#include <stdio.h>
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <linux/input.h>
+
+static void screenlight(int up)
+{
+ static const char *path = "/sys/class/backlight/gmux_backlight/brightness";
+ static int prev, next, tmp;
+ static double val;
+ static FILE *fd;
+
+ // Open brightness file
+ if (fd == NULL)
+ fd = fopen(path, "r+");
+ if (fd == NULL) {
+ printf("error opening file\n");
+ return;
+ }
+
+ // Reset if someone else changed the value
+ fseek(fd, 0, SEEK_SET);
+ fscanf(fd, "%d", &tmp);
+ if (tmp != prev)
+ val = pow(tmp/1024.0, 1/10.0);
+ //if (tmp != prev)
+ // printf("convert: %d -> %d -> %f\n",
+ // prev, tmp, val);
+
+ // Update the current value
+ val += 0.01 * (up?1:-1);
+ if (val < 0) val = 0;
+ if (val > 1) val = 1;
+
+ // Write it back to the file
+ next = pow(val, 10) * 1024;
+ if (next == prev)
+ next += (up?1:-1);
+ else
+ prev = next;
+
+ //printf("saving: %d\n", next);
+ fprintf(fd, "%d", next);
+ fflush(fd);
+}
+
+static void keylight(int up)
+{
+ //static const char *path = "/sys/class/leds/smc::kbd_backlight/brightness";
+}
+
+int main(int argc, char **argv)
+{
+ struct input_event ev;
+ int fd, len, debug=0;
+
+ //if ((fd = open("/dev/input/event4", O_RDONLY)) < 0) {
+ //if ((fd = open("/dev/input/event6", O_RDONLY)) < 0) {
+ if ((fd = open("/dev/input/event10", O_RDONLY)) < 0) {
+ printf("Error\n");
+ return 0;
+ }
+
+ while ((len = read(fd, &ev, sizeof(ev)))) {
+ if (len != sizeof(ev)) {
+ printf("Error\n");
+ sleep(1);
+ continue;
+ }
+
+ if (debug) {
+ printf("%ld.%06lu: type=%04hx code=%04hx val=%08x\n",
+ ev.time.tv_sec,
+ ev.time.tv_usec,
+ ev.type, ev.code, ev.value);
+ fflush(stdout);
+ }
+
+ if (ev.type != EV_KEY)
+ continue;
+ if (ev.value == 0) // key up
+ continue;
+
+ switch (ev.code) {
+ case KEY_BRIGHTNESSDOWN:
+ screenlight(0);
+ break;
+ case KEY_BRIGHTNESSUP:
+ screenlight(1);
+ break;
+ case KEY_KBDILLUMDOWN:
+ keylight(0);
+ break;
+ case KEY_KBDILLUMUP:
+ keylight(1);
+ break;
+ }
+ fflush(stdout);
+ }
+ return 0;
+}