Fixed mapping for PS4 controller when using the classic Joystick

interface on Linux
This commit is contained in:
Sam Lantinga 2021-11-11 07:13:29 -08:00
parent dc9de1e2bd
commit 828a0a4a10
1 changed files with 21 additions and 7 deletions

View File

@ -1573,6 +1573,7 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
SDL_OutOfMemory(); SDL_OutOfMemory();
return SDL_FALSE; return SDL_FALSE;
} }
SDL_memcpy(&joystick->guid, &item->guid, sizeof(item->guid));
joystick->hwdata = (struct joystick_hwdata *) joystick->hwdata = (struct joystick_hwdata *)
SDL_calloc(1, sizeof(*joystick->hwdata)); SDL_calloc(1, sizeof(*joystick->hwdata));
@ -1611,6 +1612,18 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
out->b.target = joystick->hwdata->key_map[BTN_B]; out->b.target = joystick->hwdata->key_map[BTN_B];
} }
/* Xbox controllers use BTN_X and BTN_Y, and PS4 controllers use BTN_WEST and BTN_NORTH */
if (SDL_JoystickGetVendor(joystick) == USB_VENDOR_SONY) {
if (joystick->hwdata->has_key[BTN_WEST]) {
out->x.kind = EMappingKind_Button;
out->x.target = joystick->hwdata->key_map[BTN_WEST];
}
if (joystick->hwdata->has_key[BTN_NORTH]) {
out->y.kind = EMappingKind_Button;
out->y.target = joystick->hwdata->key_map[BTN_NORTH];
}
} else {
if (joystick->hwdata->has_key[BTN_X]) { if (joystick->hwdata->has_key[BTN_X]) {
out->x.kind = EMappingKind_Button; out->x.kind = EMappingKind_Button;
out->x.target = joystick->hwdata->key_map[BTN_X]; out->x.target = joystick->hwdata->key_map[BTN_X];
@ -1620,6 +1633,7 @@ LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
out->y.kind = EMappingKind_Button; out->y.kind = EMappingKind_Button;
out->y.target = joystick->hwdata->key_map[BTN_Y]; out->y.target = joystick->hwdata->key_map[BTN_Y];
} }
}
if (joystick->hwdata->has_key[BTN_SELECT]) { if (joystick->hwdata->has_key[BTN_SELECT]) {
out->back.kind = EMappingKind_Button; out->back.kind = EMappingKind_Button;