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