Added SDL_JoystickGetXInputUserIndex()
authorSam Lantinga <slouken@libsdl.org>
Thu, 25 Oct 2018 12:54:42 -0700
changeset 1235740f09c8c517b
parent 12356 53d99bfefe85
child 12358 7a7612d67fa7
Added SDL_JoystickGetXInputUserIndex()
include/SDL_joystick.h
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.h
src/joystick/SDL_joystick.c
src/joystick/SDL_sysjoystick.h
src/joystick/windows/SDL_xinputjoystick.c
     1.1 --- a/include/SDL_joystick.h	Thu Oct 25 12:54:39 2018 -0700
     1.2 +++ b/include/SDL_joystick.h	Thu Oct 25 12:54:42 2018 -0700
     1.3 @@ -384,6 +384,11 @@
     1.4   */
     1.5  extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick);
     1.6  
     1.7 +/**
     1.8 + *  Return the XInput user index for this joystick, or -1 if it's not available
     1.9 + */
    1.10 +extern DECLSPEC int SDLCALL SDL_JoystickGetXInputUserIndex(SDL_Joystick * joystick);
    1.11 +
    1.12  /* Ends C function definitions when using C++ */
    1.13  #ifdef __cplusplus
    1.14  }
     2.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Thu Oct 25 12:54:39 2018 -0700
     2.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Thu Oct 25 12:54:42 2018 -0700
     2.3 @@ -698,3 +698,4 @@
     2.4  #define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_REAL
     2.5  #define SDL_HasColorKey SDL_HasColorKey_REAL
     2.6  #define SDL_CreateThreadWithStackSize SDL_CreateThreadWithStackSize_REAL
     2.7 +#define SDL_JoystickGetXInputUserIndex SDL_JoystickGetXInputUserIndex_REAL
     3.1 --- a/src/dynapi/SDL_dynapi_procs.h	Thu Oct 25 12:54:39 2018 -0700
     3.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Thu Oct 25 12:54:42 2018 -0700
     3.3 @@ -752,3 +752,4 @@
     3.4  SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithStackSize,(SDL_ThreadFunction a, const char *b, const size_t c, void *d),(a,b,c,d),return)
     3.5  #endif
     3.6  
     3.7 +SDL_DYNAPI_PROC(int,SDL_JoystickGetXInputUserIndex,(SDL_Joystick *a),(a),return)
     4.1 --- a/src/joystick/SDL_joystick.c	Thu Oct 25 12:54:39 2018 -0700
     4.2 +++ b/src/joystick/SDL_joystick.c	Thu Oct 25 12:54:42 2018 -0700
     4.3 @@ -322,6 +322,7 @@
     4.4      }
     4.5  
     4.6      joystick->guid = driver->GetDeviceGUID(device_index);
     4.7 +    joystick->userid = -1;
     4.8  
     4.9      if (joystick->naxes > 0) {
    4.10          joystick->axes = (SDL_JoystickAxisInfo *) SDL_calloc(joystick->naxes, sizeof(SDL_JoystickAxisInfo));
    4.11 @@ -1556,4 +1557,12 @@
    4.12      return joystick->epowerlevel;
    4.13  }
    4.14  
    4.15 +int SDL_JoystickGetXInputUserIndex(SDL_Joystick * joystick)
    4.16 +{
    4.17 +    if (!SDL_PrivateJoystickValid(joystick)) {
    4.18 +        return -1;
    4.19 +    }
    4.20 +    return joystick->userid;
    4.21 +}
    4.22 +
    4.23  /* vi: set ts=4 sw=4 expandtab: */
     5.1 --- a/src/joystick/SDL_sysjoystick.h	Thu Oct 25 12:54:39 2018 -0700
     5.2 +++ b/src/joystick/SDL_sysjoystick.h	Thu Oct 25 12:54:42 2018 -0700
     5.3 @@ -43,6 +43,7 @@
     5.4      SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */
     5.5      char *name;                 /* Joystick name - system dependent */
     5.6      SDL_JoystickGUID guid;      /* Joystick guid */
     5.7 +    int userid;                 /* XInput user index, if any */
     5.8  
     5.9      int naxes;                  /* Number of axis controls on the joystick */
    5.10      SDL_JoystickAxisInfo *axes;
     6.1 --- a/src/joystick/windows/SDL_xinputjoystick.c	Thu Oct 25 12:54:39 2018 -0700
     6.2 +++ b/src/joystick/windows/SDL_xinputjoystick.c	Thu Oct 25 12:54:42 2018 -0700
     6.3 @@ -322,6 +322,7 @@
     6.4      SDL_zero(state);
     6.5      joystick->hwdata->bXInputHaptic = (XINPUTSETSTATE(userId, &state) == ERROR_SUCCESS);
     6.6      joystick->hwdata->userid = userId;
     6.7 +    joystick->userid = userId;
     6.8  
     6.9      /* The XInput API has a hard coded button/axis mapping, so we just match it */
    6.10      if (SDL_XInputUseOldJoystickMapping()) {