1.1 --- a/src/drivers/joy_linux.c Mon May 12 10:00:13 2008 +0000
1.2 +++ b/src/drivers/joy_linux.c Tue Sep 09 00:49:35 2008 +0000
1.6 static gboolean linux_joystick_callback( GIOChannel *source, GIOCondition condition,
1.9 static int linux_joystick_scan();
1.10 static linux_joystick_t linux_joystick_new( const gchar *filename, int fd );
1.11 static uint16_t linux_joystick_resolve_keysym( input_driver_t dev, const gchar *str );
1.14 linux_joystick_t joy = (linux_joystick_t)dev;
1.15 if( strncasecmp( str, "Button", 6 ) == 0 ){
1.16 - unsigned long button = strtoul( str+6, NULL, 10 );
1.17 - if( button > joy->button_count ) {
1.20 - return (uint16_t)button;
1.21 + unsigned long button = strtoul( str+6, NULL, 10 );
1.22 + if( button > joy->button_count ) {
1.25 + return (uint16_t)button;
1.26 } else if( strncasecmp( str, "Axis", 4 ) == 0 ) {
1.28 - unsigned long axis = strtoul( str+4, &endptr, 10 );
1.29 - if( axis > joy->axis_count || axis == 0 ) {
1.32 - int keycode = ((axis - 1) << 1) + joy->button_count + 1;
1.33 - if( *endptr == '-' ) {
1.34 - return keycode + 1;
1.39 + unsigned long axis = strtoul( str+4, &endptr, 10 );
1.40 + if( axis > joy->axis_count || axis == 0 ) {
1.43 + int keycode = ((axis - 1) << 1) + joy->button_count + 1;
1.44 + if( *endptr == '-' ) {
1.45 + return keycode + 1;
1.57 linux_joystick_t joy = (linux_joystick_t)dev;
1.58 if( keycode == 0 ) {
1.62 if( keycode <= joy->button_count ) {
1.63 - return g_strdup_printf( "Button%d", keycode );
1.64 + return g_strdup_printf( "Button%d", keycode );
1.66 if( keycode <= joy->button_count + joy->axis_count*2 ) {
1.67 - int axis = keycode - joy->button_count - 1;
1.68 - if( (axis & 1) == 0 ) {
1.69 - return g_strdup_printf( "Axis%d+", (axis >> 1)+1 );
1.71 - return g_strdup_printf( "Axis%d-", (axis >> 1)+1 );
1.73 + int axis = keycode - joy->button_count - 1;
1.74 + if( (axis & 1) == 0 ) {
1.75 + return g_strdup_printf( "Axis%d+", (axis >> 1)+1 );
1.77 + return g_strdup_printf( "Axis%d-", (axis >> 1)+1 );
1.82 @@ -129,39 +129,39 @@
1.83 * On error, close the channel and delete the device.
1.85 static gboolean linux_joystick_callback( GIOChannel *source, GIOCondition condition,
1.89 linux_joystick_t joy = (linux_joystick_t)data;
1.91 if( condition & G_IO_HUP ) {
1.92 - INFO( "Joystick '%s' disconnected\n", joy->name );
1.93 - input_unregister_device((input_driver_t)joy);
1.95 + INFO( "Joystick '%s' disconnected\n", joy->name );
1.96 + input_unregister_device((input_driver_t)joy);
1.99 if( condition & G_IO_IN ) {
1.100 - struct js_event event;
1.101 - while( read( joy->fd, &event, sizeof(event) ) == sizeof(event) ) {
1.102 - if( event.type == JS_EVENT_BUTTON ) {
1.103 - int keycode = event.number+1;
1.104 - if( event.value == 0 ) {
1.105 - input_event_keyup( (input_driver_t)joy, keycode, 0 );
1.107 - input_event_keydown( (input_driver_t)joy, keycode, event.value );
1.109 - } else if( event.type == JS_EVENT_AXIS ) {
1.110 - int keycode = (event.number*2) + joy->button_count + 1;
1.111 - if( event.value == 0 ) {
1.112 - input_event_keyup( (input_driver_t)joy, keycode, 0 );
1.113 - input_event_keyup( (input_driver_t)joy, keycode+1, 0 );
1.114 - } else if( event.value < 0 ) {
1.115 - input_event_keydown( (input_driver_t)joy, keycode+1, -event.value );
1.116 - input_event_keyup( (input_driver_t)joy, keycode, 0 );
1.118 - input_event_keydown( (input_driver_t)joy, keycode, event.value );
1.119 - input_event_keyup( (input_driver_t)joy, keycode+1, 0 );
1.123 + struct js_event event;
1.124 + while( read( joy->fd, &event, sizeof(event) ) == sizeof(event) ) {
1.125 + if( event.type == JS_EVENT_BUTTON ) {
1.126 + int keycode = event.number+1;
1.127 + if( event.value == 0 ) {
1.128 + input_event_keyup( (input_driver_t)joy, keycode, 0 );
1.130 + input_event_keydown( (input_driver_t)joy, keycode, event.value );
1.132 + } else if( event.type == JS_EVENT_AXIS ) {
1.133 + int keycode = (event.number*2) + joy->button_count + 1;
1.134 + if( event.value == 0 ) {
1.135 + input_event_keyup( (input_driver_t)joy, keycode, 0 );
1.136 + input_event_keyup( (input_driver_t)joy, keycode+1, 0 );
1.137 + } else if( event.value < 0 ) {
1.138 + input_event_keydown( (input_driver_t)joy, keycode+1, -event.value );
1.139 + input_event_keyup( (input_driver_t)joy, keycode, 0 );
1.141 + input_event_keydown( (input_driver_t)joy, keycode, event.value );
1.142 + input_event_keyup( (input_driver_t)joy, keycode+1, 0 );
1.149 @@ -183,17 +183,17 @@
1.151 char *p = strrchr(filename, '/');
1.153 - joy->driver.id = filename;
1.154 + joy->driver.id = filename;
1.156 - joy->driver.id = p+1;
1.157 + joy->driver.id = p+1;
1.160 if( ioctl( fd, JSIOCGNAME(128), joy->name ) == -1 ||
1.161 - ioctl( fd, JSIOCGAXES, &joy->axis_count ) == -1 ||
1.162 - ioctl( fd, JSIOCGBUTTONS, &joy->button_count ) == -1 ) {
1.163 - ERROR( "Error reading joystick data from %s (%s)\n", filename, strerror(errno) );
1.166 + ioctl( fd, JSIOCGAXES, &joy->axis_count ) == -1 ||
1.167 + ioctl( fd, JSIOCGBUTTONS, &joy->button_count ) == -1 ) {
1.168 + ERROR( "Error reading joystick data from %s (%s)\n", filename, strerror(errno) );
1.173 joy->channel = g_io_channel_unix_new(fd);
1.174 @@ -208,24 +208,24 @@
1.175 DIR *dir = opendir(INPUT_PATH);
1.177 if( dir == NULL ) {
1.183 while( (ent = readdir(dir)) != NULL ) {
1.184 - if( ent->d_name[0] == 'j' && ent->d_name[1] == 's' &&
1.185 - isdigit(ent->d_name[2]) && !input_has_device(ent->d_name) ) {
1.186 - gchar *name = g_strdup_printf( "%s/%s", INPUT_PATH, ent->d_name );
1.187 - int fd = open(name, O_RDONLY|O_NONBLOCK);
1.191 - linux_joystick_t joy = linux_joystick_new( name, fd );
1.192 - input_register_device( (input_driver_t)joy, (joy->axis_count*2) + joy->button_count );
1.193 - INFO( "Attached joystick %s named '%s', (%d buttons, %d axes)",
1.194 - joy->driver.id, joy->name, joy->button_count, joy->axis_count );
1.198 + if( ent->d_name[0] == 'j' && ent->d_name[1] == 's' &&
1.199 + isdigit(ent->d_name[2]) && !input_has_device(ent->d_name) ) {
1.200 + gchar *name = g_strdup_printf( "%s/%s", INPUT_PATH, ent->d_name );
1.201 + int fd = open(name, O_RDONLY|O_NONBLOCK);
1.205 + linux_joystick_t joy = linux_joystick_new( name, fd );
1.206 + input_register_device( (input_driver_t)joy, (joy->axis_count*2) + joy->button_count );
1.207 + INFO( "Attached joystick %s named '%s', (%d buttons, %d axes)",
1.208 + joy->driver.id, joy->name, joy->button_count, joy->axis_count );
1.215 @@ -235,7 +235,7 @@
1.216 gboolean linux_joystick_init()
1.218 if( !linux_joystick_install_watch(INPUT_PATH) ) {
1.222 linux_joystick_scan();
1.224 @@ -254,11 +254,11 @@
1.225 static gboolean gtk_loop_check_input(gpointer data)
1.227 if( need_input_rescan == 1 ) {
1.228 - need_input_rescan = 0;
1.229 - int js = linux_joystick_scan();
1.231 - maple_reattach_all();
1.233 + need_input_rescan = 0;
1.234 + int js = linux_joystick_scan();
1.236 + maple_reattach_all();
1.239 return need_input_rescan != 2;
1.241 @@ -272,14 +272,14 @@
1.243 int fd = open( dir, O_RDONLY|O_NONBLOCK );
1.250 signal( SIGRTMIN+1, dnotify_handler );
1.251 fcntl(fd, F_SETSIG, SIGRTMIN + 1);
1.252 if( fcntl(fd, F_NOTIFY, DN_CREATE|DN_MULTISHOT) == -1 ) {
1.259 g_timeout_add( 500, gtk_loop_check_input, NULL );