From: Paul Gofman pgofman@codeweavers.com
--- dlls/dinput/joystick_hid.c | 40 ++++++++++++++++++++++++++++++++++- dlls/dinput/tests/joystick8.c | 16 ++++++++------ 2 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 367d6356195..17067539a66 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -239,6 +239,42 @@ struct hid_joystick_effect char *set_envelope_buf; };
+struct joystick_device +{ + WCHAR device_path[MAX_PATH]; +}; + +static CRITICAL_SECTION joystick_devices_crit; +static CRITICAL_SECTION_DEBUG joystick_devices_crit_debug = +{ + 0, 0, &joystick_devices_crit, + { &joystick_devices_crit_debug.ProcessLocksList, &joystick_devices_crit_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": joystick_devices_crit") } +}; +static CRITICAL_SECTION joystick_devices_crit = { &joystick_devices_crit_debug, -1, 0, 0, 0, 0 }; + +static struct joystick_device *joystick_devices; +static unsigned int joystick_device_count; + +static unsigned int get_joystick_index( const WCHAR *device_path ) +{ + unsigned int i; + + EnterCriticalSection( &joystick_devices_crit ); + for (i = 0; i < joystick_device_count; ++i) + if (!wcsicmp( joystick_devices[i].device_path, device_path )) break; + + if (i == joystick_device_count) + { + ++joystick_device_count; + joystick_devices = realloc( joystick_devices, sizeof(*joystick_devices) * joystick_device_count ); + wcscpy( joystick_devices[i].device_path, device_path ); + } + LeaveCriticalSection( &joystick_devices_crit ); + return i; +} + + static inline struct hid_joystick_effect *impl_from_IDirectInputEffect( IDirectInputEffect *iface ) { return CONTAINING_RECORD( iface, struct hid_joystick_effect, IDirectInputEffect_iface ); @@ -814,7 +850,7 @@ static HRESULT hid_joystick_get_property( IDirectInputDevice8W *iface, DWORD pro case (DWORD_PTR)DIPROP_JOYSTICKID: { DIPROPDWORD *value = (DIPROPDWORD *)header; - value->dwData = impl->base.instance.guidInstance.Data3; + value->dwData = get_joystick_index( impl->device_path ); return DI_OK; } case (DWORD_PTR)DIPROP_GUIDANDPATH: @@ -1602,6 +1638,8 @@ static HRESULT hid_joystick_device_open( int index, const GUID *guid, DIDEVICEIN attrs, caps, instance, version ))) continue; } + /* Assign joystick index if the device path is first seen. */ + get_joystick_index( detail->DevicePath );
/* enumerate device by GUID */ if (IsEqualGUID( guid, &instance->guidProduct ) || IsEqualGUID( guid, &instance->guidInstance )) break; diff --git a/dlls/dinput/tests/joystick8.c b/dlls/dinput/tests/joystick8.c index 1b2f008702d..2e3a1ffcf56 100644 --- a/dlls/dinput/tests/joystick8.c +++ b/dlls/dinput/tests/joystick8.c @@ -2077,7 +2077,6 @@ static void test_simple_joystick( DWORD version ) prop_dword.dwData = 0xdeadbeef; hr = IDirectInputDevice8_GetProperty( device, DIPROP_JOYSTICKID, &prop_dword.diph ); ok( hr == DI_OK, "GetProperty DIPROP_JOYSTICKID returned %#lx\n", hr ); - todo_wine ok( prop_dword.dwData == 0, "got %#lx expected 0\n", prop_dword.dwData );
prop_dword.dwData = 0xdeadbeef; @@ -5936,7 +5935,7 @@ static BOOL CALLBACK select_default_instance( const DIDEVICEINSTANCEW *devinst, ok( hr == DI_OK, "got hr %#lx.\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_JOYSTICKID, &prop_dword.diph ); ok( hr == DI_OK, "got hr %#lx.\n", hr ); - todo_wine ok( prop_dword.dwData < 100, "got %lu.\n", prop_dword.dwData ); + ok( prop_dword.dwData < 100, "got %lu.\n", prop_dword.dwData );
hr = IDirectInputDevice8_GetProperty( device, DIPROP_GUIDANDPATH, &prop_guid_path.diph ); ok( hr == DI_OK, "got hr %#lx.\n", hr ); @@ -6024,11 +6023,14 @@ static void test_joystick_id(void) hr = IDirectInput8_CreateDevice( di8, &GUID_Joystick, &device, NULL ); if (d.default_instance_found) { - ok( hr == DI_OK, "got %#lx.\n", hr ); - hr = IDirectInputDevice8_GetProperty( device, DIPROP_JOYSTICKID, &prop_dword.diph ); - ok( hr == DI_OK, "got hr %#lx.\n", hr ); - ok( !prop_dword.dwData, "got %lu.\n", prop_dword.dwData ); - IDirectInputDevice8_Release( device ); + todo_wine ok( hr == DI_OK, "got %#lx.\n", hr ); + if (hr == DI_OK) + { + hr = IDirectInputDevice8_GetProperty( device, DIPROP_JOYSTICKID, &prop_dword.diph ); + ok( hr == DI_OK, "got hr %#lx.\n", hr ); + ok( !prop_dword.dwData, "got %lu.\n", prop_dword.dwData ); + IDirectInputDevice8_Release( device ); + } } else {