13 static int tty_fd = -1;
14 static enum {RAW, CANONICAL} ttystate = CANONICAL;
16 static int keyb_fd = -1;
20 if((tty_fd = open("/dev/tty", O_RDWR)) == -1) {
21 fprintf(stderr, "Cannot open /dev/tty : %s\n", strerror(errno));
27 if(tcgetattr(tty_fd, &buf) < 0) {
28 fprintf(stderr, "Cannot get the tty parameters : %s\n", strerror(errno));
32 buf.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
33 buf.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
34 buf.c_cflag &= ~(CSIZE | PARENB);
36 buf.c_oflag &= ~(OPOST);
40 if(tcsetattr(tty_fd, TCSAFLUSH, &buf) < 0) {
48 void destroy_keyboard()
52 buf.c_lflag |= (ECHO | ICANON | IEXTEN | ISIG);
53 buf.c_iflag |= (BRKINT | ICRNL | INPCK | ISTRIP | IXON);
54 buf.c_cflag |= (CSIZE | PARENB);
56 buf.c_oflag |= (OPOST);
71 void process_keyboard_event()
74 if(read(tty_fd, &key, 1) < 1) {
82 * - handle system-wide key combinations (alt-tab?)
83 * - otherwise send keypress/release to focused window