Fixed bug 3533 - Enumeration joystick devices omitted during directinput enumeration
authorSam Lantinga <slouken@libsdl.org>
Wed, 18 Jan 2017 12:18:50 -0800
changeset 10820b0559017b1e5
parent 10819 bab110e44dcb
child 10821 b0b8395f5cf9
Fixed bug 3533 - Enumeration joystick devices omitted during directinput enumeration

white.magic

The logic which decides if a device enumerated via the direct input system in the function EnumJoysticksCallback in SDL_dinputjoystick.c is processed is discarding valid joystick devices due to the assumption that devices of the type DI8DEVTYPE_SUPPLEMENTAL are not valid devices.

This change was added with 2.0.4 with this commit http://hg.libsdl.org/SDL/rev/d5adc0c06a03 that is linked to this bug report https://bugzilla.libsdl.org/show_bug.cgi?id=2460 which indicates that in that case devices of the type DI8DEVTYPE_SUPPLEMENTAL were not desirable as they caused a singular device to emit multiple "device added" events.

Since then there appear to have been a few fixes to handle devices that fall into various other classes in the following two commits:
http://hg.libsdl.org/SDL/rev/b9488c689ce3 and http://hg.libsdl.org/SDL/rev/161fee58e36f

Two devices I have reports of failing to be listed when the DI8DEVTYPE_SUPPLEMENTAL type is excluded are ECS Gametric Throttle and Thrustmaster MFD Cougar.

Sam Lantinga

I verified that the OUYA controller shows up as a single device with this change, so I've reverted the change to ignore supplemental devices, leaving framework in place to easily add devices that we want to ignore.
src/joystick/windows/SDL_dinputjoystick.c
     1.1 --- a/src/joystick/windows/SDL_dinputjoystick.c	Wed Jan 18 11:58:16 2017 -0800
     1.2 +++ b/src/joystick/windows/SDL_dinputjoystick.c	Wed Jan 18 12:18:50 2017 -0800
     1.3 @@ -356,7 +356,20 @@
     1.4      Uint16 *guid16;
     1.5  
     1.6      if (devtype == DI8DEVTYPE_SUPPLEMENTAL) {
     1.7 -        return DIENUM_CONTINUE;  /* Ignore touchpads, etc. */
     1.8 +        /* Add any supplemental devices that should be ignored here */
     1.9 +#define MAKE_TABLE_ENTRY(VID, PID)	((((DWORD)PID)<<16)|VID)
    1.10 +		static DWORD ignored_devices[] = {
    1.11 +			MAKE_TABLE_ENTRY(0, 0)
    1.12 +		};
    1.13 +#undef MAKE_TABLE_ENTRY
    1.14 +		unsigned int i;
    1.15 +		SDL_bool should_ignore = SDL_FALSE;
    1.16 +
    1.17 +		for (i = 0; i < SDL_arraysize(ignored_devices); ++i) {
    1.18 +			if (pdidInstance->guidProduct.Data1 == ignored_devices[i]) {
    1.19 +				return DIENUM_CONTINUE;
    1.20 +			}
    1.21 +		}
    1.22      }
    1.23  
    1.24      if (SDL_IsXInputDevice(&pdidInstance->guidProduct)) {