Skip to content

Commit f4ab960

Browse files
committed
Added SDL_HINT_HIDAPI_IGNORE_DEVICES to specify devices that should be ignored in SDL_hid_enumerate()
1 parent 359d40c commit f4ab960

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/hidapi/libusb/hid.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
code repository located at:
2020
https://github.com/libusb/hidapi .
2121
********************************************************/
22+
#include "SDL_internal.h"
2223

2324
#define _GNU_SOURCE /* needed for wcsdup() before glibc 2.10 */
2425

@@ -976,6 +977,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
976977

977978
struct hid_device_info *root = NULL; /* return object */
978979
struct hid_device_info *cur_dev = NULL;
980+
const char *hint = SDL_GetHint(SDL_HINT_HIDAPI_IGNORE_DEVICES);
979981

980982
if(hid_init() < 0)
981983
return NULL;
@@ -1000,6 +1002,16 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
10001002
continue;
10011003
}
10021004

1005+
/* See if there are any devices we should skip in enumeration */
1006+
if (hint) {
1007+
char vendor_match[16], product_match[16];
1008+
SDL_snprintf(vendor_match, sizeof(vendor_match), "0x%.4x/0x0000", dev_vid);
1009+
SDL_snprintf(product_match, sizeof(product_match), "0x%.4x/0x%.4x", dev_vid, dev_pid);
1010+
if (SDL_strcasestr(hint, vendor_match) || SDL_strcasestr(hint, product_match)) {
1011+
continue;
1012+
}
1013+
}
1014+
10031015
res = libusb_get_active_config_descriptor(dev, &conf_desc);
10041016
if (res < 0)
10051017
libusb_get_config_descriptor(dev, 0, &conf_desc);

0 commit comments

Comments
 (0)