Fixed creating an Android game controller mapping for HIDAPI devices on initialization
authorSam Lantinga <slouken@libsdl.org>
Mon, 17 Sep 2018 11:35:22 -0700
changeset 12192f03ca3ab9b30
parent 12191 3c9c784e85bb
child 12193 a4c9aef03fe8
Fixed creating an Android game controller mapping for HIDAPI devices on initialization
src/joystick/SDL_gamecontroller.c
src/joystick/SDL_joystick.c
src/joystick/SDL_joystick_c.h
     1.1 --- a/src/joystick/SDL_gamecontroller.c	Sat Sep 15 14:28:10 2018 +0300
     1.2 +++ b/src/joystick/SDL_gamecontroller.c	Mon Sep 17 11:35:22 2018 -0700
     1.3 @@ -432,12 +432,12 @@
     1.4          pSupportedController = pSupportedController->next;
     1.5      }
     1.6      if (!exact_match) {
     1.7 -        if (guid->data[14] == 'h') {
     1.8 +        if (SDL_IsJoystickHIDAPI(*guid)) {
     1.9              /* This is a HIDAPI device */
    1.10              return s_pHIDAPIMapping;
    1.11          }
    1.12  #if SDL_JOYSTICK_XINPUT
    1.13 -        if (guid->data[14] == 'x') {
    1.14 +        if (SDL_IsJoystickXInput(*guid)) {
    1.15              /* This is an XInput device */
    1.16              return s_pXInputMapping;
    1.17          }
    1.18 @@ -1026,8 +1026,8 @@
    1.19          }
    1.20      }
    1.21  #ifdef __ANDROID__
    1.22 -    if (!mapping) {
    1.23 -        mapping = SDL_CreateMappingForAndroidController(name, guid);
    1.24 +    if (!mapping && name && !SDL_IsJoystickHIDAPI(guid)) {
    1.25 +		mapping = SDL_CreateMappingForAndroidController(name, guid);
    1.26      }
    1.27  #endif
    1.28      if (!mapping) {
     2.1 --- a/src/joystick/SDL_joystick.c	Sat Sep 15 14:28:10 2018 +0300
     2.2 +++ b/src/joystick/SDL_joystick.c	Mon Sep 17 11:35:22 2018 -0700
     2.3 @@ -1157,6 +1157,18 @@
     2.4      return (GuessControllerType(vendor, product) == k_eControllerType_XBoxOneController);
     2.5  }
     2.6  
     2.7 +SDL_bool
     2.8 +SDL_IsJoystickXInput(SDL_JoystickGUID guid)
     2.9 +{
    2.10 +    return (guid.data[14] == 'x') ? SDL_TRUE : SDL_FALSE;
    2.11 +}
    2.12 +
    2.13 +SDL_bool
    2.14 +SDL_IsJoystickHIDAPI(SDL_JoystickGUID guid)
    2.15 +{
    2.16 +    return (guid.data[14] == 'h') ? SDL_TRUE : SDL_FALSE;
    2.17 +}
    2.18 +
    2.19  static SDL_bool SDL_IsJoystickProductWheel(Uint32 vidpid)
    2.20  {
    2.21      static Uint32 wheel_joysticks[] = {
    2.22 @@ -1222,7 +1234,7 @@
    2.23      Uint16 product;
    2.24      Uint32 vidpid;
    2.25  
    2.26 -    if (guid.data[14] == 'x') {
    2.27 +    if (SDL_IsJoystickXInput(guid)) {
    2.28          /* XInput GUID, get the type based on the XInput device subtype */
    2.29          switch (guid.data[15]) {
    2.30          case 0x01:  /* XINPUT_DEVSUBTYPE_GAMEPAD */
     3.1 --- a/src/joystick/SDL_joystick_c.h	Sat Sep 15 14:28:10 2018 +0300
     3.2 +++ b/src/joystick/SDL_joystick_c.h	Mon Sep 17 11:35:22 2018 -0700
     3.3 @@ -62,6 +62,12 @@
     3.4  /* Function to return whether a joystick is an Xbox One controller */
     3.5  extern SDL_bool SDL_IsJoystickXboxOne(Uint16 vendor_id, Uint16 product_id);
     3.6  
     3.7 +/* Function to return whether a joystick guid comes from the XInput driver */
     3.8 +extern SDL_bool SDL_IsJoystickXInput(SDL_JoystickGUID guid);
     3.9 +
    3.10 +/* Function to return whether a joystick guid comes from the HIDAPI driver */
    3.11 +extern SDL_bool SDL_IsJoystickHIDAPI(SDL_JoystickGUID guid);
    3.12 +
    3.13  /* Function to return whether a joystick should be ignored */
    3.14  extern SDL_bool SDL_ShouldIgnoreJoystick(const char *name, SDL_JoystickGUID guid);
    3.15