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.
This commit is contained in:
Sam Lantinga
2024-05-23 16:45:56 -07:00
parent 98a9ca5e32
commit a3ab46b707

View File

@@ -783,6 +783,10 @@ static GamepadMapping_t *SDL_CreateMappingForHIDAPIGamepad(SDL_JoystickGUID guid
} else if (SDL_IsJoystickSteamController(vendor, product)) { } else if (SDL_IsJoystickSteamController(vendor, product)) {
/* Steam controllers have 2 back paddle buttons */ /* Steam controllers have 2 back paddle buttons */
SDL_strlcat(mapping_string, "paddle1:b12,paddle2:b11,", sizeof(mapping_string)); 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)) { } else if (SDL_IsJoystickNintendoSwitchJoyConPair(vendor, product)) {
/* The Nintendo Switch Joy-Con combined controllers has a share button and paddles */ /* 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)); SDL_strlcat(mapping_string, "misc1:b11,paddle1:b12,paddle2:b13,paddle3:b14,paddle4:b15,", sizeof(mapping_string));
@@ -800,24 +804,28 @@ static GamepadMapping_t *SDL_CreateMappingForHIDAPIGamepad(SDL_JoystickGUID guid
/* The original SHIELD controller has a touchpad and plus/minus buttons as well */ /* 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)); SDL_strlcat(mapping_string, "touchpad:b12,misc2:b13,misc3:b14", sizeof(mapping_string));
} }
} else if (SDL_IsJoystickPS4(vendor, product)) { } else {
switch (SDL_GetGamepadTypeFromGUID(guid, NULL)) {
case SDL_GAMEPAD_TYPE_PS4:
/* PS4 controllers have an additional touchpad button */ /* PS4 controllers have an additional touchpad button */
SDL_strlcat(mapping_string, "touchpad:b11,", sizeof(mapping_string)); SDL_strlcat(mapping_string, "touchpad:b11,", sizeof(mapping_string));
} else if (SDL_IsJoystickPS5(vendor, product)) { break;
case SDL_GAMEPAD_TYPE_PS5:
/* PS5 controllers have a microphone button and an additional touchpad button */ /* PS5 controllers have a microphone button and an additional touchpad button */
SDL_strlcat(mapping_string, "touchpad:b11,misc1:b12,", sizeof(mapping_string)); SDL_strlcat(mapping_string, "touchpad:b11,misc1:b12,", sizeof(mapping_string));
/* DualSense Edge controllers have paddles and a microphone button */ /* DualSense Edge controllers have paddles */
if (SDL_IsJoystickDualSenseEdge(vendor, product)) { if (SDL_IsJoystickDualSenseEdge(vendor, product)) {
SDL_strlcat(mapping_string, "paddle1:b16,paddle2:b15,paddle3:b14,paddle4:b13,", sizeof(mapping_string)); SDL_strlcat(mapping_string, "paddle1:b16,paddle2:b15,paddle3:b14,paddle4:b13,", sizeof(mapping_string));
} }
} else if (SDL_IsJoystickNintendoSwitchPro(vendor, product) || break;
SDL_IsJoystickNintendoSwitchProInputOnly(vendor, product)) { default:
/* Nintendo Switch Pro controllers have a screenshot button */ if (vendor == 0 && product == 0) {
SDL_strlcat(mapping_string, "misc1:b11,", sizeof(mapping_string));
} else if (vendor == 0 && product == 0) {
/* This is a Bluetooth Nintendo Switch Pro controller */ /* This is a Bluetooth Nintendo Switch Pro controller */
SDL_strlcat(mapping_string, "misc1:b11,", sizeof(mapping_string)); SDL_strlcat(mapping_string, "misc1:b11,", sizeof(mapping_string));
} }
break;
}
}
} }
return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_GAMEPAD_MAPPING_PRIORITY_DEFAULT); return SDL_PrivateAddMappingForGUID(guid, mapping_string, &existing, SDL_GAMEPAD_MAPPING_PRIORITY_DEFAULT);