2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SDL_config.h"
24 #include <sys/types.h>
25 #include <dev/wscons/wsdisplay_usl_io.h>
26 #include <sys/ioctl.h>
34 #include "../../events/SDL_sysevents.h"
35 #include "../../events/SDL_events_c.h"
36 #include "SDL_wsconsvideo.h"
37 #include "SDL_wsconsevents_c.h"
39 static int posted = 0;
41 int WSCONS_InitKeyboard(_THIS)
45 if (ioctl(private->fd, WSKBDIO_GTYPE, &private->kbdType) == -1) {
46 WSCONS_ReportError("cannot get keyboard type: %s", strerror(errno));
50 if (tcgetattr(private->fd, &private->saved_tty) == -1) {
51 WSCONS_ReportError("cannot get terminal attributes: %s", strerror(errno));
54 private->did_save_tty = 1;
55 tty = private->saved_tty;
56 tty.c_iflag = IGNPAR | IGNBRK;
58 tty.c_cflag = CREAD | CS8;
62 cfsetispeed(&tty, 9600);
63 cfsetospeed(&tty, 9600);
64 if (tcsetattr(private->fd, TCSANOW, &tty) < 0) {
65 WSCONS_ReportError("cannot set terminal attributes: %s", strerror(errno));
68 if (ioctl(private->fd, KDSKBMODE, K_RAW) == -1) {
69 WSCONS_ReportError("cannot set raw keyboard mode: %s", strerror(errno));
76 void WSCONS_ReleaseKeyboard(_THIS)
78 if (private->fd != -1) {
79 if (ioctl(private->fd, KDSKBMODE, K_XLATE) == -1) {
80 WSCONS_ReportError("cannot restore keyboard to translated mode: %s",
83 if (private->did_save_tty) {
84 if (tcsetattr(private->fd, TCSANOW, &private->saved_tty) < 0) {
85 WSCONS_ReportError("cannot restore keynoard attributes: %s",
92 static void updateMouse()
96 static SDLKey keymap[128];
98 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym)
100 keysym->scancode = scancode;
101 keysym->sym = SDLK_UNKNOWN;
102 keysym->mod = KMOD_NONE;
104 if (scancode < SDL_arraysize(keymap))
105 keysym->sym = keymap[scancode];
107 if (keysym->sym == SDLK_UNKNOWN)
108 printf("Unknown mapping for scancode %d\n", scancode);
113 static void updateKeyboard(_THIS)
115 unsigned char buf[100];
119 if ((n = read(private->fd, buf, sizeof(buf))) > 0) {
120 for (i = 0; i < n; i++) {
121 unsigned char c = buf[i] & 0x7f;
122 if (c == 224) // special key prefix -- what should we do with it?
124 posted += SDL_PrivateKeyboard((buf[i] & 0x80) ? SDL_RELEASED : SDL_PRESSED,
125 TranslateKey(c, &keysym));
130 void WSCONS_PumpEvents(_THIS)
135 updateKeyboard(this);
139 void WSCONS_InitOSKeymap(_THIS)
143 /* Make sure unknown keys are mapped correctly */
144 for (i=0; i < SDL_arraysize(keymap); i++) {
145 keymap[i] = SDLK_UNKNOWN;
148 switch (private->kbdType) {
149 #ifdef WSKBD_TYPE_ZAURUS
150 case WSKBD_TYPE_ZAURUS:
162 keymap[14] = SDLK_BACKSPACE;
177 keymap[15] = SDLK_TAB;
189 keymap[42] = SDLK_LSHIFT;
197 keymap[54] = SDLK_RSHIFT;
198 keymap[28] = SDLK_RETURN;
201 keymap[56] = SDLK_LALT;
202 keymap[29] = SDLK_LCTRL;
204 keymap[0] = SDLK_LSUPER;
205 keymap[12] = SDLK_MINUS;
206 keymap[57] = SDLK_SPACE;
207 keymap[51] = SDLK_COMMA;
208 keymap[52] = SDLK_PERIOD;
211 keymap[59] = SDLK_F1;
212 keymap[60] = SDLK_F2;
213 keymap[61] = SDLK_F3;
214 keymap[62] = SDLK_F4;
215 keymap[63] = SDLK_F5;
216 keymap[1] = SDLK_ESCAPE;
217 /* keymap[28] = SDLK_KP_ENTER; */
218 keymap[72] = SDLK_UP;
219 keymap[75] = SDLK_LEFT;
220 keymap[77] = SDLK_RIGHT;
221 keymap[80] = SDLK_DOWN;
223 #endif /* WSKBD_TYPE_ZAURUS */
226 WSCONS_ReportError("Unable to map keys for keyboard type %u",
232 /* end of SDL_wsconsevents.c ... */