Mercurial > sdl-ios-xcode
comparison src/video/vgl/SDL_vglevents.c @ 75:b0ae59d0f3ee
Added patches from FreeBSD ports
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Tue, 19 Jun 2001 13:33:54 +0000 |
parents | |
children | e8157fcb3114 |
comparison
equal
deleted
inserted
replaced
74:6e28dae59e3b | 75:b0ae59d0f3ee |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
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 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@devolution.com | |
21 */ | |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* Handle the event stream, converting X11 events into SDL events */ | |
29 | |
30 #include <stdio.h> | |
31 | |
32 #include <sys/fbio.h> | |
33 #include <sys/consio.h> | |
34 #include <sys/kbio.h> | |
35 #include <vgl.h> | |
36 | |
37 #include "SDL.h" | |
38 #include "SDL_thread.h" | |
39 #include "SDL_sysevents.h" | |
40 #include "SDL_events_c.h" | |
41 #include "SDL_vglvideo.h" | |
42 #include "SDL_vglevents_c.h" | |
43 | |
44 /* The translation tables from a console scancode to a SDL keysym */ | |
45 /* FIXME: Free the keymap when we shut down the video mode */ | |
46 static keymap_t *vga_keymap = NULL; | |
47 static SDLKey keymap[128]; | |
48 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym); | |
49 | |
50 static int posted = 0; | |
51 static int oldx = -1; | |
52 static int oldy = -1; | |
53 static struct mouse_info mouseinfo; | |
54 | |
55 /* Ugh, we have to duplicate the kernel's keysym mapping code... | |
56 Oh, it's not so bad. :-) | |
57 | |
58 FIXME: Add keyboard LED handling code | |
59 */ | |
60 int VGL_initkeymaps(int fd) | |
61 { | |
62 vga_keymap = malloc(sizeof(keymap_t)); | |
63 if ( ! vga_keymap ) { | |
64 SDL_OutOfMemory(); | |
65 return(-1); | |
66 } | |
67 if (ioctl(fd, GIO_KEYMAP, vga_keymap) == -1) { | |
68 free(vga_keymap); | |
69 vga_keymap = NULL; | |
70 SDL_SetError("Unable to get keyboard map"); | |
71 return(-1); | |
72 } | |
73 return(0); | |
74 } | |
75 | |
76 static void handle_keyboard(_THIS) | |
77 { | |
78 SDL_keysym keysym; | |
79 int c, pressed, scancode; | |
80 | |
81 while ((c = VGLKeyboardGetCh()) != 0) { | |
82 scancode = c & 0x7F; | |
83 if (c & 0x80) { | |
84 pressed = SDL_RELEASED; | |
85 } else { | |
86 pressed = SDL_PRESSED; | |
87 } | |
88 | |
89 posted += SDL_PrivateKeyboard(pressed, | |
90 TranslateKey(scancode, &keysym)); | |
91 } | |
92 } | |
93 | |
94 int VGL_initmouse(int fd) | |
95 { | |
96 mouseinfo.operation = MOUSE_GETINFO; | |
97 if (ioctl(fd, CONS_MOUSECTL, &mouseinfo) != 0) | |
98 return -1; | |
99 | |
100 return 0; | |
101 } | |
102 | |
103 static void handle_mouse(_THIS) | |
104 { | |
105 char buttons; | |
106 int x, y; | |
107 int button_state, state_changed, state; | |
108 int i; | |
109 | |
110 ioctl(0, CONS_MOUSECTL, &mouseinfo); | |
111 x = mouseinfo.u.data.x; | |
112 y = mouseinfo.u.data.y; | |
113 buttons = mouseinfo.u.data.buttons; | |
114 | |
115 if ((x != oldx) || (y != oldy)) { | |
116 posted += SDL_PrivateMouseMotion(0, 0, x, y); | |
117 oldx = x; | |
118 oldy = y; | |
119 } | |
120 | |
121 /* See what's changed */ | |
122 button_state = SDL_GetMouseState(NULL, NULL); | |
123 state_changed = button_state ^ buttons; | |
124 for (i = 0; i < 8; i++) { | |
125 if (state_changed & (1<<i)) { | |
126 if (buttons & (1<<i)) { | |
127 state = SDL_PRESSED; | |
128 } else { | |
129 state = SDL_RELEASED; | |
130 } | |
131 posted += SDL_PrivateMouseButton(state, i + 1, 0, 0); | |
132 } | |
133 } | |
134 } | |
135 | |
136 | |
137 void VGL_PumpEvents(_THIS) | |
138 { | |
139 do { | |
140 posted = 0; | |
141 handle_keyboard(this); | |
142 handle_mouse(this); | |
143 } while (posted != 0); | |
144 } | |
145 | |
146 void VGL_InitOSKeymap(_THIS) | |
147 { | |
148 int i; | |
149 | |
150 /* Initialize the BeOS key translation table */ | |
151 for ( i=0; i<SDL_TABLESIZE(keymap); ++i ) | |
152 keymap[i] = SDLK_UNKNOWN; | |
153 | |
154 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE; | |
155 keymap[SCANCODE_1] = SDLK_1; | |
156 keymap[SCANCODE_2] = SDLK_2; | |
157 keymap[SCANCODE_3] = SDLK_3; | |
158 keymap[SCANCODE_4] = SDLK_4; | |
159 keymap[SCANCODE_5] = SDLK_5; | |
160 keymap[SCANCODE_6] = SDLK_6; | |
161 keymap[SCANCODE_7] = SDLK_7; | |
162 keymap[SCANCODE_8] = SDLK_8; | |
163 keymap[SCANCODE_9] = SDLK_9; | |
164 keymap[SCANCODE_0] = SDLK_0; | |
165 keymap[SCANCODE_MINUS] = SDLK_MINUS; | |
166 keymap[SCANCODE_EQUAL] = SDLK_EQUALS; | |
167 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE; | |
168 keymap[SCANCODE_TAB] = SDLK_TAB; | |
169 keymap[SCANCODE_Q] = SDLK_q; | |
170 keymap[SCANCODE_W] = SDLK_w; | |
171 keymap[SCANCODE_E] = SDLK_e; | |
172 keymap[SCANCODE_R] = SDLK_r; | |
173 keymap[SCANCODE_T] = SDLK_t; | |
174 keymap[SCANCODE_Y] = SDLK_y; | |
175 keymap[SCANCODE_U] = SDLK_u; | |
176 keymap[SCANCODE_I] = SDLK_i; | |
177 keymap[SCANCODE_O] = SDLK_o; | |
178 keymap[SCANCODE_P] = SDLK_p; | |
179 keymap[SCANCODE_BRACKET_LEFT] = SDLK_LEFTBRACKET; | |
180 keymap[SCANCODE_BRACKET_RIGHT] = SDLK_RIGHTBRACKET; | |
181 keymap[SCANCODE_ENTER] = SDLK_RETURN; | |
182 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL; | |
183 keymap[SCANCODE_A] = SDLK_a; | |
184 keymap[SCANCODE_S] = SDLK_s; | |
185 keymap[SCANCODE_D] = SDLK_d; | |
186 keymap[SCANCODE_F] = SDLK_f; | |
187 keymap[SCANCODE_G] = SDLK_g; | |
188 keymap[SCANCODE_H] = SDLK_h; | |
189 keymap[SCANCODE_J] = SDLK_j; | |
190 keymap[SCANCODE_K] = SDLK_k; | |
191 keymap[SCANCODE_L] = SDLK_l; | |
192 keymap[SCANCODE_SEMICOLON] = SDLK_SEMICOLON; | |
193 keymap[SCANCODE_APOSTROPHE] = SDLK_QUOTE; | |
194 keymap[SCANCODE_GRAVE] = SDLK_BACKQUOTE; | |
195 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT; | |
196 keymap[SCANCODE_BACKSLASH] = SDLK_BACKSLASH; | |
197 keymap[SCANCODE_Z] = SDLK_z; | |
198 keymap[SCANCODE_X] = SDLK_x; | |
199 keymap[SCANCODE_C] = SDLK_c; | |
200 keymap[SCANCODE_V] = SDLK_v; | |
201 keymap[SCANCODE_B] = SDLK_b; | |
202 keymap[SCANCODE_N] = SDLK_n; | |
203 keymap[SCANCODE_M] = SDLK_m; | |
204 keymap[SCANCODE_COMMA] = SDLK_COMMA; | |
205 keymap[SCANCODE_PERIOD] = SDLK_PERIOD; | |
206 keymap[SCANCODE_SLASH] = SDLK_SLASH; | |
207 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT; | |
208 keymap[SCANCODE_KEYPADMULTIPLY] = SDLK_KP_MULTIPLY; | |
209 keymap[SCANCODE_LEFTALT] = SDLK_LALT; | |
210 keymap[SCANCODE_SPACE] = SDLK_SPACE; | |
211 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK; | |
212 keymap[SCANCODE_F1] = SDLK_F1; | |
213 keymap[SCANCODE_F2] = SDLK_F2; | |
214 keymap[SCANCODE_F3] = SDLK_F3; | |
215 keymap[SCANCODE_F4] = SDLK_F4; | |
216 keymap[SCANCODE_F5] = SDLK_F5; | |
217 keymap[SCANCODE_F6] = SDLK_F6; | |
218 keymap[SCANCODE_F7] = SDLK_F7; | |
219 keymap[SCANCODE_F8] = SDLK_F8; | |
220 keymap[SCANCODE_F9] = SDLK_F9; | |
221 keymap[SCANCODE_F10] = SDLK_F10; | |
222 keymap[SCANCODE_NUMLOCK] = SDLK_NUMLOCK; | |
223 keymap[SCANCODE_SCROLLLOCK] = SDLK_SCROLLOCK; | |
224 keymap[SCANCODE_KEYPAD7] = SDLK_KP7; | |
225 keymap[SCANCODE_CURSORUPLEFT] = SDLK_KP7; | |
226 keymap[SCANCODE_KEYPAD8] = SDLK_KP8; | |
227 keymap[SCANCODE_CURSORUP] = SDLK_KP8; | |
228 keymap[SCANCODE_KEYPAD9] = SDLK_KP9; | |
229 keymap[SCANCODE_CURSORUPRIGHT] = SDLK_KP9; | |
230 keymap[SCANCODE_KEYPADMINUS] = SDLK_KP_MINUS; | |
231 keymap[SCANCODE_KEYPAD4] = SDLK_KP4; | |
232 keymap[SCANCODE_CURSORLEFT] = SDLK_KP4; | |
233 keymap[SCANCODE_KEYPAD5] = SDLK_KP5; | |
234 keymap[SCANCODE_KEYPAD6] = SDLK_KP6; | |
235 keymap[SCANCODE_CURSORRIGHT] = SDLK_KP6; | |
236 keymap[SCANCODE_KEYPADPLUS] = SDLK_KP_PLUS; | |
237 keymap[SCANCODE_KEYPAD1] = SDLK_KP1; | |
238 keymap[SCANCODE_CURSORDOWNLEFT] = SDLK_KP1; | |
239 keymap[SCANCODE_KEYPAD2] = SDLK_KP2; | |
240 keymap[SCANCODE_CURSORDOWN] = SDLK_KP2; | |
241 keymap[SCANCODE_KEYPAD3] = SDLK_KP3; | |
242 keymap[SCANCODE_CURSORDOWNRIGHT] = SDLK_KP3; | |
243 keymap[SCANCODE_KEYPAD0] = SDLK_KP0; | |
244 keymap[SCANCODE_KEYPADPERIOD] = SDLK_KP_PERIOD; | |
245 keymap[SCANCODE_LESS] = SDLK_LESS; | |
246 keymap[SCANCODE_F11] = SDLK_F11; | |
247 keymap[SCANCODE_F12] = SDLK_F12; | |
248 keymap[SCANCODE_KEYPADENTER] = SDLK_KP_ENTER; | |
249 keymap[SCANCODE_RIGHTCONTROL] = SDLK_RCTRL; | |
250 keymap[SCANCODE_CONTROL] = SDLK_RCTRL; | |
251 keymap[SCANCODE_KEYPADDIVIDE] = SDLK_KP_DIVIDE; | |
252 keymap[SCANCODE_PRINTSCREEN] = SDLK_PRINT; | |
253 keymap[SCANCODE_RIGHTALT] = SDLK_RALT; | |
254 keymap[SCANCODE_BREAK] = SDLK_BREAK; | |
255 keymap[SCANCODE_BREAK_ALTERNATIVE] = SDLK_UNKNOWN; | |
256 keymap[SCANCODE_HOME] = SDLK_HOME; | |
257 keymap[SCANCODE_CURSORBLOCKUP] = SDLK_UP; | |
258 keymap[SCANCODE_PAGEUP] = SDLK_PAGEUP; | |
259 keymap[SCANCODE_CURSORBLOCKLEFT] = SDLK_LEFT; | |
260 keymap[SCANCODE_CURSORBLOCKRIGHT] = SDLK_RIGHT; | |
261 keymap[SCANCODE_END] = SDLK_END; | |
262 keymap[SCANCODE_CURSORBLOCKDOWN] = SDLK_DOWN; | |
263 keymap[SCANCODE_PAGEDOWN] = SDLK_PAGEDOWN; | |
264 keymap[SCANCODE_INSERT] = SDLK_INSERT; | |
265 keymap[SCANCODE_REMOVE] = SDLK_DELETE; | |
266 keymap[119] = SDLK_PAUSE; | |
267 keymap[SCANCODE_RIGHTWIN] = SDLK_RSUPER; | |
268 keymap[SCANCODE_LEFTWIN] = SDLK_LSUPER; | |
269 keymap[127] = SDLK_MENU; | |
270 } | |
271 | |
272 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym) | |
273 { | |
274 /* Set the keysym information */ | |
275 keysym->scancode = scancode; | |
276 keysym->sym = keymap[scancode]; | |
277 keysym->mod = KMOD_NONE; | |
278 | |
279 /* If UNICODE is on, get the UNICODE value for the key */ | |
280 keysym->unicode = 0; | |
281 if ( SDL_TranslateUNICODE && vga_keymap ) { | |
282 int map; | |
283 SDLMod modstate; | |
284 | |
285 modstate = SDL_GetModState(); | |
286 map = 0; | |
287 if ( modstate & KMOD_SHIFT ) { | |
288 map += 1; | |
289 } | |
290 if ( modstate & KMOD_CTRL ) { | |
291 map += 2; | |
292 } | |
293 if ( modstate & KMOD_ALT ) { | |
294 map += 4; | |
295 } | |
296 if ( !(vga_keymap->key[scancode].spcl & (0x80 >> map)) ) { | |
297 keysym->unicode = vga_keymap->key[scancode].map[map]; | |
298 } | |
299 | |
300 } | |
301 return(keysym); | |
302 } | |
303 |