From 733f25252a12feba7d6d8cdbee7b495b83bf8f29 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 22 Nov 2019 14:09:24 -0800 Subject: [PATCH] Fixed build --- src/joystick/SDL_gamecontroller.c | 8 ++------ src/joystick/SDL_joystick.c | 16 +++++++++++----- src/joystick/SDL_joystick_c.h | 4 ++-- src/joystick/hidapi/SDL_hidapi_ps4.c | 2 +- src/joystick/hidapi/SDL_hidapi_switch.c | 11 +---------- src/joystick/hidapi/SDL_hidapi_xbox360.c | 2 +- src/joystick/hidapi/SDL_hidapi_xboxone.c | 2 +- src/joystick/windows/SDL_dinputjoystick.c | 2 +- 8 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 47bf1bd1b..8c898fdfe 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -1418,8 +1418,7 @@ SDL_GameControllerNameForIndex(int device_index) SDL_GameControllerType SDL_GameControllerTypeForIndex(int joystick_index) { - SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(joystick_index); - return SDL_GetGameControllerTypeFromGUID(guid); + return SDL_GetJoystickGameControllerTypeFromGUID(SDL_JoystickGetDeviceGUID(joystick_index), SDL_JoystickNameForIndex(joystick_index)); } @@ -1757,10 +1756,7 @@ SDL_GameControllerName(SDL_GameController * gamecontroller) SDL_GameControllerType SDL_GameControllerGetType(SDL_GameController *gamecontroller) { - if (!gamecontroller) { - return SDL_CONTROLLER_TYPE_UNKNOWN; - } - return SDL_GetGameControllerTypeFromGUID(gamecontroller->joystick->guid); + return SDL_GetJoystickGameControllerTypeFromGUID(SDL_JoystickGetGUID(SDL_GameControllerGetJoystick(gamecontroller)), SDL_JoystickName(SDL_GameControllerGetJoystick(gamecontroller))); } int diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index eec3ea9d7..ba6d2b3bf 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -1167,13 +1167,13 @@ SDL_IsJoystickNintendoSwitchPro(Uint16 vendor, Uint16 product) } SDL_GameControllerType -SDL_GetGameControllerTypeFromGUID(SDL_JoystickGUID guid) +SDL_GetJoystickGameControllerTypeFromGUID(SDL_JoystickGUID guid, const char *name) { SDL_GameControllerType type; Uint16 vendor, product; SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL); - type = SDL_GetGameControllerType(vendor, product); + type = SDL_GetJoystickGameControllerType(vendor, product, name); if (type == SDL_CONTROLLER_TYPE_UNKNOWN) { if (SDL_IsJoystickXInput(guid)) { /* This is probably an Xbox One controller */ @@ -1184,10 +1184,16 @@ SDL_GetGameControllerTypeFromGUID(SDL_JoystickGUID guid) } SDL_GameControllerType -SDL_GetGameControllerType(Uint16 vendor, Uint16 product) +SDL_GetJoystickGameControllerType(Uint16 vendor, Uint16 product, const char *name) { - /* Filter out some bogus values here */ if (vendor == 0x0000 && product == 0x0000) { + /* Some devices are only identifiable by their name */ + if (SDL_strcmp(name, "Lic Pro Controller") == 0 || + SDL_strcmp(name, "Nintendo Wireless Gamepad") == 0 || + SDL_strcmp(name, "Wireless Gamepad") == 0) { + /* HORI or PowerA Switch Pro Controller clone */ + return SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO; + } return SDL_CONTROLLER_TYPE_UNKNOWN; } if (vendor == 0x0001 && product == 0x0001) { @@ -1501,7 +1507,7 @@ SDL_bool SDL_ShouldIgnoreJoystick(const char *name, SDL_JoystickGUID guid) } } - if (SDL_GetGameControllerType(vendor, product) == SDL_CONTROLLER_TYPE_PS4 && SDL_IsPS4RemapperRunning()) { + if (SDL_GetJoystickGameControllerType(vendor, product, name) == SDL_CONTROLLER_TYPE_PS4 && SDL_IsPS4RemapperRunning()) { return SDL_TRUE; } diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h index d84c36216..0bb963fa4 100644 --- a/src/joystick/SDL_joystick_c.h +++ b/src/joystick/SDL_joystick_c.h @@ -53,8 +53,8 @@ extern int SDL_JoystickGetDeviceIndexFromInstanceID(SDL_JoystickID instance_id); extern void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version); /* Function to return the type of a controller */ -extern SDL_GameControllerType SDL_GetGameControllerTypeFromGUID(SDL_JoystickGUID guid); -extern SDL_GameControllerType SDL_GetGameControllerType(Uint16 vendor, Uint16 product); +extern SDL_GameControllerType SDL_GetJoystickGameControllerTypeFromGUID(SDL_JoystickGUID guid, const char *name); +extern SDL_GameControllerType SDL_GetJoystickGameControllerType(Uint16 vendor, Uint16 product, const char *name); /* Function to return whether a joystick is a Nintendo Switch Pro controller */ extern SDL_bool SDL_IsJoystickNintendoSwitchProInputOnly(Uint16 vendor_id, Uint16 product_id); diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c index f69c43dd3..453996c3b 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps4.c +++ b/src/joystick/hidapi/SDL_hidapi_ps4.c @@ -141,7 +141,7 @@ static Uint32 crc32(Uint32 crc, const void *data, int count) static SDL_bool HIDAPI_DriverPS4_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, const char *name) { - return (SDL_GetGameControllerType(vendor_id, product_id) == SDL_CONTROLLER_TYPE_PS4); + return (SDL_GetJoystickGameControllerType(vendor_id, product_id, name) == SDL_CONTROLLER_TYPE_PS4); } static const char * diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c index 7c2648a69..09c7fd0fd 100644 --- a/src/joystick/hidapi/SDL_hidapi_switch.c +++ b/src/joystick/hidapi/SDL_hidapi_switch.c @@ -226,16 +226,7 @@ typedef struct { static SDL_bool HIDAPI_DriverSwitch_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, const char *name) { - if (vendor_id == 0 && product_id == 0) { - /* Some devices are only identifiable by their name */ - if (SDL_strcmp(name, "Lic Pro Controller") == 0 || - SDL_strcmp(name, "Nintendo Wireless Gamepad") == 0 || - SDL_strcmp(name, "Wireless Gamepad") == 0) { - /* HORI or PowerA Switch Pro Controller clone */ - return SDL_TRUE; - } - } - return SDL_IsJoystickNintendoSwitchPro(vendor_id, product_id); + return (SDL_GetJoystickGameControllerType(vendor_id, product_id, name) == SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO); } static const char * diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360.c b/src/joystick/hidapi/SDL_hidapi_xbox360.c index 5193c35b1..d4ba4871c 100644 --- a/src/joystick/hidapi/SDL_hidapi_xbox360.c +++ b/src/joystick/hidapi/SDL_hidapi_xbox360.c @@ -249,7 +249,7 @@ HIDAPI_DriverXbox360_QuitWindowsGamingInput(SDL_DriverXbox360_Context *ctx) static SDL_bool HIDAPI_DriverXbox360_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, const char *name) { - SDL_GameControllerType type = SDL_GameControllerType(vendor_id, product_id); + SDL_GameControllerType type = SDL_GetJoystickGameControllerType(vendor_id, product_id, name); #if defined(__MACOSX__) || defined(__WIN32__) if (vendor_id == 0x045e && product_id == 0x028e && version == 1) { diff --git a/src/joystick/hidapi/SDL_hidapi_xboxone.c b/src/joystick/hidapi/SDL_hidapi_xboxone.c index 689485412..68370a100 100644 --- a/src/joystick/hidapi/SDL_hidapi_xboxone.c +++ b/src/joystick/hidapi/SDL_hidapi_xboxone.c @@ -197,7 +197,7 @@ HIDAPI_DriverXboxOne_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint return SDL_FALSE; } #endif - return (SDL_GetGameControllerType(vendor_id, product_id) == SDL_CONTROLLER_TYPE_XBOXONE); + return (SDL_GetJoystickGameControllerType(vendor_id, product_id, name) == SDL_CONTROLLER_TYPE_XBOXONE); } static const char * diff --git a/src/joystick/windows/SDL_dinputjoystick.c b/src/joystick/windows/SDL_dinputjoystick.c index 1a39b7ad9..7182bf827 100644 --- a/src/joystick/windows/SDL_dinputjoystick.c +++ b/src/joystick/windows/SDL_dinputjoystick.c @@ -374,7 +374,7 @@ SDL_IsXInputDevice(const GUID* pGuidProductFromDirectInput) if (SDL_memcmp(&pGuidProductFromDirectInput->Data4[2], "PIDVID", 6) == 0) { Uint16 vendor_id = (Uint16)LOWORD(pGuidProductFromDirectInput->Data1); Uint16 product_id = (Uint16)HIWORD(pGuidProductFromDirectInput->Data1); - SDL_GameControllerType type = SDL_GetGameControllerType(vendor_id, product_id); + SDL_GameControllerType type = SDL_GetJoystickGameControllerType(vendor_id, product_id, ""); if (type == SDL_CONTROLLER_TYPE_XBOX360 || type == SDL_CONTROLLER_TYPE_XBOXONE || (vendor_id == 0x28DE && product_id == 0x11FF)) {