Fixed creating an Android game controller mapping for HIDAPI devices on initialization
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c
index 8616950..baf85e5 100644
--- a/src/joystick/SDL_gamecontroller.c
+++ b/src/joystick/SDL_gamecontroller.c
@@ -432,12 +432,12 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickG
pSupportedController = pSupportedController->next;
}
if (!exact_match) {
- if (guid->data[14] == 'h') {
+ if (SDL_IsJoystickHIDAPI(*guid)) {
/* This is a HIDAPI device */
return s_pHIDAPIMapping;
}
#if SDL_JOYSTICK_XINPUT
- if (guid->data[14] == 'x') {
+ if (SDL_IsJoystickXInput(*guid)) {
/* This is an XInput device */
return s_pXInputMapping;
}
@@ -1026,8 +1026,8 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const
}
}
#ifdef __ANDROID__
- if (!mapping) {
- mapping = SDL_CreateMappingForAndroidController(name, guid);
+ if (!mapping && name && !SDL_IsJoystickHIDAPI(guid)) {
+ mapping = SDL_CreateMappingForAndroidController(name, guid);
}
#endif
if (!mapping) {
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 72c5656..d274444 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -1157,6 +1157,18 @@ SDL_IsJoystickXboxOne(Uint16 vendor, Uint16 product)
return (GuessControllerType(vendor, product) == k_eControllerType_XBoxOneController);
}
+SDL_bool
+SDL_IsJoystickXInput(SDL_JoystickGUID guid)
+{
+ return (guid.data[14] == 'x') ? SDL_TRUE : SDL_FALSE;
+}
+
+SDL_bool
+SDL_IsJoystickHIDAPI(SDL_JoystickGUID guid)
+{
+ return (guid.data[14] == 'h') ? SDL_TRUE : SDL_FALSE;
+}
+
static SDL_bool SDL_IsJoystickProductWheel(Uint32 vidpid)
{
static Uint32 wheel_joysticks[] = {
@@ -1222,7 +1234,7 @@ static SDL_JoystickType SDL_GetJoystickGUIDType(SDL_JoystickGUID guid)
Uint16 product;
Uint32 vidpid;
- if (guid.data[14] == 'x') {
+ if (SDL_IsJoystickXInput(guid)) {
/* XInput GUID, get the type based on the XInput device subtype */
switch (guid.data[15]) {
case 0x01: /* XINPUT_DEVSUBTYPE_GAMEPAD */
diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h
index b457617..1ede4a1 100644
--- a/src/joystick/SDL_joystick_c.h
+++ b/src/joystick/SDL_joystick_c.h
@@ -62,6 +62,12 @@ extern SDL_bool SDL_IsJoystickXbox360(Uint16 vendor_id, Uint16 product_id);
/* Function to return whether a joystick is an Xbox One controller */
extern SDL_bool SDL_IsJoystickXboxOne(Uint16 vendor_id, Uint16 product_id);
+/* Function to return whether a joystick guid comes from the XInput driver */
+extern SDL_bool SDL_IsJoystickXInput(SDL_JoystickGUID guid);
+
+/* Function to return whether a joystick guid comes from the HIDAPI driver */
+extern SDL_bool SDL_IsJoystickHIDAPI(SDL_JoystickGUID guid);
+
/* Function to return whether a joystick should be ignored */
extern SDL_bool SDL_ShouldIgnoreJoystick(const char *name, SDL_JoystickGUID guid);