SDL: hidapi: do not enumerate XInput devices owned by a kernel driver via libusb on macOS

From cee2cb8ed1597697a4ce146e1ab7f1cefcf62081 Mon Sep 17 00:00:00 2001
From: tmkk <[EMAIL REDACTED]>
Date: Wed, 17 Jun 2026 15:57:07 +0900
Subject: [PATCH] hidapi: do not enumerate XInput devices owned by a kernel
 driver via libusb on macOS

---
 src/hidapi/libusb/hid.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/hidapi/libusb/hid.c b/src/hidapi/libusb/hid.c
index 2c6d797a7828b..66cf3375367ae 100644
--- a/src/hidapi/libusb/hid.c
+++ b/src/hidapi/libusb/hid.c
@@ -1069,6 +1069,17 @@ struct hid_device_info  HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
 						struct hid_device_info *tmp;
 
 						res = libusb_open(dev, &handle);
+#ifdef SDL_PLATFORM_MACOS
+						if (res == 0) {
+							/* Do not enumerate XInput devices already owned by a kernel driver */
+							int is_xbox = is_xbox360(dev_vid, intf_desc) || is_xboxone(dev_vid, intf_desc);
+							if (is_xbox && libusb_kernel_driver_active(handle, intf_desc->bInterfaceNumber) == 1) {
+								libusb_close(handle);
+								handle = NULL;
+								continue;
+							}
+						}
+#endif
 
 #ifdef __ANDROID__
 						if (handle) {