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