From a3ab46b7072b2b4e2d6485e59fbbca3118d28a2f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 23 May 2024 16:45:56 -0700 Subject: [PATCH] Fixed mapping the touchpad for the Qanba PS5 controllers like the Qanba Drone 2 Arcade Joystick These controllers are autodetected by the HIDAPI driver, so SDL_GetGamepadTypeFromGUID() should be used to pull the gamepad type out of the GUID. --- src/joystick/SDL_gamepad.c | 40 +++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c index 0136ec1e6f..d400b53ae3 100644 --- a/src/joystick/SDL_gamepad.c +++ b/src/joystick/SDL_gamepad.c @@ -783,6 +783,10 @@ static GamepadMapping_t *SDL_CreateMappingForHIDAPIGamepad(SDL_JoystickGUID guid } else if (SDL_IsJoystickSteamController(vendor, product)) { /* Steam controllers have 2 back paddle buttons */ SDL_strlcat(mapping_string, "paddle1:b12,paddle2:b11,", sizeof(mapping_string)); + } else if (SDL_IsJoystickNintendoSwitchPro(vendor, product) || + SDL_IsJoystickNintendoSwitchProInputOnly(vendor, product)) { + /* Nintendo Switch Pro controllers have a screenshot button */ + SDL_strlcat(mapping_string, "misc1:b11,", sizeof(mapping_string)); } else if (SDL_IsJoystickNintendoSwitchJoyConPair(vendor, product)) { /* The Nintendo Switch Joy-Con combined controllers has a share button and paddles */ SDL_strlcat(mapping_string, "misc1:b11,paddle1:b12,paddle2:b13,paddle3:b14,paddle4:b15,", sizeof(mapping_string)); @@ -800,23 +804,27 @@ static GamepadMapping_t *SDL_CreateMappingForHIDAPIGamepad(SDL_JoystickGUID guid /* The original SHIELD controller has a touchpad and plus/minus buttons as well */ SDL_strlcat(mapping_string, "touchpad:b12,misc2:b13,misc3:b14", sizeof(mapping_string)); } - } else if (SDL_IsJoystickPS4(vendor, product)) { - /* PS4 controllers have an additional touchpad button */ - SDL_strlcat(mapping_string, "touchpad:b11,", sizeof(mapping_string)); - } else if (SDL_IsJoystickPS5(vendor, product)) { - /* PS5 controllers have a microphone button and an additional touchpad button */ - SDL_strlcat(mapping_string, "touchpad:b11,misc1:b12,", sizeof(mapping_string)); - /* DualSense Edge controllers have paddles and a microphone button */ - if (SDL_IsJoystickDualSenseEdge(vendor, product)) { - SDL_strlcat(mapping_string, "paddle1:b16,paddle2:b15,paddle3:b14,paddle4:b13,", sizeof(mapping_string)); + } else { + switch (SDL_GetGamepadTypeFromGUID(guid, NULL)) { + case SDL_GAMEPAD_TYPE_PS4: + /* PS4 controllers have an additional touchpad button */ + SDL_strlcat(mapping_string, "touchpad:b11,", sizeof(mapping_string)); + break; + case SDL_GAMEPAD_TYPE_PS5: + /* PS5 controllers have a microphone button and an additional touchpad button */ + SDL_strlcat(mapping_string, "touchpad:b11,misc1:b12,", sizeof(mapping_string)); + /* DualSense Edge controllers have paddles */ + if (SDL_IsJoystickDualSenseEdge(vendor, product)) { + SDL_strlcat(mapping_string, "paddle1:b16,paddle2:b15,paddle3:b14,paddle4:b13,", sizeof(mapping_string)); + } + break; + default: + if (vendor == 0 && product == 0) { + /* This is a Bluetooth Nintendo Switch Pro controller */ + SDL_strlcat(mapping_string, "misc1:b11,", sizeof(mapping_string)); + } + break; } - } else if (SDL_IsJoystickNintendoSwitchPro(vendor, product) || - SDL_IsJoystickNintendoSwitchProInputOnly(vendor, product)) { - /* Nintendo Switch Pro controllers have a screenshot button */ - SDL_strlcat(mapping_string, "misc1:b11,", sizeof(mapping_string)); - } else if (vendor == 0 && product == 0) { - /* This is a Bluetooth Nintendo Switch Pro controller */ - SDL_strlcat(mapping_string, "misc1:b11,", sizeof(mapping_string)); } }