15 static int dev_fd = -1;
16 static enum {RAW, CANONICAL} ttystate = CANONICAL;
20 if((dev_fd = open("/dev/tty", O_RDWR)) == -1) {
21 fprintf(stderr, "Cannot open /dev/tty : %s\n", strerror(errno));
27 if(tcgetattr(dev_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);
38 if(tcsetattr(dev_fd, TCSAFLUSH, &buf) < 0) {
46 void destroy_keyboard()
50 if(tcgetattr(dev_fd, &buf) < 0) {
51 fprintf(stderr, "Cannot get the tty parameters : %s\n", strerror(errno));
54 buf.c_lflag |= (ECHO | ICANON | IEXTEN | ISIG);
55 buf.c_iflag |= (BRKINT | ICRNL | INPCK | ISTRIP | IXON);
56 buf.c_cflag |= (CSIZE | PARENB);
58 buf.c_oflag |= (OPOST);
60 if(tcsetattr(dev_fd, TCSAFLUSH, &buf) < 0) {
61 fprintf(stderr, "Cannot set the tty parameters : %s\n", strerror(errno));
77 void process_keyboard_event()
80 if(read(dev_fd, &key, 1) < 1) {
88 Window *focused_win = wm->get_focused_window();
90 KeyboardFuncType keyb_callback = focused_win->get_keyboard_callback();
92 keyb_callback(focused_win, key, true);
97 * - handle system-wide key combinations (alt-tab?)
98 * - otherwise send keypress/release to focused window