19 enum {RAW, CANONICAL} ttystate;
22 static Keyboard *keyboard;
26 if(!(keyboard = (Keyboard*)sh_malloc(sizeof *keyboard))) {
30 keyboard->ttystate = keyboard->CANONICAL;
31 keyboard->dev_fd = -1;
33 if((keyboard->dev_fd = open("/dev/tty", O_RDWR)) == -1) {
34 fprintf(stderr, "Cannot open /dev/tty : %s\n", strerror(errno));
40 if(tcgetattr(keyboard->dev_fd, &buf) < 0) {
41 fprintf(stderr, "Cannot get the tty parameters : %s\n", strerror(errno));
45 buf.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
46 buf.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
47 buf.c_cflag &= ~(CSIZE | PARENB);
49 buf.c_oflag &= ~(OPOST);
51 if(tcsetattr(keyboard->dev_fd, TCSAFLUSH, &buf) < 0) {
55 keyboard->ttystate = keyboard->RAW;
59 void destroy_keyboard()
63 if(tcgetattr(keyboard->dev_fd, &buf) < 0) {
64 fprintf(stderr, "Cannot get the tty parameters : %s\n", strerror(errno));
67 buf.c_lflag |= (ECHO | ICANON | IEXTEN | ISIG);
68 buf.c_iflag |= (BRKINT | ICRNL | INPCK | ISTRIP | IXON);
69 buf.c_cflag |= (CSIZE | PARENB);
71 buf.c_oflag |= (OPOST);
73 if(tcsetattr(keyboard->dev_fd, TCSAFLUSH, &buf) < 0) {
74 fprintf(stderr, "Cannot set the tty parameters : %s\n", strerror(errno));
77 keyboard->ttystate = keyboard->CANONICAL;
79 if(keyboard->dev_fd != -1) {
80 close(keyboard->dev_fd);
81 keyboard->dev_fd = -1;
89 return keyboard->dev_fd;
92 void process_keyboard_event()
95 if(read(keyboard->dev_fd, &key, 1) < 1) {
103 Window *focused_win = wm->get_focused_window();
105 KeyboardFuncType keyb_callback = focused_win->get_keyboard_callback();
107 keyb_callback(focused_win, key, true); //TODO: true??
112 * - handle system-wide key combinations (alt-tab?)
113 * - otherwise send keypress/release to focused window
116 #endif // WINNIE_FBDEV