8 static struct termios orig_state;
9 static int term_fd = -1; /* tty file descriptor */
11 static void (*keyb_func)(int, int, void*);
12 static void *keyb_cls;
13 static void (*mbutton_func)(int, int, int, int, void*);
14 static void *mbutton_cls;
15 static void (*mmotion_func)(int, int, void*);
16 static void *mmotion_cls;
21 struct termios tstate;
23 if((term_fd = open("/dev/tty", O_RDWR)) == -1) {
24 perror("failed to open tty");
27 fcntl(term_fd, F_SETFL, fcntl(term_fd, F_GETFL) | O_NONBLOCK);
29 if(tcgetattr(term_fd, &tstate) == -1) {
30 perror("failed to retrieve tty attribs");
37 if(tcsetattr(term_fd, TCSANOW, &tstate) == -1) {
44 void fbev_shutdown(void)
47 tcsetattr(term_fd, TCSANOW, &orig_state);
53 void fbev_update(void)
59 while((sz = read(term_fd, buf, 64)) > 0) {
62 keyb_func(buf[i], 1, keyb_cls);
68 void fbev_keyboard(void (*func)(int, int, void*), void *cls)
74 void fbev_mbutton(void (*func)(int, int, int, int, void*), void *cls)
80 void fbev_mmotion(void (*func)(int, int, void*), void *cls)