From d2d3959d3d29b3da334b53283b34cafde653b3e8 Mon Sep 17 00:00:00 2001 From: Brendan Shanks Date: Tue, 13 Aug 2019 14:40:38 -0700 Subject: [PATCH] dinput: Add "PIDVID" guidProduct and use for non-keyboards/mice. Windows uses an undocumented GUID (ending in ASCII "PIDVID") for non-keyboard/mouse devices. Various games (DiRT Rally 2) and libraries (SDL, GLFW) look for this GUID to match specific devices or know that the PID/VID can be extracted. Signed-off-by: Brendan Shanks Signed-off-by: Alexandre Julliard --- dlls/dinput/device_private.h | 2 ++ dlls/dinput/joystick.c | 8 ++++++++ dlls/dinput/joystick_linux.c | 15 +-------------- dlls/dinput/joystick_linuxinput.c | 15 +-------------- dlls/dinput/joystick_osx.c | 6 +++--- 5 files changed, 15 insertions(+), 31 deletions(-) diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index d9e2997eaaf..27e9c262869 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -114,6 +114,8 @@ typedef struct LPDIRECTINPUTEFFECT ref; } effect_list_item; +extern const GUID DInput_PIDVID_Product_GUID DECLSPEC_HIDDEN; + /* Various debug tools */ extern void _dump_DIPROPHEADER(LPCDIPROPHEADER diph) DECLSPEC_HIDDEN; extern void _dump_OBJECTINSTANCEA(const DIDEVICEOBJECTINSTANCEA *ddoi) DECLSPEC_HIDDEN; diff --git a/dlls/dinput/joystick.c b/dlls/dinput/joystick.c index a5308b6cc48..2220b5d576c 100644 --- a/dlls/dinput/joystick.c +++ b/dlls/dinput/joystick.c @@ -52,6 +52,14 @@ static const WORD PID_XBOX_CONTROLLERS[] = { 0x0719, /* Xbox 360 Wireless Adapter */ }; +/* Windows uses this GUID for guidProduct on non-keyboard/mouse devices. + * Data1 contains the device VID (low word) and PID (high word). + * Data4 ends with the ASCII bytes "PIDVID". + */ +const GUID DInput_PIDVID_Product_GUID = { /* device_pidvid-0000-0000-0000-504944564944 */ + 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44} +}; + static inline JoystickGenericImpl *impl_from_IDirectInputDevice8A(IDirectInputDevice8A *iface) { return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8A_iface), JoystickGenericImpl, base); diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c index 7e01f90843b..4ee7397c2c9 100644 --- a/dlls/dinput/joystick_linux.c +++ b/dlls/dinput/joystick_linux.c @@ -126,19 +126,6 @@ static const GUID DInput_Wine_Joystick_GUID = { /* 9e573ed9-7734-11d2-8d4a-23903 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7} }; -/* - * Construct the GUID in the same way of Windows doing this. - * Data1 is concatenation of productid and vendorid. - * Data2 and Data3 are NULL. - * Data4 seems to be a constant. - */ -static const GUID DInput_Wine_Joystick_Constant_Part_GUID = { - 0x000000000, - 0x0000, - 0x0000, - {0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44} -}; - #define MAX_JOYSTICKS 64 static INT joystick_devices_count = -1; static struct JoyDev *joystick_devices; @@ -327,7 +314,7 @@ static INT find_joystick_devices(void) else { /* Concatenate product_id with vendor_id to mimic Windows behaviour */ - joydev.guid_product = DInput_Wine_Joystick_Constant_Part_GUID; + joydev.guid_product = DInput_PIDVID_Product_GUID; joydev.guid_product.Data1 = MAKELONG(joydev.vendor_id, joydev.product_id); } diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c index 1e8c542f21d..b5418d805cc 100644 --- a/dlls/dinput/joystick_linuxinput.c +++ b/dlls/dinput/joystick_linuxinput.c @@ -165,19 +165,6 @@ static const GUID DInput_Wine_Joystick_Base_GUID = { /* 9e573eda-7734-11d2-8d4a- {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7} }; -/* - * Construct the GUID in the same way of Windows doing this. - * Data1 is concatenation of productid and vendorid. - * Data2 and Data3 are NULL. - * Data4 seems to be a constant. - */ -static const GUID DInput_Wine_Joystick_Constant_Part_GUID = { - 0x000000000, - 0x0000, - 0x0000, - {0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44} -}; - #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7))) #define MAX_JOYDEV 64 @@ -344,7 +331,7 @@ static void find_joydevs(void) joydev.bus_type = device_id.bustype; /* Concatenate product_id with vendor_id to mimic Windows behaviour */ - joydev.guid_product = DInput_Wine_Joystick_Constant_Part_GUID; + joydev.guid_product = DInput_PIDVID_Product_GUID; joydev.guid_product.Data1 = MAKELONG(joydev.vendor_id, joydev.product_id); } diff --git a/dlls/dinput/joystick_osx.c b/dlls/dinput/joystick_osx.c index 884dd7f3e19..990f5d1f077 100644 --- a/dlls/dinput/joystick_osx.c +++ b/dlls/dinput/joystick_osx.c @@ -985,7 +985,7 @@ static HRESULT joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINS /* Return joystick */ lpddi->guidInstance = DInput_Wine_OsX_Joystick_GUID; lpddi->guidInstance.Data3 = id; - lpddi->guidProduct = DInput_Wine_OsX_Joystick_GUID; + lpddi->guidProduct = DInput_PIDVID_Product_GUID; lpddi->guidProduct.Data1 = make_vid_pid(device); lpddi->dwDevType = get_device_type(version, is_joystick); lpddi->dwDevType |= DIDEVTYPE_HID; @@ -1033,7 +1033,7 @@ static HRESULT joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINS /* Return joystick */ lpddi->guidInstance = DInput_Wine_OsX_Joystick_GUID; lpddi->guidInstance.Data3 = id; - lpddi->guidProduct = DInput_Wine_OsX_Joystick_GUID; + lpddi->guidProduct = DInput_PIDVID_Product_GUID; lpddi->guidProduct.Data1 = make_vid_pid(device); lpddi->dwDevType = get_device_type(version, is_joystick); lpddi->dwDevType |= DIDEVTYPE_HID; @@ -1109,7 +1109,7 @@ static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput, newDevice->generic.guidInstance = DInput_Wine_OsX_Joystick_GUID; newDevice->generic.guidInstance.Data3 = index; - newDevice->generic.guidProduct = DInput_Wine_OsX_Joystick_GUID; + newDevice->generic.guidProduct = DInput_PIDVID_Product_GUID; newDevice->generic.guidProduct.Data1 = make_vid_pid(device); newDevice->generic.joy_polldev = poll_osx_device_state;