Added custom names for some controllers

This commit is contained in:
Sam Lantinga
2019-12-11 17:47:01 -08:00
parent e029fdbb38
commit 0f52916027
8 changed files with 533 additions and 481 deletions

View File

@@ -220,6 +220,7 @@ AddXInputDevice(Uint8 userid, BYTE SubType, JoyStick_DeviceData **pContext)
Uint16 vendor = 0;
Uint16 product = 0;
Uint16 version = 0;
const char *name;
JoyStick_DeviceData *pPrevJoystick = NULL;
JoyStick_DeviceData *pNewJoystick = *pContext;
@@ -247,22 +248,13 @@ AddXInputDevice(Uint8 userid, BYTE SubType, JoyStick_DeviceData **pContext)
pNewJoystick = pNewJoystick->pNext;
}
pNewJoystick = (JoyStick_DeviceData *)SDL_malloc(sizeof(JoyStick_DeviceData));
pNewJoystick = (JoyStick_DeviceData *)SDL_calloc(1, sizeof(JoyStick_DeviceData));
if (!pNewJoystick) {
return; /* better luck next time? */
}
SDL_zerop(pNewJoystick);
pNewJoystick->joystickname = GetXInputName(userid, SubType);
if (!pNewJoystick->joystickname) {
SDL_free(pNewJoystick);
return; /* better luck next time? */
}
pNewJoystick->bXInputDevice = SDL_TRUE;
if (SDL_XInputUseOldJoystickMapping()) {
SDL_zero(pNewJoystick->guid);
} else {
if (!SDL_XInputUseOldJoystickMapping()) {
Uint16 *guid16 = (Uint16 *)pNewJoystick->guid.data;
GuessXInputDevice(userid, &vendor, &product, &version);
@@ -283,6 +275,17 @@ AddXInputDevice(Uint8 userid, BYTE SubType, JoyStick_DeviceData **pContext)
pNewJoystick->SubType = SubType;
pNewJoystick->XInputUserId = userid;
name = SDL_GetCustomJoystickName(vendor, product);
if (name) {
pNewJoystick->joystickname = SDL_strdup(name);
} else {
pNewJoystick->joystickname = GetXInputName(userid, SubType);
}
if (!pNewJoystick->joystickname) {
SDL_free(pNewJoystick);
return; /* better luck next time? */
}
if (SDL_ShouldIgnoreJoystick(pNewJoystick->joystickname, pNewJoystick->guid)) {
SDL_free(pNewJoystick);
return;