Fixed controllers showing up under both MFI and HIDAPI drivers
The Game Controller Kit doesn't show the controllers at startup, so the HIDAPI driver sees them first and therefore gets preference when a controller is supported by both drivers. This fixes bug https://github.com/libsdl-org/SDL/issues/4209
This commit is contained in:
parent
46869db01c
commit
2a53f8315a
3 changed files with 99 additions and 5 deletions
|
@ -1110,6 +1110,40 @@ HIDAPI_IsEquivalentToDevice(Uint16 vendor_id, Uint16 product_id, SDL_HIDAPI_Devi
|
|||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
HIDAPI_IsDeviceTypePresent(SDL_GameControllerType type)
|
||||
{
|
||||
SDL_HIDAPI_Device *device;
|
||||
SDL_bool result = SDL_FALSE;
|
||||
|
||||
/* Make sure we're initialized, as this could be called from other drivers during startup */
|
||||
if (HIDAPI_JoystickInit() < 0) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (SDL_AtomicTryLock(&SDL_HIDAPI_spinlock)) {
|
||||
HIDAPI_UpdateDeviceList();
|
||||
SDL_AtomicUnlock(&SDL_HIDAPI_spinlock);
|
||||
}
|
||||
|
||||
SDL_LockJoysticks();
|
||||
device = SDL_HIDAPI_devices;
|
||||
while (device) {
|
||||
if (device->driver &&
|
||||
SDL_GetJoystickGameControllerType(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol) == type) {
|
||||
result = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
device = device->next;
|
||||
}
|
||||
SDL_UnlockJoysticks();
|
||||
|
||||
#ifdef DEBUG_HIDAPI
|
||||
SDL_Log("HIDAPI_IsDeviceTypePresent() returning %s for %d\n", result ? "true" : "false", type);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name)
|
||||
{
|
||||
|
@ -1152,6 +1186,7 @@ HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, cons
|
|||
if (device->driver &&
|
||||
HIDAPI_IsEquivalentToDevice(vendor_id, product_id, device)) {
|
||||
result = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
device = device->next;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue