Skip to content

Commit

Permalink
Fixed build
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 22, 2019
1 parent 13006ba commit 733f252
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 27 deletions.
8 changes: 2 additions & 6 deletions src/joystick/SDL_gamecontroller.c
Expand Up @@ -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));
}


Expand Down Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions src/joystick/SDL_joystick.c
Expand Up @@ -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 */
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/joystick/SDL_joystick_c.h
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/joystick/hidapi/SDL_hidapi_ps4.c
Expand Up @@ -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 *
Expand Down
11 changes: 1 addition & 10 deletions src/joystick/hidapi/SDL_hidapi_switch.c
Expand Up @@ -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 *
Expand Down
2 changes: 1 addition & 1 deletion src/joystick/hidapi/SDL_hidapi_xbox360.c
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/joystick/hidapi/SDL_hidapi_xboxone.c
Expand Up @@ -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 *
Expand Down
2 changes: 1 addition & 1 deletion src/joystick/windows/SDL_dinputjoystick.c
Expand Up @@ -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)) {
Expand Down

0 comments on commit 733f252

Please sign in to comment.