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