Added generic xinput fallback for XBox compatible controllers on Linux
authorSam Lantinga <slouken@libsdl.org>
Wed, 13 May 2015 22:37:26 -0700
changeset 9596ac646c8a73ae
parent 9595 6027a65e8528
child 9597 345bc53b52b8
Added generic xinput fallback for XBox compatible controllers on Linux
src/joystick/SDL_gamecontroller.c
src/joystick/SDL_gamecontrollerdb.h
     1.1 --- a/src/joystick/SDL_gamecontroller.c	Mon May 11 21:03:36 2015 -0300
     1.2 +++ b/src/joystick/SDL_gamecontroller.c	Wed May 13 22:37:26 2015 -0700
     1.3 @@ -259,22 +259,29 @@
     1.4   */
     1.5  ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
     1.6  {
     1.7 +    SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID(device_index);
     1.8 +    ControllerMapping_t *mapping;
     1.9 +
    1.10 +    mapping = SDL_PrivateGetControllerMappingForGUID(&jGUID);
    1.11  #if SDL_JOYSTICK_XINPUT
    1.12 -    if (SDL_SYS_IsXInputGamepad_DeviceIndex(device_index) && s_pXInputMapping) {
    1.13 -        return s_pXInputMapping;
    1.14 +    if (!mapping && SDL_SYS_IsXInputGamepad_DeviceIndex(device_index)) {
    1.15 +        mapping = s_pXInputMapping;
    1.16      }
    1.17 -    else
    1.18  #endif
    1.19  #if defined(SDL_JOYSTICK_EMSCRIPTEN)
    1.20 -    if (s_pEmscriptenMapping) {
    1.21 -        return s_pEmscriptenMapping;
    1.22 +    if (!mapping && s_pEmscriptenMapping) {
    1.23 +        mapping = s_pEmscriptenMapping;
    1.24      }
    1.25 -    else
    1.26  #endif
    1.27 -    {
    1.28 -        SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID(device_index);
    1.29 -        return SDL_PrivateGetControllerMappingForGUID(&jGUID);
    1.30 +    if (!mapping) {
    1.31 +        const char *name = SDL_JoystickNameForIndex(device_index);
    1.32 +        if (name) {
    1.33 +            if (SDL_strstr(name, "Xbox") || SDL_strstr(name, "X-Box")) {
    1.34 +                mapping = s_pXInputMapping;
    1.35 +            }
    1.36 +        }
    1.37      }
    1.38 +    return mapping;
    1.39  }
    1.40  
    1.41  static const char* map_StringForControllerAxis[] = {
     2.1 --- a/src/joystick/SDL_gamecontrollerdb.h	Mon May 11 21:03:36 2015 -0300
     2.2 +++ b/src/joystick/SDL_gamecontrollerdb.h	Wed May 13 22:37:26 2015 -0700
     2.3 @@ -67,14 +67,14 @@
     2.4      "03000000550900001072000011010000,NVIDIA Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b8,lefttrigger:a5,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a4,rightx:a2,righty:a3,start:b7,x:b2,y:b3,",
     2.5      "050000003620000100000002010000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,x:b1,y:b2,",
     2.6      "030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
     2.7 +    "03000000341a00003608000011010000,PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
     2.8      "030000004c050000c405000011010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
     2.9      "050000004c050000c405000000010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
    2.10      "03000000de280000fc11000001000000,Steam Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
    2.11      "03000000de280000ff11000001000000,Valve Streaming Gamepad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
    2.12 -    "030000005e0400008e02000014010000,X360 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
    2.13 -    "030000005e0400008e02000010010000,X360 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
    2.14      "030000005e0400001907000000010000,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
    2.15      "030000005e0400009102000007010000,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
    2.16 +    "xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
    2.17      "030000005e040000d102000001010000,Xbox One Wireless Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
    2.18  #endif
    2.19  #if defined(__ANDROID__)