18 enum {RAW, CANONICAL} ttystate;
21 static Keyboard *keyboard;
25 if(!(keyboard = (Keyboard*)malloc(sizeof *keyboard))) {
29 keyboard->ttystate = keyboard->CANONICAL;
30 keyboard->dev_fd = -1;
32 if((keyboard->dev_fd = open("/dev/tty", O_RDWR)) == -1) {
33 fprintf(stderr, "Cannot open /dev/tty : %s\n", strerror(errno));
39 if(tcgetattr(keyboard->dev_fd, &buf) < 0) {
40 fprintf(stderr, "Cannot get the tty parameters : %s\n", strerror(errno));
44 buf.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
45 buf.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
46 buf.c_cflag &= ~(CSIZE | PARENB);
48 buf.c_oflag &= ~(OPOST);
50 if(tcsetattr(keyboard->dev_fd, TCSAFLUSH, &buf) < 0) {
54 keyboard->ttystate = keyboard->RAW;
58 void destroy_keyboard()
62 if(tcgetattr(keyboard->dev_fd, &buf) < 0) {
63 fprintf(stderr, "Cannot get the tty parameters : %s\n", strerror(errno));
66 buf.c_lflag |= (ECHO | ICANON | IEXTEN | ISIG);
67 buf.c_iflag |= (BRKINT | ICRNL | INPCK | ISTRIP | IXON);
68 buf.c_cflag |= (CSIZE | PARENB);
70 buf.c_oflag |= (OPOST);
72 if(tcsetattr(keyboard->dev_fd, TCSAFLUSH, &buf) < 0) {
73 fprintf(stderr, "Cannot set the tty parameters : %s\n", strerror(errno));
76 keyboard->ttystate = keyboard->CANONICAL;
78 if(keyboard->dev_fd != -1) {
79 close(keyboard->dev_fd);
80 keyboard->dev_fd = -1;
88 return keyboard->dev_fd;
91 void process_keyboard_event()
94 if(read(keyboard->dev_fd, &key, 1) < 1) {
102 Window *focused_win = wm->get_focused_window();
104 KeyboardFuncType keyb_callback = focused_win->get_keyboard_callback();
106 keyb_callback(focused_win, key, true); //TODO: true??
111 * - handle system-wide key combinations (alt-tab?)
112 * - otherwise send keypress/release to focused window
115 #endif // WINNIE_FBDEV