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