Mercurial > sdl-ios-xcode
annotate src/video/fbcon/SDL_fbevents.c @ 59:b685c94f8db7
Ryan's IMPS/2 mouse fix
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Mon, 11 Jun 2001 15:48:32 +0000 |
parents | 4f6c5f021323 |
children | e093bbc72ab9 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 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 console events into SDL events */ | |
29 | |
30 #include <sys/types.h> | |
31 #include <sys/time.h> | |
32 #include <sys/ioctl.h> | |
33 #include <stdlib.h> | |
34 #include <stdio.h> | |
35 #include <unistd.h> | |
36 #include <fcntl.h> | |
37 #include <string.h> | |
38 #include <errno.h> | |
39 #include <limits.h> | |
40 | |
41 /* For parsing /proc */ | |
42 #include <dirent.h> | |
43 #include <ctype.h> | |
44 | |
45 #include <linux/vt.h> | |
46 #include <linux/kd.h> | |
47 #include <linux/keyboard.h> | |
48 | |
49 #include "SDL.h" | |
50 #include "SDL_mutex.h" | |
51 #include "SDL_sysevents.h" | |
52 #include "SDL_sysvideo.h" | |
53 #include "SDL_events_c.h" | |
54 #include "SDL_fbvideo.h" | |
55 #include "SDL_fbevents_c.h" | |
56 #include "SDL_fbkeys.h" | |
57 | |
58 #include "SDL_fbelo.h" | |
59 | |
60 #ifndef GPM_NODE_FIFO | |
61 #define GPM_NODE_FIFO "/dev/gpmdata" | |
62 #endif | |
63 | |
64 | |
65 /* The translation tables from a console scancode to a SDL keysym */ | |
66 #define NUM_VGAKEYMAPS (1<<KG_CAPSSHIFT) | |
67 static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS]; | |
68 static SDLKey keymap[128]; | |
69 static Uint16 keymap_temp[128]; /* only used at startup */ | |
70 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym); | |
71 | |
72 /* Ugh, we have to duplicate the kernel's keysym mapping code... | |
73 Oh, it's not so bad. :-) | |
74 | |
75 FIXME: Add keyboard LED handling code | |
76 */ | |
77 static void FB_vgainitkeymaps(int fd) | |
78 { | |
79 struct kbentry entry; | |
80 int map, i; | |
81 | |
82 /* Don't do anything if we are passed a closed keyboard */ | |
83 if ( fd < 0 ) { | |
84 return; | |
85 } | |
86 | |
87 /* Load all the keysym mappings */ | |
88 for ( map=0; map<NUM_VGAKEYMAPS; ++map ) { | |
89 memset(vga_keymap[map], 0, NR_KEYS*sizeof(Uint16)); | |
90 for ( i=0; i<NR_KEYS; ++i ) { | |
91 entry.kb_table = map; | |
92 entry.kb_index = i; | |
93 if ( ioctl(fd, KDGKBENT, &entry) == 0 ) { | |
94 /* fill keytemp. This replaces SDL_fbkeys.h */ | |
95 if ( (map == 0) && (i<128) ) { | |
96 keymap_temp[i] = entry.kb_value; | |
97 } | |
98 /* The "Enter" key is a special case */ | |
99 if ( entry.kb_value == K_ENTER ) { | |
100 entry.kb_value = K(KT_ASCII,13); | |
101 } | |
102 /* Handle numpad specially as well */ | |
103 if ( KTYP(entry.kb_value) == KT_PAD ) { | |
104 switch ( entry.kb_value ) { | |
105 case K_P0: | |
106 case K_P1: | |
107 case K_P2: | |
108 case K_P3: | |
109 case K_P4: | |
110 case K_P5: | |
111 case K_P6: | |
112 case K_P7: | |
113 case K_P8: | |
114 case K_P9: | |
115 vga_keymap[map][i]=entry.kb_value; | |
116 vga_keymap[map][i]+= '0'; | |
117 break; | |
118 case K_PPLUS: | |
119 vga_keymap[map][i]=K(KT_ASCII,'+'); | |
120 break; | |
121 case K_PMINUS: | |
122 vga_keymap[map][i]=K(KT_ASCII,'-'); | |
123 break; | |
124 case K_PSTAR: | |
125 vga_keymap[map][i]=K(KT_ASCII,'*'); | |
126 break; | |
127 case K_PSLASH: | |
128 vga_keymap[map][i]=K(KT_ASCII,'/'); | |
129 break; | |
130 case K_PENTER: | |
131 vga_keymap[map][i]=K(KT_ASCII,'\r'); | |
132 break; | |
133 case K_PCOMMA: | |
134 vga_keymap[map][i]=K(KT_ASCII,','); | |
135 break; | |
136 case K_PDOT: | |
137 vga_keymap[map][i]=K(KT_ASCII,'.'); | |
138 break; | |
139 default: | |
140 break; | |
141 } | |
142 } | |
143 /* Do the normal key translation */ | |
144 if ( (KTYP(entry.kb_value) == KT_LATIN) || | |
145 (KTYP(entry.kb_value) == KT_ASCII) || | |
146 (KTYP(entry.kb_value) == KT_LETTER) ) { | |
147 vga_keymap[map][i] = entry.kb_value; | |
148 } | |
149 } | |
150 } | |
151 } | |
152 } | |
153 | |
154 int FB_InGraphicsMode(_THIS) | |
155 { | |
156 return((keyboard_fd >= 0) && (saved_kbd_mode >= 0)); | |
157 } | |
158 | |
159 int FB_EnterGraphicsMode(_THIS) | |
160 { | |
161 struct termios keyboard_termios; | |
162 | |
163 /* Set medium-raw keyboard mode */ | |
164 if ( (keyboard_fd >= 0) && !FB_InGraphicsMode(this) ) { | |
165 | |
166 /* Switch to the correct virtual terminal */ | |
167 if ( current_vt > 0 ) { | |
168 struct vt_stat vtstate; | |
169 | |
170 if ( ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0 ) { | |
171 saved_vt = vtstate.v_active; | |
172 } | |
173 if ( ioctl(keyboard_fd, VT_ACTIVATE, current_vt) == 0 ) { | |
174 ioctl(keyboard_fd, VT_WAITACTIVE, current_vt); | |
175 } | |
176 } | |
177 | |
178 /* Set the terminal input mode */ | |
179 if ( tcgetattr(keyboard_fd, &saved_kbd_termios) < 0 ) { | |
180 SDL_SetError("Unable to get terminal attributes"); | |
181 if ( keyboard_fd > 0 ) { | |
182 close(keyboard_fd); | |
183 } | |
184 keyboard_fd = -1; | |
185 return(-1); | |
186 } | |
187 if ( ioctl(keyboard_fd, KDGKBMODE, &saved_kbd_mode) < 0 ) { | |
188 SDL_SetError("Unable to get current keyboard mode"); | |
189 if ( keyboard_fd > 0 ) { | |
190 close(keyboard_fd); | |
191 } | |
192 keyboard_fd = -1; | |
193 return(-1); | |
194 } | |
195 keyboard_termios = saved_kbd_termios; | |
196 keyboard_termios.c_lflag &= ~(ICANON | ECHO | ISIG); | |
197 keyboard_termios.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); | |
198 keyboard_termios.c_cc[VMIN] = 0; | |
199 keyboard_termios.c_cc[VTIME] = 0; | |
200 if (tcsetattr(keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) { | |
201 FB_CloseKeyboard(this); | |
202 SDL_SetError("Unable to set terminal attributes"); | |
203 return(-1); | |
204 } | |
205 /* This will fail if we aren't root or this isn't our tty */ | |
206 if ( ioctl(keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0 ) { | |
207 FB_CloseKeyboard(this); | |
208 SDL_SetError("Unable to set keyboard in raw mode"); | |
209 return(-1); | |
210 } | |
211 if ( ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0 ) { | |
212 FB_CloseKeyboard(this); | |
213 SDL_SetError("Unable to set keyboard in graphics mode"); | |
214 return(-1); | |
215 } | |
216 } | |
217 return(keyboard_fd); | |
218 } | |
219 | |
220 void FB_LeaveGraphicsMode(_THIS) | |
221 { | |
222 if ( FB_InGraphicsMode(this) ) { | |
223 ioctl(keyboard_fd, KDSETMODE, KD_TEXT); | |
224 ioctl(keyboard_fd, KDSKBMODE, saved_kbd_mode); | |
225 tcsetattr(keyboard_fd, TCSAFLUSH, &saved_kbd_termios); | |
226 saved_kbd_mode = -1; | |
227 | |
228 /* Head back over to the original virtual terminal */ | |
229 if ( saved_vt > 0 ) { | |
230 ioctl(keyboard_fd, VT_ACTIVATE, saved_vt); | |
231 } | |
232 } | |
233 } | |
234 | |
235 void FB_CloseKeyboard(_THIS) | |
236 { | |
237 if ( keyboard_fd >= 0 ) { | |
238 FB_LeaveGraphicsMode(this); | |
239 if ( keyboard_fd > 0 ) { | |
240 close(keyboard_fd); | |
241 } | |
242 } | |
243 keyboard_fd = -1; | |
244 } | |
245 | |
246 int FB_OpenKeyboard(_THIS) | |
247 { | |
248 /* Open only if not already opened */ | |
249 if ( keyboard_fd < 0 ) { | |
250 char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL }; | |
251 char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL }; | |
252 int i, tty0_fd; | |
253 | |
254 /* Try to query for a free virtual terminal */ | |
255 tty0_fd = -1; | |
256 for ( i=0; tty0[i] && (tty0_fd < 0); ++i ) { | |
257 tty0_fd = open(tty0[i], O_WRONLY, 0); | |
258 } | |
259 if ( tty0_fd < 0 ) { | |
260 tty0_fd = dup(0); /* Maybe stdin is a VT? */ | |
261 } | |
262 ioctl(tty0_fd, VT_OPENQRY, ¤t_vt); | |
263 close(tty0_fd); | |
264 if ( (geteuid() == 0) && (current_vt > 0) ) { | |
265 for ( i=0; vcs[i] && (keyboard_fd < 0); ++i ) { | |
266 char vtpath[12]; | |
267 | |
268 sprintf(vtpath, vcs[i], current_vt); | |
269 keyboard_fd = open(vtpath, O_RDWR, 0); | |
270 #ifdef DEBUG_KEYBOARD | |
271 fprintf(stderr, "vtpath = %s, fd = %d\n", | |
272 vtpath, keyboard_fd); | |
273 #endif /* DEBUG_KEYBOARD */ | |
274 | |
275 /* This needs to be our controlling tty | |
276 so that the kernel ioctl() calls work | |
277 */ | |
278 if ( keyboard_fd >= 0 ) { | |
279 tty0_fd = open("/dev/tty", O_RDWR, 0); | |
280 if ( tty0_fd >= 0 ) { | |
281 ioctl(tty0_fd, TIOCNOTTY, 0); | |
282 close(tty0_fd); | |
283 } | |
284 } | |
285 } | |
286 } | |
287 if ( keyboard_fd < 0 ) { | |
288 /* Last resort, maybe our tty is a usable VT */ | |
289 current_vt = 0; | |
290 keyboard_fd = open("/dev/tty", O_RDWR); | |
291 } | |
292 #ifdef DEBUG_KEYBOARD | |
293 fprintf(stderr, "Current VT: %d\n", current_vt); | |
294 #endif | |
295 saved_kbd_mode = -1; | |
296 | |
297 /* Make sure that our input is a console terminal */ | |
298 { int dummy; | |
299 if ( ioctl(keyboard_fd, KDGKBMODE, &dummy) < 0 ) { | |
300 close(keyboard_fd); | |
301 keyboard_fd = -1; | |
302 SDL_SetError("Unable to open a console terminal"); | |
303 } | |
304 } | |
305 | |
306 /* Set up keymap */ | |
307 FB_vgainitkeymaps(keyboard_fd); | |
308 } | |
309 return(keyboard_fd); | |
310 } | |
311 | |
312 static enum { | |
313 MOUSE_NONE = -1, | |
314 MOUSE_GPM, /* Note: GPM uses the MSC protocol */ | |
315 MOUSE_PS2, | |
316 MOUSE_IMPS2, | |
317 MOUSE_MS, | |
318 MOUSE_BM, | |
319 MOUSE_ELO, | |
320 NUM_MOUSE_DRVS | |
321 } mouse_drv = MOUSE_NONE; | |
322 | |
323 void FB_CloseMouse(_THIS) | |
324 { | |
325 if ( mouse_fd > 0 ) { | |
326 close(mouse_fd); | |
327 } | |
328 mouse_fd = -1; | |
329 } | |
330 | |
331 /* Returns processes listed in /proc with the desired name */ | |
332 static int find_pid(DIR *proc, const char *wanted_name) | |
333 { | |
334 struct dirent *entry; | |
335 int pid; | |
336 | |
337 /* First scan proc for the gpm process */ | |
338 pid = 0; | |
339 while ( (pid == 0) && ((entry=readdir(proc)) != NULL) ) { | |
340 if ( isdigit(entry->d_name[0]) ) { | |
341 FILE *status; | |
342 char path[PATH_MAX]; | |
343 char name[PATH_MAX]; | |
344 | |
345 sprintf(path, "/proc/%s/status", entry->d_name); | |
346 status=fopen(path, "r"); | |
347 if ( status ) { | |
348 name[0] = '\0'; | |
349 fscanf(status, "Name: %s", name); | |
350 if ( strcmp(name, wanted_name) == 0 ) { | |
351 pid = atoi(entry->d_name); | |
352 } | |
353 fclose(status); | |
354 } | |
355 } | |
356 } | |
357 return pid; | |
358 } | |
359 | |
360 /* Returns true if /dev/gpmdata is being written to by gpm */ | |
361 static int gpm_available(void) | |
362 { | |
363 int available; | |
364 DIR *proc; | |
365 int pid; | |
366 int cmdline, len, arglen; | |
367 char path[PATH_MAX]; | |
368 char args[PATH_MAX], *arg; | |
369 | |
370 /* Don't bother looking if the fifo isn't there */ | |
371 if ( access(GPM_NODE_FIFO, F_OK) < 0 ) { | |
372 return(0); | |
373 } | |
374 | |
375 available = 0; | |
376 proc = opendir("/proc"); | |
377 if ( proc ) { | |
378 while ( (pid=find_pid(proc, "gpm")) > 0 ) { | |
379 sprintf(path, "/proc/%d/cmdline", pid); | |
380 cmdline = open(path, O_RDONLY, 0); | |
381 if ( cmdline >= 0 ) { | |
382 len = read(cmdline, args, sizeof(args)); | |
383 arg = args; | |
384 while ( len > 0 ) { | |
385 if ( strcmp(arg, "-R") == 0 ) { | |
386 available = 1; | |
387 } | |
388 arglen = strlen(arg)+1; | |
389 len -= arglen; | |
390 arg += arglen; | |
391 } | |
392 close(cmdline); | |
393 } | |
394 } | |
395 closedir(proc); | |
396 } | |
397 return available; | |
398 } | |
399 | |
59 | 400 |
401 /* rcg06112001 Set up IMPS/2 mode, if possible. This gives | |
402 * us access to the mousewheel, etc. Returns zero if | |
403 * writes to device failed, but you still need to query the | |
404 * device to see which mode it's actually in. | |
405 */ | |
406 static int set_imps2_mode(int fd) | |
407 { | |
408 /* If you wanted to control the mouse mode (and we do :) ) ... | |
409 Set IMPS/2 protocol: | |
410 {0xf3,200,0xf3,100,0xf3,80} | |
411 Reset mouse device: | |
412 {0xFF} | |
413 */ | |
414 Uint8 set_imps2[] = {0xf3, 200, 0xf3, 100, 0xf3, 80}; | |
415 Uint8 reset = 0xff; | |
416 fd_set fdset; | |
417 struct timeval tv; | |
418 int retval = 0; | |
419 | |
420 if ( write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2) ) { | |
421 if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) { | |
422 retval = 1; | |
423 } | |
424 } | |
425 | |
426 /* Get rid of any chatter from the above */ | |
427 FD_ZERO(&fdset); | |
428 FD_SET(fd, &fdset); | |
429 tv.tv_sec = 0; | |
430 tv.tv_usec = 0; | |
431 while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) { | |
432 char temp[32]; | |
433 read(fd, temp, sizeof(temp)); | |
434 } | |
435 | |
436 return retval; | |
437 } | |
438 | |
439 | |
0 | 440 /* Returns true if the mouse uses the IMPS/2 protocol */ |
441 static int detect_imps2(int fd) | |
442 { | |
443 int imps2; | |
444 | |
445 imps2 = 0; | |
59 | 446 |
447 /* rcg06112001 Attempt to set IMPS/2 mode first, even with envr var... */ | |
448 set_imps2_mode(fd); | |
449 | |
0 | 450 if ( getenv("SDL_MOUSEDEV_IMPS2") ) { |
451 imps2 = 1; | |
452 } | |
453 if ( ! imps2 ) { | |
59 | 454 Uint8 query_ps2 = 0xF2; |
0 | 455 fd_set fdset; |
456 struct timeval tv; | |
457 | |
458 /* Get rid of any mouse motion noise */ | |
459 FD_ZERO(&fdset); | |
460 FD_SET(fd, &fdset); | |
461 tv.tv_sec = 0; | |
462 tv.tv_usec = 0; | |
463 while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) { | |
464 char temp[32]; | |
465 read(fd, temp, sizeof(temp)); | |
466 } | |
467 | |
59 | 468 /* Query for the type of mouse protocol */ |
469 if ( write(fd, &query_ps2, sizeof (query_ps2)) == sizeof (query_ps2)) { | |
470 Uint8 ch = 0; | |
0 | 471 |
472 /* Get the mouse protocol response */ | |
473 do { | |
474 FD_ZERO(&fdset); | |
475 FD_SET(fd, &fdset); | |
476 tv.tv_sec = 1; | |
477 tv.tv_usec = 0; | |
478 if ( select(fd+1, &fdset, 0, 0, &tv) < 1 ) { | |
479 break; | |
480 } | |
59 | 481 } while ( (read(fd, &ch, sizeof (ch)) == sizeof (ch)) && |
0 | 482 ((ch == 0xFA) || (ch == 0xAA)) ); |
483 | |
484 /* Experimental values (Logitech wheelmouse) */ | |
485 #ifdef DEBUG_MOUSE | |
486 fprintf(stderr, "Last mouse mode: 0x%x\n", ch); | |
487 #endif | |
488 if ( ch == 3 ) { | |
489 imps2 = 1; | |
490 } | |
491 } | |
492 } | |
493 return imps2; | |
494 } | |
495 | |
496 int FB_OpenMouse(_THIS) | |
497 { | |
498 const char *mousedev; | |
499 const char *mousedrv; | |
500 | |
501 mousedrv = getenv("SDL_MOUSEDRV"); | |
502 mousedev = getenv("SDL_MOUSEDEV"); | |
503 mouse_fd = -1; | |
504 | |
505 /* ELO TOUCHSCREEN SUPPORT */ | |
506 | |
507 if( (mousedrv != NULL) && (strcmp(mousedrv, "ELO") == 0) ) { | |
508 mouse_fd = open(mousedev, O_RDWR); | |
509 if ( mouse_fd >= 0 ) { | |
510 if(eloInitController(mouse_fd)) { | |
511 #ifdef DEBUG_MOUSE | |
512 fprintf(stderr, "Using ELO touchscreen\n"); | |
513 #endif | |
514 mouse_drv = MOUSE_ELO; | |
515 } | |
516 | |
517 } | |
518 else if ( mouse_fd < 0 ) { | |
519 mouse_drv = MOUSE_NONE; | |
520 } | |
521 | |
522 return(mouse_fd); | |
523 } | |
524 | |
525 /* STD MICE */ | |
526 | |
527 if ( mousedev == NULL ) { | |
528 /* First try to use GPM in repeater mode */ | |
529 if ( mouse_fd < 0 ) { | |
530 if ( gpm_available() ) { | |
531 mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0); | |
532 if ( mouse_fd >= 0 ) { | |
533 #ifdef DEBUG_MOUSE | |
534 fprintf(stderr, "Using GPM mouse\n"); | |
535 #endif | |
536 mouse_drv = MOUSE_GPM; | |
537 } | |
538 } | |
539 } | |
540 /* Now try to use the new HID unified mouse device */ | |
541 if ( mouse_fd < 0 ) { | |
59 | 542 mouse_fd = open("/dev/input/mice", O_RDWR, 0); |
543 if (mouse_fd < 0) { | |
544 mouse_fd = open("/dev/input/mice", O_RDONLY, 0); | |
545 } | |
546 if (mouse_fd >= 0) { | |
547 if (detect_imps2(mouse_fd)) { | |
548 mouse_drv = MOUSE_IMPS2; | |
549 } else { | |
550 mouse_drv = MOUSE_PS2; | |
551 } | |
0 | 552 } |
553 } | |
554 /* Now try to use a modern PS/2 port mouse */ | |
555 if ( mouse_fd < 0 ) { | |
556 mouse_fd = open("/dev/psaux", O_RDWR, 0); | |
557 if ( mouse_fd < 0 ) { | |
558 mouse_fd = open("/dev/psaux", O_RDONLY, 0); | |
559 } | |
560 if ( mouse_fd >= 0 ) { | |
561 if ( detect_imps2(mouse_fd) ) { | |
562 #ifdef DEBUG_MOUSE | |
563 fprintf(stderr, "Using IMPS/2 mouse\n"); | |
564 #endif | |
565 mouse_drv = MOUSE_IMPS2; | |
566 } else { | |
567 #ifdef DEBUG_MOUSE | |
568 fprintf(stderr, "Using PS/2 mouse\n"); | |
569 #endif | |
570 mouse_drv = MOUSE_PS2; | |
571 } | |
572 } | |
573 } | |
574 /* Next try to use a PPC ADB port mouse */ | |
575 if ( mouse_fd < 0 ) { | |
576 mouse_fd = open("/dev/adbmouse", O_RDONLY, 0); | |
577 if ( mouse_fd >= 0 ) { | |
578 #ifdef DEBUG_MOUSE | |
579 fprintf(stderr, "Using ADB mouse\n"); | |
580 #endif | |
581 mouse_drv = MOUSE_BM; | |
582 } | |
583 } | |
584 } | |
585 /* Default to a serial Microsoft mouse */ | |
586 if ( mouse_fd < 0 ) { | |
587 if ( mousedev == NULL ) { | |
588 mousedev = "/dev/mouse"; | |
589 } | |
590 mouse_fd = open(mousedev, O_RDONLY, 0); | |
591 if ( mouse_fd >= 0 ) { | |
592 struct termios mouse_termios; | |
593 | |
594 /* Set the sampling speed to 1200 baud */ | |
595 tcgetattr(mouse_fd, &mouse_termios); | |
596 mouse_termios.c_iflag = IGNBRK | IGNPAR; | |
597 mouse_termios.c_oflag = 0; | |
598 mouse_termios.c_lflag = 0; | |
599 mouse_termios.c_line = 0; | |
600 mouse_termios.c_cc[VTIME] = 0; | |
601 mouse_termios.c_cc[VMIN] = 1; | |
602 mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL; | |
603 mouse_termios.c_cflag |= CS8; | |
604 mouse_termios.c_cflag |= B1200; | |
605 tcsetattr(mouse_fd, TCSAFLUSH, &mouse_termios); | |
606 #ifdef DEBUG_MOUSE | |
607 fprintf(stderr, "Using Microsoft mouse on %s\n", mousedev); | |
608 #endif | |
609 mouse_drv = MOUSE_MS; | |
610 } | |
611 } | |
612 if ( mouse_fd < 0 ) { | |
613 mouse_drv = MOUSE_NONE; | |
614 } | |
615 return(mouse_fd); | |
616 } | |
617 | |
618 static int posted = 0; | |
619 | |
620 void FB_vgamousecallback(int button, int relative, int dx, int dy) | |
621 { | |
622 int button_1, button_3; | |
623 int button_state; | |
624 int state_changed; | |
625 int i; | |
626 Uint8 state; | |
627 | |
628 if ( dx || dy ) { | |
629 posted += SDL_PrivateMouseMotion(0, relative, dx, dy); | |
630 } | |
631 | |
632 /* Swap button 1 and 3 */ | |
633 button_1 = (button & 0x04) >> 2; | |
634 button_3 = (button & 0x01) << 2; | |
635 button &= ~0x05; | |
636 button |= (button_1|button_3); | |
637 | |
638 /* See what changed */ | |
639 button_state = SDL_GetMouseState(NULL, NULL); | |
640 state_changed = button_state ^ button; | |
641 for ( i=0; i<8; ++i ) { | |
642 if ( state_changed & (1<<i) ) { | |
643 if ( button & (1<<i) ) { | |
644 state = SDL_PRESSED; | |
645 } else { | |
646 state = SDL_RELEASED; | |
647 } | |
648 posted += SDL_PrivateMouseButton(state, i+1, 0, 0); | |
649 } | |
650 } | |
651 } | |
652 | |
653 /* For now, use GPM, PS/2, and MS protocols | |
654 Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.) | |
655 */ | |
656 static void handle_mouse(_THIS) | |
657 { | |
658 static int start = 0; | |
659 static unsigned char mousebuf[BUFSIZ]; | |
660 static int relative = 1; | |
661 | |
662 int i, nread; | |
663 int button = 0; | |
664 int dx = 0, dy = 0; | |
665 int packetsize = 0; | |
4
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
666 int realx, realy; |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
667 |
0 | 668 /* Figure out the mouse packet size */ |
669 switch (mouse_drv) { | |
670 case MOUSE_NONE: | |
671 /* Ack! */ | |
672 read(mouse_fd, mousebuf, BUFSIZ); | |
673 return; | |
674 case MOUSE_GPM: | |
675 packetsize = 5; | |
676 break; | |
677 case MOUSE_IMPS2: | |
678 packetsize = 4; | |
679 break; | |
680 case MOUSE_PS2: | |
681 case MOUSE_MS: | |
682 case MOUSE_BM: | |
683 packetsize = 3; | |
684 break; | |
685 case MOUSE_ELO: | |
686 packetsize = ELO_PACKET_SIZE; | |
687 relative = 0; | |
688 break; | |
689 case NUM_MOUSE_DRVS: | |
690 /* Uh oh.. */ | |
691 packetsize = 0; | |
692 break; | |
693 } | |
694 | |
4
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
695 /* Special handling for the quite sensitive ELO controller */ |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
696 if (mouse_drv == MOUSE_ELO) { |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
697 |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
698 /* try to read the next packet */ |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
699 if(eloReadPosition(this, mouse_fd, &dx, &dy, &button, &realx, &realy)) { |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
700 button = (button & 0x01) << 2; |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
701 FB_vgamousecallback(button, relative, dx, dy); |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
702 } |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
703 |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
704 return; |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
705 } |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
706 |
0 | 707 /* Read as many packets as possible */ |
708 nread = read(mouse_fd, &mousebuf[start], BUFSIZ-start); | |
709 if ( nread < 0 ) { | |
710 return; | |
711 } | |
712 nread += start; | |
713 #ifdef DEBUG_MOUSE | |
714 fprintf(stderr, "Read %d bytes from mouse, start = %d\n", nread, start); | |
715 #endif | |
716 for ( i=0; i<(nread-(packetsize-1)); i += packetsize ) { | |
717 switch (mouse_drv) { | |
718 case MOUSE_NONE: | |
719 break; | |
720 case MOUSE_GPM: | |
721 /* GPM protocol has 0x80 in high byte */ | |
722 if ( (mousebuf[i] & 0xF8) != 0x80 ) { | |
723 /* Go to next byte */ | |
724 i -= (packetsize-1); | |
725 continue; | |
726 } | |
727 /* Get current mouse state */ | |
728 button = (~mousebuf[i]) & 0x07; | |
729 dx = (signed char)(mousebuf[i+1]) + | |
730 (signed char)(mousebuf[i+3]); | |
731 dy = -((signed char)(mousebuf[i+2]) + | |
732 (signed char)(mousebuf[i+4])); | |
733 break; | |
734 case MOUSE_PS2: | |
735 /* PS/2 protocol has nothing in high byte */ | |
736 if ( (mousebuf[i] & 0xC0) != 0 ) { | |
737 /* Go to next byte */ | |
738 i -= (packetsize-1); | |
739 continue; | |
740 } | |
741 /* Get current mouse state */ | |
742 button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/ | |
743 (mousebuf[i] & 0x02) >> 1 | /*Right*/ | |
744 (mousebuf[i] & 0x01) << 2; /*Left*/ | |
745 dx = (mousebuf[i] & 0x10) ? | |
746 mousebuf[i+1] - 256 : mousebuf[i+1]; | |
747 dy = (mousebuf[i] & 0x20) ? | |
748 -(mousebuf[i+2] - 256) : -mousebuf[i+2]; | |
749 break; | |
750 case MOUSE_IMPS2: | |
751 /* Get current mouse state */ | |
752 button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/ | |
753 (mousebuf[i] & 0x02) >> 1 | /*Right*/ | |
754 (mousebuf[i] & 0x01) << 2 | /*Left*/ | |
755 (mousebuf[i] & 0x40) >> 3 | /* 4 */ | |
756 (mousebuf[i] & 0x80) >> 3; /* 5 */ | |
757 dx = (mousebuf[i] & 0x10) ? | |
758 mousebuf[i+1] - 256 : mousebuf[i+1]; | |
759 dy = (mousebuf[i] & 0x20) ? | |
760 -(mousebuf[i+2] - 256) : -mousebuf[i+2]; | |
761 switch (mousebuf[i+3]&0x0F) { | |
762 case 0x0E: /* DX = +1 */ | |
763 case 0x02: /* DX = -1 */ | |
764 break; | |
765 case 0x0F: /* DY = +1 (map button 4) */ | |
766 button |= (1<<3); | |
767 break; | |
768 case 0x01: /* DY = -1 (map button 5) */ | |
769 button |= (1<<4); | |
770 break; | |
771 } | |
772 break; | |
773 case MOUSE_MS: | |
774 /* Microsoft protocol has 0x40 in high byte */ | |
775 if ( (mousebuf[i] & 0x40) != 0x40 ) { | |
776 /* Go to next byte */ | |
777 i -= (packetsize-1); | |
778 continue; | |
779 } | |
780 /* Get current mouse state */ | |
781 button = ((mousebuf[i] & 0x20) >> 3) | | |
782 ((mousebuf[i] & 0x10) >> 4); | |
783 dx = (signed char)(((mousebuf[i] & 0x03) << 6) | | |
784 (mousebuf[i + 1] & 0x3F)); | |
785 dy = (signed char)(((mousebuf[i] & 0x0C) << 4) | | |
786 (mousebuf[i + 2] & 0x3F)); | |
787 break; | |
788 case MOUSE_BM: | |
789 /* BusMouse protocol has 0xF8 in high byte */ | |
790 if ( (mousebuf[i] & 0xF8) != 0x80 ) { | |
791 /* Go to next byte */ | |
792 i -= (packetsize-1); | |
793 continue; | |
794 } | |
795 /* Get current mouse state */ | |
796 button = (~mousebuf[i]) & 0x07; | |
797 dx = (signed char)mousebuf[i+1]; | |
798 dy = -(signed char)mousebuf[i+2]; | |
799 break; | |
4
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
800 /* |
0 | 801 case MOUSE_ELO: |
802 if ( mousebuf[i] != ELO_START_BYTE ) { | |
803 i -= (packetsize-1); | |
804 continue; | |
805 } | |
806 | |
807 if(!eloParsePacket(&(mousebuf[i]), &dx, &dy, &button)) { | |
4
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
808 i -= (packetsize-1); |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
809 continue; |
0 | 810 } |
811 | |
812 button = (button & 0x01) << 2; | |
813 | |
814 eloConvertXY(this, &dx, &dy); | |
815 break; | |
4
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
816 */ |
0 | 817 |
4
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
818 case MOUSE_ELO: |
0 | 819 case NUM_MOUSE_DRVS: |
820 /* Uh oh.. */ | |
821 dx = 0; | |
822 dy = 0; | |
823 break; | |
824 } | |
825 FB_vgamousecallback(button, relative, dx, dy); | |
826 } | |
827 if ( i < nread ) { | |
828 memcpy(mousebuf, &mousebuf[i], (nread-i)); | |
829 start = (nread-i); | |
830 } else { | |
831 start = 0; | |
832 } | |
833 return; | |
834 } | |
835 | |
836 /* Handle switching to another VC, returns when our VC is back */ | |
837 static void switch_vt(_THIS, unsigned short which) | |
838 { | |
839 struct vt_stat vtstate; | |
840 unsigned short current; | |
841 SDL_Surface *screen; | |
842 __u16 saved_pal[3*256]; | |
843 Uint32 screen_arealen; | |
844 Uint8 *screen_contents; | |
845 | |
846 /* Figure out whether or not we're switching to a new console */ | |
847 if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) || | |
848 (which == vtstate.v_active) ) { | |
849 return; | |
850 } | |
851 current = vtstate.v_active; | |
852 | |
853 /* Save the contents of the screen, and go to text mode */ | |
854 SDL_mutexP(hw_lock); | |
855 screen = SDL_VideoSurface; | |
856 screen_arealen = (screen->h*screen->pitch); | |
857 screen_contents = (Uint8 *)malloc(screen_arealen); | |
858 if ( screen_contents ) { | |
859 memcpy(screen_contents, screen->pixels, screen_arealen); | |
860 } | |
861 FB_SavePaletteTo(this, 256, saved_pal); | |
862 ioctl(keyboard_fd, KDSETMODE, KD_TEXT); | |
863 | |
864 /* New console, switch to it */ | |
865 if ( ioctl(keyboard_fd, VT_ACTIVATE, which) == 0 ) { | |
866 /* Wait for our console to be activated again */ | |
867 ioctl(keyboard_fd, VT_WAITACTIVE, which); | |
868 while ( ioctl(keyboard_fd, VT_WAITACTIVE, current) < 0 ) { | |
869 if ( (errno != EINTR) && (errno != EAGAIN) ) { | |
870 /* Unknown VT error - cancel this */ | |
871 break; | |
872 } | |
873 SDL_Delay(500); | |
874 } | |
875 } | |
876 | |
877 /* Restore graphics mode and the contents of the screen */ | |
878 ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS); | |
879 FB_RestorePaletteFrom(this, 256, saved_pal); | |
880 if ( screen_contents ) { | |
881 memcpy(screen->pixels, screen_contents, screen_arealen); | |
882 free(screen_contents); | |
883 } | |
884 SDL_mutexV(hw_lock); | |
885 } | |
886 | |
887 static void handle_keyboard(_THIS) | |
888 { | |
889 unsigned char keybuf[BUFSIZ]; | |
890 int i, nread; | |
891 int pressed; | |
892 int scancode; | |
893 SDL_keysym keysym; | |
894 | |
895 nread = read(keyboard_fd, keybuf, BUFSIZ); | |
896 for ( i=0; i<nread; ++i ) { | |
897 scancode = keybuf[i] & 0x7F; | |
898 if ( keybuf[i] & 0x80 ) { | |
899 pressed = SDL_RELEASED; | |
900 } else { | |
901 pressed = SDL_PRESSED; | |
902 } | |
903 TranslateKey(scancode, &keysym); | |
904 /* Handle Alt-FN for vt switch */ | |
905 switch (keysym.sym) { | |
906 case SDLK_F1: | |
907 case SDLK_F2: | |
908 case SDLK_F3: | |
909 case SDLK_F4: | |
910 case SDLK_F5: | |
911 case SDLK_F6: | |
912 case SDLK_F7: | |
913 case SDLK_F8: | |
914 case SDLK_F9: | |
915 case SDLK_F10: | |
916 case SDLK_F11: | |
917 case SDLK_F12: | |
918 if ( SDL_GetModState() & KMOD_ALT ) { | |
919 switch_vt(this, (keysym.sym-SDLK_F1)+1); | |
920 break; | |
921 } | |
922 /* Fall through to normal processing */ | |
923 default: | |
924 posted += SDL_PrivateKeyboard(pressed, &keysym); | |
925 break; | |
926 } | |
927 } | |
928 } | |
929 | |
930 void FB_PumpEvents(_THIS) | |
931 { | |
932 fd_set fdset; | |
933 int max_fd; | |
934 static struct timeval zero; | |
935 | |
936 do { | |
937 posted = 0; | |
938 | |
939 FD_ZERO(&fdset); | |
940 max_fd = 0; | |
941 if ( keyboard_fd >= 0 ) { | |
942 FD_SET(keyboard_fd, &fdset); | |
943 if ( max_fd < keyboard_fd ) { | |
944 max_fd = keyboard_fd; | |
945 } | |
946 } | |
947 if ( mouse_fd >= 0 ) { | |
948 FD_SET(mouse_fd, &fdset); | |
949 if ( max_fd < mouse_fd ) { | |
950 max_fd = mouse_fd; | |
951 } | |
952 } | |
953 if ( select(max_fd+1, &fdset, NULL, NULL, &zero) > 0 ) { | |
954 if ( keyboard_fd >= 0 ) { | |
955 if ( FD_ISSET(keyboard_fd, &fdset) ) { | |
956 handle_keyboard(this); | |
957 } | |
958 } | |
959 if ( mouse_fd >= 0 ) { | |
960 if ( FD_ISSET(mouse_fd, &fdset) ) { | |
961 handle_mouse(this); | |
962 } | |
963 } | |
964 } | |
965 } while ( posted ); | |
966 } | |
967 | |
968 void FB_InitOSKeymap(_THIS) | |
969 { | |
970 int i; | |
971 | |
972 /* Initialize the Linux key translation table */ | |
973 | |
974 /* First get the ascii keys and others not well handled */ | |
975 for (i=0; i<SDL_TABLESIZE(keymap); ++i) { | |
976 switch(i) { | |
977 /* These aren't handled by the x86 kernel keymapping (?) */ | |
978 case SCANCODE_PRINTSCREEN: | |
979 keymap[i] = SDLK_PRINT; | |
980 break; | |
981 case SCANCODE_BREAK: | |
982 keymap[i] = SDLK_BREAK; | |
983 break; | |
984 case SCANCODE_BREAK_ALTERNATIVE: | |
985 keymap[i] = SDLK_PAUSE; | |
986 break; | |
987 case SCANCODE_LEFTSHIFT: | |
988 keymap[i] = SDLK_LSHIFT; | |
989 break; | |
990 case SCANCODE_RIGHTSHIFT: | |
991 keymap[i] = SDLK_RSHIFT; | |
992 break; | |
993 case SCANCODE_LEFTCONTROL: | |
994 keymap[i] = SDLK_LCTRL; | |
995 break; | |
996 case SCANCODE_RIGHTCONTROL: | |
997 keymap[i] = SDLK_RCTRL; | |
998 break; | |
999 case SCANCODE_RIGHTWIN: | |
1000 keymap[i] = SDLK_RSUPER; | |
1001 break; | |
1002 case SCANCODE_LEFTWIN: | |
1003 keymap[i] = SDLK_LSUPER; | |
1004 break; | |
1005 case 127: | |
1006 keymap[i] = SDLK_MENU; | |
1007 break; | |
1008 /* this should take care of all standard ascii keys */ | |
1009 default: | |
1010 keymap[i] = KVAL(vga_keymap[0][i]); | |
1011 break; | |
1012 } | |
1013 } | |
1014 for (i=0; i<SDL_TABLESIZE(keymap); ++i) { | |
1015 switch(keymap_temp[i]) { | |
1016 case K_F1: keymap[i] = SDLK_F1; break; | |
1017 case K_F2: keymap[i] = SDLK_F2; break; | |
1018 case K_F3: keymap[i] = SDLK_F3; break; | |
1019 case K_F4: keymap[i] = SDLK_F4; break; | |
1020 case K_F5: keymap[i] = SDLK_F5; break; | |
1021 case K_F6: keymap[i] = SDLK_F6; break; | |
1022 case K_F7: keymap[i] = SDLK_F7; break; | |
1023 case K_F8: keymap[i] = SDLK_F8; break; | |
1024 case K_F9: keymap[i] = SDLK_F9; break; | |
1025 case K_F10: keymap[i] = SDLK_F10; break; | |
1026 case K_F11: keymap[i] = SDLK_F11; break; | |
1027 case K_F12: keymap[i] = SDLK_F12; break; | |
1028 | |
1029 case K_DOWN: keymap[i] = SDLK_DOWN; break; | |
1030 case K_LEFT: keymap[i] = SDLK_LEFT; break; | |
1031 case K_RIGHT: keymap[i] = SDLK_RIGHT; break; | |
1032 case K_UP: keymap[i] = SDLK_UP; break; | |
1033 | |
1034 case K_P0: keymap[i] = SDLK_KP0; break; | |
1035 case K_P1: keymap[i] = SDLK_KP1; break; | |
1036 case K_P2: keymap[i] = SDLK_KP2; break; | |
1037 case K_P3: keymap[i] = SDLK_KP3; break; | |
1038 case K_P4: keymap[i] = SDLK_KP4; break; | |
1039 case K_P5: keymap[i] = SDLK_KP5; break; | |
1040 case K_P6: keymap[i] = SDLK_KP6; break; | |
1041 case K_P7: keymap[i] = SDLK_KP7; break; | |
1042 case K_P8: keymap[i] = SDLK_KP8; break; | |
1043 case K_P9: keymap[i] = SDLK_KP9; break; | |
1044 case K_PPLUS: keymap[i] = SDLK_KP_PLUS; break; | |
1045 case K_PMINUS: keymap[i] = SDLK_KP_MINUS; break; | |
1046 case K_PSTAR: keymap[i] = SDLK_KP_MULTIPLY; break; | |
1047 case K_PSLASH: keymap[i] = SDLK_KP_DIVIDE; break; | |
1048 case K_PENTER: keymap[i] = SDLK_KP_ENTER; break; | |
1049 case K_PDOT: keymap[i] = SDLK_KP_PERIOD; break; | |
1050 | |
1051 case K_SHIFT: if ( keymap[i] != SDLK_RSHIFT ) | |
1052 keymap[i] = SDLK_LSHIFT; | |
1053 break; | |
1054 case K_SHIFTL: keymap[i] = SDLK_LSHIFT; break; | |
1055 case K_SHIFTR: keymap[i] = SDLK_RSHIFT; break; | |
1056 case K_CTRL: if ( keymap[i] != SDLK_RCTRL ) | |
1057 keymap[i] = SDLK_LCTRL; | |
1058 break; | |
1059 case K_CTRLL: keymap[i] = SDLK_LCTRL; break; | |
1060 case K_CTRLR: keymap[i] = SDLK_RCTRL; break; | |
1061 case K_ALT: keymap[i] = SDLK_LALT; break; | |
1062 case K_ALTGR: keymap[i] = SDLK_RALT; break; | |
1063 | |
1064 case K_INSERT: keymap[i] = SDLK_INSERT; break; | |
1065 case K_REMOVE: keymap[i] = SDLK_DELETE; break; | |
1066 case K_PGUP: keymap[i] = SDLK_PAGEUP; break; | |
1067 case K_PGDN: keymap[i] = SDLK_PAGEDOWN; break; | |
1068 case K_FIND: keymap[i] = SDLK_HOME; break; | |
1069 case K_SELECT: keymap[i] = SDLK_END; break; | |
1070 | |
1071 case K_NUM: keymap[i] = SDLK_NUMLOCK; break; | |
1072 case K_CAPS: keymap[i] = SDLK_CAPSLOCK; break; | |
1073 | |
1074 case K_F13: keymap[i] = SDLK_PRINT; break; | |
1075 case K_HOLD: keymap[i] = SDLK_SCROLLOCK; break; | |
1076 case K_PAUSE: keymap[i] = SDLK_PAUSE; break; | |
1077 | |
1078 case 127: keymap[i] = SDLK_BACKSPACE; break; | |
1079 | |
1080 default: break; | |
1081 } | |
1082 } | |
1083 } | |
1084 | |
1085 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym) | |
1086 { | |
1087 /* Set the keysym information */ | |
1088 keysym->scancode = scancode; | |
1089 keysym->sym = keymap[scancode]; | |
1090 keysym->mod = KMOD_NONE; | |
1091 | |
1092 /* If UNICODE is on, get the UNICODE value for the key */ | |
1093 keysym->unicode = 0; | |
1094 if ( SDL_TranslateUNICODE ) { | |
1095 int map; | |
1096 SDLMod modstate; | |
1097 | |
1098 modstate = SDL_GetModState(); | |
1099 map = 0; | |
1100 if ( modstate & KMOD_SHIFT ) { | |
1101 map |= (1<<KG_SHIFT); | |
1102 } | |
1103 if ( modstate & KMOD_CTRL ) { | |
1104 map |= (1<<KG_CTRL); | |
1105 } | |
1106 if ( modstate & KMOD_ALT ) { | |
1107 map |= (1<<KG_ALT); | |
1108 } | |
1109 if ( modstate & KMOD_MODE ) { | |
1110 map |= (1<<KG_ALTGR); | |
1111 } | |
1112 if ( KTYP(vga_keymap[map][scancode]) == KT_LETTER ) { | |
1113 if ( modstate & KMOD_CAPS ) { | |
1114 map ^= (1<<KG_SHIFT); | |
1115 } | |
1116 } | |
1117 if ( KTYP(vga_keymap[map][scancode]) == KT_PAD ) { | |
1118 if ( modstate & KMOD_NUM ) { | |
1119 keysym->unicode=KVAL(vga_keymap[map][scancode]); | |
1120 } | |
1121 } else { | |
1122 keysym->unicode = KVAL(vga_keymap[map][scancode]); | |
1123 } | |
1124 } | |
1125 return(keysym); | |
1126 } |