From 8e78fadbeb8f771d3fc0b46d07297532fa621443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 8 Jan 2024 09:55:11 +0800 Subject: [PATCH] Gamepad: don't provide device names of XBox compatible controllers --- src/detection/gamepad/gamepad_apple.c | 16 ++++++----- src/detection/gamepad/gamepad_windows.c | 35 +++++-------------------- 2 files changed, 15 insertions(+), 36 deletions(-) diff --git a/src/detection/gamepad/gamepad_apple.c b/src/detection/gamepad/gamepad_apple.c index 6927d6213..814e2c3b8 100644 --- a/src/detection/gamepad/gamepad_apple.c +++ b/src/detection/gamepad/gamepad_apple.c @@ -4,16 +4,18 @@ #include #include -static void enumSet(const void* value, void *context) +static void enumSet(IOHIDDeviceRef value, FFlist* results) { - CFStringRef product = IOHIDDeviceGetProperty((IOHIDDeviceRef) value, CFSTR(kIOHIDProductKey)); - CFStringRef serialNumber = IOHIDDeviceGetProperty((IOHIDDeviceRef) value, CFSTR(kIOHIDSerialNumberKey)); - FFGamepadDevice* device = (FFGamepadDevice*) ffListAdd((FFlist*) context); + FFGamepadDevice* device = (FFGamepadDevice*) ffListAdd(results); ffStrbufInit(&device->identifier); - ffCfStrGetString(serialNumber, &device->identifier); ffStrbufInit(&device->name); - ffCfStrGetString(product, &device->name); device->battery = 0; + + CFStringRef serialNumber = IOHIDDeviceGetProperty(value, CFSTR(kIOHIDSerialNumberKey)); + ffCfStrGetString(serialNumber, &device->identifier); + + CFStringRef product = IOHIDDeviceGetProperty(value, CFSTR(kIOHIDProductKey)); + ffCfStrGetString(product, &device->name); } const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */) @@ -35,7 +37,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */) CFSetRef FF_CFTYPE_AUTO_RELEASE set = IOHIDManagerCopyDevices(manager); if (set) - CFSetApplyFunction(set, &enumSet, devices); + CFSetApplyFunction(set, (CFSetApplierFunction) &enumSet, devices); IOHIDManagerClose(manager, 0); return NULL; diff --git a/src/detection/gamepad/gamepad_windows.c b/src/detection/gamepad/gamepad_windows.c index ef99cedb9..7d533a616 100644 --- a/src/detection/gamepad/gamepad_windows.c +++ b/src/detection/gamepad/gamepad_windows.c @@ -7,7 +7,7 @@ #include #include -static const char* detectKnownGamepad(uint32_t vendorId, uint32_t productId) +static const char* detectKnownDeviceName(uint32_t vendorId, uint32_t productId) { switch (vendorId) { @@ -31,38 +31,14 @@ static const char* detectKnownGamepad(uint32_t vendorId, uint32_t productId) { switch (productId) { - case 0x0268: return "Sony Playstation 3 Controller"; + case 0x0268: return "Sony DualShock 3 / Six Axis"; case 0x05C4: return "Sony DualShock 4 Gen1"; case 0x09CC: return "Sony DualShock 4 Gen2"; - case 0x0BA0: return "Sony PS4 Controller USB receiver"; + case 0x0BA0: return "Sony DualShock 4 USB receiver"; case 0x0CE6: return "Sony DualSense"; - - default: return NULL; - } - } - - // Microsoft - case 0x045E: - { - switch (productId) - { - case 0x02E0: return "Microsoft X-Box One S pad (Wireless)"; - case 0x02FD: return "Microsoft X-Box One S pad (Wireless, 2016 FW)"; - case 0x0B05: return "Microsoft X-Box One Elite Series 2 pad (Wireless)"; - case 0x0B13: return "Microsoft X-Box Series X (Wireless)"; - - case 0x028E: return "Microsoft XBox 360"; - case 0x028F: return "Microsoft XBox 360 v2"; - case 0x02A1: return "Microsoft XBox 360"; - case 0x0291: return "Microsoft XBox 360 USB receiver"; - case 0x02A0: return "Microsoft XBox 360 Big Button IR"; - case 0x02DD: return "Microsoft XBox One"; - case 0xB326: return "Microsoft XBox One Firmware 2015"; - case 0x02E3: return "Microsoft XBox One Elite"; - case 0x02FF: return "Microsoft XBox One Elite"; - case 0x02EA: return "Microsoft XBox One S"; + case 0x0DF2: return "Sony DualSense Edge"; default: return NULL; } @@ -84,6 +60,7 @@ static const char* detectKnownGamepad(uint32_t vendorId, uint32_t productId) } } + case 0x045E: // Microsoft Xbox compatible controllers should be handled by Windows without problems default: return NULL; } } @@ -123,7 +100,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */) ffStrbufInit(&device->name); device->battery = 0; - const char* knownGamepad = detectKnownGamepad(rdi.hid.dwVendorId, rdi.hid.dwProductId); + const char* knownGamepad = detectKnownDeviceName(rdi.hid.dwVendorId, rdi.hid.dwProductId); if (knownGamepad) ffStrbufSetS(&device->name, knownGamepad); HANDLE FF_AUTO_CLOSE_FD hHidFile = CreateFileW(devName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);