Organized joystick hotplug code a bit.
authorSam Lantinga <slouken@libsdl.org>
Tue, 27 Nov 2012 00:58:12 -0800
changeset 670770eeb7e3ec2f
parent 6706 b9f5fb1e78b5
child 6708 1fa41febb331
Organized joystick hotplug code a bit.
Cleaned up names, return types, etc.
include/SDL_joystick.h
src/joystick/SDL_joystick.c
src/joystick/SDL_joystick_c.h
src/joystick/SDL_sysjoystick.h
src/joystick/android/SDL_sysjoystick.c
src/joystick/beos/SDL_bejoystick.cc
src/joystick/bsd/SDL_sysjoystick.c
src/joystick/darwin/SDL_sysjoystick.c
src/joystick/dummy/SDL_sysjoystick.c
src/joystick/iphoneos/SDL_sysjoystick.m
src/joystick/linux/SDL_sysjoystick.c
src/joystick/nds/SDL_sysjoystick.c
src/joystick/windows/SDL_dxjoystick.c
src/joystick/windows/SDL_mmjoystick.c
     1.1 --- a/include/SDL_joystick.h	Mon Nov 26 23:58:53 2012 -0800
     1.2 +++ b/include/SDL_joystick.h	Tue Nov 27 00:58:12 2012 -0800
     1.3 @@ -62,8 +62,14 @@
     1.4  struct _SDL_Joystick;
     1.5  typedef struct _SDL_Joystick SDL_Joystick;
     1.6  
     1.7 +/* A structure that encodes the stable unique id for a joystick device */
     1.8 +typedef struct {
     1.9 +	Uint8 data[16];
    1.10 +} JoystickGUID;
    1.11 +
    1.12  typedef int SDL_JoystickID;
    1.13 -	
    1.14 +
    1.15 +
    1.16  /* Function prototypes */
    1.17  /**
    1.18   *  Count the number of joysticks attached to the system right now
    1.19 @@ -93,12 +99,6 @@
    1.20   */
    1.21  extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick * joystick);
    1.22  	
    1.23 -/* A structure that encodes the stable unique id for a joystick device */
    1.24 -typedef struct
    1.25 -{
    1.26 -	Uint8 data[16];
    1.27 -} JoystickGUID;
    1.28 -
    1.29  /**
    1.30   *  Return the GUID for the joystick at this index
    1.31   */
    1.32 @@ -119,14 +119,13 @@
    1.33   */
    1.34  extern DECLSPEC JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
    1.35  
    1.36 +/**
    1.37 + *  Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not.
    1.38 + */
    1.39 +extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick);
    1.40  
    1.41  /**
    1.42 - *  Returns 1 if the joystick has been opened and currently connected, or 0 if it has not.
    1.43 - */
    1.44 -extern DECLSPEC int SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick);
    1.45 -
    1.46 -/**
    1.47 - *  Get the device index of an opened joystick.
    1.48 + *  Get the instance ID of an opened joystick.
    1.49   */
    1.50  extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick * joystick);
    1.51  
     2.1 --- a/src/joystick/SDL_joystick.c	Mon Nov 26 23:58:53 2012 -0800
     2.2 +++ b/src/joystick/SDL_joystick.c	Tue Nov 27 00:58:12 2012 -0800
     2.3 @@ -63,7 +63,7 @@
     2.4          SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
     2.5          return (NULL);
     2.6      }
     2.7 -    return (SDL_SYS_JoystickNameForIndex(device_index));
     2.8 +    return (SDL_SYS_JoystickNameForDeviceIndex(device_index));
     2.9  }
    2.10  
    2.11  /*
    2.12 @@ -112,7 +112,7 @@
    2.13          return NULL;
    2.14      }
    2.15  
    2.16 -	joystickname = SDL_SYS_JoystickNameForIndex( device_index );
    2.17 +	joystickname = SDL_SYS_JoystickNameForDeviceIndex( device_index );
    2.18  	if ( joystickname )
    2.19  		joystick->name = SDL_strdup( joystickname );
    2.20  	else
    2.21 @@ -332,11 +332,11 @@
    2.22   * Return if the joystick in question is currently attached to the system,
    2.23   *  \return 0 if not plugged in, 1 if still present.
    2.24   */
    2.25 -int
    2.26 -SDL_JoystickGetAttached( SDL_Joystick * joystick )
    2.27 +SDL_bool
    2.28 +SDL_JoystickGetAttached(SDL_Joystick * joystick)
    2.29  {
    2.30  	if (!SDL_PrivateJoystickValid(joystick)) {
    2.31 -        return (0);
    2.32 +        return SDL_FALSE;
    2.33      }
    2.34  
    2.35  	return SDL_SYS_JoystickAttached(joystick);
    2.36 @@ -346,7 +346,7 @@
    2.37   * Get the instance id for this opened joystick
    2.38   */
    2.39  SDL_JoystickID 
    2.40 -SDL_JoystickInstanceID( SDL_Joystick * joystick )
    2.41 +SDL_JoystickInstanceID(SDL_Joystick * joystick)
    2.42  {
    2.43  	if (!SDL_PrivateJoystickValid(joystick)) {
    2.44          return (-1);
    2.45 @@ -645,13 +645,13 @@
    2.46  }
    2.47  
    2.48  /* return 1 if you want to run the joystick update loop this frame, used by hotplug support */
    2.49 -int 
    2.50 +SDL_bool 
    2.51  SDL_PrivateJoystickNeedsPolling()
    2.52  {
    2.53  	if ( SDL_SYS_JoystickNeedsPolling() )
    2.54  	{
    2.55  		// sys layer needs us to think
    2.56 -		return 1;
    2.57 +		return SDL_TRUE;
    2.58  	}
    2.59  	else
    2.60  	{
    2.61 @@ -662,16 +662,15 @@
    2.62  
    2.63  
    2.64  /* return the guid for this index */
    2.65 -JoystickGUID SDL_JoystickGetDeviceGUID( int device_index )
    2.66 +JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
    2.67  {
    2.68 -	return SDL_SYS_PrivateJoystickGetDeviceGUID( device_index );
    2.69 +	return SDL_SYS_JoystickGetDeviceGUID( device_index );
    2.70  }
    2.71  
    2.72  /* return the guid for this opened device */
    2.73  JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick)
    2.74  {
    2.75 -	return SDL_SYS_PrivateJoystickGetGUID( joystick );
    2.76 -
    2.77 +	return SDL_SYS_JoystickGetGUID( joystick );
    2.78  }
    2.79  
    2.80  /* convert the guid to a printable string */
     3.1 --- a/src/joystick/SDL_joystick_c.h	Mon Nov 26 23:58:53 2012 -0800
     3.2 +++ b/src/joystick/SDL_joystick_c.h	Tue Nov 27 00:58:12 2012 -0800
     3.3 @@ -43,7 +43,7 @@
     3.4                                       Uint8 button, Uint8 state);
     3.5  									 
     3.6  /* Helper function to let lower sys layer tell the event system if the joystick code needs to think */
     3.7 -extern int SDL_PrivateJoystickNeedsPolling();
     3.8 +extern SDL_bool SDL_PrivateJoystickNeedsPolling();
     3.9  
    3.10  /* Internal sanity checking functions */
    3.11  extern int SDL_PrivateJoystickValid(SDL_Joystick * joystick);
     4.1 --- a/src/joystick/SDL_sysjoystick.h	Mon Nov 26 23:58:53 2012 -0800
     4.2 +++ b/src/joystick/SDL_sysjoystick.h	Tue Nov 27 00:58:12 2012 -0800
     4.3 @@ -63,18 +63,32 @@
     4.4   */
     4.5  extern int SDL_SYS_JoystickInit(void);
     4.6  
     4.7 +/* Function to return the number of joystick devices plugged in right now */
     4.8 +extern int SDL_SYS_NumJoysticks();
     4.9 +
    4.10 +/* Function to cause any queued joystick insertions to be processed */
    4.11 +extern void SDL_SYS_JoystickDetect();
    4.12 +
    4.13 +/* Function to determine if the joystick loop needs to run right now */
    4.14 +extern SDL_bool SDL_SYS_JoystickNeedsPolling();
    4.15 +
    4.16  /* Function to get the device-dependent name of a joystick */
    4.17 -extern const char *SDL_SYS_JoystickNameForIndex(int index);
    4.18 +extern const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index);
    4.19  
    4.20  /* Function to get the current instance id of the joystick located at device_index */
    4.21 -extern SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex( int device_index );
    4.22 +extern SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index);
    4.23  
    4.24  /* Function to open a joystick for use.
    4.25     The joystick to open is specified by the index field of the joystick.
    4.26     This should fill the nbuttons and naxes fields of the joystick structure.
    4.27     It returns 0, or -1 if there is an error.
    4.28   */
    4.29 -extern int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index );
    4.30 +extern int SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index);
    4.31 +
    4.32 +/* Function to query if the joystick is currently attached
    4.33 + *   It returns 1 if attached, 0 otherwise.
    4.34 + */
    4.35 +extern SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick * joystick);
    4.36  
    4.37  /* Function to update the state of a joystick - called as a device poll.
    4.38   * This function shouldn't update the joystick structure directly,
    4.39 @@ -89,32 +103,15 @@
    4.40  /* Function to perform any system-specific joystick related cleanup */
    4.41  extern void SDL_SYS_JoystickQuit(void);
    4.42  
    4.43 -/* Function to query if the joystick is currently attached
    4.44 - *   It returns 1 if attached, 0 otherwise.
    4.45 - */
    4.46 -extern int SDL_SYS_JoystickAttached(SDL_Joystick * joystick);
    4.47 +/* Function to return the stable GUID for a plugged in device */
    4.48 +extern JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index);
    4.49  
    4.50 -/* Function to return the number of joystick devices plugged in right now*/
    4.51 -extern int SDL_SYS_NumJoysticks();
    4.52 -
    4.53 -/* Function to cause any queued joystick insertions to be processed
    4.54 - */
    4.55 -extern void SDL_SYS_JoystickDetect();
    4.56 -
    4.57 -/* Function to determine if the joystick loop needs to run right now
    4.58 - */
    4.59 -extern int SDL_SYS_JoystickNeedsPolling();
    4.60 -
    4.61 -/* Function to return the stable GUID for a plugged in device
    4.62 - */
    4.63 -extern JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index );
    4.64 -
    4.65 -/* Function to return the stable GUID for a opened joystick
    4.66 - */
    4.67 -extern JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick);
    4.68 +/* Function to return the stable GUID for a opened joystick */
    4.69 +extern JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick);
    4.70  
    4.71  #ifdef SDL_JOYSTICK_DINPUT
    4.72  /* Function to get the current instance id of the joystick located at device_index */
    4.73 -extern int SDL_SYS_IsXInputDeviceIndex( int device_index );
    4.74 +extern SDL_bool SDL_SYS_IsXInputDeviceIndex( int device_index );
    4.75  #endif
    4.76 +
    4.77  /* vi: set ts=4 sw=4 expandtab: */
     5.1 --- a/src/joystick/android/SDL_sysjoystick.c	Mon Nov 26 23:58:53 2012 -0800
     5.2 +++ b/src/joystick/android/SDL_sysjoystick.c	Tue Nov 27 00:58:12 2012 -0800
     5.3 @@ -46,16 +46,31 @@
     5.4      return (1);
     5.5  }
     5.6  
     5.7 +int SDL_SYS_NumJoysticks()
     5.8 +{
     5.9 +    return 1;
    5.10 +}
    5.11 +
    5.12 +void SDL_SYS_JoystickDetect()
    5.13 +{
    5.14 +}
    5.15 +
    5.16 +SDL_bool SDL_SYS_JoystickNeedsPolling()
    5.17 +{
    5.18 +    return SDL_FALSE;
    5.19 +}
    5.20 +
    5.21  /* Function to get the device-dependent name of a joystick */
    5.22  const char *
    5.23 -SDL_SYS_JoystickNameForIndex(int index)
    5.24 +SDL_SYS_JoystickNameForDeviceIndex(int device_index)
    5.25  {
    5.26 -    if (index == 0) {
    5.27 -        return accelerometerName;
    5.28 -    } else {
    5.29 -        SDL_SetError("No joystick available with that index");
    5.30 -        return (NULL);
    5.31 -    }
    5.32 +    return accelerometerName;
    5.33 +}
    5.34 +
    5.35 +/* Function to perform the mapping from device index to the instance id for this index */
    5.36 +SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
    5.37 +{
    5.38 +    return device_index;
    5.39  }
    5.40  
    5.41  /* Function to open a joystick for use.
    5.42 @@ -78,6 +93,11 @@
    5.43  	}
    5.44  }
    5.45  
    5.46 +/* Function to determine is this joystick is attached to the system right now */
    5.47 +SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
    5.48 +{
    5.49 +    return SDL_TRUE;
    5.50 +}
    5.51  
    5.52  /* Function to update the state of a joystick - called as a device poll.
    5.53   * This function shouldn't update the joystick structure directly,
    5.54 @@ -111,43 +131,17 @@
    5.55  {
    5.56  }
    5.57  
    5.58 -/* Function to perform the mapping from device index to the instance id for this index */
    5.59 -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index)
    5.60 -{
    5.61 -    return index;
    5.62 -}
    5.63 -
    5.64 -/* Function to determine is this joystick is attached to the system right now */
    5.65 -int SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
    5.66 -{
    5.67 -    return 1;
    5.68 -}
    5.69 -
    5.70 -int SDL_SYS_NumJoysticks()
    5.71 -{
    5.72 -    return 1;
    5.73 -}
    5.74 -
    5.75 -int SDL_SYS_JoystickNeedsPolling()
    5.76 -{
    5.77 -    return 0;
    5.78 -}
    5.79 -
    5.80 -void SDL_SYS_JoystickDetect()
    5.81 -{
    5.82 -}
    5.83 -
    5.84 -JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
    5.85 +JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
    5.86  {
    5.87      JoystickGUID guid;
    5.88      // the GUID is just the first 16 chars of the name for now
    5.89 -    const char *name = SDL_SYS_JoystickNameForIndex( device_index );
    5.90 +    const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
    5.91      SDL_zero( guid );
    5.92      SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
    5.93      return guid;
    5.94  }
    5.95  
    5.96 -JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick)
    5.97 +JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
    5.98  {
    5.99      JoystickGUID guid;
   5.100      // the GUID is just the first 16 chars of the name for now
   5.101 @@ -157,6 +151,6 @@
   5.102      return guid;
   5.103  }
   5.104  
   5.105 -#endif /* SDL_JOYSTICK_NDS */
   5.106 +#endif /* SDL_JOYSTICK_ANDROID */
   5.107  
   5.108  /* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/joystick/beos/SDL_bejoystick.cc	Mon Nov 26 23:58:53 2012 -0800
     6.2 +++ b/src/joystick/beos/SDL_bejoystick.cc	Tue Nov 27 00:58:12 2012 -0800
     6.3 @@ -85,10 +85,30 @@
     6.4          return (SDL_SYS_numjoysticks);
     6.5      }
     6.6  
     6.7 +    int SDL_SYS_NumJoysticks()
     6.8 +    {
     6.9 +        return SDL_SYS_numjoysticks;
    6.10 +    }
    6.11 +
    6.12 +    void SDL_SYS_JoystickDetect()
    6.13 +    {
    6.14 +    }
    6.15 +
    6.16 +    SDL_bool SDL_SYS_JoystickNeedsPolling()
    6.17 +    {
    6.18 +        return SDL_FALSE;
    6.19 +    }
    6.20 +
    6.21  /* Function to get the device-dependent name of a joystick */
    6.22 -    const char *SDL_SYS_JoystickNameForIndex(int index)
    6.23 +    const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index)
    6.24      {
    6.25 -        return SDL_joyname[index];
    6.26 +        return SDL_joyname[device_index];
    6.27 +    }
    6.28 +
    6.29 +/* Function to perform the mapping from device index to the instance id for this index */
    6.30 +    SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
    6.31 +    {
    6.32 +        return device_index;
    6.33      }
    6.34  
    6.35  /* Function to open a joystick for use.
    6.36 @@ -141,6 +161,12 @@
    6.37          return (0);
    6.38      }
    6.39  
    6.40 +/* Function to determine is this joystick is attached to the system right now */
    6.41 +    SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
    6.42 +    {
    6.43 +        return SDL_TRUE;
    6.44 +    }
    6.45 +
    6.46  /* Function to update the state of a joystick - called as a device poll.
    6.47   * This function shouldn't update the joystick structure directly,
    6.48   * but instead should call SDL_PrivateJoystick*() to deliver events
    6.49 @@ -235,44 +261,17 @@
    6.50          SDL_joyname[0] = NULL;
    6.51      }
    6.52  
    6.53 -/* Function to perform the mapping from device index to the instance id for this index */
    6.54 -    SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index)
    6.55 -    {
    6.56 -        return index;
    6.57 -    }
    6.58 -
    6.59 -/* Function to determine is this joystick is attached to the system right now */
    6.60 -    int SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
    6.61 -    {
    6.62 -        return 1;
    6.63 -    }
    6.64 -
    6.65 -    int SDL_SYS_NumJoysticks()
    6.66 -    {
    6.67 -        return SDL_SYS_numjoysticks;
    6.68 -    }
    6.69 -
    6.70 -    int SDL_SYS_JoystickNeedsPolling()
    6.71 -    {
    6.72 -        return 0;
    6.73 -    }
    6.74 -
    6.75 -    void SDL_SYS_JoystickDetect()
    6.76 -    {
    6.77 -    }
    6.78 -
    6.79 -    JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
    6.80 +    JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
    6.81      {
    6.82          JoystickGUID guid;
    6.83          // the GUID is just the first 16 chars of the name for now
    6.84 -        const char *name = SDL_SYS_JoystickNameForIndex( device_index );
    6.85 +        const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
    6.86          SDL_zero( guid );
    6.87          SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
    6.88          return guid;
    6.89      }
    6.90  
    6.91 -
    6.92 -    JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick)
    6.93 +    JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
    6.94      {
    6.95          JoystickGUID guid;
    6.96          // the GUID is just the first 16 chars of the name for now
     7.1 --- a/src/joystick/bsd/SDL_sysjoystick.c	Mon Nov 26 23:58:53 2012 -0800
     7.2 +++ b/src/joystick/bsd/SDL_sysjoystick.c	Tue Nov 27 00:58:12 2012 -0800
     7.3 @@ -157,7 +157,7 @@
     7.4  #define REP_BUF_DATA(rep) ((rep)->buf->data)
     7.5  #endif
     7.6  
     7.7 -int SDL_SYS_numjoysticks = 0;
     7.8 +static int SDL_SYS_numjoysticks = 0;
     7.9  
    7.10  int
    7.11  SDL_SYS_JoystickInit(void)
    7.12 @@ -200,13 +200,33 @@
    7.13      return (SDL_SYS_numjoysticks);
    7.14  }
    7.15  
    7.16 +int SDL_SYS_NumJoysticks()
    7.17 +{
    7.18 +    return SDL_SYS_numjoysticks;
    7.19 +}
    7.20 +
    7.21 +void SDL_SYS_JoystickDetect()
    7.22 +{
    7.23 +}
    7.24 +
    7.25 +SDL_bool SDL_SYS_JoystickNeedsPolling()
    7.26 +{
    7.27 +    return SDL_FALSE;
    7.28 +}
    7.29 +
    7.30  const char *
    7.31 -SDL_SYS_JoystickNameForIndex(int index)
    7.32 +SDL_SYS_JoystickNameForDeviceIndex(int device_index)
    7.33  {
    7.34 -    if (joydevnames[index] != NULL) {
    7.35 -        return (joydevnames[index]);
    7.36 +    if (joydevnames[device_index] != NULL) {
    7.37 +        return (joydevnames[device_index]);
    7.38      }
    7.39 -    return (joynames[index]);
    7.40 +    return (joynames[device_index]);
    7.41 +}
    7.42 +
    7.43 +/* Function to perform the mapping from device index to the instance id for this index */
    7.44 +SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
    7.45 +{
    7.46 +    return device_index;
    7.47  }
    7.48  
    7.49  static int
    7.50 @@ -404,6 +424,12 @@
    7.51      return (-1);
    7.52  }
    7.53  
    7.54 +/* Function to determine is this joystick is attached to the system right now */
    7.55 +SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
    7.56 +{
    7.57 +    return SDL_TRUE;
    7.58 +}
    7.59 +
    7.60  void
    7.61  SDL_SYS_JoystickUpdate(SDL_Joystick * joy)
    7.62  {
    7.63 @@ -558,43 +584,17 @@
    7.64      return;
    7.65  }
    7.66  
    7.67 -/* Function to perform the mapping from device index to the instance id for this index */
    7.68 -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index)
    7.69 -{
    7.70 -    return index;
    7.71 -}
    7.72 -
    7.73 -/* Function to determine is this joystick is attached to the system right now */
    7.74 -int SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
    7.75 -{
    7.76 -    return 1;
    7.77 -}
    7.78 -
    7.79 -int SDL_SYS_NumJoysticks()
    7.80 -{
    7.81 -    return SDL_SYS_numjoysticks;
    7.82 -}
    7.83 -
    7.84 -int SDL_SYS_JoystickNeedsPolling()
    7.85 -{
    7.86 -    return 0;
    7.87 -}
    7.88 -
    7.89 -void SDL_SYS_JoystickDetect()
    7.90 -{
    7.91 -}
    7.92 -
    7.93 -JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
    7.94 +JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
    7.95  {
    7.96      JoystickGUID guid;
    7.97      // the GUID is just the first 16 chars of the name for now
    7.98 -    const char *name = SDL_SYS_JoystickNameForIndex( device_index );
    7.99 +    const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
   7.100      SDL_zero( guid );
   7.101      SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
   7.102      return guid;
   7.103  }
   7.104  
   7.105 -JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick)
   7.106 +JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
   7.107  {
   7.108      JoystickGUID guid;
   7.109      // the GUID is just the first 16 chars of the name for now
     8.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Mon Nov 26 23:58:53 2012 -0800
     8.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Tue Nov 27 00:58:12 2012 -0800
     8.3 @@ -63,7 +63,7 @@
     8.4  /* OSX reference to the notification object that tells us about device insertion/removal */
     8.5  IONotificationPortRef notificationPort = 0;
     8.6  /* if 1 then a device was added since the last update call */
     8.7 -Uint8 s_bDeviceAdded = 0;
     8.8 +static SDL_bool s_bDeviceAdded = SDL_FALSE;
     8.9  
    8.10  /* static incrementing counter for new joystick devices seen on the system. Devices should start with index 0 */
    8.11  static int s_joystick_instance_id = -1;
    8.12 @@ -674,7 +674,7 @@
    8.13  	}
    8.14  	
    8.15  	device->send_open_event = 1;
    8.16 -	s_bDeviceAdded = 1;
    8.17 +	s_bDeviceAdded = SDL_TRUE;
    8.18  	
    8.19  	/* Add device to the end of the list */
    8.20  	if ( !gpDeviceList )
    8.21 @@ -805,18 +805,89 @@
    8.22      return SDL_SYS_NumJoysticks();
    8.23  }
    8.24  
    8.25 +/* Function to return the number of joystick devices plugged in right now */
    8.26 +int
    8.27 +SDL_SYS_NumJoysticks()
    8.28 +{
    8.29 +	recDevice *device = gpDeviceList;
    8.30 +    int nJoySticks = 0;
    8.31 +	
    8.32 +	while ( device )
    8.33 +	{
    8.34 +		nJoySticks++;
    8.35 +        device = device->pNext;
    8.36 +	}
    8.37 +
    8.38 +	return nJoySticks;
    8.39 +}
    8.40 +
    8.41 +/* Function to cause any queued joystick insertions to be processed
    8.42 + */
    8.43 +void
    8.44 +SDL_SYS_JoystickDetect()
    8.45 +{
    8.46 +	if ( s_bDeviceAdded )
    8.47 +	{
    8.48 +		recDevice *device = gpDeviceList;
    8.49 +		s_bDeviceAdded = SDL_FALSE;
    8.50 +		int device_index = 0;
    8.51 +		// send notifications
    8.52 +		while ( device )
    8.53 +		{
    8.54 +			if ( device->send_open_event )
    8.55 +			{
    8.56 +				device->send_open_event = 0;
    8.57 +#if !SDL_EVENTS_DISABLED
    8.58 +				SDL_Event event;
    8.59 +				event.type = SDL_JOYDEVICEADDED;
    8.60 +				
    8.61 +				if (SDL_GetEventState(event.type) == SDL_ENABLE) {
    8.62 +					event.jdevice.which = device_index;
    8.63 +					if ((SDL_EventOK == NULL)
    8.64 +						|| (*SDL_EventOK) (SDL_EventOKParam, &event)) {
    8.65 +						SDL_PushEvent(&event);
    8.66 +					}
    8.67 +				}
    8.68 +#endif /* !SDL_EVENTS_DISABLED */
    8.69 +			}
    8.70 +			device_index++;
    8.71 +			device = device->pNext;
    8.72 +		}
    8.73 +	}
    8.74 +}
    8.75 +
    8.76 +SDL_bool
    8.77 +SDL_SYS_JoystickNeedsPolling()
    8.78 +{
    8.79 +	return s_bDeviceAdded;
    8.80 +}
    8.81 +
    8.82  /* Function to get the device-dependent name of a joystick */
    8.83  const char *
    8.84 -SDL_SYS_JoystickNameForIndex(int index)
    8.85 +SDL_SYS_JoystickNameForDeviceIndex(int device_index)
    8.86  {
    8.87      recDevice *device = gpDeviceList;
    8.88  
    8.89 -    for (; index > 0; index--)
    8.90 +    for (; device_index > 0; device_index--)
    8.91          device = device->pNext;
    8.92  
    8.93  	return device->product;
    8.94  }
    8.95  
    8.96 +/* Function to return the instance id of the joystick at device_index
    8.97 + */
    8.98 +SDL_JoystickID
    8.99 +SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
   8.100 +{
   8.101 +    recDevice *device = gpDeviceList;
   8.102 +    int index;
   8.103 +	
   8.104 +    for (index = device_index; index > 0; index--)
   8.105 +        device = device->pNext;
   8.106 +
   8.107 +	return device->instance_id;
   8.108 +}
   8.109 +
   8.110  /* Function to open a joystick for use.
   8.111   * The joystick to open is specified by the index field of the joystick.
   8.112   * This should fill the nbuttons and naxes fields of the joystick structure.
   8.113 @@ -842,58 +913,26 @@
   8.114      return 0;
   8.115  }
   8.116  
   8.117 -
   8.118 -/* Function to return the instance id of the joystick at device_index
   8.119 +/* Function to query if the joystick is currently attached
   8.120 + *   It returns 1 if attached, 0 otherwise.
   8.121   */
   8.122 -SDL_JoystickID
   8.123 -SDL_SYS_GetInstanceIdOfDeviceIndex( int device_index )
   8.124 +SDL_bool
   8.125 +SDL_SYS_JoystickAttached(SDL_Joystick * joystick)
   8.126  {
   8.127 -    recDevice *device = gpDeviceList;
   8.128 +	recDevice *device = gpDeviceList;
   8.129      int index;
   8.130  	
   8.131 -    for (index = device_index; index > 0; index--)
   8.132 +	while ( device )
   8.133 +	{
   8.134 +		if ( joystick->instance_id == device->instance_id )
   8.135 +			return SDL_TRUE;
   8.136 +
   8.137          device = device->pNext;
   8.138 -
   8.139 -	return device->instance_id;
   8.140 +	}
   8.141 +	
   8.142 +	return SDL_FALSE;
   8.143  }
   8.144  
   8.145 -
   8.146 -/* Function to cause any queued joystick insertions to be processed
   8.147 - */
   8.148 -void
   8.149 -SDL_SYS_JoystickDetect()
   8.150 -{
   8.151 -	if ( s_bDeviceAdded )
   8.152 -	{
   8.153 -		recDevice *device = gpDeviceList;
   8.154 -		s_bDeviceAdded = 0;
   8.155 -		int device_index = 0;
   8.156 -		// send notifications
   8.157 -		while ( device )
   8.158 -		{
   8.159 -			if ( device->send_open_event )
   8.160 -			{
   8.161 -				device->send_open_event = 0;
   8.162 -#if !SDL_EVENTS_DISABLED
   8.163 -				SDL_Event event;
   8.164 -				event.type = SDL_JOYDEVICEADDED;
   8.165 -				
   8.166 -				if (SDL_GetEventState(event.type) == SDL_ENABLE) {
   8.167 -					event.jdevice.which = device_index;
   8.168 -					if ((SDL_EventOK == NULL)
   8.169 -						|| (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   8.170 -						SDL_PushEvent(&event);
   8.171 -					}
   8.172 -				}
   8.173 -#endif /* !SDL_EVENTS_DISABLED */
   8.174 -			}
   8.175 -			device_index++;
   8.176 -			device = device->pNext;
   8.177 -		}
   8.178 -	}
   8.179 -}
   8.180 -
   8.181 -
   8.182  /* Function to update the state of a joystick - called as a device poll.
   8.183   * This function shouldn't update the joystick structure directly,
   8.184   * but instead should call SDL_PrivateJoystick*() to deliver events
   8.185 @@ -1023,28 +1062,6 @@
   8.186      return;
   8.187  }
   8.188  
   8.189 -
   8.190 -/* Function to query if the joystick is currently attached
   8.191 - *   It returns 1 if attached, 0 otherwise.
   8.192 - */
   8.193 -int
   8.194 -SDL_SYS_JoystickAttached(SDL_Joystick * joystick)
   8.195 -{
   8.196 -	recDevice *device = gpDeviceList;
   8.197 -    int index;
   8.198 -	
   8.199 -	while ( device )
   8.200 -	{
   8.201 -		if ( joystick->instance_id == device->instance_id )
   8.202 -			return (1);
   8.203 -		
   8.204 -        device = device->pNext;
   8.205 -	}
   8.206 -	
   8.207 -	return 0;
   8.208 -}
   8.209 -
   8.210 -
   8.211  /* Function to close a joystick after use */
   8.212  void
   8.213  SDL_SYS_JoystickClose(SDL_Joystick * joystick)
   8.214 @@ -1067,29 +1084,7 @@
   8.215  }
   8.216  
   8.217  
   8.218 -/* Function to return the number of joystick devices plugged in right now*/
   8.219 -int
   8.220 -SDL_SYS_NumJoysticks()
   8.221 -{
   8.222 -	recDevice *device = gpDeviceList;
   8.223 -    int nJoySticks = 0;
   8.224 -	
   8.225 -	while ( device )
   8.226 -	{
   8.227 -		nJoySticks++;
   8.228 -        device = device->pNext;
   8.229 -	}
   8.230 -
   8.231 -	return nJoySticks;
   8.232 -}
   8.233 -
   8.234 -int
   8.235 -SDL_SYS_JoystickNeedsPolling()
   8.236 -{
   8.237 -	return s_bDeviceAdded;
   8.238 -}
   8.239 -
   8.240 -JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
   8.241 +JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
   8.242  {
   8.243      recDevice *device = gpDeviceList;
   8.244      int index;
   8.245 @@ -1100,7 +1095,7 @@
   8.246  	return device->guid;	
   8.247  }
   8.248  
   8.249 -JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick *joystick)
   8.250 +JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
   8.251  {
   8.252  	return joystick->hwdata->guid;
   8.253  }
     9.1 --- a/src/joystick/dummy/SDL_sysjoystick.c	Mon Nov 26 23:58:53 2012 -0800
     9.2 +++ b/src/joystick/dummy/SDL_sysjoystick.c	Tue Nov 27 00:58:12 2012 -0800
     9.3 @@ -37,14 +37,34 @@
     9.4      return (0);
     9.5  }
     9.6  
     9.7 +int SDL_SYS_NumJoysticks()
     9.8 +{
     9.9 +    return 0;
    9.10 +}
    9.11 +
    9.12 +void SDL_SYS_JoystickDetect()
    9.13 +{
    9.14 +}
    9.15 +
    9.16 +SDL_bool SDL_SYS_JoystickNeedsPolling()
    9.17 +{
    9.18 +    return SDL_FALSE;
    9.19 +}
    9.20 +
    9.21  /* Function to get the device-dependent name of a joystick */
    9.22  const char *
    9.23 -SDL_SYS_JoystickNameForIndex(int index)
    9.24 +SDL_SYS_JoystickNameForDeviceIndex(int device_index)
    9.25  {
    9.26      SDL_SetError("Logic error: No joysticks available");
    9.27      return (NULL);
    9.28  }
    9.29  
    9.30 +/* Function to perform the mapping from device index to the instance id for this index */
    9.31 +SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
    9.32 +{
    9.33 +    return device_index;
    9.34 +}
    9.35 +
    9.36  /* Function to open a joystick for use.
    9.37     The joystick to open is specified by the index field of the joystick.
    9.38     This should fill the nbuttons and naxes fields of the joystick structure.
    9.39 @@ -57,6 +77,12 @@
    9.40      return (-1);
    9.41  }
    9.42  
    9.43 +/* Function to determine is this joystick is attached to the system right now */
    9.44 +SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
    9.45 +{
    9.46 +    return SDL_TRUE;
    9.47 +}
    9.48 +
    9.49  /* Function to update the state of a joystick - called as a device poll.
    9.50   * This function shouldn't update the joystick structure directly,
    9.51   * but instead should call SDL_PrivateJoystick*() to deliver events
    9.52 @@ -82,44 +108,18 @@
    9.53      return;
    9.54  }
    9.55  
    9.56 -/* Function to perform the mapping from device index to the instance id for this index */
    9.57 -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index)
    9.58 -{
    9.59 -    return index;
    9.60 -}
    9.61 -
    9.62 -/* Function to determine is this joystick is attached to the system right now */
    9.63 -int SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
    9.64 -{
    9.65 -    return 1;
    9.66 -}
    9.67 -
    9.68 -int SDL_SYS_NumJoysticks()
    9.69 -{
    9.70 -    return 0;
    9.71 -}
    9.72 -
    9.73 -int SDL_SYS_JoystickNeedsPolling()
    9.74 -{
    9.75 -    return 0;
    9.76 -}
    9.77 -
    9.78 -void SDL_SYS_JoystickDetect()
    9.79 -{
    9.80 -}
    9.81 -
    9.82 -JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
    9.83 +JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
    9.84  {
    9.85      JoystickGUID guid;
    9.86      // the GUID is just the first 16 chars of the name for now
    9.87 -    const char *name = SDL_SYS_JoystickNameForIndex( device_index );
    9.88 +    const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
    9.89      SDL_zero( guid );
    9.90      SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
    9.91      return guid;
    9.92  }
    9.93  
    9.94  
    9.95 -JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick)
    9.96 +JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
    9.97  {
    9.98      JoystickGUID guid;
    9.99      // the GUID is just the first 16 chars of the name for now
    10.1 --- a/src/joystick/iphoneos/SDL_sysjoystick.m	Mon Nov 26 23:58:53 2012 -0800
    10.2 +++ b/src/joystick/iphoneos/SDL_sysjoystick.m	Tue Nov 27 00:58:12 2012 -0800
    10.3 @@ -40,17 +40,31 @@
    10.4      return (1);
    10.5  }
    10.6  
    10.7 +int SDL_SYS_NumJoysticks()
    10.8 +{
    10.9 +    return 1;
   10.10 +}
   10.11 +
   10.12 +void SDL_SYS_JoystickDetect()
   10.13 +{
   10.14 +}
   10.15 +
   10.16 +SDL_bool SDL_SYS_JoystickNeedsPolling()
   10.17 +{
   10.18 +    return SDL_FALSE;
   10.19 +}
   10.20 +
   10.21  /* Function to get the device-dependent name of a joystick */
   10.22  const char *
   10.23 -SDL_SYS_JoystickNameForIndex(int index)
   10.24 +SDL_SYS_JoystickNameForDeviceIndex(int device_index)
   10.25  {
   10.26 -	switch(index) {
   10.27 -		case 0:
   10.28 -			return accelerometerName;
   10.29 -		default:
   10.30 -			SDL_SetError("No joystick available with that index");
   10.31 -			return NULL;
   10.32 -	}
   10.33 +    return accelerometerName;
   10.34 +}
   10.35 +
   10.36 +/* Function to perform the mapping from device index to the instance id for this index */
   10.37 +SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
   10.38 +{
   10.39 +    return device_index;
   10.40  }
   10.41  
   10.42  /* Function to open a joystick for use.
   10.43 @@ -61,17 +75,18 @@
   10.44  int
   10.45  SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
   10.46  {
   10.47 -	if (device_index == 0) {
   10.48 -		joystick->naxes = 3;
   10.49 -		joystick->nhats = 0;
   10.50 -		joystick->nballs = 0;
   10.51 -		joystick->nbuttons = 0;
   10.52 -		[[SDLUIAccelerationDelegate sharedDelegate] startup];
   10.53 -		return 0;
   10.54 -	} else {
   10.55 -		SDL_SetError("No joystick available with that index");
   10.56 -		return (-1);
   10.57 -	}
   10.58 +    joystick->naxes = 3;
   10.59 +    joystick->nhats = 0;
   10.60 +    joystick->nballs = 0;
   10.61 +    joystick->nbuttons = 0;
   10.62 +    [[SDLUIAccelerationDelegate sharedDelegate] startup];
   10.63 +    return 0;
   10.64 +}
   10.65 +
   10.66 +/* Function to determine is this joystick is attached to the system right now */
   10.67 +SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
   10.68 +{
   10.69 +    return SDL_TRUE;
   10.70  }
   10.71  
   10.72  /* Function to update the state of a joystick - called as a device poll.
   10.73 @@ -118,43 +133,17 @@
   10.74      return;
   10.75  }
   10.76  
   10.77 -/* Function to perform the mapping from device index to the instance id for this index */
   10.78 -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index)
   10.79 -{
   10.80 -    return index;
   10.81 -}
   10.82 -
   10.83 -/* Function to determine is this joystick is attached to the system right now */
   10.84 -int SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
   10.85 -{
   10.86 -    return 1;
   10.87 -}
   10.88 -
   10.89 -int SDL_SYS_NumJoysticks()
   10.90 -{
   10.91 -    return 1;
   10.92 -}
   10.93 -
   10.94 -int SDL_SYS_JoystickNeedsPolling()
   10.95 -{
   10.96 -    return 0;
   10.97 -}
   10.98 -
   10.99 -void SDL_SYS_JoystickDetect()
  10.100 -{
  10.101 -}
  10.102 -
  10.103 -JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
  10.104 +JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
  10.105  {
  10.106      JoystickGUID guid;
  10.107      // the GUID is just the first 16 chars of the name for now
  10.108 -    const char *name = SDL_SYS_JoystickNameForIndex( device_index );
  10.109 +    const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
  10.110      SDL_zero( guid );
  10.111      SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
  10.112      return guid;
  10.113  }
  10.114  
  10.115 -JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick)
  10.116 +JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
  10.117  {
  10.118      JoystickGUID guid;
  10.119      // the GUID is just the first 16 chars of the name for now
    11.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Mon Nov 26 23:58:53 2012 -0800
    11.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Tue Nov 27 00:58:12 2012 -0800
    11.3 @@ -298,7 +298,7 @@
    11.4      ret = 0;
    11.5  
    11.6      for (i = 0; i < max; i++) {
    11.7 -        name = SDL_SYS_JoystickNameForIndex(i);
    11.8 +        name = SDL_SYS_JoystickNameForDeviceIndex(i);
    11.9  
   11.10          fd = open(SDL_joylist[i].fname, O_RDONLY, 0);
   11.11          if (fd >= 0) {
   11.12 @@ -507,27 +507,41 @@
   11.13      return (numjoysticks);
   11.14  }
   11.15  
   11.16 +int SDL_SYS_NumJoysticks()
   11.17 +{
   11.18 +    return SDL_SYS_numjoysticks;
   11.19 +}
   11.20 +
   11.21 +void SDL_SYS_JoystickDetect()
   11.22 +{
   11.23 +}
   11.24 +
   11.25 +SDL_bool SDL_SYS_JoystickNeedsPolling()
   11.26 +{
   11.27 +    return SDL_FALSE;
   11.28 +}
   11.29 +
   11.30  /* Function to get the device-dependent name of a joystick */
   11.31  const char *
   11.32 -SDL_SYS_JoystickNameForIndex(int index)
   11.33 +SDL_SYS_JoystickNameForDeviceIndex(int device_index)
   11.34  {
   11.35      int fd;
   11.36      static char namebuf[128];
   11.37      const char *name;
   11.38 -    SDL_logical_joydecl(int oindex = index);
   11.39 +    SDL_logical_joydecl(int oindex = device_index);
   11.40  
   11.41  #ifndef NO_LOGICAL_JOYSTICKS
   11.42 -    SDL_joylist_head(index, index);
   11.43 +    SDL_joylist_head(device_index, device_index);
   11.44  #endif
   11.45      name = NULL;
   11.46 -    fd = open(SDL_joylist[index].fname, O_RDONLY, 0);
   11.47 +    fd = open(SDL_joylist[device_index].fname, O_RDONLY, 0);
   11.48      if (fd >= 0) {
   11.49          if (
   11.50  #if SDL_INPUT_LINUXEV
   11.51                 (ioctl(fd, EVIOCGNAME(sizeof(namebuf)), namebuf) <= 0) &&
   11.52  #endif
   11.53                 (ioctl(fd, JSIOCGNAME(sizeof(namebuf)), namebuf) <= 0)) {
   11.54 -            name = SDL_joylist[index].fname;
   11.55 +            name = SDL_joylist[device_index].fname;
   11.56          } else {
   11.57              name = namebuf;
   11.58          }
   11.59 @@ -536,7 +550,7 @@
   11.60  
   11.61  #ifndef NO_LOGICAL_JOYSTICKS
   11.62          if (SDL_joylist[oindex].prev || SDL_joylist[oindex].next
   11.63 -            || index != oindex) {
   11.64 +            || device_index != oindex) {
   11.65              LogicalSuffix(SDL_joylist[oindex].logicalno, namebuf, 128);
   11.66          }
   11.67  #endif
   11.68 @@ -544,6 +558,12 @@
   11.69      return name;
   11.70  }
   11.71  
   11.72 +/* Function to perform the mapping from device index to the instance id for this index */
   11.73 +SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
   11.74 +{
   11.75 +    return device_index;
   11.76 +}
   11.77 +
   11.78  static int
   11.79  allocate_hatdata(SDL_Joystick * joystick)
   11.80  {
   11.81 @@ -604,7 +624,7 @@
   11.82          joystick->nbuttons = n;
   11.83      }
   11.84  
   11.85 -    name = SDL_SYS_JoystickNameForIndex(joystick->instance_id);
   11.86 +    name = SDL_SYS_JoystickNameForDeviceIndex(joystick->instance_id);
   11.87  
   11.88      /* Generic analog joystick support */
   11.89      if (SDL_strstr(name, "Analog") == name && SDL_strstr(name, "-hat")) {
   11.90 @@ -856,6 +876,12 @@
   11.91      return (0);
   11.92  }
   11.93  
   11.94 +/* Function to determine is this joystick is attached to the system right now */
   11.95 +SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
   11.96 +{
   11.97 +    return SDL_TRUE;
   11.98 +}
   11.99 +
  11.100  #ifndef NO_LOGICAL_JOYSTICKS
  11.101  
  11.102  static SDL_Joystick *
  11.103 @@ -1239,44 +1265,17 @@
  11.104      }
  11.105  }
  11.106  
  11.107 -/* Function to perform the mapping from device index to the instance id for this index */
  11.108 -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index)
  11.109 -{
  11.110 -    return index;
  11.111 -}
  11.112 -
  11.113 -/* Function to determine is this joystick is attached to the system right now */
  11.114 -int SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
  11.115 -{
  11.116 -    return 1;
  11.117 -}
  11.118 -
  11.119 -int SDL_SYS_NumJoysticks()
  11.120 -{
  11.121 -    return SDL_SYS_numjoysticks;
  11.122 -}
  11.123 -
  11.124 -int SDL_SYS_JoystickNeedsPolling()
  11.125 -{
  11.126 -    return 0;
  11.127 -}
  11.128 -
  11.129 -void SDL_SYS_JoystickDetect()
  11.130 -{
  11.131 -}
  11.132 -
  11.133 -JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
  11.134 +JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
  11.135  {
  11.136      JoystickGUID guid;
  11.137      // the GUID is just the first 16 chars of the name for now
  11.138 -    const char *name = SDL_SYS_JoystickNameForIndex( device_index );
  11.139 +    const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
  11.140      SDL_zero( guid );
  11.141      SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
  11.142      return guid;
  11.143  }
  11.144  
  11.145 -
  11.146 -JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick)
  11.147 +JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
  11.148  {
  11.149      JoystickGUID guid;
  11.150      // the GUID is just the first 16 chars of the name for now
    12.1 --- a/src/joystick/nds/SDL_sysjoystick.c	Mon Nov 26 23:58:53 2012 -0800
    12.2 +++ b/src/joystick/nds/SDL_sysjoystick.c	Tue Nov 27 00:58:12 2012 -0800
    12.3 @@ -36,9 +36,6 @@
    12.4  #include "../../video/nds/SDL_ndsevents_c.h"
    12.5  
    12.6  /* Function to scan the system for joysticks.
    12.7 - * This function should set SDL_numjoysticks to the number of available
    12.8 - * joysticks.  Joystick 0 should be the system default joystick.
    12.9 - * It should return 0, or -1 on an unrecoverable fatal error.
   12.10   */
   12.11  int
   12.12  SDL_SYS_JoystickInit(void)
   12.13 @@ -46,14 +43,31 @@
   12.14      return (1);
   12.15  }
   12.16  
   12.17 +int SDL_SYS_NumJoysticks()
   12.18 +{
   12.19 +    return 1;
   12.20 +}
   12.21 +
   12.22 +void SDL_SYS_JoystickDetect()
   12.23 +{
   12.24 +}
   12.25 +
   12.26 +SDL_bool SDL_SYS_JoystickNeedsPolling()
   12.27 +{
   12.28 +    return SDL_FALSE;
   12.29 +}
   12.30 +
   12.31  /* Function to get the device-dependent name of a joystick */
   12.32  const char *
   12.33 -SDL_SYS_JoystickNameForIndex(int index)
   12.34 +SDL_SYS_JoystickNameForDeviceIndex(int device_index)
   12.35  {
   12.36 -    if (!index)
   12.37 -        return "NDS builtin joypad";
   12.38 -    SDL_SetError("No joystick available with that index");
   12.39 -    return (NULL);
   12.40 +    return "NDS builtin joypad";
   12.41 +}
   12.42 +
   12.43 +/* Function to perform the mapping from device index to the instance id for this index */
   12.44 +SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
   12.45 +{
   12.46 +    return device_index;
   12.47  }
   12.48  
   12.49  /* Function to open a joystick for use.
   12.50 @@ -71,6 +85,11 @@
   12.51      return 0;
   12.52  }
   12.53  
   12.54 +/* Function to determine is this joystick is attached to the system right now */
   12.55 +SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
   12.56 +{
   12.57 +    return SDL_TRUE;
   12.58 +}
   12.59  
   12.60  /* Function to update the state of a joystick - called as a device poll.
   12.61   * This function shouldn't update the joystick structure directly,
   12.62 @@ -167,44 +186,17 @@
   12.63  {
   12.64  }
   12.65  
   12.66 -/* Function to perform the mapping from device index to the instance id for this index */
   12.67 -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index)
   12.68 -{
   12.69 -    return index;
   12.70 -}
   12.71 -
   12.72 -/* Function to determine is this joystick is attached to the system right now */
   12.73 -int SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
   12.74 -{
   12.75 -    return 1;
   12.76 -}
   12.77 -
   12.78 -int SDL_SYS_NumJoysticks()
   12.79 -{
   12.80 -    return 1;
   12.81 -}
   12.82 -
   12.83 -int SDL_SYS_JoystickNeedsPolling()
   12.84 -{
   12.85 -    return 0;
   12.86 -}
   12.87 -
   12.88 -void SDL_SYS_JoystickDetect()
   12.89 -{
   12.90 -}
   12.91 -
   12.92 -JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
   12.93 +JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
   12.94  {
   12.95      JoystickGUID guid;
   12.96      // the GUID is just the first 16 chars of the name for now
   12.97 -    const char *name = SDL_SYS_JoystickNameForIndex( device_index );
   12.98 +    const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
   12.99      SDL_zero( guid );
  12.100      SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
  12.101      return guid;
  12.102  }
  12.103  
  12.104 -
  12.105 -JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick)
  12.106 +JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
  12.107  {
  12.108      JoystickGUID guid;
  12.109      // the GUID is just the first 16 chars of the name for now
    13.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Mon Nov 26 23:58:53 2012 -0800
    13.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Tue Nov 27 00:58:12 2012 -0800
    13.3 @@ -84,7 +84,7 @@
    13.4  	char *joystickname;
    13.5  	Uint8 send_add_event;
    13.6  	int nInstanceID;
    13.7 -	Uint8 bXInputDevice;
    13.8 +	SDL_bool bXInputDevice;
    13.9  	Uint8 XInputUserId;
   13.10  	struct JoyStick_DeviceData_ *pNext;
   13.11  };
   13.12 @@ -674,18 +674,215 @@
   13.13  	    return SDL_SYS_NumJoysticks();
   13.14  }
   13.15  
   13.16 +/* return the number of joysticks that are connected right now */
   13.17 +int SDL_SYS_NumJoysticks()
   13.18 +{
   13.19 +	int nJoysticks = 0;
   13.20 +	JoyStick_DeviceData *device = SYS_Joystick;
   13.21 +	while ( device )
   13.22 +	{
   13.23 +		nJoysticks++;
   13.24 +		device = device->pNext;
   13.25 +	}
   13.26 +
   13.27 +	return nJoysticks;
   13.28 +}
   13.29 +
   13.30 +static int s_iNewGUID = 0;
   13.31 +
   13.32 +/* helper function for direct input, gets called for each connected joystick */
   13.33 +static BOOL CALLBACK
   13.34 +	EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
   13.35 +{
   13.36 +	JoyStick_DeviceData *pNewJoystick;
   13.37 +	SDL_bool bXInputDevice;
   13.38 +	pNewJoystick = *(JoyStick_DeviceData **)pContext;
   13.39 +	while ( pNewJoystick )
   13.40 +	{
   13.41 +		if ( !SDL_memcmp( &pNewJoystick->dxdevice.guidInstance, &pdidInstance->guidInstance, sizeof(pNewJoystick->dxdevice.guidInstance) ) )
   13.42 +		{
   13.43 +			if ( SYS_Joystick )
   13.44 +			{
   13.45 +				pNewJoystick->pNext = SYS_Joystick;
   13.46 +			}
   13.47 +			SYS_Joystick = pNewJoystick;
   13.48 +			/* if we are replacing the front of the list then update it */
   13.49 +			if ( pNewJoystick == *(JoyStick_DeviceData **)pContext ) 
   13.50 +			{
   13.51 +				*(JoyStick_DeviceData **)pContext = pNewJoystick->pNext;
   13.52 +			}
   13.53 +
   13.54 +			s_pKnownJoystickGUIDs[ s_iNewGUID ] = pdidInstance->guidInstance;
   13.55 +			s_iNewGUID++;
   13.56 +			if ( s_iNewGUID < MAX_JOYSTICKS )
   13.57 +				return DIENUM_CONTINUE; // already have this joystick loaded, just keep going
   13.58 +			else
   13.59 +				return DIENUM_STOP; 
   13.60 +		}
   13.61 +
   13.62 +		pNewJoystick = pNewJoystick->pNext;
   13.63 +	}
   13.64 +
   13.65 +	s_bDeviceAdded = SDL_TRUE;
   13.66 +
   13.67 +	bXInputDevice = IsXInputDevice( &pdidInstance->guidProduct );
   13.68 +
   13.69 +	pNewJoystick = (JoyStick_DeviceData *)SDL_malloc( sizeof(JoyStick_DeviceData) );
   13.70 +
   13.71 +	if ( bXInputDevice )
   13.72 +	{
   13.73 +		SDL_memset(&(pNewJoystick->dxdevice), 0x0,
   13.74 +			sizeof(DIDEVICEINSTANCE));
   13.75 +		pNewJoystick->bXInputDevice = SDL_TRUE;
   13.76 +		pNewJoystick->XInputUserId = INVALID_XINPUT_USERID;
   13.77 +	}
   13.78 +	else
   13.79 +	{
   13.80 +		pNewJoystick->bXInputDevice = SDL_FALSE;
   13.81 +		SDL_memcpy(&(pNewJoystick->dxdevice), pdidInstance,
   13.82 +			sizeof(DIDEVICEINSTANCE));
   13.83 +	}
   13.84 +	pNewJoystick->joystickname = WIN_StringToUTF8(pdidInstance->tszProductName);
   13.85 +	pNewJoystick->send_add_event = 1;
   13.86 +	pNewJoystick->nInstanceID = ++s_nInstanceID;
   13.87 +	SDL_memcpy( &pNewJoystick->guid, &pdidInstance->guidProduct, sizeof(pNewJoystick->guid) );
   13.88 +	pNewJoystick->pNext = NULL;
   13.89 +
   13.90 +	if ( SYS_Joystick )
   13.91 +	{
   13.92 +		pNewJoystick->pNext = SYS_Joystick;
   13.93 +	}
   13.94 +	SYS_Joystick = pNewJoystick;
   13.95 +
   13.96 +	s_pKnownJoystickGUIDs[ s_iNewGUID ] = pdidInstance->guidInstance;
   13.97 +	s_iNewGUID++;
   13.98 +
   13.99 +	if ( s_iNewGUID < MAX_JOYSTICKS )
  13.100 +		return DIENUM_CONTINUE; // already have this joystick loaded, just keep going
  13.101 +	else
  13.102 +		return DIENUM_STOP; 
  13.103 +}
  13.104 +
  13.105 +/* detect any new joysticks being inserted into the system */
  13.106 +void SDL_SYS_JoystickDetect()
  13.107 +{
  13.108 +	HRESULT result;
  13.109 +	JoyStick_DeviceData *pCurList = NULL;
  13.110 +	/* only enum the devices if the joystick thread told us something changed */
  13.111 +	if ( s_bDeviceAdded || s_bDeviceRemoved )
  13.112 +	{
  13.113 +		s_bDeviceAdded = SDL_FALSE;
  13.114 +		s_bDeviceRemoved = SDL_FALSE;
  13.115 +
  13.116 +		pCurList = SYS_Joystick;
  13.117 +		SYS_Joystick = NULL;
  13.118 +		s_iNewGUID = 0;
  13.119 +		SDL_mutexP( s_mutexJoyStickEnum );
  13.120 +
  13.121 +		if ( !s_pKnownJoystickGUIDs )
  13.122 +			s_pKnownJoystickGUIDs = SDL_malloc( sizeof(GUID)*MAX_JOYSTICKS );
  13.123 +				
  13.124 +		SDL_memset( s_pKnownJoystickGUIDs, 0x0, sizeof(GUID)*MAX_JOYSTICKS );
  13.125 +
  13.126 +		/* Look for joysticks, wheels, head trackers, gamepads, etc.. */
  13.127 +		result = IDirectInput8_EnumDevices(dinput,
  13.128 +			DI8DEVCLASS_GAMECTRL,
  13.129 +			EnumJoysticksCallback,
  13.130 +			&pCurList, DIEDFL_ATTACHEDONLY);
  13.131 +
  13.132 +		SDL_mutexV( s_mutexJoyStickEnum );
  13.133 +	}
  13.134 +
  13.135 +	if ( pCurList )
  13.136 +	{
  13.137 +		while ( pCurList )
  13.138 +		{
  13.139 +			JoyStick_DeviceData *pListNext = NULL;
  13.140 +#if !SDL_EVENTS_DISABLED
  13.141 +			SDL_Event event;
  13.142 +			event.type = SDL_JOYDEVICEREMOVED;
  13.143 +
  13.144 +			if (SDL_GetEventState(event.type) == SDL_ENABLE) {
  13.145 +				event.jdevice.which = pCurList->nInstanceID;
  13.146 +				if ((SDL_EventOK == NULL)
  13.147 +					|| (*SDL_EventOK) (SDL_EventOKParam, &event)) {
  13.148 +						SDL_PushEvent(&event);
  13.149 +				}
  13.150 +			}
  13.151 +#endif // !SDL_EVENTS_DISABLED 
  13.152 +
  13.153 +			pListNext = pCurList->pNext;
  13.154 +			SDL_free(pCurList->joystickname);
  13.155 +			SDL_free( pCurList );
  13.156 +			pCurList = pListNext;
  13.157 +		}
  13.158 +
  13.159 +	}
  13.160 +
  13.161 +	if ( s_bDeviceAdded )
  13.162 +	{
  13.163 +		JoyStick_DeviceData *pNewJoystick;
  13.164 +		int device_index = 0;
  13.165 +		s_bDeviceAdded = SDL_FALSE;
  13.166 +		pNewJoystick = SYS_Joystick;
  13.167 +		while ( pNewJoystick )
  13.168 +		{
  13.169 +			if ( pNewJoystick->send_add_event )
  13.170 +			{
  13.171 +#if !SDL_EVENTS_DISABLED
  13.172 +				SDL_Event event;
  13.173 +				event.type = SDL_JOYDEVICEADDED;
  13.174 +
  13.175 +				if (SDL_GetEventState(event.type) == SDL_ENABLE) {
  13.176 +					event.jdevice.which = device_index;
  13.177 +					if ((SDL_EventOK == NULL)
  13.178 +						|| (*SDL_EventOK) (SDL_EventOKParam, &event)) {
  13.179 +							SDL_PushEvent(&event);
  13.180 +					}
  13.181 +				}
  13.182 +#endif /* !SDL_EVENTS_DISABLED */
  13.183 +				pNewJoystick->send_add_event = 0;
  13.184 +			}
  13.185 +			device_index++;
  13.186 +			pNewJoystick = pNewJoystick->pNext;
  13.187 +		}
  13.188 +	}
  13.189 +}
  13.190 +
  13.191 +/* we need to poll if we have pending hotplug device changes or connected devices */
  13.192 +SDL_bool SDL_SYS_JoystickNeedsPolling()
  13.193 +{
  13.194 +	/* we have a new device or one was pulled, we need to think this frame please */
  13.195 +	if ( s_bDeviceAdded || s_bDeviceRemoved )
  13.196 +		return SDL_TRUE;
  13.197 +
  13.198 +	return SDL_FALSE;
  13.199 +}
  13.200 +
  13.201  /* Function to get the device-dependent name of a joystick */
  13.202  const char *
  13.203 -SDL_SYS_JoystickNameForIndex(int index)
  13.204 +SDL_SYS_JoystickNameForDeviceIndex(int device_index)
  13.205  {
  13.206  	JoyStick_DeviceData *device = SYS_Joystick;
  13.207  
  13.208 -	for (; index > 0; index--)
  13.209 +	for (; device_index > 0; device_index--)
  13.210  		device = device->pNext;
  13.211  
  13.212  	return device->joystickname;
  13.213  }
  13.214  
  13.215 +/* Function to perform the mapping between current device instance and this joysticks instance id */
  13.216 +SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
  13.217 +{
  13.218 +	JoyStick_DeviceData *device = SYS_Joystick;
  13.219 +	int index;
  13.220 +
  13.221 +	for (index = device_index; index > 0; index--)
  13.222 +		device = device->pNext;
  13.223 +
  13.224 +	return device->nInstanceID;
  13.225 +}
  13.226 +
  13.227  /* Function to open a joystick for use.
  13.228     The joystick to open is specified by the index field of the joystick.
  13.229     This should fill the nbuttons and naxes fields of the joystick structure.
  13.230 @@ -907,6 +1104,13 @@
  13.231      return (0);
  13.232  }
  13.233  
  13.234 +/* return true if this joystick is plugged in right now */
  13.235 +SDL_bool SDL_SYS_JoystickAttached( SDL_Joystick * joystick )
  13.236 +{
  13.237 +	return joystick->closed == 0 && joystick->hwdata->removed == 0;
  13.238 +}
  13.239 +
  13.240 +
  13.241  /* Sort using the data offset into the DInput struct.
  13.242   * This gives a reasonable ordering for the inputs. */
  13.243  static int
  13.244 @@ -1444,214 +1648,8 @@
  13.245  }
  13.246  
  13.247  
  13.248 -/* Function to perform the mapping between current device instance and this joysticks instance id */
  13.249 -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
  13.250 -{
  13.251 -	JoyStick_DeviceData *device = SYS_Joystick;
  13.252 -	int index;
  13.253 -
  13.254 -	for (index = device_index; index > 0; index--)
  13.255 -		device = device->pNext;
  13.256 -
  13.257 -	return device->nInstanceID;
  13.258 -}
  13.259 -
  13.260 -/* return true if this joystick is plugged in right now */
  13.261 -int SDL_SYS_JoystickAttached( SDL_Joystick * joystick )
  13.262 -{
  13.263 -	return joystick->closed == 0 && joystick->hwdata->removed == 0;
  13.264 -}
  13.265 -
  13.266 -
  13.267 -/* return the number of joysticks that are connected right now */
  13.268 -int SDL_SYS_NumJoysticks()
  13.269 -{
  13.270 -	int nJoysticks = 0;
  13.271 -	JoyStick_DeviceData *device = SYS_Joystick;
  13.272 -	while ( device )
  13.273 -	{
  13.274 -		nJoysticks++;
  13.275 -		device = device->pNext;
  13.276 -	}
  13.277 -
  13.278 -	return nJoysticks;
  13.279 -}
  13.280 -
  13.281 -static int s_iNewGUID = 0;
  13.282 -
  13.283 -/* helper function for direct input, gets called for each connected joystick */
  13.284 -static BOOL CALLBACK
  13.285 -	EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
  13.286 -{
  13.287 -	JoyStick_DeviceData *pNewJoystick;
  13.288 -	SDL_bool bXInputDevice;
  13.289 -	pNewJoystick = *(JoyStick_DeviceData **)pContext;
  13.290 -	while ( pNewJoystick )
  13.291 -	{
  13.292 -		if ( !SDL_memcmp( &pNewJoystick->dxdevice.guidInstance, &pdidInstance->guidInstance, sizeof(pNewJoystick->dxdevice.guidInstance) ) )
  13.293 -		{
  13.294 -			if ( SYS_Joystick )
  13.295 -			{
  13.296 -				pNewJoystick->pNext = SYS_Joystick;
  13.297 -			}
  13.298 -			SYS_Joystick = pNewJoystick;
  13.299 -			/* if we are replacing the front of the list then update it */
  13.300 -			if ( pNewJoystick == *(JoyStick_DeviceData **)pContext ) 
  13.301 -			{
  13.302 -				*(JoyStick_DeviceData **)pContext = pNewJoystick->pNext;
  13.303 -			}
  13.304 -
  13.305 -			s_pKnownJoystickGUIDs[ s_iNewGUID ] = pdidInstance->guidInstance;
  13.306 -			s_iNewGUID++;
  13.307 -			if ( s_iNewGUID < MAX_JOYSTICKS )
  13.308 -				return DIENUM_CONTINUE; // already have this joystick loaded, just keep going
  13.309 -			else
  13.310 -				return DIENUM_STOP; 
  13.311 -		}
  13.312 -
  13.313 -		pNewJoystick = pNewJoystick->pNext;
  13.314 -	}
  13.315 -
  13.316 -	s_bDeviceAdded = SDL_TRUE;
  13.317 -
  13.318 -	bXInputDevice = IsXInputDevice( &pdidInstance->guidProduct );
  13.319 -
  13.320 -	pNewJoystick = (JoyStick_DeviceData *)SDL_malloc( sizeof(JoyStick_DeviceData) );
  13.321 -
  13.322 -	if ( bXInputDevice )
  13.323 -	{
  13.324 -		SDL_memset(&(pNewJoystick->dxdevice), 0x0,
  13.325 -			sizeof(DIDEVICEINSTANCE));
  13.326 -		pNewJoystick->bXInputDevice = 1;
  13.327 -		pNewJoystick->XInputUserId = INVALID_XINPUT_USERID;
  13.328 -	}
  13.329 -	else
  13.330 -	{
  13.331 -		pNewJoystick->bXInputDevice = 0;
  13.332 -		SDL_memcpy(&(pNewJoystick->dxdevice), pdidInstance,
  13.333 -			sizeof(DIDEVICEINSTANCE));
  13.334 -	}
  13.335 -	pNewJoystick->joystickname = WIN_StringToUTF8(pdidInstance->tszProductName);
  13.336 -	pNewJoystick->send_add_event = 1;
  13.337 -	pNewJoystick->nInstanceID = ++s_nInstanceID;
  13.338 -	SDL_memcpy( &pNewJoystick->guid, &pdidInstance->guidProduct, sizeof(pNewJoystick->guid) );
  13.339 -	pNewJoystick->pNext = NULL;
  13.340 -
  13.341 -	if ( SYS_Joystick )
  13.342 -	{
  13.343 -		pNewJoystick->pNext = SYS_Joystick;
  13.344 -	}
  13.345 -	SYS_Joystick = pNewJoystick;
  13.346 -
  13.347 -	s_pKnownJoystickGUIDs[ s_iNewGUID ] = pdidInstance->guidInstance;
  13.348 -	s_iNewGUID++;
  13.349 -
  13.350 -	if ( s_iNewGUID < MAX_JOYSTICKS )
  13.351 -		return DIENUM_CONTINUE; // already have this joystick loaded, just keep going
  13.352 -	else
  13.353 -		return DIENUM_STOP; 
  13.354 -}
  13.355 -
  13.356 -
  13.357 -/* detect any new joysticks being inserted into the system */
  13.358 -void SDL_SYS_JoystickDetect()
  13.359 -{
  13.360 -	HRESULT result;
  13.361 -	JoyStick_DeviceData *pCurList = NULL;
  13.362 -	/* only enum the devices if the joystick thread told us something changed */
  13.363 -	if ( s_bDeviceAdded || s_bDeviceRemoved )
  13.364 -	{
  13.365 -		s_bDeviceAdded = SDL_FALSE;
  13.366 -		s_bDeviceRemoved = SDL_FALSE;
  13.367 -
  13.368 -		pCurList = SYS_Joystick;
  13.369 -		SYS_Joystick = NULL;
  13.370 -		s_iNewGUID = 0;
  13.371 -		SDL_mutexP( s_mutexJoyStickEnum );
  13.372 -
  13.373 -		if ( !s_pKnownJoystickGUIDs )
  13.374 -			s_pKnownJoystickGUIDs = SDL_malloc( sizeof(GUID)*MAX_JOYSTICKS );
  13.375 -				
  13.376 -		SDL_memset( s_pKnownJoystickGUIDs, 0x0, sizeof(GUID)*MAX_JOYSTICKS );
  13.377 -
  13.378 -		/* Look for joysticks, wheels, head trackers, gamepads, etc.. */
  13.379 -		result = IDirectInput8_EnumDevices(dinput,
  13.380 -			DI8DEVCLASS_GAMECTRL,
  13.381 -			EnumJoysticksCallback,
  13.382 -			&pCurList, DIEDFL_ATTACHEDONLY);
  13.383 -
  13.384 -		SDL_mutexV( s_mutexJoyStickEnum );
  13.385 -	}
  13.386 -
  13.387 -	if ( pCurList )
  13.388 -	{
  13.389 -		while ( pCurList )
  13.390 -		{
  13.391 -			JoyStick_DeviceData *pListNext = NULL;
  13.392 -#if !SDL_EVENTS_DISABLED
  13.393 -			SDL_Event event;
  13.394 -			event.type = SDL_JOYDEVICEREMOVED;
  13.395 -
  13.396 -			if (SDL_GetEventState(event.type) == SDL_ENABLE) {
  13.397 -				event.jdevice.which = pCurList->nInstanceID;
  13.398 -				if ((SDL_EventOK == NULL)
  13.399 -					|| (*SDL_EventOK) (SDL_EventOKParam, &event)) {
  13.400 -						SDL_PushEvent(&event);
  13.401 -				}
  13.402 -			}
  13.403 -#endif // !SDL_EVENTS_DISABLED 
  13.404 -
  13.405 -			pListNext = pCurList->pNext;
  13.406 -			SDL_free(pCurList->joystickname);
  13.407 -			SDL_free( pCurList );
  13.408 -			pCurList = pListNext;
  13.409 -		}
  13.410 -
  13.411 -	}
  13.412 -
  13.413 -	if ( s_bDeviceAdded )
  13.414 -	{
  13.415 -		JoyStick_DeviceData *pNewJoystick;
  13.416 -		int device_index = 0;
  13.417 -		s_bDeviceAdded = SDL_FALSE;
  13.418 -		pNewJoystick = SYS_Joystick;
  13.419 -		while ( pNewJoystick )
  13.420 -		{
  13.421 -			if ( pNewJoystick->send_add_event )
  13.422 -			{
  13.423 -#if !SDL_EVENTS_DISABLED
  13.424 -				SDL_Event event;
  13.425 -				event.type = SDL_JOYDEVICEADDED;
  13.426 -
  13.427 -				if (SDL_GetEventState(event.type) == SDL_ENABLE) {
  13.428 -					event.jdevice.which = device_index;
  13.429 -					if ((SDL_EventOK == NULL)
  13.430 -						|| (*SDL_EventOK) (SDL_EventOKParam, &event)) {
  13.431 -							SDL_PushEvent(&event);
  13.432 -					}
  13.433 -				}
  13.434 -#endif /* !SDL_EVENTS_DISABLED */
  13.435 -				pNewJoystick->send_add_event = 0;
  13.436 -			}
  13.437 -			device_index++;
  13.438 -			pNewJoystick = pNewJoystick->pNext;
  13.439 -		}
  13.440 -	}
  13.441 -}
  13.442 -
  13.443 -
  13.444 -/* we need to poll if we have pending hotplug device changes or connected devices */
  13.445 -int SDL_SYS_JoystickNeedsPolling()
  13.446 -{
  13.447 -	/* we have a new device or one was pulled, we need to think this frame please */
  13.448 -	if ( s_bDeviceAdded || s_bDeviceRemoved )
  13.449 -		return 1;
  13.450 -
  13.451 -	return 0;
  13.452 -}
  13.453 -
  13.454  /* return the stable device guid for this device index */
  13.455 -JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
  13.456 +JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
  13.457  {
  13.458  	JoyStick_DeviceData *device = SYS_Joystick;
  13.459  	int index;
  13.460 @@ -1662,8 +1660,13 @@
  13.461  	return device->guid;
  13.462  }
  13.463  
  13.464 -/* return 1 if this device is using XInput */
  13.465 -int SDL_SYS_IsXInputDeviceIndex( int device_index )
  13.466 +JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
  13.467 +{
  13.468 +	return joystick->hwdata->guid;
  13.469 +}
  13.470 +
  13.471 +/* return SDL_TRUE if this device is using XInput */
  13.472 +SDL_bool SDL_SYS_IsXInputDeviceIndex(int device_index)
  13.473  {
  13.474  	JoyStick_DeviceData *device = SYS_Joystick;
  13.475  	int index;
  13.476 @@ -1674,11 +1677,6 @@
  13.477  	return device->bXInputDevice;
  13.478  }
  13.479  
  13.480 -JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick)
  13.481 -{
  13.482 -	return joystick->hwdata->guid;
  13.483 -}
  13.484 -
  13.485  #endif /* SDL_JOYSTICK_DINPUT */
  13.486  
  13.487  /* vi: set ts=4 sw=4 expandtab: */
    14.1 --- a/src/joystick/windows/SDL_mmjoystick.c	Mon Nov 26 23:58:53 2012 -0800
    14.2 +++ b/src/joystick/windows/SDL_mmjoystick.c	Tue Nov 27 00:58:12 2012 -0800
    14.3 @@ -179,17 +179,37 @@
    14.4      return (SDL_SYS_numjoysticks);
    14.5  }
    14.6  
    14.7 +int SDL_SYS_NumJoysticks()
    14.8 +{
    14.9 +    return SDL_SYS_numjoysticks;
   14.10 +}
   14.11 +
   14.12 +void SDL_SYS_JoystickDetect()
   14.13 +{
   14.14 +}
   14.15 +
   14.16 +SDL_bool SDL_SYS_JoystickNeedsPolling()
   14.17 +{
   14.18 +    return SDL_FALSE;
   14.19 +}
   14.20 +
   14.21  /* Function to get the device-dependent name of a joystick */
   14.22  const char *
   14.23 -SDL_SYS_JoystickNameForIndex(int index)
   14.24 +SDL_SYS_JoystickNameForDeviceIndex(int device_index)
   14.25  {
   14.26 -    if (SYS_JoystickName[index] != NULL) {
   14.27 -        return (SYS_JoystickName[index]);
   14.28 +    if (SYS_JoystickName[device_index] != NULL) {
   14.29 +        return (SYS_JoystickName[device_index]);
   14.30      } else {
   14.31 -        return (SYS_Joystick[index].szPname);
   14.32 +        return (SYS_Joystick[device_index].szPname);
   14.33      }
   14.34  }
   14.35  
   14.36 +/* Function to perform the mapping from device index to the instance id for this index */
   14.37 +SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
   14.38 +{
   14.39 +    return device_index;
   14.40 +}
   14.41 +
   14.42  /* Function to open a joystick for use.
   14.43     The joystick to open is specified by the index field of the joystick.
   14.44     This should fill the nbuttons and naxes fields of the joystick structure.
   14.45 @@ -253,6 +273,12 @@
   14.46      return (0);
   14.47  }
   14.48  
   14.49 +/* Function to determine is this joystick is attached to the system right now */
   14.50 +SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
   14.51 +{
   14.52 +    return SDL_TRUE;
   14.53 +}
   14.54 +
   14.55  static Uint8
   14.56  TranslatePOV(DWORD value)
   14.57  {
   14.58 @@ -379,44 +405,17 @@
   14.59      }
   14.60  }
   14.61  
   14.62 -/* Function to perform the mapping from device index to the instance id for this index */
   14.63 -SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index)
   14.64 -{
   14.65 -    return index;
   14.66 -}
   14.67 -
   14.68 -/* Function to determine is this joystick is attached to the system right now */
   14.69 -int SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
   14.70 -{
   14.71 -    return 1;
   14.72 -}
   14.73 -
   14.74 -int SDL_SYS_NumJoysticks()
   14.75 -{
   14.76 -    return SDL_SYS_numjoysticks;
   14.77 -}
   14.78 -
   14.79 -int SDL_SYS_JoystickNeedsPolling()
   14.80 -{
   14.81 -    return 0;
   14.82 -}
   14.83 -
   14.84 -void SDL_SYS_JoystickDetect()
   14.85 -{
   14.86 -}
   14.87 -
   14.88 -JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
   14.89 +JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
   14.90  {
   14.91      JoystickGUID guid;
   14.92      // the GUID is just the first 16 chars of the name for now
   14.93 -    const char *name = SDL_SYS_JoystickNameForIndex( device_index );
   14.94 +    const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
   14.95      SDL_zero( guid );
   14.96      SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
   14.97      return guid;
   14.98  }
   14.99  
  14.100 -
  14.101 -JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick)
  14.102 +JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
  14.103  {
  14.104      JoystickGUID guid;
  14.105      // the GUID is just the first 16 chars of the name for now
  14.106 @@ -472,4 +471,5 @@
  14.107  }
  14.108  
  14.109  #endif /* SDL_JOYSTICK_WINMM */
  14.110 +
  14.111  /* vi: set ts=4 sw=4 expandtab: */