[PATCH] Linux Joystick

When both joydev and evdev are loaded in Linux the SDL library was
registering every joystick twice, one for each interface. The attached
patch fixes an earlier fix for this…

It also contains a wee function name change from ConfigJoystick to
JS_ConfigJoystick to clarify it’s only for joystick devices. This
is similar to other funtion names.

If this is okay, I have another revision to come too.

PS Please CC as I’m not on the mailing list and the last archives
stopped in May 2002?–
Alan.

“One must never be purposelessnessnesslessness.”
-------------- next part --------------
— SDL-1.2.5/src/joystick/linux/SDL_sysjoystick.c Thu Jun 13 00:49:31 2002
+++ SDL-1.2.5-custom/src/joystick/linux/SDL_sysjoystick.c Thu Nov 14 17:00:48 2002
@@ -146,14 +146,14 @@
{
/* The base path of the joystick devices */
const char *joydev_pattern[] = {

  •   "/dev/js%d",
    

#ifdef USE_INPUT_EVENTS
"/dev/input/event%d",
#endif

  •   "/dev/input/js%d"
    
  •   "/dev/input/js%d",
    
  •   "/dev/js%d"
    
    };
    int numjoysticks;
  • int i, j, done;
  • int i, j;
    int fd;
    char path[PATH_MAX];
    dev_t dev_nums[MAX_JOYSTICKS]; /* major/minor device numbers */
    @@ -179,9 +179,9 @@
    }
    }
    }
  • for ( i=0; i<SDL_TABLESIZE(joydev_pattern); ++i ) {
  •   done = 0;
    
  •   for ( j=0; (j < MAX_JOYSTICKS) && !done; ++j ) {
    
  •   for ( j=0; (j < MAX_JOYSTICKS); ++j ) {
      	sprintf(path, joydev_pattern[i], j);
    
      	/* rcg06302000 replaced access(F_OK) call with stat().
    

@@ -210,7 +210,7 @@
#ifdef DEBUG_INPUT_EVENTS
printf(“Checking %s\n”, path);
#endif

  •   		if ( (i > 0) && ! EV_IsJoystick(fd) ) {
    
  •   		if ( !i && ! EV_IsJoystick(fd) ) {
      			close(fd);
      			continue;
      		}
    

@@ -223,20 +223,20 @@
dev_nums[numjoysticks] = sb.st_rdev;
++numjoysticks;
}

  •   	} else {
    
  •   		done = 1;
    
  •   	}
    
  •   	} else
    
  •   		break;
      }
    
  •    /* This is a special case...
    
  •       If we're looking at the /dev/input event devices, and we found
    
  •       at least one, then we don't want to look at the input joystick
    
  •       devices, since they're built on top of devices that we've already
    
  •       seen, so we're done.
    
  •     */
    
  •    if ( i > 0 && j > 0 ) {
    
  •        done = 1;
    
  •    }
    
  •   /* If the event devices are valid then the joystick devices
    
  •      will be duplicates but without information about their hats
    
  •      or balls. Eg: /dev/input/eventX = /dev/input/jsY = /dev/jsY
    
  •   */
    

+#ifdef USE_INPUT_EVENTS

  •       if ( i == 0 && numjoysticks )
    
  •           break;
    

+#endif
}
+
return(numjoysticks);
}

@@ -298,7 +298,7 @@
return(0);
}

-static SDL_bool ConfigJoystick(SDL_Joystick *joystick,
+static SDL_bool JS_ConfigJoystick(SDL_Joystick *joystick,
const char *name, const char config)
{
char cfg_name[128];
@@ -495,12 +495,12 @@
/
Check for special joystick support */
name = SDL_SYS_JoystickName(joystick->index);
for ( i=0; special_joysticks[i]; ++i ) {

  •   	if (ConfigJoystick(joystick,name,special_joysticks[i])){
    
  •   	if (JS_ConfigJoystick(joystick,name,special_joysticks[i])){
      		break;
      	}
      }
      if ( special_joysticks[i] == NULL ) {
    
  •   	ConfigJoystick(joystick, name,
    
  •   	JS_ConfigJoystick(joystick, name,
      			getenv("SDL_LINUX_JOYSTICK"));
      }
    

#endif /* FANCY_HATS_AND_BALLS */
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 240 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20021117/7bb45d4f/attachment.pgp