Don't update the device list for devices we know aren't supported
authorSam Lantinga <slouken@libsdl.org>
Thu, 09 Aug 2018 16:04:30 -0700
changeset 12095d985a68d32ea
parent 12094 1517756022e5
child 12096 5b4b8242d21e
Don't update the device list for devices we know aren't supported
This should reduce HID enumeration (hitting the USB bus) if for some reason we're getting spammed with false device insert/removal events
src/joystick/hidapi/SDL_hidapijoystick.c
     1.1 --- a/src/joystick/hidapi/SDL_hidapijoystick.c	Thu Aug 09 16:04:25 2018 -0700
     1.2 +++ b/src/joystick/hidapi/SDL_hidapijoystick.c	Thu Aug 09 16:04:30 2018 -0700
     1.3 @@ -79,6 +79,20 @@
     1.4  static int SDL_HIDAPI_numjoysticks = 0;
     1.5  static Uint32 SDL_HIDAPI_last_detect = 0;
     1.6  
     1.7 +static SDL_bool
     1.8 +HIDAPI_IsDeviceSupported(Uint16 vendor_id, Uint16 product_id)
     1.9 +{
    1.10 +    int i;
    1.11 +
    1.12 +    for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
    1.13 +        SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
    1.14 +        if (driver->enabled && driver->IsSupportedDevice(vendor_id, product_id, -1, 0, 0)) {
    1.15 +            return SDL_TRUE;
    1.16 +        }
    1.17 +    }
    1.18 +    return SDL_FALSE;
    1.19 +}
    1.20 +
    1.21  static SDL_HIDAPI_DeviceDriver *
    1.22  HIDAPI_GetDeviceDriver(SDL_HIDAPI_Device *device)
    1.23  {
    1.24 @@ -388,6 +402,11 @@
    1.25  {
    1.26      SDL_HIDAPI_Device *device;
    1.27  
    1.28 +    /* Don't update the device list for devices we know aren't supported */
    1.29 +    if (!HIDAPI_IsDeviceSupported(vendor_id, product_id)) {
    1.30 +        return SDL_FALSE;
    1.31 +    }
    1.32 +
    1.33      /* Make sure the device list is completely up to date when we check for device presence */
    1.34      HIDAPI_UpdateDeviceList();
    1.35