Mercurial > sdl-ios-xcode
annotate src/video/svga/SDL_svgaevents.c @ 1145:d31afac94eff
Patch from Martin Lange (mala-sdl at hotmail.com) to unregister SDL's win32
windowclass when shutting down the video subsystem...this allows you to
safely unload/reload the SDL shared library on Windows between
initializations.
Discussion is here:
http://www.devolution.com/pipermail/sdl/2005-February/067424.html
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 27 Sep 2005 09:00:42 +0000 |
parents | b8d311d90021 |
children | c9b51268668f |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
3 Copyright (C) 1997-2004 Sam Lantinga |
0 | 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 | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
75
diff
changeset
|
20 slouken@libsdl.org |
0 | 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> | |
75
b0ae59d0f3ee
Added patches from FreeBSD ports
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
31 #include <stdlib.h> |
0 | 32 |
33 #include <vga.h> | |
34 #include <vgamouse.h> | |
35 #include <vgakeyboard.h> | |
36 #if defined(linux) | |
37 #include <linux/kd.h> | |
38 #include <linux/keyboard.h> | |
39 #elif defined(__FreeBSD__) | |
40 #include <sys/kbio.h> | |
41 #else | |
42 #error You must choose your operating system here | |
43 #endif | |
44 | |
45 #include "SDL.h" | |
46 #include "SDL_sysevents.h" | |
47 #include "SDL_events_c.h" | |
48 #include "SDL_svgavideo.h" | |
49 #include "SDL_svgaevents_c.h" | |
50 | |
51 /* The translation tables from a console scancode to a SDL keysym */ | |
52 #if defined(linux) | |
53 #define NUM_VGAKEYMAPS (1<<KG_CAPSSHIFT) | |
54 static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS]; | |
55 #elif defined(__FreeBSD__) | |
56 /* FIXME: Free the keymap when we shut down the video mode */ | |
57 static keymap_t *vga_keymap = NULL; | |
58 #else | |
59 #error You must choose your operating system here | |
60 #endif | |
61 static SDLKey keymap[128]; | |
62 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym); | |
63 | |
64 /* Ugh, we have to duplicate the kernel's keysym mapping code... | |
65 Oh, it's not so bad. :-) | |
66 | |
67 FIXME: Add keyboard LED handling code | |
68 */ | |
69 #if defined(linux) | |
70 int SVGA_initkeymaps(int fd) | |
71 { | |
72 struct kbentry entry; | |
73 int map, i; | |
74 | |
75 /* Load all the keysym mappings */ | |
76 for ( map=0; map<NUM_VGAKEYMAPS; ++map ) { | |
77 memset(vga_keymap[map], 0, NR_KEYS*sizeof(Uint16)); | |
78 for ( i=0; i<NR_KEYS; ++i ) { | |
79 entry.kb_table = map; | |
80 entry.kb_index = i; | |
81 if ( ioctl(fd, KDGKBENT, &entry) == 0 ) { | |
82 /* The "Enter" key is a special case */ | |
83 if ( entry.kb_value == K_ENTER ) { | |
84 entry.kb_value = K(KT_ASCII,13); | |
85 } | |
86 /* Handle numpad specially as well */ | |
87 if ( KTYP(entry.kb_value) == KT_PAD ) { | |
88 switch ( entry.kb_value ) { | |
89 case K_P0: | |
90 case K_P1: | |
91 case K_P2: | |
92 case K_P3: | |
93 case K_P4: | |
94 case K_P5: | |
95 case K_P6: | |
96 case K_P7: | |
97 case K_P8: | |
98 case K_P9: | |
99 vga_keymap[map][i]=entry.kb_value; | |
100 vga_keymap[map][i]+= '0'; | |
101 break; | |
102 case K_PPLUS: | |
103 vga_keymap[map][i]=K(KT_ASCII,'+'); | |
104 break; | |
105 case K_PMINUS: | |
106 vga_keymap[map][i]=K(KT_ASCII,'-'); | |
107 break; | |
108 case K_PSTAR: | |
109 vga_keymap[map][i]=K(KT_ASCII,'*'); | |
110 break; | |
111 case K_PSLASH: | |
112 vga_keymap[map][i]=K(KT_ASCII,'/'); | |
113 break; | |
114 case K_PENTER: | |
115 vga_keymap[map][i]=K(KT_ASCII,'\r'); | |
116 break; | |
117 case K_PCOMMA: | |
118 vga_keymap[map][i]=K(KT_ASCII,','); | |
119 break; | |
120 case K_PDOT: | |
121 vga_keymap[map][i]=K(KT_ASCII,'.'); | |
122 break; | |
123 default: | |
124 break; | |
125 } | |
126 } | |
127 /* Do the normal key translation */ | |
128 if ( (KTYP(entry.kb_value) == KT_LATIN) || | |
129 (KTYP(entry.kb_value) == KT_ASCII) || | |
130 (KTYP(entry.kb_value) == KT_LETTER) ) { | |
131 vga_keymap[map][i] = entry.kb_value; | |
132 } | |
133 } | |
134 } | |
135 } | |
136 return(0); | |
137 } | |
138 #elif defined(__FreeBSD__) | |
139 int SVGA_initkeymaps(int fd) | |
140 { | |
141 vga_keymap = malloc(sizeof(keymap_t)); | |
142 if ( ! vga_keymap ) { | |
143 SDL_OutOfMemory(); | |
144 return(-1); | |
145 } | |
146 if (ioctl(fd, GIO_KEYMAP, vga_keymap) == -1) { | |
147 free(vga_keymap); | |
148 vga_keymap = NULL; | |
149 SDL_SetError("Unable to get keyboard map"); | |
150 return(-1); | |
151 } | |
152 return(0); | |
153 } | |
154 #else | |
155 #error You must choose your operating system here | |
156 #endif | |
157 | |
158 int posted = 0; | |
159 | |
160 void SVGA_mousecallback(int button, int dx, int dy, | |
161 int u1,int u2,int u3, int u4) | |
162 { | |
163 if ( dx || dy ) { | |
164 posted += SDL_PrivateMouseMotion(0, 1, dx, dy); | |
165 } | |
166 if ( button & MOUSE_LEFTBUTTON ) { | |
167 if ( !(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(1)) ) { | |
168 posted += SDL_PrivateMouseButton(SDL_PRESSED, 1, 0, 0); | |
169 } | |
170 } else { | |
171 if ( (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(1)) ) { | |
172 posted += SDL_PrivateMouseButton(SDL_RELEASED, 1, 0, 0); | |
173 } | |
174 } | |
175 if ( button & MOUSE_MIDDLEBUTTON ) { | |
176 if ( !(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(2)) ) { | |
177 posted += SDL_PrivateMouseButton(SDL_PRESSED, 2, 0, 0); | |
178 } | |
179 } else { | |
180 if ( (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(2)) ) { | |
181 posted += SDL_PrivateMouseButton(SDL_RELEASED, 2, 0, 0); | |
182 } | |
183 } | |
184 if ( button & MOUSE_RIGHTBUTTON ) { | |
185 if ( !(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(3)) ) { | |
186 posted += SDL_PrivateMouseButton(SDL_PRESSED, 3, 0, 0); | |
187 } | |
188 } else { | |
189 if ( (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(3)) ) { | |
190 posted += SDL_PrivateMouseButton(SDL_RELEASED, 3, 0, 0); | |
191 } | |
192 } | |
193 } | |
194 | |
195 void SVGA_keyboardcallback(int scancode, int pressed) | |
196 { | |
197 SDL_keysym keysym; | |
198 | |
199 if ( pressed ) { | |
200 posted += SDL_PrivateKeyboard(SDL_PRESSED, | |
201 TranslateKey(scancode, &keysym)); | |
202 } else { | |
203 posted += SDL_PrivateKeyboard(SDL_RELEASED, | |
204 TranslateKey(scancode, &keysym)); | |
205 } | |
206 } | |
207 | |
208 void SVGA_PumpEvents(_THIS) | |
209 { | |
210 do { | |
211 posted = 0; | |
212 mouse_update(); | |
213 keyboard_update(); | |
214 } while ( posted ); | |
215 } | |
216 | |
217 void SVGA_InitOSKeymap(_THIS) | |
218 { | |
219 int i; | |
220 | |
221 /* Initialize the BeOS key translation table */ | |
222 for ( i=0; i<SDL_TABLESIZE(keymap); ++i ) | |
223 keymap[i] = SDLK_UNKNOWN; | |
224 | |
225 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE; | |
226 keymap[SCANCODE_1] = SDLK_1; | |
227 keymap[SCANCODE_2] = SDLK_2; | |
228 keymap[SCANCODE_3] = SDLK_3; | |
229 keymap[SCANCODE_4] = SDLK_4; | |
230 keymap[SCANCODE_5] = SDLK_5; | |
231 keymap[SCANCODE_6] = SDLK_6; | |
232 keymap[SCANCODE_7] = SDLK_7; | |
233 keymap[SCANCODE_8] = SDLK_8; | |
234 keymap[SCANCODE_9] = SDLK_9; | |
235 keymap[SCANCODE_0] = SDLK_0; | |
236 keymap[SCANCODE_MINUS] = SDLK_MINUS; | |
237 keymap[SCANCODE_EQUAL] = SDLK_EQUALS; | |
238 keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE; | |
239 keymap[SCANCODE_TAB] = SDLK_TAB; | |
240 keymap[SCANCODE_Q] = SDLK_q; | |
241 keymap[SCANCODE_W] = SDLK_w; | |
242 keymap[SCANCODE_E] = SDLK_e; | |
243 keymap[SCANCODE_R] = SDLK_r; | |
244 keymap[SCANCODE_T] = SDLK_t; | |
245 keymap[SCANCODE_Y] = SDLK_y; | |
246 keymap[SCANCODE_U] = SDLK_u; | |
247 keymap[SCANCODE_I] = SDLK_i; | |
248 keymap[SCANCODE_O] = SDLK_o; | |
249 keymap[SCANCODE_P] = SDLK_p; | |
250 keymap[SCANCODE_BRACKET_LEFT] = SDLK_LEFTBRACKET; | |
251 keymap[SCANCODE_BRACKET_RIGHT] = SDLK_RIGHTBRACKET; | |
252 keymap[SCANCODE_ENTER] = SDLK_RETURN; | |
253 keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL; | |
254 keymap[SCANCODE_A] = SDLK_a; | |
255 keymap[SCANCODE_S] = SDLK_s; | |
256 keymap[SCANCODE_D] = SDLK_d; | |
257 keymap[SCANCODE_F] = SDLK_f; | |
258 keymap[SCANCODE_G] = SDLK_g; | |
259 keymap[SCANCODE_H] = SDLK_h; | |
260 keymap[SCANCODE_J] = SDLK_j; | |
261 keymap[SCANCODE_K] = SDLK_k; | |
262 keymap[SCANCODE_L] = SDLK_l; | |
263 keymap[SCANCODE_SEMICOLON] = SDLK_SEMICOLON; | |
264 keymap[SCANCODE_APOSTROPHE] = SDLK_QUOTE; | |
265 keymap[SCANCODE_GRAVE] = SDLK_BACKQUOTE; | |
266 keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT; | |
267 keymap[SCANCODE_BACKSLASH] = SDLK_BACKSLASH; | |
268 keymap[SCANCODE_Z] = SDLK_z; | |
269 keymap[SCANCODE_X] = SDLK_x; | |
270 keymap[SCANCODE_C] = SDLK_c; | |
271 keymap[SCANCODE_V] = SDLK_v; | |
272 keymap[SCANCODE_B] = SDLK_b; | |
273 keymap[SCANCODE_N] = SDLK_n; | |
274 keymap[SCANCODE_M] = SDLK_m; | |
275 keymap[SCANCODE_COMMA] = SDLK_COMMA; | |
276 keymap[SCANCODE_PERIOD] = SDLK_PERIOD; | |
277 keymap[SCANCODE_SLASH] = SDLK_SLASH; | |
278 keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT; | |
279 keymap[SCANCODE_KEYPADMULTIPLY] = SDLK_KP_MULTIPLY; | |
280 keymap[SCANCODE_LEFTALT] = SDLK_LALT; | |
281 keymap[SCANCODE_SPACE] = SDLK_SPACE; | |
282 keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK; | |
283 keymap[SCANCODE_F1] = SDLK_F1; | |
284 keymap[SCANCODE_F2] = SDLK_F2; | |
285 keymap[SCANCODE_F3] = SDLK_F3; | |
286 keymap[SCANCODE_F4] = SDLK_F4; | |
287 keymap[SCANCODE_F5] = SDLK_F5; | |
288 keymap[SCANCODE_F6] = SDLK_F6; | |
289 keymap[SCANCODE_F7] = SDLK_F7; | |
290 keymap[SCANCODE_F8] = SDLK_F8; | |
291 keymap[SCANCODE_F9] = SDLK_F9; | |
292 keymap[SCANCODE_F10] = SDLK_F10; | |
293 keymap[SCANCODE_NUMLOCK] = SDLK_NUMLOCK; | |
294 keymap[SCANCODE_SCROLLLOCK] = SDLK_SCROLLOCK; | |
295 keymap[SCANCODE_KEYPAD7] = SDLK_KP7; | |
296 keymap[SCANCODE_CURSORUPLEFT] = SDLK_KP7; | |
297 keymap[SCANCODE_KEYPAD8] = SDLK_KP8; | |
298 keymap[SCANCODE_CURSORUP] = SDLK_KP8; | |
299 keymap[SCANCODE_KEYPAD9] = SDLK_KP9; | |
300 keymap[SCANCODE_CURSORUPRIGHT] = SDLK_KP9; | |
301 keymap[SCANCODE_KEYPADMINUS] = SDLK_KP_MINUS; | |
302 keymap[SCANCODE_KEYPAD4] = SDLK_KP4; | |
303 keymap[SCANCODE_CURSORLEFT] = SDLK_KP4; | |
304 keymap[SCANCODE_KEYPAD5] = SDLK_KP5; | |
305 keymap[SCANCODE_KEYPAD6] = SDLK_KP6; | |
306 keymap[SCANCODE_CURSORRIGHT] = SDLK_KP6; | |
307 keymap[SCANCODE_KEYPADPLUS] = SDLK_KP_PLUS; | |
308 keymap[SCANCODE_KEYPAD1] = SDLK_KP1; | |
309 keymap[SCANCODE_CURSORDOWNLEFT] = SDLK_KP1; | |
310 keymap[SCANCODE_KEYPAD2] = SDLK_KP2; | |
311 keymap[SCANCODE_CURSORDOWN] = SDLK_KP2; | |
312 keymap[SCANCODE_KEYPAD3] = SDLK_KP3; | |
313 keymap[SCANCODE_CURSORDOWNRIGHT] = SDLK_KP3; | |
314 keymap[SCANCODE_KEYPAD0] = SDLK_KP0; | |
315 keymap[SCANCODE_KEYPADPERIOD] = SDLK_KP_PERIOD; | |
316 keymap[SCANCODE_LESS] = SDLK_LESS; | |
317 keymap[SCANCODE_F11] = SDLK_F11; | |
318 keymap[SCANCODE_F12] = SDLK_F12; | |
319 keymap[SCANCODE_KEYPADENTER] = SDLK_KP_ENTER; | |
320 keymap[SCANCODE_RIGHTCONTROL] = SDLK_RCTRL; | |
321 keymap[SCANCODE_CONTROL] = SDLK_RCTRL; | |
322 keymap[SCANCODE_KEYPADDIVIDE] = SDLK_KP_DIVIDE; | |
323 keymap[SCANCODE_PRINTSCREEN] = SDLK_PRINT; | |
324 keymap[SCANCODE_RIGHTALT] = SDLK_RALT; | |
325 keymap[SCANCODE_BREAK] = SDLK_BREAK; | |
326 keymap[SCANCODE_BREAK_ALTERNATIVE] = SDLK_UNKNOWN; | |
327 keymap[SCANCODE_HOME] = SDLK_HOME; | |
328 keymap[SCANCODE_CURSORBLOCKUP] = SDLK_UP; | |
329 keymap[SCANCODE_PAGEUP] = SDLK_PAGEUP; | |
330 keymap[SCANCODE_CURSORBLOCKLEFT] = SDLK_LEFT; | |
331 keymap[SCANCODE_CURSORBLOCKRIGHT] = SDLK_RIGHT; | |
332 keymap[SCANCODE_END] = SDLK_END; | |
333 keymap[SCANCODE_CURSORBLOCKDOWN] = SDLK_DOWN; | |
334 keymap[SCANCODE_PAGEDOWN] = SDLK_PAGEDOWN; | |
335 keymap[SCANCODE_INSERT] = SDLK_INSERT; | |
336 keymap[SCANCODE_REMOVE] = SDLK_DELETE; | |
337 keymap[119] = SDLK_PAUSE; | |
338 keymap[SCANCODE_RIGHTWIN] = SDLK_RSUPER; | |
339 keymap[SCANCODE_LEFTWIN] = SDLK_LSUPER; | |
340 keymap[127] = SDLK_MENU; | |
341 } | |
342 | |
343 #if defined(linux) | |
344 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym) | |
345 { | |
346 /* Set the keysym information */ | |
347 keysym->scancode = scancode; | |
348 keysym->sym = keymap[scancode]; | |
349 keysym->mod = KMOD_NONE; | |
350 | |
351 /* If UNICODE is on, get the UNICODE value for the key */ | |
352 keysym->unicode = 0; | |
353 if ( SDL_TranslateUNICODE ) { | |
354 int map; | |
355 SDLMod modstate; | |
356 | |
357 modstate = SDL_GetModState(); | |
358 map = 0; | |
359 if ( modstate & KMOD_SHIFT ) { | |
360 map |= (1<<KG_SHIFT); | |
361 } | |
362 if ( modstate & KMOD_CTRL ) { | |
363 map |= (1<<KG_CTRL); | |
364 } | |
365 if ( modstate & KMOD_ALT ) { | |
366 map |= (1<<KG_ALT); | |
367 } | |
368 if ( modstate & KMOD_MODE ) { | |
369 map |= (1<<KG_ALTGR); | |
370 } | |
371 if ( KTYP(vga_keymap[map][scancode]) == KT_LETTER ) { | |
372 if ( modstate & KMOD_CAPS ) { | |
373 map ^= (1<<KG_SHIFT); | |
374 } | |
375 } | |
376 if ( KTYP(vga_keymap[map][scancode]) == KT_PAD ) { | |
377 if ( modstate & KMOD_NUM ) { | |
378 keysym->unicode=KVAL(vga_keymap[map][scancode]); | |
379 } | |
380 } else { | |
381 keysym->unicode = KVAL(vga_keymap[map][scancode]); | |
382 } | |
383 } | |
384 return(keysym); | |
385 } | |
386 #elif defined(__FreeBSD__) | |
387 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym) | |
388 { | |
389 /* Set the keysym information */ | |
390 keysym->scancode = scancode; | |
391 keysym->sym = keymap[scancode]; | |
392 keysym->mod = KMOD_NONE; | |
393 | |
394 /* If UNICODE is on, get the UNICODE value for the key */ | |
395 keysym->unicode = 0; | |
396 if ( SDL_TranslateUNICODE && vga_keymap ) { | |
397 int map; | |
398 SDLMod modstate; | |
399 | |
400 modstate = SDL_GetModState(); | |
401 map = 0; | |
402 if ( modstate & KMOD_SHIFT ) { | |
403 map += 1; | |
404 } | |
405 if ( modstate & KMOD_CTRL ) { | |
406 map += 2; | |
407 } | |
408 if ( modstate & KMOD_ALT ) { | |
409 map += 4; | |
410 } | |
411 if ( !(vga_keymap->key[scancode].spcl & (0x80 >> map)) ) { | |
412 keysym->unicode = vga_keymap->key[scancode].map[map]; | |
413 } | |
414 | |
415 } | |
416 return(keysym); | |
417 } | |
418 #else | |
419 #error You must choose your operating system here | |
420 #endif |