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