X-Git-Url: http://git.mutantstargoat.com?p=winnie;a=blobdiff_plain;f=src%2Fkeyboard.cc;h=810607a2ad08485dda72c5ec119635adb4c19a5e;hp=8933d4282c39a96cde761a808f3daaf8e1ac28b6;hb=ffd2c0a0f8b898cb4199a0c63aff255a85cc0f11;hpb=f71618aebfa6b8754dd056689a6c5821b755972c diff --git a/src/keyboard.cc b/src/keyboard.cc index 8933d42..810607a 100644 --- a/src/keyboard.cc +++ b/src/keyboard.cc @@ -9,22 +9,22 @@ #include #include "keyboard.h" +#include "window.h" +#include "wm.h" -static int tty_fd = -1; +static int dev_fd = -1; static enum {RAW, CANONICAL} ttystate = CANONICAL; -static int keyb_fd = -1; - bool init_keyboard() { - if((tty_fd = open("/dev/tty", O_RDWR)) == -1) { + if((dev_fd = open("/dev/tty", O_RDWR)) == -1) { fprintf(stderr, "Cannot open /dev/tty : %s\n", strerror(errno)); return false; } struct termios buf; - if(tcgetattr(tty_fd, &buf) < 0) { + if(tcgetattr(dev_fd, &buf) < 0) { fprintf(stderr, "Cannot get the tty parameters : %s\n", strerror(errno)); return false; } @@ -34,10 +34,8 @@ bool init_keyboard() buf.c_cflag &= ~(CSIZE | PARENB); buf.c_cflag |= CS8; buf.c_oflag &= ~(OPOST); - buf.c_cc[VMIN] = 1; - buf.c_cc[VTIME] = 0; - if(tcsetattr(tty_fd, TCSAFLUSH, &buf) < 0) { + if(tcsetattr(dev_fd, TCSAFLUSH, &buf) < 0) { return false; } @@ -49,35 +47,50 @@ void destroy_keyboard() { struct termios buf; + if(tcgetattr(dev_fd, &buf) < 0) { + fprintf(stderr, "Cannot get the tty parameters : %s\n", strerror(errno)); + } + buf.c_lflag |= (ECHO | ICANON | IEXTEN | ISIG); buf.c_iflag |= (BRKINT | ICRNL | INPCK | ISTRIP | IXON); buf.c_cflag |= (CSIZE | PARENB); buf.c_cflag &= CS8; buf.c_oflag |= (OPOST); - buf.c_cc[VMIN] = 1; - buf.c_cc[VTIME] = 0; + + if(tcsetattr(dev_fd, TCSAFLUSH, &buf) < 0) { + fprintf(stderr, "Cannot set the tty parameters : %s\n", strerror(errno)); + } ttystate = CANONICAL; - close(tty_fd); + close(dev_fd); - tty_fd = -1; + dev_fd = -1; } int get_keyboard_fd() { - return tty_fd; + return dev_fd; } void process_keyboard_event() { char key; - if(read(tty_fd, &key, 1) < 1) { + if(read(dev_fd, &key, 1) < 1) { return; } if(key == 'q') { exit(0); } + + Window *focused_win = wm->get_focused_window(); + if(focused_win) { + KeyboardFuncType keyb_callback = focused_win->get_keyboard_callback(); + if(keyb_callback) { + keyb_callback(focused_win, key, true); + } + } + /* TODO: * - handle system-wide key combinations (alt-tab?) * - otherwise send keypress/release to focused window