Mercurial > sdl-ios-xcode
annotate src/video/fbcon/SDL_fbevents.c @ 1312:c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
I batch edited these files, so please let me know if I've accidentally removed anybody's
credit here.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 01 Feb 2006 06:32:25 +0000 |
parents | 4b2146866b82 |
children | be736c197ceb |
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 */ |
0 | 22 |
23 /* Handle the event stream, converting console events into SDL events */ | |
24 | |
25 #include <sys/types.h> | |
26 #include <sys/time.h> | |
27 #include <sys/ioctl.h> | |
28 #include <stdlib.h> | |
29 #include <stdio.h> | |
30 #include <unistd.h> | |
31 #include <fcntl.h> | |
32 #include <string.h> | |
33 #include <errno.h> | |
34 #include <limits.h> | |
35 | |
36 /* For parsing /proc */ | |
37 #include <dirent.h> | |
38 #include <ctype.h> | |
39 | |
40 #include <linux/vt.h> | |
41 #include <linux/kd.h> | |
42 #include <linux/keyboard.h> | |
43 | |
44 #include "SDL.h" | |
45 #include "SDL_mutex.h" | |
46 #include "SDL_sysevents.h" | |
47 #include "SDL_sysvideo.h" | |
48 #include "SDL_events_c.h" | |
49 #include "SDL_fbvideo.h" | |
50 #include "SDL_fbevents_c.h" | |
51 #include "SDL_fbkeys.h" | |
52 | |
53 #include "SDL_fbelo.h" | |
54 | |
55 #ifndef GPM_NODE_FIFO | |
56 #define GPM_NODE_FIFO "/dev/gpmdata" | |
57 #endif | |
58 | |
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 ) { | |
84 memset(vga_keymap[map], 0, NR_KEYS*sizeof(Uint16)); | |
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 | |
263 sprintf(vtpath, vcs[i], current_vt); | |
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 { | |
1201
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
321 #ifdef HAVE_TSLIB |
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 } |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
327 #endif /* HAVE_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 | |
348 sprintf(path, "/proc/%s/status", entry->d_name); | |
349 status=fopen(path, "r"); | |
350 if ( status ) { | |
351 name[0] = '\0'; | |
352 fscanf(status, "Name: %s", name); | |
353 if ( strcmp(name, wanted_name) == 0 ) { | |
354 pid = atoi(entry->d_name); | |
355 } | |
356 fclose(status); | |
357 } | |
358 } | |
359 } | |
360 return pid; | |
361 } | |
362 | |
363 /* Returns true if /dev/gpmdata is being written to by gpm */ | |
364 static int gpm_available(void) | |
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 */ | |
374 if ( access(GPM_NODE_FIFO, F_OK) < 0 ) { | |
375 return(0); | |
376 } | |
377 | |
378 available = 0; | |
379 proc = opendir("/proc"); | |
380 if ( proc ) { | |
381 while ( (pid=find_pid(proc, "gpm")) > 0 ) { | |
382 sprintf(path, "/proc/%d/cmdline", pid); | |
383 cmdline = open(path, O_RDONLY, 0); | |
384 if ( cmdline >= 0 ) { | |
385 len = read(cmdline, args, sizeof(args)); | |
386 arg = args; | |
387 while ( len > 0 ) { | |
388 if ( strcmp(arg, "-R") == 0 ) { | |
389 available = 1; | |
390 } | |
391 arglen = strlen(arg)+1; | |
392 len -= arglen; | |
393 arg += arglen; | |
394 } | |
395 close(cmdline); | |
396 } | |
397 } | |
398 closedir(proc); | |
399 } | |
400 return available; | |
401 } | |
402 | |
59 | 403 |
404 /* rcg06112001 Set up IMPS/2 mode, if possible. This gives | |
405 * us access to the mousewheel, etc. Returns zero if | |
406 * writes to device failed, but you still need to query the | |
407 * device to see which mode it's actually in. | |
408 */ | |
409 static int set_imps2_mode(int fd) | |
410 { | |
411 /* If you wanted to control the mouse mode (and we do :) ) ... | |
412 Set IMPS/2 protocol: | |
413 {0xf3,200,0xf3,100,0xf3,80} | |
414 Reset mouse device: | |
415 {0xFF} | |
416 */ | |
417 Uint8 set_imps2[] = {0xf3, 200, 0xf3, 100, 0xf3, 80}; | |
418 Uint8 reset = 0xff; | |
419 fd_set fdset; | |
420 struct timeval tv; | |
421 int retval = 0; | |
422 | |
423 if ( write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2) ) { | |
424 if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) { | |
425 retval = 1; | |
426 } | |
427 } | |
428 | |
429 /* Get rid of any chatter from the above */ | |
430 FD_ZERO(&fdset); | |
431 FD_SET(fd, &fdset); | |
432 tv.tv_sec = 0; | |
433 tv.tv_usec = 0; | |
434 while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) { | |
435 char temp[32]; | |
436 read(fd, temp, sizeof(temp)); | |
437 } | |
438 | |
439 return retval; | |
440 } | |
441 | |
442 | |
0 | 443 /* Returns true if the mouse uses the IMPS/2 protocol */ |
444 static int detect_imps2(int fd) | |
445 { | |
446 int imps2; | |
447 | |
448 imps2 = 0; | |
59 | 449 |
0 | 450 if ( getenv("SDL_MOUSEDEV_IMPS2") ) { |
451 imps2 = 1; | |
452 } | |
453 if ( ! imps2 ) { | |
59 | 454 Uint8 query_ps2 = 0xF2; |
0 | 455 fd_set fdset; |
456 struct timeval tv; | |
457 | |
458 /* Get rid of any mouse motion noise */ | |
459 FD_ZERO(&fdset); | |
460 FD_SET(fd, &fdset); | |
461 tv.tv_sec = 0; | |
462 tv.tv_usec = 0; | |
463 while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) { | |
464 char temp[32]; | |
465 read(fd, temp, sizeof(temp)); | |
466 } | |
467 | |
59 | 468 /* Query for the type of mouse protocol */ |
469 if ( write(fd, &query_ps2, sizeof (query_ps2)) == sizeof (query_ps2)) { | |
470 Uint8 ch = 0; | |
0 | 471 |
472 /* Get the mouse protocol response */ | |
473 do { | |
474 FD_ZERO(&fdset); | |
475 FD_SET(fd, &fdset); | |
476 tv.tv_sec = 1; | |
477 tv.tv_usec = 0; | |
478 if ( select(fd+1, &fdset, 0, 0, &tv) < 1 ) { | |
479 break; | |
480 } | |
59 | 481 } while ( (read(fd, &ch, sizeof (ch)) == sizeof (ch)) && |
0 | 482 ((ch == 0xFA) || (ch == 0xAA)) ); |
483 | |
484 /* Experimental values (Logitech wheelmouse) */ | |
485 #ifdef DEBUG_MOUSE | |
486 fprintf(stderr, "Last mouse mode: 0x%x\n", ch); | |
487 #endif | |
104
a746656b7599
Detect more types of IMPS/2 mouse
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
488 if ( (ch == 3) || (ch == 4) ) { |
0 | 489 imps2 = 1; |
490 } | |
491 } | |
492 } | |
493 return imps2; | |
494 } | |
495 | |
496 int FB_OpenMouse(_THIS) | |
497 { | |
69
280ff3af2ecc
Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents:
60
diff
changeset
|
498 int i; |
0 | 499 const char *mousedev; |
500 const char *mousedrv; | |
501 | |
502 mousedrv = getenv("SDL_MOUSEDRV"); | |
503 mousedev = getenv("SDL_MOUSEDEV"); | |
504 mouse_fd = -1; | |
505 | |
1201
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
506 #ifdef HAVE_TSLIB |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
507 if ((mousedrv != NULL) && (strcmp(mousedrv, "TSLIB") == 0)) { |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
508 if (mousedev == NULL) mousedev = getenv("TSLIB_TSDEVICE"); |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
509 if (mousedev != NULL) { |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
510 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
|
511 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
|
512 #ifdef DEBUG_MOUSE |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
513 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
|
514 #endif |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
515 mouse_drv = MOUSE_TSLIB; |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
516 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
|
517 return mouse_fd; |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
518 } |
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 mouse_drv = MOUSE_NONE; |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
521 return mouse_fd; |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
522 } |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
523 #endif /* HAVE_TSLIB */ |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
524 |
0 | 525 /* ELO TOUCHSCREEN SUPPORT */ |
526 | |
527 if( (mousedrv != NULL) && (strcmp(mousedrv, "ELO") == 0) ) { | |
528 mouse_fd = open(mousedev, O_RDWR); | |
529 if ( mouse_fd >= 0 ) { | |
530 if(eloInitController(mouse_fd)) { | |
531 #ifdef DEBUG_MOUSE | |
532 fprintf(stderr, "Using ELO touchscreen\n"); | |
533 #endif | |
534 mouse_drv = MOUSE_ELO; | |
535 } | |
536 | |
537 } | |
538 else if ( mouse_fd < 0 ) { | |
539 mouse_drv = MOUSE_NONE; | |
540 } | |
541 | |
542 return(mouse_fd); | |
543 } | |
544 | |
545 /* STD MICE */ | |
546 | |
547 if ( mousedev == NULL ) { | |
69
280ff3af2ecc
Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents:
60
diff
changeset
|
548 /* FIXME someday... allow multiple mice in this driver */ |
91
e85e03f195b4
From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents:
69
diff
changeset
|
549 static const char * const ps2mice[] = { |
69
280ff3af2ecc
Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents:
60
diff
changeset
|
550 "/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
|
551 }; |
0 | 552 /* First try to use GPM in repeater mode */ |
553 if ( mouse_fd < 0 ) { | |
554 if ( gpm_available() ) { | |
555 mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0); | |
556 if ( mouse_fd >= 0 ) { | |
557 #ifdef DEBUG_MOUSE | |
558 fprintf(stderr, "Using GPM mouse\n"); | |
559 #endif | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
104
diff
changeset
|
560 mouse_drv = MOUSE_MSC; |
0 | 561 } |
562 } | |
563 } | |
69
280ff3af2ecc
Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents:
60
diff
changeset
|
564 /* 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
|
565 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
|
566 mouse_fd = open(ps2mice[i], O_RDWR, 0); |
59 | 567 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
|
568 mouse_fd = open(ps2mice[i], O_RDONLY, 0); |
59 | 569 } |
570 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
|
571 /* rcg06112001 Attempt to set IMPS/2 mode */ |
280ff3af2ecc
Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents:
60
diff
changeset
|
572 if ( i == 0 ) { |
280ff3af2ecc
Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents:
60
diff
changeset
|
573 set_imps2_mode(mouse_fd); |
59 | 574 } |
69
280ff3af2ecc
Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents:
60
diff
changeset
|
575 if (detect_imps2(mouse_fd)) { |
0 | 576 #ifdef DEBUG_MOUSE |
69
280ff3af2ecc
Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents:
60
diff
changeset
|
577 fprintf(stderr, "Using IMPS2 mouse\n"); |
0 | 578 #endif |
579 mouse_drv = MOUSE_IMPS2; | |
580 } else { | |
581 #ifdef DEBUG_MOUSE | |
69
280ff3af2ecc
Added /dev/usbmouse to the list of mice to check
Sam Lantinga <slouken@lokigames.com>
parents:
60
diff
changeset
|
582 fprintf(stderr, "Using PS2 mouse\n"); |
0 | 583 #endif |
584 mouse_drv = MOUSE_PS2; | |
585 } | |
586 } | |
587 } | |
588 /* Next try to use a PPC ADB port mouse */ | |
589 if ( mouse_fd < 0 ) { | |
590 mouse_fd = open("/dev/adbmouse", O_RDONLY, 0); | |
591 if ( mouse_fd >= 0 ) { | |
592 #ifdef DEBUG_MOUSE | |
593 fprintf(stderr, "Using ADB mouse\n"); | |
594 #endif | |
595 mouse_drv = MOUSE_BM; | |
596 } | |
597 } | |
598 } | |
599 /* Default to a serial Microsoft mouse */ | |
600 if ( mouse_fd < 0 ) { | |
601 if ( mousedev == NULL ) { | |
602 mousedev = "/dev/mouse"; | |
603 } | |
604 mouse_fd = open(mousedev, O_RDONLY, 0); | |
605 if ( mouse_fd >= 0 ) { | |
606 struct termios mouse_termios; | |
607 | |
608 /* Set the sampling speed to 1200 baud */ | |
609 tcgetattr(mouse_fd, &mouse_termios); | |
610 mouse_termios.c_iflag = IGNBRK | IGNPAR; | |
611 mouse_termios.c_oflag = 0; | |
612 mouse_termios.c_lflag = 0; | |
613 mouse_termios.c_line = 0; | |
614 mouse_termios.c_cc[VTIME] = 0; | |
615 mouse_termios.c_cc[VMIN] = 1; | |
616 mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL; | |
617 mouse_termios.c_cflag |= CS8; | |
618 mouse_termios.c_cflag |= B1200; | |
619 tcsetattr(mouse_fd, TCSAFLUSH, &mouse_termios); | |
620 #ifdef DEBUG_MOUSE | |
621 fprintf(stderr, "Using Microsoft mouse on %s\n", mousedev); | |
622 #endif | |
623 mouse_drv = MOUSE_MS; | |
624 } | |
625 } | |
626 if ( mouse_fd < 0 ) { | |
627 mouse_drv = MOUSE_NONE; | |
628 } | |
629 return(mouse_fd); | |
630 } | |
631 | |
632 static int posted = 0; | |
633 | |
634 void FB_vgamousecallback(int button, int relative, int dx, int dy) | |
635 { | |
636 int button_1, button_3; | |
637 int button_state; | |
638 int state_changed; | |
639 int i; | |
640 Uint8 state; | |
641 | |
642 if ( dx || dy ) { | |
643 posted += SDL_PrivateMouseMotion(0, relative, dx, dy); | |
644 } | |
645 | |
646 /* Swap button 1 and 3 */ | |
647 button_1 = (button & 0x04) >> 2; | |
648 button_3 = (button & 0x01) << 2; | |
649 button &= ~0x05; | |
650 button |= (button_1|button_3); | |
651 | |
652 /* See what changed */ | |
653 button_state = SDL_GetMouseState(NULL, NULL); | |
654 state_changed = button_state ^ button; | |
655 for ( i=0; i<8; ++i ) { | |
656 if ( state_changed & (1<<i) ) { | |
657 if ( button & (1<<i) ) { | |
658 state = SDL_PRESSED; | |
659 } else { | |
660 state = SDL_RELEASED; | |
661 } | |
662 posted += SDL_PrivateMouseButton(state, i+1, 0, 0); | |
663 } | |
664 } | |
665 } | |
666 | |
1201
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
667 /* Handle input from tslib */ |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
668 #ifdef HAVE_TSLIB |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
669 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
|
670 { |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
671 struct ts_sample sample; |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
672 int button; |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
673 |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
674 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
|
675 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
|
676 button <<= 2; /* must report it as button 3 */ |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
677 FB_vgamousecallback(button, 0, sample.x, sample.y); |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
678 } |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
679 return; |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
680 } |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
681 #endif /* HAVE_TSLIB */ |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
682 |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
104
diff
changeset
|
683 /* For now, use MSC, PS/2, and MS protocols |
0 | 684 Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.) |
685 */ | |
686 static void handle_mouse(_THIS) | |
687 { | |
688 static int start = 0; | |
689 static unsigned char mousebuf[BUFSIZ]; | |
690 static int relative = 1; | |
691 | |
692 int i, nread; | |
693 int button = 0; | |
694 int dx = 0, dy = 0; | |
695 int packetsize = 0; | |
4
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
696 int realx, realy; |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
697 |
0 | 698 /* Figure out the mouse packet size */ |
699 switch (mouse_drv) { | |
700 case MOUSE_NONE: | |
701 /* Ack! */ | |
702 read(mouse_fd, mousebuf, BUFSIZ); | |
703 return; | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
104
diff
changeset
|
704 case MOUSE_MSC: |
0 | 705 packetsize = 5; |
706 break; | |
707 case MOUSE_IMPS2: | |
708 packetsize = 4; | |
709 break; | |
710 case MOUSE_PS2: | |
711 case MOUSE_MS: | |
712 case MOUSE_BM: | |
713 packetsize = 3; | |
714 break; | |
715 case MOUSE_ELO: | |
716 packetsize = ELO_PACKET_SIZE; | |
717 relative = 0; | |
718 break; | |
1201
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
719 case MOUSE_TSLIB: |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
720 #ifdef HAVE_TSLIB |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
721 handle_tslib(this); |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
722 #endif |
718d00094f82
Date: Sat, 10 Dec 2005 18:29:41 +0100
Ryan C. Gordon <icculus@icculus.org>
parents:
1022
diff
changeset
|
723 return; /* nothing left to do */ |
0 | 724 case NUM_MOUSE_DRVS: |
725 /* Uh oh.. */ | |
726 packetsize = 0; | |
727 break; | |
728 } | |
729 | |
4
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
730 /* 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
|
731 if (mouse_drv == MOUSE_ELO) { |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
732 |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
733 /* try to read the next packet */ |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
734 if(eloReadPosition(this, mouse_fd, &dx, &dy, &button, &realx, &realy)) { |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
735 button = (button & 0x01) << 2; |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
736 FB_vgamousecallback(button, relative, dx, dy); |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
737 } |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
738 |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
739 return; |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
740 } |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
741 |
0 | 742 /* Read as many packets as possible */ |
743 nread = read(mouse_fd, &mousebuf[start], BUFSIZ-start); | |
744 if ( nread < 0 ) { | |
745 return; | |
746 } | |
747 nread += start; | |
748 #ifdef DEBUG_MOUSE | |
749 fprintf(stderr, "Read %d bytes from mouse, start = %d\n", nread, start); | |
750 #endif | |
751 for ( i=0; i<(nread-(packetsize-1)); i += packetsize ) { | |
752 switch (mouse_drv) { | |
753 case MOUSE_NONE: | |
754 break; | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
104
diff
changeset
|
755 case MOUSE_MSC: |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
104
diff
changeset
|
756 /* MSC protocol has 0x80 in high byte */ |
0 | 757 if ( (mousebuf[i] & 0xF8) != 0x80 ) { |
758 /* Go to next byte */ | |
759 i -= (packetsize-1); | |
760 continue; | |
761 } | |
762 /* Get current mouse state */ | |
763 button = (~mousebuf[i]) & 0x07; | |
764 dx = (signed char)(mousebuf[i+1]) + | |
765 (signed char)(mousebuf[i+3]); | |
766 dy = -((signed char)(mousebuf[i+2]) + | |
767 (signed char)(mousebuf[i+4])); | |
768 break; | |
769 case MOUSE_PS2: | |
770 /* PS/2 protocol has nothing in high byte */ | |
771 if ( (mousebuf[i] & 0xC0) != 0 ) { | |
772 /* Go to next byte */ | |
773 i -= (packetsize-1); | |
774 continue; | |
775 } | |
776 /* Get current mouse state */ | |
777 button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/ | |
778 (mousebuf[i] & 0x02) >> 1 | /*Right*/ | |
779 (mousebuf[i] & 0x01) << 2; /*Left*/ | |
780 dx = (mousebuf[i] & 0x10) ? | |
781 mousebuf[i+1] - 256 : mousebuf[i+1]; | |
782 dy = (mousebuf[i] & 0x20) ? | |
783 -(mousebuf[i+2] - 256) : -mousebuf[i+2]; | |
784 break; | |
785 case MOUSE_IMPS2: | |
786 /* Get current mouse state */ | |
787 button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/ | |
788 (mousebuf[i] & 0x02) >> 1 | /*Right*/ | |
789 (mousebuf[i] & 0x01) << 2 | /*Left*/ | |
790 (mousebuf[i] & 0x40) >> 3 | /* 4 */ | |
791 (mousebuf[i] & 0x80) >> 3; /* 5 */ | |
792 dx = (mousebuf[i] & 0x10) ? | |
793 mousebuf[i+1] - 256 : mousebuf[i+1]; | |
794 dy = (mousebuf[i] & 0x20) ? | |
795 -(mousebuf[i+2] - 256) : -mousebuf[i+2]; | |
796 switch (mousebuf[i+3]&0x0F) { | |
797 case 0x0E: /* DX = +1 */ | |
798 case 0x02: /* DX = -1 */ | |
799 break; | |
800 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
|
801 FB_vgamousecallback(button | (1<<3), |
2604a7be65af
Added button-up with mouse-wheel on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents:
109
diff
changeset
|
802 1, 0, 0); |
0 | 803 break; |
804 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
|
805 FB_vgamousecallback(button | (1<<4), |
2604a7be65af
Added button-up with mouse-wheel on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents:
109
diff
changeset
|
806 1, 0, 0); |
0 | 807 break; |
808 } | |
809 break; | |
810 case MOUSE_MS: | |
811 /* Microsoft protocol has 0x40 in high byte */ | |
812 if ( (mousebuf[i] & 0x40) != 0x40 ) { | |
813 /* Go to next byte */ | |
814 i -= (packetsize-1); | |
815 continue; | |
816 } | |
817 /* Get current mouse state */ | |
818 button = ((mousebuf[i] & 0x20) >> 3) | | |
819 ((mousebuf[i] & 0x10) >> 4); | |
820 dx = (signed char)(((mousebuf[i] & 0x03) << 6) | | |
821 (mousebuf[i + 1] & 0x3F)); | |
822 dy = (signed char)(((mousebuf[i] & 0x0C) << 4) | | |
823 (mousebuf[i + 2] & 0x3F)); | |
824 break; | |
825 case MOUSE_BM: | |
826 /* BusMouse protocol has 0xF8 in high byte */ | |
827 if ( (mousebuf[i] & 0xF8) != 0x80 ) { | |
828 /* Go to next byte */ | |
829 i -= (packetsize-1); | |
830 continue; | |
831 } | |
832 /* Get current mouse state */ | |
833 button = (~mousebuf[i]) & 0x07; | |
834 dx = (signed char)mousebuf[i+1]; | |
835 dy = -(signed char)mousebuf[i+2]; | |
836 break; | |
4
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
837 /* |
0 | 838 case MOUSE_ELO: |
839 if ( mousebuf[i] != ELO_START_BYTE ) { | |
840 i -= (packetsize-1); | |
841 continue; | |
842 } | |
843 | |
844 if(!eloParsePacket(&(mousebuf[i]), &dx, &dy, &button)) { | |
4
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
845 i -= (packetsize-1); |
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
846 continue; |
0 | 847 } |
848 | |
849 button = (button & 0x01) << 2; | |
850 | |
851 eloConvertXY(this, &dx, &dy); | |
852 break; | |
4
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
853 */ |
0 | 854 |
4
4f6c5f021323
Date: Thu, 26 Apr 2001 10:46:23 +0200
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
855 case MOUSE_ELO: |
0 | 856 case NUM_MOUSE_DRVS: |
857 /* Uh oh.. */ | |
858 dx = 0; | |
859 dy = 0; | |
860 break; | |
861 } | |
862 FB_vgamousecallback(button, relative, dx, dy); | |
863 } | |
864 if ( i < nread ) { | |
865 memcpy(mousebuf, &mousebuf[i], (nread-i)); | |
866 start = (nread-i); | |
867 } else { | |
868 start = 0; | |
869 } | |
870 return; | |
871 } | |
872 | |
109
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
104
diff
changeset
|
873 /* 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
|
874 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
|
875 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
|
876 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
|
877 */ |
0 | 878 static void switch_vt(_THIS, unsigned short which) |
879 { | |
1241
4b2146866b82
Properly restore vidmode when switching back to SDL's virtual terminal with
Ryan C. Gordon <icculus@icculus.org>
parents:
1201
diff
changeset
|
880 struct fb_var_screeninfo vinfo; |
0 | 881 struct vt_stat vtstate; |
1022
3d4f1930ed02
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
882 unsigned short v_active; |
0 | 883 SDL_Surface *screen; |
884 __u16 saved_pal[3*256]; | |
885 Uint32 screen_arealen; | |
886 Uint8 *screen_contents; | |
887 | |
888 /* Figure out whether or not we're switching to a new console */ | |
889 if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) || | |
890 (which == vtstate.v_active) ) { | |
891 return; | |
892 } | |
1022
3d4f1930ed02
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
893 v_active = vtstate.v_active; |
0 | 894 |
895 /* Save the contents of the screen, and go to text mode */ | |
896 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
|
897 wait_idle(this); |
0 | 898 screen = SDL_VideoSurface; |
899 screen_arealen = (screen->h*screen->pitch); | |
900 screen_contents = (Uint8 *)malloc(screen_arealen); | |
901 if ( screen_contents ) { | |
902 memcpy(screen_contents, screen->pixels, screen_arealen); | |
903 } | |
904 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
|
905 ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo); |
0 | 906 ioctl(keyboard_fd, KDSETMODE, KD_TEXT); |
907 | |
908 /* New console, switch to it */ | |
909 if ( ioctl(keyboard_fd, VT_ACTIVATE, which) == 0 ) { | |
910 /* Wait for our console to be activated again */ | |
911 ioctl(keyboard_fd, VT_WAITACTIVE, which); | |
1022
3d4f1930ed02
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
912 while ( ioctl(keyboard_fd, VT_WAITACTIVE, v_active) < 0 ) { |
0 | 913 if ( (errno != EINTR) && (errno != EAGAIN) ) { |
914 /* Unknown VT error - cancel this */ | |
915 break; | |
916 } | |
917 SDL_Delay(500); | |
918 } | |
919 } | |
920 | |
921 /* Restore graphics mode and the contents of the screen */ | |
922 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
|
923 ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo); |
0 | 924 FB_RestorePaletteFrom(this, 256, saved_pal); |
925 if ( screen_contents ) { | |
926 memcpy(screen->pixels, screen_contents, screen_arealen); | |
927 free(screen_contents); | |
928 } | |
929 SDL_mutexV(hw_lock); | |
930 } | |
931 | |
932 static void handle_keyboard(_THIS) | |
933 { | |
934 unsigned char keybuf[BUFSIZ]; | |
935 int i, nread; | |
936 int pressed; | |
937 int scancode; | |
938 SDL_keysym keysym; | |
939 | |
940 nread = read(keyboard_fd, keybuf, BUFSIZ); | |
941 for ( i=0; i<nread; ++i ) { | |
942 scancode = keybuf[i] & 0x7F; | |
943 if ( keybuf[i] & 0x80 ) { | |
944 pressed = SDL_RELEASED; | |
945 } else { | |
946 pressed = SDL_PRESSED; | |
947 } | |
948 TranslateKey(scancode, &keysym); | |
949 /* Handle Alt-FN for vt switch */ | |
950 switch (keysym.sym) { | |
951 case SDLK_F1: | |
952 case SDLK_F2: | |
953 case SDLK_F3: | |
954 case SDLK_F4: | |
955 case SDLK_F5: | |
956 case SDLK_F6: | |
957 case SDLK_F7: | |
958 case SDLK_F8: | |
959 case SDLK_F9: | |
960 case SDLK_F10: | |
961 case SDLK_F11: | |
962 case SDLK_F12: | |
963 if ( 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
|
964 if ( pressed ) { |
5a9c36a45db1
Fixed switching away from the SDL at the framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
104
diff
changeset
|
965 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
|
966 } |
0 | 967 break; |
968 } | |
969 /* Fall through to normal processing */ | |
970 default: | |
971 posted += SDL_PrivateKeyboard(pressed, &keysym); | |
972 break; | |
973 } | |
974 } | |
975 } | |
976 | |
977 void FB_PumpEvents(_THIS) | |
978 { | |
979 fd_set fdset; | |
980 int max_fd; | |
981 static struct timeval zero; | |
982 | |
983 do { | |
984 posted = 0; | |
985 | |
986 FD_ZERO(&fdset); | |
987 max_fd = 0; | |
988 if ( keyboard_fd >= 0 ) { | |
989 FD_SET(keyboard_fd, &fdset); | |
990 if ( max_fd < keyboard_fd ) { | |
991 max_fd = keyboard_fd; | |
992 } | |
993 } | |
994 if ( mouse_fd >= 0 ) { | |
995 FD_SET(mouse_fd, &fdset); | |
996 if ( max_fd < mouse_fd ) { | |
997 max_fd = mouse_fd; | |
998 } | |
999 } | |
1000 if ( select(max_fd+1, &fdset, NULL, NULL, &zero) > 0 ) { | |
1001 if ( keyboard_fd >= 0 ) { | |
1002 if ( FD_ISSET(keyboard_fd, &fdset) ) { | |
1003 handle_keyboard(this); | |
1004 } | |
1005 } | |
1006 if ( mouse_fd >= 0 ) { | |
1007 if ( FD_ISSET(mouse_fd, &fdset) ) { | |
1008 handle_mouse(this); | |
1009 } | |
1010 } | |
1011 } | |
1012 } while ( posted ); | |
1013 } | |
1014 | |
1015 void FB_InitOSKeymap(_THIS) | |
1016 { | |
1017 int i; | |
1018 | |
1019 /* Initialize the Linux key translation table */ | |
1020 | |
1021 /* First get the ascii keys and others not well handled */ | |
1022 for (i=0; i<SDL_TABLESIZE(keymap); ++i) { | |
1023 switch(i) { | |
1024 /* These aren't handled by the x86 kernel keymapping (?) */ | |
1025 case SCANCODE_PRINTSCREEN: | |
1026 keymap[i] = SDLK_PRINT; | |
1027 break; | |
1028 case SCANCODE_BREAK: | |
1029 keymap[i] = SDLK_BREAK; | |
1030 break; | |
1031 case SCANCODE_BREAK_ALTERNATIVE: | |
1032 keymap[i] = SDLK_PAUSE; | |
1033 break; | |
1034 case SCANCODE_LEFTSHIFT: | |
1035 keymap[i] = SDLK_LSHIFT; | |
1036 break; | |
1037 case SCANCODE_RIGHTSHIFT: | |
1038 keymap[i] = SDLK_RSHIFT; | |
1039 break; | |
1040 case SCANCODE_LEFTCONTROL: | |
1041 keymap[i] = SDLK_LCTRL; | |
1042 break; | |
1043 case SCANCODE_RIGHTCONTROL: | |
1044 keymap[i] = SDLK_RCTRL; | |
1045 break; | |
1046 case SCANCODE_RIGHTWIN: | |
1047 keymap[i] = SDLK_RSUPER; | |
1048 break; | |
1049 case SCANCODE_LEFTWIN: | |
1050 keymap[i] = SDLK_LSUPER; | |
1051 break; | |
1052 case 127: | |
1053 keymap[i] = SDLK_MENU; | |
1054 break; | |
1055 /* this should take care of all standard ascii keys */ | |
1056 default: | |
1057 keymap[i] = KVAL(vga_keymap[0][i]); | |
1058 break; | |
1059 } | |
1060 } | |
1061 for (i=0; i<SDL_TABLESIZE(keymap); ++i) { | |
1062 switch(keymap_temp[i]) { | |
1063 case K_F1: keymap[i] = SDLK_F1; break; | |
1064 case K_F2: keymap[i] = SDLK_F2; break; | |
1065 case K_F3: keymap[i] = SDLK_F3; break; | |
1066 case K_F4: keymap[i] = SDLK_F4; break; | |
1067 case K_F5: keymap[i] = SDLK_F5; break; | |
1068 case K_F6: keymap[i] = SDLK_F6; break; | |
1069 case K_F7: keymap[i] = SDLK_F7; break; | |
1070 case K_F8: keymap[i] = SDLK_F8; break; | |
1071 case K_F9: keymap[i] = SDLK_F9; break; | |
1072 case K_F10: keymap[i] = SDLK_F10; break; | |
1073 case K_F11: keymap[i] = SDLK_F11; break; | |
1074 case K_F12: keymap[i] = SDLK_F12; break; | |
1075 | |
1076 case K_DOWN: keymap[i] = SDLK_DOWN; break; | |
1077 case K_LEFT: keymap[i] = SDLK_LEFT; break; | |
1078 case K_RIGHT: keymap[i] = SDLK_RIGHT; break; | |
1079 case K_UP: keymap[i] = SDLK_UP; break; | |
1080 | |
1081 case K_P0: keymap[i] = SDLK_KP0; break; | |
1082 case K_P1: keymap[i] = SDLK_KP1; break; | |
1083 case K_P2: keymap[i] = SDLK_KP2; break; | |
1084 case K_P3: keymap[i] = SDLK_KP3; break; | |
1085 case K_P4: keymap[i] = SDLK_KP4; break; | |
1086 case K_P5: keymap[i] = SDLK_KP5; break; | |
1087 case K_P6: keymap[i] = SDLK_KP6; break; | |
1088 case K_P7: keymap[i] = SDLK_KP7; break; | |
1089 case K_P8: keymap[i] = SDLK_KP8; break; | |
1090 case K_P9: keymap[i] = SDLK_KP9; break; | |
1091 case K_PPLUS: keymap[i] = SDLK_KP_PLUS; break; | |
1092 case K_PMINUS: keymap[i] = SDLK_KP_MINUS; break; | |
1093 case K_PSTAR: keymap[i] = SDLK_KP_MULTIPLY; break; | |
1094 case K_PSLASH: keymap[i] = SDLK_KP_DIVIDE; break; | |
1095 case K_PENTER: keymap[i] = SDLK_KP_ENTER; break; | |
1096 case K_PDOT: keymap[i] = SDLK_KP_PERIOD; break; | |
1097 | |
1098 case K_SHIFT: if ( keymap[i] != SDLK_RSHIFT ) | |
1099 keymap[i] = SDLK_LSHIFT; | |
1100 break; | |
1101 case K_SHIFTL: keymap[i] = SDLK_LSHIFT; break; | |
1102 case K_SHIFTR: keymap[i] = SDLK_RSHIFT; break; | |
1103 case K_CTRL: if ( keymap[i] != SDLK_RCTRL ) | |
1104 keymap[i] = SDLK_LCTRL; | |
1105 break; | |
1106 case K_CTRLL: keymap[i] = SDLK_LCTRL; break; | |
1107 case K_CTRLR: keymap[i] = SDLK_RCTRL; break; | |
1108 case K_ALT: keymap[i] = SDLK_LALT; break; | |
1109 case K_ALTGR: keymap[i] = SDLK_RALT; break; | |
1110 | |
1111 case K_INSERT: keymap[i] = SDLK_INSERT; break; | |
1112 case K_REMOVE: keymap[i] = SDLK_DELETE; break; | |
1113 case K_PGUP: keymap[i] = SDLK_PAGEUP; break; | |
1114 case K_PGDN: keymap[i] = SDLK_PAGEDOWN; break; | |
1115 case K_FIND: keymap[i] = SDLK_HOME; break; | |
1116 case K_SELECT: keymap[i] = SDLK_END; break; | |
1117 | |
1118 case K_NUM: keymap[i] = SDLK_NUMLOCK; break; | |
1119 case K_CAPS: keymap[i] = SDLK_CAPSLOCK; break; | |
1120 | |
1121 case K_F13: keymap[i] = SDLK_PRINT; break; | |
1122 case K_HOLD: keymap[i] = SDLK_SCROLLOCK; break; | |
1123 case K_PAUSE: keymap[i] = SDLK_PAUSE; break; | |
1124 | |
1125 case 127: keymap[i] = SDLK_BACKSPACE; break; | |
1126 | |
1127 default: break; | |
1128 } | |
1129 } | |
1130 } | |
1131 | |
1132 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym) | |
1133 { | |
1134 /* Set the keysym information */ | |
1135 keysym->scancode = scancode; | |
1136 keysym->sym = keymap[scancode]; | |
1137 keysym->mod = KMOD_NONE; | |
1138 | |
1139 /* If UNICODE is on, get the UNICODE value for the key */ | |
1140 keysym->unicode = 0; | |
1141 if ( SDL_TranslateUNICODE ) { | |
1142 int map; | |
1143 SDLMod modstate; | |
1144 | |
1145 modstate = SDL_GetModState(); | |
1146 map = 0; | |
1147 if ( modstate & KMOD_SHIFT ) { | |
1148 map |= (1<<KG_SHIFT); | |
1149 } | |
1150 if ( modstate & KMOD_CTRL ) { | |
1151 map |= (1<<KG_CTRL); | |
1152 } | |
1153 if ( modstate & KMOD_ALT ) { | |
1154 map |= (1<<KG_ALT); | |
1155 } | |
1156 if ( modstate & KMOD_MODE ) { | |
1157 map |= (1<<KG_ALTGR); | |
1158 } | |
1159 if ( KTYP(vga_keymap[map][scancode]) == KT_LETTER ) { | |
1160 if ( modstate & KMOD_CAPS ) { | |
1161 map ^= (1<<KG_SHIFT); | |
1162 } | |
1163 } | |
1164 if ( KTYP(vga_keymap[map][scancode]) == KT_PAD ) { | |
1165 if ( modstate & KMOD_NUM ) { | |
1166 keysym->unicode=KVAL(vga_keymap[map][scancode]); | |
1167 } | |
1168 } else { | |
1169 keysym->unicode = KVAL(vga_keymap[map][scancode]); | |
1170 } | |
1171 } | |
1172 return(keysym); | |
1173 } |