mirror of https://github.com/encounter/SDL.git
Don't clobber an existing entry with a different version when adding a gamepad mapping
(cherry picked from commit 727c7d4e2f44102bb571180929bfbb5d527f4f27) (cherry picked from commit 660fc89967257cf66938fa564208984c4a45e0ff)
This commit is contained in:
parent
fa9f7c70c5
commit
cbc2b014b6
|
@ -770,7 +770,7 @@ static ControllerMapping_t *SDL_PrivateMatchControllerMappingForGUID(SDL_Joystic
|
||||||
/*
|
/*
|
||||||
* Helper function to scan the mappings database for a controller with the specified GUID
|
* Helper function to scan the mappings database for a controller with the specified GUID
|
||||||
*/
|
*/
|
||||||
static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID guid, SDL_bool create_mapping)
|
static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID guid, SDL_bool adding_mapping)
|
||||||
{
|
{
|
||||||
ControllerMapping_t *mapping;
|
ControllerMapping_t *mapping;
|
||||||
Uint16 vendor, product, crc;
|
Uint16 vendor, product, crc;
|
||||||
|
@ -790,6 +790,13 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickG
|
||||||
return mapping;
|
return mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (adding_mapping) {
|
||||||
|
/* We didn't find an existing mapping */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Try harder to get the best match, or create a mapping */
|
||||||
|
|
||||||
if (vendor && product) {
|
if (vendor && product) {
|
||||||
/* Try again, ignoring the version */
|
/* Try again, ignoring the version */
|
||||||
if (crc) {
|
if (crc) {
|
||||||
|
@ -805,17 +812,12 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickG
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!create_mapping) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if SDL_JOYSTICK_XINPUT
|
#if SDL_JOYSTICK_XINPUT
|
||||||
if (SDL_IsJoystickXInput(guid)) {
|
if (SDL_IsJoystickXInput(guid)) {
|
||||||
/* This is an XInput device */
|
/* This is an XInput device */
|
||||||
return s_pXInputMapping;
|
return s_pXInputMapping;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!mapping) {
|
|
||||||
if (SDL_IsJoystickHIDAPI(guid)) {
|
if (SDL_IsJoystickHIDAPI(guid)) {
|
||||||
mapping = SDL_CreateMappingForHIDAPIController(guid);
|
mapping = SDL_CreateMappingForHIDAPIController(guid);
|
||||||
} else if (SDL_IsJoystickRAWINPUT(guid)) {
|
} else if (SDL_IsJoystickRAWINPUT(guid)) {
|
||||||
|
@ -829,7 +831,6 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickG
|
||||||
mapping = SDL_CreateMappingForAndroidController(guid);
|
mapping = SDL_CreateMappingForAndroidController(guid);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return mapping;
|
return mapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1276,7 +1277,7 @@ SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, const char *mappingString,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pControllerMapping = SDL_PrivateGetControllerMappingForGUID(jGUID, SDL_FALSE);
|
pControllerMapping = SDL_PrivateGetControllerMappingForGUID(jGUID, SDL_TRUE);
|
||||||
if (pControllerMapping) {
|
if (pControllerMapping) {
|
||||||
/* Only overwrite the mapping if the priority is the same or higher. */
|
/* Only overwrite the mapping if the priority is the same or higher. */
|
||||||
if (pControllerMapping->priority <= priority) {
|
if (pControllerMapping->priority <= priority) {
|
||||||
|
@ -1336,7 +1337,7 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const
|
||||||
{
|
{
|
||||||
ControllerMapping_t *mapping;
|
ControllerMapping_t *mapping;
|
||||||
|
|
||||||
mapping = SDL_PrivateGetControllerMappingForGUID(guid, SDL_TRUE);
|
mapping = SDL_PrivateGetControllerMappingForGUID(guid, SDL_FALSE);
|
||||||
#ifdef __LINUX__
|
#ifdef __LINUX__
|
||||||
if (!mapping && name) {
|
if (!mapping && name) {
|
||||||
if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) {
|
if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) {
|
||||||
|
@ -1751,7 +1752,7 @@ SDL_GameControllerMappingForIndex(int mapping_index)
|
||||||
char *
|
char *
|
||||||
SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
|
SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
|
||||||
{
|
{
|
||||||
ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(guid, SDL_TRUE);
|
ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(guid, SDL_FALSE);
|
||||||
if (mapping) {
|
if (mapping) {
|
||||||
return CreateMappingString(mapping, guid);
|
return CreateMappingString(mapping, guid);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue