comparison src/video/fbcon/SDL_fbevents.c @ 1662:782fd950bd46 SDL-1.3

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