mirror of https://github.com/encounter/SDL.git
Wait for the GCController framework to see IOKit devices
It occasionally takes a few millseconds for the GCController framework to handle the device notification and set up the device Fixes the duplicate controller issue in https://github.com/libsdl-org/SDL/issues/6686 (cherry picked from commit 645823fc901c98b688512d3b3e70cc8922e8140c) (cherry picked from commit 3f00fa16c656d0651c43720d8f84138ac3b998ee)
This commit is contained in:
parent
596a594714
commit
45167b9d13
|
@ -1677,31 +1677,14 @@ IOS_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
|
||||||
SDL_bool IOS_SupportedHIDDevice(IOHIDDeviceRef device)
|
SDL_bool IOS_SupportedHIDDevice(IOHIDDeviceRef device)
|
||||||
{
|
{
|
||||||
if (@available(macOS 10.16, *)) {
|
if (@available(macOS 10.16, *)) {
|
||||||
if ([GCController supportsHIDDevice:device]) {
|
const int MAX_ATTEMPTS = 3;
|
||||||
return SDL_TRUE;
|
for (int attempt = 0; attempt < MAX_ATTEMPTS; ++attempt) {
|
||||||
}
|
if ([GCController supportsHIDDevice:device]) {
|
||||||
|
|
||||||
/* GCController supportsHIDDevice may return false if the device hasn't been
|
|
||||||
* seen by the framework yet, so check a few controllers we know are supported.
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
Sint32 vendor = 0;
|
|
||||||
Sint32 product = 0;
|
|
||||||
CFTypeRef refCF = NULL;
|
|
||||||
|
|
||||||
refCF = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey));
|
|
||||||
if (refCF) {
|
|
||||||
CFNumberGetValue(refCF, kCFNumberSInt32Type, &vendor);
|
|
||||||
}
|
|
||||||
|
|
||||||
refCF = IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductIDKey));
|
|
||||||
if (refCF) {
|
|
||||||
CFNumberGetValue(refCF, kCFNumberSInt32Type, &product);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vendor == USB_VENDOR_MICROSOFT && SDL_IsJoystickXboxSeriesX(vendor, product)) {
|
|
||||||
return SDL_TRUE;
|
return SDL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The framework may not have seen the device yet */
|
||||||
|
SDL_Delay(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
|
|
Loading…
Reference in New Issue