Added SDL_HINT_HIDAPI_IGNORE_DEVICES to specify devices that should be ignored in SDL_hid_enumerate()

This commit is contained in:
Sam Lantinga 2023-05-24 22:37:38 -07:00
parent e6834a1535
commit 007c36e513
9 changed files with 84 additions and 21 deletions

View file

@ -51,6 +51,9 @@
#ifndef SDL_HIDAPI_DISABLED
extern "C" {
#include "../SDL_hidapi_c.h"
}
#include "../../core/android/SDL_android.h"
#define hid_close PLATFORM_hid_close
@ -1064,7 +1067,6 @@ int hid_init(void)
struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
struct hid_device_info *root = NULL;
const char *hint = SDL_GetHint(SDL_HINT_HIDAPI_IGNORE_DEVICES);
hid_mutex_guard l( &g_DevicesMutex );
for ( hid_device_ref<CHIDDevice> pDevice = g_Devices; pDevice; pDevice = pDevice->next )
@ -1072,13 +1074,8 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
const hid_device_info *info = pDevice->GetDeviceInfo();
/* See if there are any devices we should skip in enumeration */
if (hint) {
char vendor_match[16], product_match[16];
SDL_snprintf(vendor_match, sizeof(vendor_match), "0x%.4x/0x0000", info->vendor_id);
SDL_snprintf(product_match, sizeof(product_match), "0x%.4x/0x%.4x", info->vendor_id, info->product_id);
if (SDL_strcasestr(hint, vendor_match) || SDL_strcasestr(hint, product_match)) {
continue;
}
if (SDL_HIDAPI_ShouldIgnoreDevice(info->vendor_id, info->product_id)) {
continue;
}
if ( ( vendor_id == 0x0 || info->vendor_id == vendor_id ) &&