Mercurial > sdl-ios-xcode
comparison src/video/fbcon/SDL_fbevents.c @ 1772:5115185b6e3c
Fixed bug #102
Improved GPM mouse protocol detection.
The original patch had a bunch of bugs, so I completely rewrote it to hopefully fix them, and to support more protocols.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 07 May 2006 06:20:39 +0000 |
parents | 980d2a0dc2a3 |
children | ed39aa7383ea |
comparison
equal
deleted
inserted
replaced
1771:8d3ca155c396 | 1772:5115185b6e3c |
---|---|
53 | 53 |
54 #ifndef GPM_NODE_FIFO | 54 #ifndef GPM_NODE_FIFO |
55 #define GPM_NODE_FIFO "/dev/gpmdata" | 55 #define GPM_NODE_FIFO "/dev/gpmdata" |
56 #endif | 56 #endif |
57 | 57 |
58 /*#define DEBUG_MOUSE*/ | |
58 | 59 |
59 /* The translation tables from a console scancode to a SDL keysym */ | 60 /* The translation tables from a console scancode to a SDL keysym */ |
60 #define NUM_VGAKEYMAPS (1<<KG_CAPSSHIFT) | 61 #define NUM_VGAKEYMAPS (1<<KG_CAPSSHIFT) |
61 static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS]; | 62 static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS]; |
62 static SDLKey keymap[128]; | 63 static SDLKey keymap[128]; |
358 } | 359 } |
359 return pid; | 360 return pid; |
360 } | 361 } |
361 | 362 |
362 /* Returns true if /dev/gpmdata is being written to by gpm */ | 363 /* Returns true if /dev/gpmdata is being written to by gpm */ |
363 static int gpm_available(void) | 364 static int gpm_available(char *proto, size_t protolen) |
364 { | 365 { |
365 int available; | 366 int available; |
366 DIR *proc; | 367 DIR *proc; |
367 int pid; | 368 int pid; |
368 int cmdline, len, arglen; | 369 int cmdline, len, arglen; |
369 char path[PATH_MAX]; | 370 char path[PATH_MAX]; |
370 char args[PATH_MAX], *arg; | 371 char args[PATH_MAX], *arg; |
371 | 372 |
372 /* Don't bother looking if the fifo isn't there */ | 373 /* Don't bother looking if the fifo isn't there */ |
374 #ifdef DEBUG_MOUSE | |
375 fprintf(stderr,"testing gpm\n"); | |
376 #endif | |
373 if ( access(GPM_NODE_FIFO, F_OK) < 0 ) { | 377 if ( access(GPM_NODE_FIFO, F_OK) < 0 ) { |
374 return(0); | 378 return(0); |
375 } | 379 } |
376 | 380 |
377 available = 0; | 381 available = 0; |
378 proc = opendir("/proc"); | 382 proc = opendir("/proc"); |
379 if ( proc ) { | 383 if ( proc ) { |
380 while ( (pid=find_pid(proc, "gpm")) > 0 ) { | 384 char raw_proto[10] = { '\0' }; |
385 char repeat_proto[10] = { '\0' }; | |
386 while ( !available && (pid=find_pid(proc, "gpm")) > 0 ) { | |
381 SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid); | 387 SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid); |
382 cmdline = open(path, O_RDONLY, 0); | 388 cmdline = open(path, O_RDONLY, 0); |
383 if ( cmdline >= 0 ) { | 389 if ( cmdline >= 0 ) { |
384 len = read(cmdline, args, sizeof(args)); | 390 len = read(cmdline, args, sizeof(args)); |
385 arg = args; | 391 arg = args; |
386 while ( len > 0 ) { | 392 while ( len > 0 ) { |
387 if ( SDL_strcmp(arg, "-R") == 0 ) { | 393 arglen = SDL_strlen(arg)+1; |
394 #ifdef DEBUG_MOUSE | |
395 fprintf(stderr,"gpm arg %s len %d\n",arg,arglen); | |
396 #endif | |
397 if ( SDL_strcmp(arg, "-t") == 0) { | |
398 /* protocol string, keep it for later */ | |
399 char *t, *s; | |
400 t = arg + arglen; | |
401 s = SDL_strchr(t, ' '); | |
402 if (s) *s = 0; | |
403 SDL_strncpy(raw_proto, t, SDL_arraysize(raw_proto)); | |
404 if (s) *s = ' '; | |
405 } | |
406 if ( SDL_strncmp(arg, "-R", 2) == 0 ) { | |
407 char *t, *s; | |
388 available = 1; | 408 available = 1; |
409 t = arg + 2; | |
410 s = SDL_strchr(t, ' '); | |
411 if (s) *s = 0; | |
412 SDL_strncpy(repeat_proto, t, SDL_arraysize(repeat_proto)); | |
413 if (s) *s = ' '; | |
389 } | 414 } |
390 arglen = SDL_strlen(arg)+1; | |
391 len -= arglen; | 415 len -= arglen; |
392 arg += arglen; | 416 arg += arglen; |
393 } | 417 } |
394 close(cmdline); | 418 close(cmdline); |
395 } | 419 } |
396 } | 420 } |
397 closedir(proc); | 421 closedir(proc); |
422 | |
423 if ( available ) { | |
424 if ( SDL_strcmp(repeat_proto, "raw") == 0 ) { | |
425 SDL_strlcpy(proto, raw_proto, protolen); | |
426 } else if ( *repeat_proto ) { | |
427 SDL_strlcpy(proto, repeat_proto, protolen); | |
428 } else { | |
429 SDL_strlcpy(proto, "msc", protolen); | |
430 } | |
431 } | |
398 } | 432 } |
399 return available; | 433 return available; |
400 } | 434 } |
401 | 435 |
402 | 436 |
550 static const char *ps2mice[] = { | 584 static const char *ps2mice[] = { |
551 "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL | 585 "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL |
552 }; | 586 }; |
553 /* First try to use GPM in repeater mode */ | 587 /* First try to use GPM in repeater mode */ |
554 if ( mouse_fd < 0 ) { | 588 if ( mouse_fd < 0 ) { |
555 if ( gpm_available() ) { | 589 char proto[10]; |
590 if ( gpm_available(proto, SDL_arraysize(proto)) ) { | |
556 mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0); | 591 mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0); |
557 if ( mouse_fd >= 0 ) { | 592 if ( mouse_fd >= 0 ) { |
593 if ( SDL_strcmp(proto, "msc") == 0 ) { | |
594 mouse_drv = MOUSE_MSC; | |
595 } else if ( SDL_strcmp(proto, "ps2") == 0 ) { | |
596 mouse_drv = MOUSE_PS2; | |
597 } else if ( SDL_strcmp(proto, "imps2") == 0 ) { | |
598 mouse_drv = MOUSE_IMPS2; | |
599 } else if ( SDL_strcmp(proto, "ms") == 0 || | |
600 SDL_strcmp(proto, "bare") == 0 ) { | |
601 mouse_drv = MOUSE_MS; | |
602 } else if ( SDL_strcmp(proto, "bm") == 0 ) { | |
603 mouse_drv = MOUSE_BM; | |
604 } else { | |
605 /* Unknown protocol... */ | |
558 #ifdef DEBUG_MOUSE | 606 #ifdef DEBUG_MOUSE |
559 fprintf(stderr, "Using GPM mouse\n"); | 607 fprintf(stderr, "GPM mouse using unknown protocol = %s\n", proto); |
560 #endif | 608 #endif |
561 mouse_drv = MOUSE_MSC; | 609 close(mouse_fd); |
562 } | 610 mouse_fd = -1; |
611 } | |
612 } | |
613 #ifdef DEBUG_MOUSE | |
614 if ( mouse_fd >= 0 ) { | |
615 fprintf(stderr, "Using GPM mouse, protocol = %s\n", proto); | |
616 } | |
617 #endif /* DEBUG_MOUSE */ | |
563 } | 618 } |
564 } | 619 } |
565 /* Now try to use a modern PS/2 mouse */ | 620 /* Now try to use a modern PS/2 mouse */ |
566 for ( i=0; (mouse_fd < 0) && ps2mice[i]; ++i ) { | 621 for ( i=0; (mouse_fd < 0) && ps2mice[i]; ++i ) { |
567 mouse_fd = open(ps2mice[i], O_RDWR, 0); | 622 mouse_fd = open(ps2mice[i], O_RDWR, 0); |