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