Detect steam virtual gamepads more accurately on macOS

This commit is contained in:
tmkk
2026-02-22 14:35:33 +09:00
committed by Sam Lantinga
parent 50d0e2ede2
commit bbcc205de9
3 changed files with 33 additions and 1 deletions

View File

@@ -573,6 +573,7 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
{
unsigned short dev_vid;
unsigned short dev_pid;
unsigned short dev_version;
int BUF_LEN = 256;
wchar_t buf[BUF_LEN];
CFTypeRef transport_prop;
@@ -593,6 +594,7 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
dev_vid = get_vendor_id(dev);
dev_pid = get_product_id(dev);
dev_version = get_int_property(dev, CFSTR(kIOHIDVersionNumberKey));
#ifdef HIDAPI_IGNORE_DEVICE
/* See if there are any devices we should skip in enumeration */
@@ -602,6 +604,19 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
}
#endif
#ifdef HIDAPI_USING_SDL_RUNTIME
if (IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDVirtualHIDevice)) == kCFBooleanTrue) {
/* Steam virtual gamepads always have kIOHIDVirtualHIDevice property unlike real devices */
if (SDL_IsJoystickSteamVirtualGamepad(dev_vid, dev_pid, dev_version)) {
const char *allow_steam_virtual_gamepad = SDL_getenv_unsafe("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD");
if (!SDL_GetStringBoolean(allow_steam_virtual_gamepad, false)) {
free(cur_dev);
return NULL;
}
}
}
#endif
cur_dev->usage_page = usage_page;
cur_dev->usage = usage;
@@ -649,7 +664,7 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
cur_dev->product_id = dev_pid;
/* Release Number */
cur_dev->release_number = get_int_property(dev, CFSTR(kIOHIDVersionNumberKey));
cur_dev->release_number = dev_version;
/* Interface Number.
* We can only retrieve the interface number for USB HID devices.