mirror of https://github.com/libsdl-org/SDL
Only update the serial number if it hasn't already been set
This fixes the serial number for Nintendo Switch Pro, which is queried from the hardware in device initialization, and was later clobbered by the USB string which isn't correct.
This commit is contained in:
parent
c8051b11e8
commit
2042e9c4e3
|
@ -672,6 +672,22 @@ static void HIDAPI_UpdateJoystickSerial(SDL_HIDAPI_Device *device)
|
|||
}
|
||||
}
|
||||
|
||||
static SDL_bool HIDAPI_SerialIsEmpty(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
SDL_bool all_zeroes = SDL_TRUE;
|
||||
|
||||
if (device->serial) {
|
||||
const char *serial = device->serial;
|
||||
for (serial = device->serial; *serial; ++serial) {
|
||||
if (*serial != '0') {
|
||||
all_zeroes = SDL_FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return all_zeroes;
|
||||
}
|
||||
|
||||
void HIDAPI_SetDeviceSerial(SDL_HIDAPI_Device *device, const char *serial)
|
||||
{
|
||||
if (serial && *serial && (!device->serial || SDL_strcmp(serial, device->serial) != 0)) {
|
||||
|
@ -1081,7 +1097,9 @@ static void HIDAPI_UpdateDeviceList(void)
|
|||
device->seen = SDL_TRUE;
|
||||
|
||||
/* Check to see if the serial number is available now */
|
||||
HIDAPI_SetDeviceSerialW(device, info->serial_number);
|
||||
if(HIDAPI_SerialIsEmpty(device)) {
|
||||
HIDAPI_SetDeviceSerialW(device, info->serial_number);
|
||||
}
|
||||
} else {
|
||||
HIDAPI_AddDevice(info, 0, NULL);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue