2 winnie - an experimental window system
4 Copyright (C) 2013 Eleni Maria Stea
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 Author: Eleni Maria Stea <elene.mst@gmail.com>
29 #include <sys/ioctl.h>
41 enum {RAW, CANONICAL} ttystate;
44 static Keyboard *keyboard;
48 if(!(keyboard = (Keyboard*)sh_malloc(sizeof *keyboard))) {
52 get_subsys()->keyboard_offset = (int)((char*)keyboard - (char*)get_pool());
54 keyboard->ttystate = keyboard->CANONICAL;
55 keyboard->dev_fd = -1;
57 if((keyboard->dev_fd = open("/dev/tty", O_RDWR)) == -1) {
58 fprintf(stderr, "Cannot open /dev/tty : %s\n", strerror(errno));
64 if(tcgetattr(keyboard->dev_fd, &buf) < 0) {
65 fprintf(stderr, "Cannot get the tty parameters : %s\n", strerror(errno));
69 buf.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
70 buf.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
71 buf.c_cflag &= ~(CSIZE | PARENB);
73 buf.c_oflag &= ~(OPOST);
75 if(tcsetattr(keyboard->dev_fd, TCSAFLUSH, &buf) < 0) {
79 keyboard->ttystate = keyboard->RAW;
83 void destroy_keyboard()
87 if(tcgetattr(keyboard->dev_fd, &buf) < 0) {
88 fprintf(stderr, "Cannot get the tty parameters : %s\n", strerror(errno));
91 buf.c_lflag |= (ECHO | ICANON | IEXTEN | ISIG);
92 buf.c_iflag |= (BRKINT | ICRNL | INPCK | ISTRIP | IXON);
93 buf.c_cflag |= (CSIZE | PARENB);
95 buf.c_oflag |= (OPOST);
97 if(tcsetattr(keyboard->dev_fd, TCSAFLUSH, &buf) < 0) {
98 fprintf(stderr, "Cannot set the tty parameters : %s\n", strerror(errno));
101 keyboard->ttystate = keyboard->CANONICAL;
103 if(keyboard->dev_fd != -1) {
104 close(keyboard->dev_fd);
105 keyboard->dev_fd = -1;
111 bool client_open_keyboard(void *smem_start, int offset)
113 keyboard = (Keyboard*)((unsigned char*)smem_start + offset);
117 void client_close_keyboard()
121 int get_keyboard_fd()
123 return keyboard->dev_fd;
126 void process_keyboard_event()
129 if(read(keyboard->dev_fd, &key, 1) < 1) {
137 Window *focused_win = wm->get_focused_window();
139 KeyboardFuncType keyb_callback = focused_win->get_keyboard_callback();
141 keyb_callback(focused_win, key, true); //TODO: true??
146 * - handle system-wide key combinations (alt-tab?)
147 * - otherwise send keypress/release to focused window
150 #endif // WINNIE_FBDEV