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