Generalized the XInput user index into a player index
authorSam Lantinga <slouken@libsdl.org>
Thu, 25 Oct 2018 16:53:14 -0700
changeset 12359691c32a30fb9
parent 12358 7a7612d67fa7
child 12360 a21c0a3bf183
Generalized the XInput user index into a player index
include/SDL_gamecontroller.h
include/SDL_joystick.h
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.h
src/joystick/SDL_gamecontroller.c
src/joystick/SDL_joystick.c
src/joystick/SDL_sysjoystick.h
src/joystick/android/SDL_sysjoystick.c
src/joystick/bsd/SDL_sysjoystick.c
src/joystick/darwin/SDL_sysjoystick.c
src/joystick/dummy/SDL_sysjoystick.c
src/joystick/emscripten/SDL_sysjoystick.c
src/joystick/haiku/SDL_haikujoystick.cc
src/joystick/hidapi/SDL_hidapijoystick.c
src/joystick/iphoneos/SDL_sysjoystick.m
src/joystick/linux/SDL_sysjoystick.c
src/joystick/windows/SDL_windowsjoystick.c
src/joystick/windows/SDL_xinputjoystick.c
     1.1 --- a/include/SDL_gamecontroller.h	Thu Oct 25 13:22:34 2018 -0700
     1.2 +++ b/include/SDL_gamecontroller.h	Thu Oct 25 16:53:14 2018 -0700
     1.3 @@ -205,6 +205,13 @@
     1.4  extern DECLSPEC const char *SDLCALL SDL_GameControllerName(SDL_GameController *gamecontroller);
     1.5  
     1.6  /**
     1.7 + *  Get the player index of an opened game controller, or -1 if it's not available
     1.8 + *
     1.9 + *  For XInput controllers this returns the XInput user index.
    1.10 + */
    1.11 +extern DECLSPEC int SDLCALL SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller);
    1.12 +
    1.13 +/**
    1.14   *  Get the USB vendor ID of an opened controller, if available.
    1.15   *  If the vendor ID isn't available this function returns 0.
    1.16   */
     2.1 --- a/include/SDL_joystick.h	Thu Oct 25 13:22:34 2018 -0700
     2.2 +++ b/include/SDL_joystick.h	Thu Oct 25 16:53:14 2018 -0700
     2.3 @@ -133,6 +133,12 @@
     2.4  extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index);
     2.5  
     2.6  /**
     2.7 + *  Get the player index of a joystick, or -1 if it's not available
     2.8 + *  This can be called before any joysticks are opened.
     2.9 + */
    2.10 +extern DECLSPEC int SDLCALL SDL_JoystickGetDevicePlayerIndex(int device_index);
    2.11 +
    2.12 +/**
    2.13   *  Return the GUID for the joystick at this index
    2.14   *  This can be called before any joysticks are opened.
    2.15   */
    2.16 @@ -195,6 +201,13 @@
    2.17  extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick * joystick);
    2.18  
    2.19  /**
    2.20 + *  Get the player index of an opened joystick, or -1 if it's not available
    2.21 + *
    2.22 + *  For XInput controllers this returns the XInput user index.
    2.23 + */
    2.24 +extern DECLSPEC int SDLCALL SDL_JoystickGetPlayerIndex(SDL_Joystick * joystick);
    2.25 +
    2.26 +/**
    2.27   *  Return the GUID for this opened joystick
    2.28   */
    2.29  extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);
    2.30 @@ -384,11 +397,6 @@
    2.31   */
    2.32  extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick);
    2.33  
    2.34 -/**
    2.35 - *  Return the XInput user index for this joystick, or -1 if it's not available
    2.36 - */
    2.37 -extern DECLSPEC int SDLCALL SDL_JoystickGetXInputUserIndex(SDL_Joystick * joystick);
    2.38 -
    2.39  /* Ends C function definitions when using C++ */
    2.40  #ifdef __cplusplus
    2.41  }
     3.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Thu Oct 25 13:22:34 2018 -0700
     3.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Thu Oct 25 16:53:14 2018 -0700
     3.3 @@ -698,4 +698,6 @@
     3.4  #define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_REAL
     3.5  #define SDL_HasColorKey SDL_HasColorKey_REAL
     3.6  #define SDL_CreateThreadWithStackSize SDL_CreateThreadWithStackSize_REAL
     3.7 -#define SDL_JoystickGetXInputUserIndex SDL_JoystickGetXInputUserIndex_REAL
     3.8 +#define SDL_JoystickGetDevicePlayerIndex SDL_JoystickGetDevicePlayerIndex_REAL
     3.9 +#define SDL_JoystickGetPlayerIndex SDL_JoystickGetPlayerIndex_REAL
    3.10 +#define SDL_GameControllerGetPlayerIndex SDL_GameControllerGetPlayerIndex_REAL
     4.1 --- a/src/dynapi/SDL_dynapi_procs.h	Thu Oct 25 13:22:34 2018 -0700
     4.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Thu Oct 25 16:53:14 2018 -0700
     4.3 @@ -752,4 +752,6 @@
     4.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)
     4.5  #endif
     4.6  
     4.7 -SDL_DYNAPI_PROC(int,SDL_JoystickGetXInputUserIndex,(SDL_Joystick *a),(a),return)
     4.8 +SDL_DYNAPI_PROC(int,SDL_JoystickGetDevicePlayerIndex,(int a),(a),return)
     4.9 +SDL_DYNAPI_PROC(int,SDL_JoystickGetPlayerIndex,(SDL_Joystick *a),(a),return)
    4.10 +SDL_DYNAPI_PROC(int,SDL_GameControllerGetPlayerIndex,(SDL_GameController *a),(a),return)
     5.1 --- a/src/joystick/SDL_gamecontroller.c	Thu Oct 25 13:22:34 2018 -0700
     5.2 +++ b/src/joystick/SDL_gamecontroller.c	Thu Oct 25 16:53:14 2018 -0700
     5.3 @@ -1716,6 +1716,12 @@
     5.4      }
     5.5  }
     5.6  
     5.7 +int
     5.8 +SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller)
     5.9 +{
    5.10 +    return SDL_JoystickGetPlayerIndex(SDL_GameControllerGetJoystick(gamecontroller));
    5.11 +}
    5.12 +
    5.13  Uint16
    5.14  SDL_GameControllerGetVendor(SDL_GameController * gamecontroller)
    5.15  {
     6.1 --- a/src/joystick/SDL_joystick.c	Thu Oct 25 13:22:34 2018 -0700
     6.2 +++ b/src/joystick/SDL_joystick.c	Thu Oct 25 16:53:14 2018 -0700
     6.3 @@ -227,6 +227,21 @@
     6.4      return name;
     6.5  }
     6.6  
     6.7 +int
     6.8 +SDL_JoystickGetDevicePlayerIndex(int device_index)
     6.9 +{
    6.10 +    SDL_JoystickDriver *driver;
    6.11 +    int player_index = -1;
    6.12 +
    6.13 +    SDL_LockJoysticks();
    6.14 +    if (SDL_GetDriverAndJoystickIndex(device_index, &driver, &device_index)) {
    6.15 +        player_index = driver->GetDevicePlayerIndex(device_index);
    6.16 +    }
    6.17 +    SDL_UnlockJoysticks();
    6.18 +
    6.19 +    return player_index;
    6.20 +}
    6.21 +
    6.22  /*
    6.23   * Return true if this joystick is known to have all axes centered at zero
    6.24   * This isn't generally needed unless the joystick never generates an initial axis value near zero,
    6.25 @@ -307,7 +322,7 @@
    6.26      joystick->driver = driver;
    6.27      joystick->instance_id = instance_id;
    6.28      joystick->attached = SDL_TRUE;
    6.29 -    joystick->userid = -1;
    6.30 +    joystick->player_index = -1;
    6.31  
    6.32      if (driver->Open(joystick, device_index) < 0) {
    6.33          SDL_free(joystick);
    6.34 @@ -604,6 +619,15 @@
    6.35  }
    6.36  
    6.37  int
    6.38 +SDL_JoystickGetPlayerIndex(SDL_Joystick * joystick)
    6.39 +{
    6.40 +    if (!SDL_PrivateJoystickValid(joystick)) {
    6.41 +        return -1;
    6.42 +    }
    6.43 +    return joystick->player_index;
    6.44 +}
    6.45 +
    6.46 +int
    6.47  SDL_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
    6.48  {
    6.49      if (!SDL_PrivateJoystickValid(joystick)) {
    6.50 @@ -1557,12 +1581,4 @@
    6.51      return joystick->epowerlevel;
    6.52  }
    6.53  
    6.54 -int SDL_JoystickGetXInputUserIndex(SDL_Joystick * joystick)
    6.55 -{
    6.56 -    if (!SDL_PrivateJoystickValid(joystick)) {
    6.57 -        return -1;
    6.58 -    }
    6.59 -    return joystick->userid;
    6.60 -}
    6.61 -
    6.62  /* vi: set ts=4 sw=4 expandtab: */
     7.1 --- a/src/joystick/SDL_sysjoystick.h	Thu Oct 25 13:22:34 2018 -0700
     7.2 +++ b/src/joystick/SDL_sysjoystick.h	Thu Oct 25 16:53:14 2018 -0700
     7.3 @@ -42,8 +42,8 @@
     7.4  {
     7.5      SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */
     7.6      char *name;                 /* Joystick name - system dependent */
     7.7 +    int player_index;           /* Joystick player index, or -1 if unavailable */
     7.8      SDL_JoystickGUID guid;      /* Joystick guid */
     7.9 -    int userid;                 /* XInput user index, if any */
    7.10  
    7.11      int naxes;                  /* Number of axis controls on the joystick */
    7.12      SDL_JoystickAxisInfo *axes;
    7.13 @@ -106,6 +106,9 @@
    7.14      /* Function to get the device-dependent name of a joystick */
    7.15      const char *(*GetDeviceName)(int device_index);
    7.16  
    7.17 +    /* Function to get the player index of a joystick */
    7.18 +    int (*GetDevicePlayerIndex)(int device_index);
    7.19 +
    7.20      /* Function to return the stable GUID for a plugged in device */
    7.21      SDL_JoystickGUID (*GetDeviceGUID)(int device_index);
    7.22  
     8.1 --- a/src/joystick/android/SDL_sysjoystick.c	Thu Oct 25 13:22:34 2018 -0700
     8.2 +++ b/src/joystick/android/SDL_sysjoystick.c	Thu Oct 25 16:53:14 2018 -0700
     8.3 @@ -581,6 +581,12 @@
     8.4      return JoystickByDevIndex(device_index)->name;
     8.5  }
     8.6  
     8.7 +static int
     8.8 +ANDROID_JoystickGetDevicePlayerIndex(int device_index)
     8.9 +{
    8.10 +    return -1;
    8.11 +}
    8.12 +
    8.13  static SDL_JoystickGUID
    8.14  ANDROID_JoystickGetDeviceGUID(int device_index)
    8.15  {
    8.16 @@ -689,6 +695,7 @@
    8.17      ANDROID_JoystickGetCount,
    8.18      ANDROID_JoystickDetect,
    8.19      ANDROID_JoystickGetDeviceName,
    8.20 +    ANDROID_JoystickGetDevicePlayerIndex,
    8.21      ANDROID_JoystickGetDeviceGUID,
    8.22      ANDROID_JoystickGetDeviceInstanceID,
    8.23      ANDROID_JoystickOpen,
     9.1 --- a/src/joystick/bsd/SDL_sysjoystick.c	Thu Oct 25 13:22:34 2018 -0700
     9.2 +++ b/src/joystick/bsd/SDL_sysjoystick.c	Thu Oct 25 16:53:14 2018 -0700
     9.3 @@ -227,6 +227,12 @@
     9.4      return (joynames[device_index]);
     9.5  }
     9.6  
     9.7 +static int
     9.8 +BSD_JoystickGetDevicePlayerIndex(int device_index)
     9.9 +{
    9.10 +    return -1;
    9.11 +}
    9.12 +
    9.13  /* Function to perform the mapping from device index to the instance id for this index */
    9.14  static SDL_JoystickID
    9.15  BSD_JoystickGetDeviceInstanceID(int device_index)
    9.16 @@ -687,6 +693,7 @@
    9.17      BSD_JoystickGetCount,
    9.18      BSD_JoystickDetect,
    9.19      BSD_JoystickGetDeviceName,
    9.20 +    BSD_JoystickGetDevicePlayerIndex,
    9.21      BSD_JoystickGetDeviceGUID,
    9.22      BSD_JoystickGetDeviceInstanceID,
    9.23      BSD_JoystickOpen,
    10.1 --- a/src/joystick/darwin/SDL_sysjoystick.c	Thu Oct 25 13:22:34 2018 -0700
    10.2 +++ b/src/joystick/darwin/SDL_sysjoystick.c	Thu Oct 25 16:53:14 2018 -0700
    10.3 @@ -700,6 +700,12 @@
    10.4      return device ? device->product : "UNKNOWN";
    10.5  }
    10.6  
    10.7 +static int
    10.8 +DARWIN_JoystickGetDevicePlayerIndex(int device_index)
    10.9 +{
   10.10 +    return -1;
   10.11 +}
   10.12 +
   10.13  static SDL_JoystickGUID
   10.14  DARWIN_JoystickGetDeviceGUID( int device_index )
   10.15  {
   10.16 @@ -998,6 +1004,7 @@
   10.17      DARWIN_JoystickGetCount,
   10.18      DARWIN_JoystickDetect,
   10.19      DARWIN_JoystickGetDeviceName,
   10.20 +    DARWIN_JoystickGetDevicePlayerIndex,
   10.21      DARWIN_JoystickGetDeviceGUID,
   10.22      DARWIN_JoystickGetDeviceInstanceID,
   10.23      DARWIN_JoystickOpen,
    11.1 --- a/src/joystick/dummy/SDL_sysjoystick.c	Thu Oct 25 13:22:34 2018 -0700
    11.2 +++ b/src/joystick/dummy/SDL_sysjoystick.c	Thu Oct 25 16:53:14 2018 -0700
    11.3 @@ -52,6 +52,12 @@
    11.4      return NULL;
    11.5  }
    11.6  
    11.7 +static int
    11.8 +DUMMY_JoystickGetDevicePlayerIndex(int device_index)
    11.9 +{
   11.10 +    return -1;
   11.11 +}
   11.12 +
   11.13  static SDL_JoystickGUID
   11.14  DUMMY_JoystickGetDeviceGUID(int device_index)
   11.15  {
   11.16 @@ -99,6 +105,7 @@
   11.17      DUMMY_JoystickGetCount,
   11.18      DUMMY_JoystickDetect,
   11.19      DUMMY_JoystickGetDeviceName,
   11.20 +    DUMMY_JoystickGetDevicePlayerIndex,
   11.21      DUMMY_JoystickGetDeviceGUID,
   11.22      DUMMY_JoystickGetDeviceInstanceID,
   11.23      DUMMY_JoystickOpen,
    12.1 --- a/src/joystick/emscripten/SDL_sysjoystick.c	Thu Oct 25 13:22:34 2018 -0700
    12.2 +++ b/src/joystick/emscripten/SDL_sysjoystick.c	Thu Oct 25 16:53:14 2018 -0700
    12.3 @@ -279,6 +279,12 @@
    12.4      return JoystickByDeviceIndex(device_index)->name;
    12.5  }
    12.6  
    12.7 +static int
    12.8 +EMSCRIPTEN_JoystickGetDevicePlayerIndex(int device_index)
    12.9 +{
   12.10 +    return -1;
   12.11 +}
   12.12 +
   12.13  static SDL_JoystickID
   12.14  EMSCRIPTEN_JoystickGetDeviceInstanceID(int device_index)
   12.15  {
   12.16 @@ -394,6 +400,7 @@
   12.17      EMSCRIPTEN_JoystickGetCount,
   12.18      EMSCRIPTEN_JoystickDetect,
   12.19      EMSCRIPTEN_JoystickGetDeviceName,
   12.20 +    EMSCRIPTEN_JoystickGetDevicePlayerIndex,
   12.21      EMSCRIPTEN_JoystickGetDeviceGUID,
   12.22      EMSCRIPTEN_JoystickGetDeviceInstanceID,
   12.23      EMSCRIPTEN_JoystickOpen,
    13.1 --- a/src/joystick/haiku/SDL_haikujoystick.cc	Thu Oct 25 13:22:34 2018 -0700
    13.2 +++ b/src/joystick/haiku/SDL_haikujoystick.cc	Thu Oct 25 16:53:14 2018 -0700
    13.3 @@ -99,6 +99,11 @@
    13.4          return SDL_joyname[device_index];
    13.5      }
    13.6  
    13.7 +    static int HAIKU_JoystickGetDevicePlayerIndex(int device_index)
    13.8 +    {
    13.9 +        return -1;
   13.10 +    }
   13.11 +
   13.12  /* Function to perform the mapping from device index to the instance id for this index */
   13.13      static SDL_JoystickID HAIKU_JoystickGetDeviceInstanceID(int device_index)
   13.14      {
   13.15 @@ -256,6 +261,7 @@
   13.16          HAIKU_JoystickGetCount,
   13.17          HAIKU_JoystickDetect,
   13.18          HAIKU_JoystickGetDeviceName,
   13.19 +        HAIKU_JoystickGetDevicePlayerIndex,
   13.20          HAIKU_JoystickGetDeviceGUID,
   13.21          HAIKU_JoystickGetDeviceInstanceID,
   13.22          HAIKU_JoystickOpen,
    14.1 --- a/src/joystick/hidapi/SDL_hidapijoystick.c	Thu Oct 25 13:22:34 2018 -0700
    14.2 +++ b/src/joystick/hidapi/SDL_hidapijoystick.c	Thu Oct 25 16:53:14 2018 -0700
    14.3 @@ -932,6 +932,12 @@
    14.4      return HIDAPI_GetJoystickByIndex(device_index)->name;
    14.5  }
    14.6  
    14.7 +static int
    14.8 +HIDAPI_JoystickGetDevicePlayerIndex(int device_index)
    14.9 +{
   14.10 +    return -1;
   14.11 +}
   14.12 +
   14.13  static SDL_JoystickGUID
   14.14  HIDAPI_JoystickGetDeviceGUID(int device_index)
   14.15  {
   14.16 @@ -1048,6 +1054,7 @@
   14.17      HIDAPI_JoystickGetCount,
   14.18      HIDAPI_JoystickDetect,
   14.19      HIDAPI_JoystickGetDeviceName,
   14.20 +    HIDAPI_JoystickGetDevicePlayerIndex,
   14.21      HIDAPI_JoystickGetDeviceGUID,
   14.22      HIDAPI_JoystickGetDeviceInstanceID,
   14.23      HIDAPI_JoystickOpen,
    15.1 --- a/src/joystick/iphoneos/SDL_sysjoystick.m	Thu Oct 25 13:22:34 2018 -0700
    15.2 +++ b/src/joystick/iphoneos/SDL_sysjoystick.m	Thu Oct 25 16:53:14 2018 -0700
    15.3 @@ -358,6 +358,12 @@
    15.4      return device ? device->name : "Unknown";
    15.5  }
    15.6  
    15.7 +static int
    15.8 +IOS_JoystickGetDevicePlayerIndex(int device_index)
    15.9 +{
   15.10 +    return -1;
   15.11 +}
   15.12 +
   15.13  static SDL_JoystickGUID
   15.14  IOS_JoystickGetDeviceGUID( int device_index )
   15.15  {
   15.16 @@ -715,6 +721,7 @@
   15.17      IOS_JoystickGetCount,
   15.18      IOS_JoystickDetect,
   15.19      IOS_JoystickGetDeviceName,
   15.20 +    IOS_JoystickGetDevicePlayerIndex,
   15.21      IOS_JoystickGetDeviceGUID,
   15.22      IOS_JoystickGetDeviceInstanceID,
   15.23      IOS_JoystickOpen,
    16.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Thu Oct 25 13:22:34 2018 -0700
    16.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Thu Oct 25 16:53:14 2018 -0700
    16.3 @@ -582,6 +582,12 @@
    16.4      return JoystickByDevIndex(device_index)->name;
    16.5  }
    16.6  
    16.7 +static int
    16.8 +LINUX_JoystickGetDevicePlayerIndex(int device_index)
    16.9 +{
   16.10 +    return -1;
   16.11 +}
   16.12 +
   16.13  static SDL_JoystickGUID
   16.14  LINUX_JoystickGetDeviceGUID( int device_index )
   16.15  {
   16.16 @@ -1100,6 +1106,7 @@
   16.17      LINUX_JoystickGetCount,
   16.18      LINUX_JoystickDetect,
   16.19      LINUX_JoystickGetDeviceName,
   16.20 +    LINUX_JoystickGetDevicePlayerIndex,
   16.21      LINUX_JoystickGetDeviceGUID,
   16.22      LINUX_JoystickGetDeviceInstanceID,
   16.23      LINUX_JoystickOpen,
    17.1 --- a/src/joystick/windows/SDL_windowsjoystick.c	Thu Oct 25 13:22:34 2018 -0700
    17.2 +++ b/src/joystick/windows/SDL_windowsjoystick.c	Thu Oct 25 16:53:14 2018 -0700
    17.3 @@ -407,6 +407,18 @@
    17.4      return device->joystickname;
    17.5  }
    17.6  
    17.7 +static int
    17.8 +WINDOWS_JoystickGetDevicePlayerIndex(int device_index)
    17.9 +{
   17.10 +    JoyStick_DeviceData *device = SYS_Joystick;
   17.11 +    int index;
   17.12 +
   17.13 +    for (index = device_index; index > 0; index--)
   17.14 +        device = device->pNext;
   17.15 +
   17.16 +    return device->bXInputDevice ? (int)device->XInputUserId : -1;
   17.17 +}
   17.18 +
   17.19  /* return the stable device guid for this device index */
   17.20  static SDL_JoystickGUID
   17.21  WINDOWS_JoystickGetDeviceGUID(int device_index)
   17.22 @@ -544,6 +556,7 @@
   17.23      WINDOWS_JoystickGetCount,
   17.24      WINDOWS_JoystickDetect,
   17.25      WINDOWS_JoystickGetDeviceName,
   17.26 +    WINDOWS_JoystickGetDevicePlayerIndex,
   17.27      WINDOWS_JoystickGetDeviceGUID,
   17.28      WINDOWS_JoystickGetDeviceInstanceID,
   17.29      WINDOWS_JoystickOpen,
    18.1 --- a/src/joystick/windows/SDL_xinputjoystick.c	Thu Oct 25 13:22:34 2018 -0700
    18.2 +++ b/src/joystick/windows/SDL_xinputjoystick.c	Thu Oct 25 16:53:14 2018 -0700
    18.3 @@ -312,6 +312,8 @@
    18.4      SDL_assert(XINPUTSETSTATE);
    18.5      SDL_assert(userId < XUSER_MAX_COUNT);
    18.6  
    18.7 +    joystick->player_index = userId;
    18.8 +
    18.9      joystick->hwdata->bXInputDevice = SDL_TRUE;
   18.10  
   18.11      if (XINPUTGETCAPABILITIES(userId, XINPUT_FLAG_GAMEPAD, &capabilities) != ERROR_SUCCESS) {
   18.12 @@ -322,7 +324,6 @@
   18.13      SDL_zero(state);
   18.14      joystick->hwdata->bXInputHaptic = (XINPUTSETSTATE(userId, &state) == ERROR_SUCCESS);
   18.15      joystick->hwdata->userid = userId;
   18.16 -    joystick->userid = userId;
   18.17  
   18.18      /* The XInput API has a hard coded button/axis mapping, so we just match it */
   18.19      if (SDL_XInputUseOldJoystickMapping()) {