Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 20 ++++++++++++++++++ dlls/dinput/device_private.h | 3 +++ dlls/dinput/joystick_hid.c | 27 +++++-------------------- dlls/dinput/keyboard.c | 39 +++++++++++------------------------- dlls/dinput/mouse.c | 21 ++----------------- 5 files changed, 42 insertions(+), 68 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index d8bb5e84417..93236cf6bd0 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -1176,6 +1176,25 @@ HRESULT WINAPI IDirectInputDevice2WImpl_SetCooperativeLevel(LPDIRECTINPUTDEVICE8 return hr; }
+HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo( IDirectInputDevice8W *iface, DIDEVICEINSTANCEW *instance ) +{ + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); + DWORD size; + + TRACE( "iface %p, instance %p.\n", iface, instance ); + + if (!instance) return E_POINTER; + if (instance->dwSize != sizeof(DIDEVICEINSTANCE_DX3W) && + instance->dwSize != sizeof(DIDEVICEINSTANCEW)) + return DIERR_INVALIDPARAM; + + size = instance->dwSize; + memcpy( instance, &impl->instance, size ); + instance->dwSize = size; + + return S_OK; +} + /****************************************************************************** * SetEventNotification : specifies event to be sent on state change */ @@ -1740,6 +1759,7 @@ HRESULT direct_input_device_alloc( SIZE_T size, const IDirectInputDevice8WVtbl * This->IDirectInputDevice8W_iface.lpVtbl = vtbl; This->ref = 1; This->guid = *guid; + This->instance.dwSize = sizeof(DIDEVICEINSTANCEW); This->data_format.wine_df = format; InitializeCriticalSection( &This->crit ); This->dinput = dinput; diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 321a9702642..683db8d35ab 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -67,6 +67,7 @@ struct IDirectInputDeviceImpl IDirectInputImpl *dinput; struct list entry; /* entry into acquired device list */ HANDLE hEvent; + DIDEVICEINSTANCEW instance; DWORD dwCoopLevel; HWND win; int acquired; @@ -120,6 +121,8 @@ extern HRESULT WINAPI IDirectInputDevice2WImpl_Acquire(LPDIRECTINPUTDEVICE8W ifa extern HRESULT WINAPI IDirectInputDevice2WImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirectInputDevice2WImpl_SetDataFormat(LPDIRECTINPUTDEVICE8W iface, LPCDIDATAFORMAT df) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirectInputDevice2WImpl_SetCooperativeLevel(LPDIRECTINPUTDEVICE8W iface, HWND hwnd, DWORD dwflags) DECLSPEC_HIDDEN; +extern HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo( IDirectInputDevice8W *iface, + DIDEVICEINSTANCEW *instance ); extern HRESULT WINAPI IDirectInputDevice2WImpl_SetEventNotification(LPDIRECTINPUTDEVICE8W iface, HANDLE hnd) DECLSPEC_HIDDEN; extern ULONG WINAPI IDirectInputDevice2WImpl_Release(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(LPDIRECTINPUTDEVICE8W iface, REFIID riid, LPVOID *ppobj) DECLSPEC_HIDDEN; diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 203a5d7788d..4b0a4861fb7 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -161,7 +161,6 @@ struct hid_joystick OVERLAPPED read_ovl; PHIDP_PREPARSED_DATA preparsed;
- DIDEVICEINSTANCEW instance; WCHAR device_path[MAX_PATH]; HIDD_ATTRIBUTES attrs; DIDEVCAPS dev_caps; @@ -775,14 +774,14 @@ static HRESULT WINAPI hid_joystick_GetProperty( IDirectInputDevice8W *iface, con { DIPROPSTRING *value = (DIPROPSTRING *)header; if (header->dwSize != sizeof(DIPROPSTRING)) return DIERR_INVALIDPARAM; - lstrcpynW( value->wsz, impl->instance.tszProductName, MAX_PATH ); + lstrcpynW( value->wsz, impl->base.instance.tszProductName, MAX_PATH ); return DI_OK; } case (DWORD_PTR)DIPROP_INSTANCENAME: { DIPROPSTRING *value = (DIPROPSTRING *)header; if (header->dwSize != sizeof(DIPROPSTRING)) return DIERR_INVALIDPARAM; - lstrcpynW( value->wsz, impl->instance.tszInstanceName, MAX_PATH ); + lstrcpynW( value->wsz, impl->base.instance.tszInstanceName, MAX_PATH ); return DI_OK; } case (DWORD_PTR)DIPROP_VIDPID: @@ -797,7 +796,7 @@ static HRESULT WINAPI hid_joystick_GetProperty( IDirectInputDevice8W *iface, con { DIPROPDWORD *value = (DIPROPDWORD *)header; if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; - value->dwData = impl->instance.guidInstance.Data3; + value->dwData = impl->base.instance.guidInstance.Data3; return DI_OK; } case (DWORD_PTR)DIPROP_GUIDANDPATH: @@ -1060,22 +1059,6 @@ static HRESULT WINAPI hid_joystick_GetObjectInfo( IDirectInputDevice8W *iface, D return DIERR_NOTFOUND; }
-static HRESULT WINAPI hid_joystick_GetDeviceInfo( IDirectInputDevice8W *iface, DIDEVICEINSTANCEW *instance ) -{ - struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface ); - - TRACE( "iface %p, instance %p.\n", iface, instance ); - - if (!instance) return E_POINTER; - if (instance->dwSize != sizeof(DIDEVICEINSTANCE_DX3W) && - instance->dwSize != sizeof(DIDEVICEINSTANCEW)) - return DIERR_INVALIDPARAM; - - memcpy( instance, &impl->instance, instance->dwSize ); - - return S_OK; -} - static HRESULT hid_joystick_effect_create( struct hid_joystick *joystick, IDirectInputEffect **out );
static HRESULT WINAPI hid_joystick_CreateEffect( IDirectInputDevice8W *iface, const GUID *guid, @@ -1457,7 +1440,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl = IDirectInputDevice2WImpl_SetEventNotification, IDirectInputDevice2WImpl_SetCooperativeLevel, hid_joystick_GetObjectInfo, - hid_joystick_GetDeviceInfo, + IDirectInputDevice2WImpl_GetDeviceInfo, IDirectInputDevice2WImpl_RunControlPanel, IDirectInputDevice2WImpl_Initialize, /*** IDirectInputDevice2 methods ***/ @@ -2277,7 +2260,7 @@ static HRESULT hid_joystick_create_device( IDirectInputImpl *dinput, const GUID if (hr != DI_OK) goto failed;
impl->ref = 1; - impl->instance = instance; + impl->base.instance = instance; impl->attrs = attrs; impl->dev_caps.dwSize = sizeof(impl->dev_caps); impl->dev_caps.dwFlags = DIDC_ATTACHED | DIDC_EMULATED; diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index f687eec5259..3d78fd4de54 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -43,7 +43,6 @@ struct SysKeyboardImpl { struct IDirectInputDeviceImpl base; BYTE DInputKeyState[WINE_DINPUT_KEYBOARD_MAX_KEYS]; - DWORD subtype; };
static inline SysKeyboardImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface) @@ -89,9 +88,9 @@ static BYTE map_dik_code(DWORD scanCode, DWORD vkCode, DWORD subType, DWORD vers int dinput_keyboard_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam ) { SysKeyboardImpl *This = impl_from_IDirectInputDevice8W( iface ); + BYTE new_diks, subtype = GET_DIDEVICE_SUBTYPE( This->base.instance.dwDevType ); int dik_code, ret = This->base.dwCoopLevel & DISCL_EXCLUSIVE; KBDLLHOOKSTRUCT *hook = (KBDLLHOOKSTRUCT *)lparam; - BYTE new_diks;
if (wparam != WM_KEYDOWN && wparam != WM_KEYUP && wparam != WM_SYSKEYDOWN && wparam != WM_SYSKEYUP) @@ -108,7 +107,8 @@ int dinput_keyboard_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lpa case VK_NUMLOCK : dik_code = DIK_NUMLOCK; break; case VK_SUBTRACT: dik_code = DIK_SUBTRACT; break; default: - dik_code = map_dik_code(hook->scanCode & 0xff, hook->vkCode, This->subtype, This->base.dinput->dwVersion); + dik_code = map_dik_code( hook->scanCode & 0xff, hook->vkCode, subtype, + This->base.dinput->dwVersion ); if (hook->flags & LLKHF_EXTENDED) dik_code |= 0x80; } new_diks = hook->flags & LLKHF_UP ? 0 : 0x80; @@ -193,6 +193,7 @@ static HRESULT keyboarddev_enum_device(DWORD dwDevType, DWORD dwFlags, LPDIDEVIC
static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysKeyboardImpl **out ) { + BYTE subtype = get_keyboard_subtype(); SysKeyboardImpl* newDevice; LPDIDATAFORMAT df = NULL; int i, idx = 0; @@ -203,7 +204,7 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysKeyboar df = newDevice->base.data_format.wine_df; newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysKeyboardImpl*->base.crit");
- newDevice->subtype = get_keyboard_subtype(); + fill_keyboard_dideviceinstanceW( &newDevice->base.instance, newDevice->base.dinput->dwVersion, subtype );
/* Create copy of default data format */ memcpy(df, &c_dfDIKeyboard, c_dfDIKeyboard.dwSize); @@ -217,7 +218,7 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysKeyboar if (!GetKeyNameTextA(((i & 0x7f) << 16) | ((i & 0x80) << 17), buf, sizeof(buf))) continue;
- dik_code = map_dik_code(i, 0, newDevice->subtype, dinput->dwVersion); + dik_code = map_dik_code( i, 0, subtype, dinput->dwVersion ); memcpy(&df->rgodf[idx], &c_dfDIKeyboard.rgodf[dik_code], df->dwObjSize); df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(dik_code) | DIDFT_PSHBUTTON; } @@ -294,6 +295,7 @@ static HRESULT WINAPI SysKeyboardWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W ifac static HRESULT WINAPI SysKeyboardWImpl_GetCapabilities(LPDIRECTINPUTDEVICE8W iface, LPDIDEVCAPS lpDIDevCaps) { SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface); + BYTE subtype = GET_DIDEVICE_SUBTYPE( This->base.instance.dwDevType ); DIDEVCAPS devcaps;
TRACE("(this=%p,%p)\n",This,lpDIDevCaps); @@ -306,9 +308,9 @@ static HRESULT WINAPI SysKeyboardWImpl_GetCapabilities(LPDIRECTINPUTDEVICE8W ifa devcaps.dwSize = lpDIDevCaps->dwSize; devcaps.dwFlags = DIDC_ATTACHED | DIDC_EMULATED; if (This->base.dinput->dwVersion >= 0x0800) - devcaps.dwDevType = DI8DEVTYPE_KEYBOARD | (This->subtype << 8); + devcaps.dwDevType = DI8DEVTYPE_KEYBOARD | (subtype << 8); else - devcaps.dwDevType = DIDEVTYPE_KEYBOARD | (This->subtype << 8); + devcaps.dwDevType = DIDEVTYPE_KEYBOARD | (subtype << 8); devcaps.dwAxes = 0; devcaps.dwButtons = This->base.data_format.wine_df->dwNumObjs; devcaps.dwPOVs = 0; @@ -367,13 +369,14 @@ static HRESULT WINAPI SysKeyboardWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface DWORD dwHow) { SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface); + BYTE subtype = GET_DIDEVICE_SUBTYPE( This->base.instance.dwDevType ); HRESULT res; LONG scan;
res = IDirectInputDevice2WImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow); if (res != DI_OK) return res;
- scan = map_dik_to_scan(DIDFT_GETINSTANCE(pdidoi->dwType), This->subtype); + scan = map_dik_to_scan( DIDFT_GETINSTANCE( pdidoi->dwType ), subtype ); if (!GetKeyNameTextW((scan & 0x80) << 17 | (scan & 0x7f) << 16, pdidoi->tszName, ARRAY_SIZE(pdidoi->tszName))) return DIERR_OBJECTNOTFOUND; @@ -382,24 +385,6 @@ static HRESULT WINAPI SysKeyboardWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface return res; }
-/****************************************************************************** - * GetDeviceInfo : get information about a device's identity - */ -static HRESULT WINAPI SysKeyboardWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW pdidi) -{ - SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface); - TRACE("(this=%p,%p)\n", This, pdidi); - - if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)) { - WARN(" dinput3 not supported yet...\n"); - return DI_OK; - } - - fill_keyboard_dideviceinstanceW(pdidi, This->base.dinput->dwVersion, This->subtype); - - return DI_OK; -} - /****************************************************************************** * GetProperty : Retrieves information about the input device. */ @@ -496,7 +481,7 @@ static const IDirectInputDevice8WVtbl SysKeyboardWvt = IDirectInputDevice2WImpl_SetEventNotification, IDirectInputDevice2WImpl_SetCooperativeLevel, SysKeyboardWImpl_GetObjectInfo, - SysKeyboardWImpl_GetDeviceInfo, + IDirectInputDevice2WImpl_GetDeviceInfo, IDirectInputDevice2WImpl_RunControlPanel, IDirectInputDevice2WImpl_Initialize, IDirectInputDevice2WImpl_CreateEffect, diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 97e2b58c6cd..e11a9260fb2 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -148,6 +148,7 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseIm df = newDevice->base.data_format.wine_df; newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit");
+ fill_mouse_dideviceinstanceW( &newDevice->base.instance, newDevice->base.dinput->dwVersion ); newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
get_app_key(&hkey, &appkey); @@ -705,24 +706,6 @@ static HRESULT WINAPI SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface, return res; }
-/****************************************************************************** - * GetDeviceInfo : get information about a device's identity - */ -static HRESULT WINAPI SysMouseWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW pdidi) -{ - SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface); - TRACE("(this=%p,%p)\n", This, pdidi); - - if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)) { - WARN(" dinput3 not supported yet...\n"); - return DI_OK; - } - - fill_mouse_dideviceinstanceW(pdidi, This->base.dinput->dwVersion); - - return DI_OK; -} - static HRESULT WINAPI SysMouseWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, @@ -761,7 +744,7 @@ static const IDirectInputDevice8WVtbl SysMouseWvt = IDirectInputDevice2WImpl_SetEventNotification, IDirectInputDevice2WImpl_SetCooperativeLevel, SysMouseWImpl_GetObjectInfo, - SysMouseWImpl_GetDeviceInfo, + IDirectInputDevice2WImpl_GetDeviceInfo, IDirectInputDevice2WImpl_RunControlPanel, IDirectInputDevice2WImpl_Initialize, IDirectInputDevice2WImpl_CreateEffect,
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 21 ++++++++++++++ dlls/dinput/device_private.h | 2 ++ dlls/dinput/joystick_hid.c | 54 +++++++++++++----------------------- dlls/dinput/keyboard.c | 42 ++++------------------------ dlls/dinput/mouse.c | 42 ++++------------------------ dlls/dinput8/tests/hid.c | 1 - 6 files changed, 53 insertions(+), 109 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 93236cf6bd0..6c2fe7737d5 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -1243,6 +1243,25 @@ ULONG WINAPI IDirectInputDevice2WImpl_Release(LPDIRECTINPUTDEVICE8W iface) return ref; }
+HRESULT WINAPI IDirectInputDevice2WImpl_GetCapabilities( IDirectInputDevice8W *iface, DIDEVCAPS *caps ) +{ + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); + DWORD size; + + TRACE( "iface %p, caps %p.\n", iface, caps ); + + if (!caps) return E_POINTER; + if (caps->dwSize != sizeof(DIDEVCAPS_DX3) && + caps->dwSize != sizeof(DIDEVCAPS)) + return DIERR_INVALIDPARAM; + + size = caps->dwSize; + memcpy( caps, &impl->caps, size ); + caps->dwSize = size; + + return DI_OK; +} + HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(LPDIRECTINPUTDEVICE8W iface, REFIID riid, LPVOID *ppobj) { IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface); @@ -1760,6 +1779,8 @@ HRESULT direct_input_device_alloc( SIZE_T size, const IDirectInputDevice8WVtbl * This->ref = 1; This->guid = *guid; This->instance.dwSize = sizeof(DIDEVICEINSTANCEW); + This->caps.dwSize = sizeof(DIDEVCAPS); + This->caps.dwFlags = DIDC_ATTACHED | DIDC_EMULATED; This->data_format.wine_df = format; InitializeCriticalSection( &This->crit ); This->dinput = dinput; diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 683db8d35ab..3fcb9240581 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -68,6 +68,7 @@ struct IDirectInputDeviceImpl struct list entry; /* entry into acquired device list */ HANDLE hEvent; DIDEVICEINSTANCEW instance; + DIDEVCAPS caps; DWORD dwCoopLevel; HWND win; int acquired; @@ -119,6 +120,7 @@ extern HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lp /* And the stubs */ extern HRESULT WINAPI IDirectInputDevice2WImpl_Acquire(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirectInputDevice2WImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_HIDDEN; +extern HRESULT WINAPI IDirectInputDevice2WImpl_GetCapabilities( IDirectInputDevice8W *iface, DIDEVCAPS *caps ); extern HRESULT WINAPI IDirectInputDevice2WImpl_SetDataFormat(LPDIRECTINPUTDEVICE8W iface, LPCDIDATAFORMAT df) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirectInputDevice2WImpl_SetCooperativeLevel(LPDIRECTINPUTDEVICE8W iface, HWND hwnd, DWORD dwflags) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo( IDirectInputDevice8W *iface, diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 4b0a4861fb7..65b9a809e5c 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -163,7 +163,6 @@ struct hid_joystick
WCHAR device_path[MAX_PATH]; HIDD_ATTRIBUTES attrs; - DIDEVCAPS dev_caps; HIDP_CAPS caps;
struct extra_caps *input_extra_caps; @@ -621,19 +620,6 @@ static ULONG WINAPI hid_joystick_Release( IDirectInputDevice8W *iface ) return ref; }
-static HRESULT WINAPI hid_joystick_GetCapabilities( IDirectInputDevice8W *iface, DIDEVCAPS *caps ) -{ - struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface ); - - TRACE( "iface %p, caps %p.\n", iface, caps ); - - if (!caps) return E_POINTER; - - *caps = impl->dev_caps; - - return DI_OK; -} - struct enum_objects_params { LPDIENUMDEVICEOBJECTSCALLBACKW callback; @@ -1075,7 +1061,7 @@ static HRESULT WINAPI hid_joystick_CreateEffect( IDirectInputDevice8W *iface, co if (!out) return E_POINTER; *out = NULL;
- if (!(impl->dev_caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_UNSUPPORTED; + if (!(impl->base.caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_UNSUPPORTED; if (FAILED(hr = hid_joystick_effect_create( impl, out ))) return hr;
hr = IDirectInputEffect_Initialize( *out, DINPUT_instance, impl->base.dinput->dwVersion, guid ); @@ -1184,7 +1170,7 @@ static HRESULT WINAPI hid_joystick_GetEffectInfo( IDirectInputDevice8W *iface, D
if (!info) return E_POINTER; if (info->dwSize != sizeof(DIEFFECTINFOW)) return DIERR_INVALIDPARAM; - if (!(impl->dev_caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_DEVICENOTREG; + if (!(impl->base.caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_DEVICENOTREG;
switch ((usage = effect_guid_to_usage( guid ))) { @@ -1345,7 +1331,7 @@ static HRESULT WINAPI hid_joystick_SendForceFeedbackCommand( IDirectInputDevice8 default: return DIERR_INVALIDPARAM; }
- if (!(impl->dev_caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_UNSUPPORTED; + if (!(impl->base.caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_UNSUPPORTED;
EnterCriticalSection( &impl->base.crit ); if (!impl->base.acquired || !(impl->base.dwCoopLevel & DISCL_EXCLUSIVE)) @@ -1428,7 +1414,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl = hid_joystick_AddRef, hid_joystick_Release, /*** IDirectInputDevice methods ***/ - hid_joystick_GetCapabilities, + IDirectInputDevice2WImpl_GetCapabilities, hid_joystick_EnumObjects, hid_joystick_GetProperty, hid_joystick_SetProperty, @@ -1917,9 +1903,9 @@ static BOOL init_objects( struct hid_joystick *impl, struct hid_value_caps *caps
format->dwNumObjs++; format->dwDataSize = max( format->dwDataSize, instance->dwOfs + sizeof(LONG) ); - if (instance->dwType & DIDFT_BUTTON) impl->dev_caps.dwButtons++; - if (instance->dwType & DIDFT_AXIS) impl->dev_caps.dwAxes++; - if (instance->dwType & DIDFT_POV) impl->dev_caps.dwPOVs++; + if (instance->dwType & DIDFT_BUTTON) impl->base.caps.dwButtons++; + if (instance->dwType & DIDFT_AXIS) impl->base.caps.dwAxes++; + if (instance->dwType & DIDFT_POV) impl->base.caps.dwPOVs++;
if (instance->dwType & (DIDFT_BUTTON|DIDFT_AXIS|DIDFT_POV) && (instance->wUsagePage == HID_USAGE_PAGE_GENERIC || @@ -2261,10 +2247,8 @@ static HRESULT hid_joystick_create_device( IDirectInputImpl *dinput, const GUID
impl->ref = 1; impl->base.instance = instance; + impl->base.caps.dwDevType = instance.dwDevType; impl->attrs = attrs; - impl->dev_caps.dwSize = sizeof(impl->dev_caps); - impl->dev_caps.dwFlags = DIDC_ATTACHED | DIDC_EMULATED; - impl->dev_caps.dwDevType = instance.dwDevType; list_init( &impl->effect_list );
preparsed = (struct hid_preparsed_data *)impl->preparsed; @@ -2302,27 +2286,27 @@ static HRESULT hid_joystick_create_device( IDirectInputImpl *dinput, const GUID
if (impl->pid_device_control.id) { - impl->dev_caps.dwFlags |= DIDC_FORCEFEEDBACK; + impl->base.caps.dwFlags |= DIDC_FORCEFEEDBACK; if (impl->pid_effect_update.start_delay_caps) - impl->dev_caps.dwFlags |= DIDC_STARTDELAY; + impl->base.caps.dwFlags |= DIDC_STARTDELAY; if (impl->pid_set_envelope.attack_level_caps || impl->pid_set_envelope.attack_time_caps) - impl->dev_caps.dwFlags |= DIDC_FFATTACK; + impl->base.caps.dwFlags |= DIDC_FFATTACK; if (impl->pid_set_envelope.fade_level_caps || impl->pid_set_envelope.fade_time_caps) - impl->dev_caps.dwFlags |= DIDC_FFFADE; + impl->base.caps.dwFlags |= DIDC_FFFADE; if (impl->pid_set_condition.positive_coefficient_caps || impl->pid_set_condition.negative_coefficient_caps) - impl->dev_caps.dwFlags |= DIDC_POSNEGCOEFFICIENTS; + impl->base.caps.dwFlags |= DIDC_POSNEGCOEFFICIENTS; if (impl->pid_set_condition.positive_saturation_caps || impl->pid_set_condition.negative_saturation_caps) - impl->dev_caps.dwFlags |= DIDC_SATURATION|DIDC_POSNEGSATURATION; + impl->base.caps.dwFlags |= DIDC_SATURATION|DIDC_POSNEGSATURATION; if (impl->pid_set_condition.dead_band_caps) - impl->dev_caps.dwFlags |= DIDC_DEADBAND; - impl->dev_caps.dwFFSamplePeriod = 1000000; - impl->dev_caps.dwFFMinTimeResolution = 1000000; - impl->dev_caps.dwHardwareRevision = 1; - impl->dev_caps.dwFFDriverVersion = 1; + impl->base.caps.dwFlags |= DIDC_DEADBAND; + impl->base.caps.dwFFSamplePeriod = 1000000; + impl->base.caps.dwFFMinTimeResolution = 1000000; + impl->base.caps.dwHardwareRevision = 1; + impl->base.caps.dwFFDriverVersion = 1; }
format = impl->base.data_format.wine_df; diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index 3d78fd4de54..0a8c5b282ba 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -205,6 +205,9 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysKeyboar newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysKeyboardImpl*->base.crit");
fill_keyboard_dideviceinstanceW( &newDevice->base.instance, newDevice->base.dinput->dwVersion, subtype ); + newDevice->base.caps.dwDevType = newDevice->base.instance.dwDevType; + newDevice->base.caps.dwFirmwareRevision = 100; + newDevice->base.caps.dwHardwareRevision = 100;
/* Create copy of default data format */ memcpy(df, &c_dfDIKeyboard, c_dfDIKeyboard.dwSize); @@ -223,6 +226,7 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysKeyboar df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(dik_code) | DIDFT_PSHBUTTON; } df->dwNumObjs = idx; + newDevice->base.caps.dwButtons = idx;
*out = newDevice; return DI_OK; @@ -289,42 +293,6 @@ static HRESULT WINAPI SysKeyboardWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W ifac return DI_OK; }
-/****************************************************************************** - * GetCapabilities : get the device capabilities - */ -static HRESULT WINAPI SysKeyboardWImpl_GetCapabilities(LPDIRECTINPUTDEVICE8W iface, LPDIDEVCAPS lpDIDevCaps) -{ - SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface); - BYTE subtype = GET_DIDEVICE_SUBTYPE( This->base.instance.dwDevType ); - DIDEVCAPS devcaps; - - TRACE("(this=%p,%p)\n",This,lpDIDevCaps); - - if ((lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) && (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS_DX3))) { - WARN("invalid parameter\n"); - return DIERR_INVALIDPARAM; - } - - devcaps.dwSize = lpDIDevCaps->dwSize; - devcaps.dwFlags = DIDC_ATTACHED | DIDC_EMULATED; - if (This->base.dinput->dwVersion >= 0x0800) - devcaps.dwDevType = DI8DEVTYPE_KEYBOARD | (subtype << 8); - else - devcaps.dwDevType = DIDEVTYPE_KEYBOARD | (subtype << 8); - devcaps.dwAxes = 0; - devcaps.dwButtons = This->base.data_format.wine_df->dwNumObjs; - devcaps.dwPOVs = 0; - devcaps.dwFFSamplePeriod = 0; - devcaps.dwFFMinTimeResolution = 0; - devcaps.dwFirmwareRevision = 100; - devcaps.dwHardwareRevision = 100; - devcaps.dwFFDriverVersion = 0; - - memcpy(lpDIDevCaps, &devcaps, lpDIDevCaps->dwSize); - - return DI_OK; -} - static DWORD map_dik_to_scan(DWORD dik_code, DWORD subtype) { if (dik_code == DIK_PAUSE || dik_code == DIK_NUMLOCK) dik_code ^= 0x80; @@ -469,7 +437,7 @@ static const IDirectInputDevice8WVtbl SysKeyboardWvt = IDirectInputDevice2WImpl_QueryInterface, IDirectInputDevice2WImpl_AddRef, IDirectInputDevice2WImpl_Release, - SysKeyboardWImpl_GetCapabilities, + IDirectInputDevice2WImpl_GetCapabilities, IDirectInputDevice2WImpl_EnumObjects, SysKeyboardWImpl_GetProperty, IDirectInputDevice2WImpl_SetProperty, diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index e11a9260fb2..6901cc09a31 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -149,6 +149,11 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseIm newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit");
fill_mouse_dideviceinstanceW( &newDevice->base.instance, newDevice->base.dinput->dwVersion ); + newDevice->base.caps.dwDevType = newDevice->base.instance.dwDevType; + newDevice->base.caps.dwAxes = 3; + newDevice->base.caps.dwButtons = 8; + newDevice->base.caps.dwFirmwareRevision = 100; + newDevice->base.caps.dwHardwareRevision = 100; newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
get_app_key(&hkey, &appkey); @@ -643,41 +648,6 @@ static HRESULT WINAPI SysMouseWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, REF return DI_OK; }
-/****************************************************************************** - * GetCapabilities : get the device capabilities - */ -static HRESULT WINAPI SysMouseWImpl_GetCapabilities(LPDIRECTINPUTDEVICE8W iface, LPDIDEVCAPS lpDIDevCaps) -{ - SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface); - DIDEVCAPS devcaps; - - TRACE("(this=%p,%p)\n",This,lpDIDevCaps); - - if ((lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) && (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS_DX3))) { - WARN("invalid parameter\n"); - return DIERR_INVALIDPARAM; - } - - devcaps.dwSize = lpDIDevCaps->dwSize; - devcaps.dwFlags = DIDC_ATTACHED | DIDC_EMULATED; - if (This->base.dinput->dwVersion >= 0x0800) - devcaps.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8); - else - devcaps.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8); - devcaps.dwAxes = 3; - devcaps.dwButtons = 8; - devcaps.dwPOVs = 0; - devcaps.dwFFSamplePeriod = 0; - devcaps.dwFFMinTimeResolution = 0; - devcaps.dwFirmwareRevision = 100; - devcaps.dwHardwareRevision = 100; - devcaps.dwFFDriverVersion = 0; - - memcpy(lpDIDevCaps, &devcaps, lpDIDevCaps->dwSize); - - return DI_OK; -} - /****************************************************************************** * GetObjectInfo : get information about a device object such as a button * or axis @@ -732,7 +702,7 @@ static const IDirectInputDevice8WVtbl SysMouseWvt = IDirectInputDevice2WImpl_QueryInterface, IDirectInputDevice2WImpl_AddRef, IDirectInputDevice2WImpl_Release, - SysMouseWImpl_GetCapabilities, + IDirectInputDevice2WImpl_GetCapabilities, IDirectInputDevice2WImpl_EnumObjects, SysMouseWImpl_GetProperty, IDirectInputDevice2WImpl_SetProperty, diff --git a/dlls/dinput8/tests/hid.c b/dlls/dinput8/tests/hid.c index a2719f65488..cf50dd32fb9 100644 --- a/dlls/dinput8/tests/hid.c +++ b/dlls/dinput8/tests/hid.c @@ -3867,7 +3867,6 @@ static void test_simple_joystick(void) hr = IDirectInputDevice8_GetCapabilities( device, NULL ); ok( hr == E_POINTER, "GetCapabilities returned %#x\n", hr ); hr = IDirectInputDevice8_GetCapabilities( device, &caps ); - todo_wine ok( hr == DIERR_INVALIDPARAM, "GetCapabilities returned %#x\n", hr ); caps.dwSize = sizeof(DIDEVCAPS); hr = IDirectInputDevice8_GetCapabilities( device, &caps );
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=99940
Your paranoid android.
=== debiant2 (32 bit French report) ===
dinput8: hid.c:4269: Test failed: GetDeviceData returned 0x8007000c hid.c:4270: Test failed: got 1 expected 0 hid.c:4274: Test failed: WaitForSingleObject failed hid.c:4279: Test failed: GetDeviceData returned 0x8007000c hid.c:4280: Test failed: got 1 expected 0 hid.c:4285: Test failed: got 1 expected 0 hid.c:4288: Test failed: Unacquire returned: 0x1 hid.c:4316: Test failed: objdata[3]: got dwOfs 0x31, expected 0x30 hid.c:4333: Test failed: GetDeviceData returned 0 hid.c:4336: Test succeeded inside todo block: got dwOfs 0x4, expected 0x4 hid.c:4338: Test succeeded inside todo block: got dwData 0x512b, expected 0x512b hid.c:4348: Test succeeded inside todo block: objdata[0]: got dwOfs 0, expected 0 hid.c:4348: Test succeeded inside todo block: objdata[1]: got dwOfs 0x20, expected 0x20 hid.c:4350: Test succeeded inside todo block: objdata[1]: got dwData 0xffffffff, expected 0xffffffff hid.c:4348: Test succeeded inside todo block: objdata[2]: got dwOfs 0x30, expected 0x30 hid.c:4350: Test succeeded inside todo block: objdata[2]: got dwData 0, expected 0 hid.c:4348: Test succeeded inside todo block: objdata[3]: got dwOfs 0x31, expected 0x31 hid.c:4348: Test succeeded inside todo block: objdata[4]: got dwOfs 0x4, expected 0x4 hid.c:4348: Test succeeded inside todo block: objdata[5]: got dwOfs 0, expected 0 hid.c:4348: Test succeeded inside todo block: objdata[6]: got dwOfs 0x30, expected 0x30 hid.c:4350: Test succeeded inside todo block: objdata[6]: got dwData 0x80, expected 0x80 hid.c:4348: Test succeeded inside todo block: objdata[7]: got dwOfs 0x31, expected 0x31
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 160 ++++++++++++++++++----------------- dlls/dinput/device_private.h | 1 - dlls/dinput/joystick_hid.c | 12 +-- dlls/dinput/keyboard.c | 13 +-- dlls/dinput/mouse.c | 12 +-- 5 files changed, 87 insertions(+), 111 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 6c2fe7737d5..5528d3d328c 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -827,68 +827,6 @@ static BOOL set_app_data(IDirectInputDeviceImpl *dev, int offset, UINT_PTR app_d return TRUE; }
-HRESULT _build_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, DWORD devMask, LPCDIDATAFORMAT df) -{ - IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface); - WCHAR username[MAX_PATH]; - DWORD username_size = MAX_PATH; - int i; - BOOL load_success = FALSE, has_actions = FALSE; - - /* Unless asked the contrary by these flags, try to load a previous mapping */ - if (!(dwFlags & DIDBAM_HWDEFAULTS)) - { - /* Retrieve logged user name if necessary */ - if (lpszUserName == NULL) - GetUserNameW(username, &username_size); - else - lstrcpynW(username, lpszUserName, MAX_PATH); - - load_success = load_mapping_settings(This, lpdiaf, username); - } - - if (load_success) return DI_OK; - - for (i=0; i < lpdiaf->dwNumActions; i++) - { - /* Don't touch a user configured action */ - if (lpdiaf->rgoAction[i].dwHow == DIAH_USERCONFIG) continue; - - if ((lpdiaf->rgoAction[i].dwSemantic & devMask) == devMask) - { - DWORD obj_id = semantic_to_obj_id(This, lpdiaf->rgoAction[i].dwSemantic); - DWORD type = DIDFT_GETTYPE(obj_id); - DWORD inst = DIDFT_GETINSTANCE(obj_id); - - LPDIOBJECTDATAFORMAT odf; - - if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON; - if (type == DIDFT_RELAXIS) type = DIDFT_AXIS; - - /* Make sure the object exists */ - odf = dataformat_to_odf_by_type(df, inst, type); - - if (odf != NULL) - { - lpdiaf->rgoAction[i].dwObjID = obj_id; - lpdiaf->rgoAction[i].guidInstance = This->guid; - lpdiaf->rgoAction[i].dwHow = DIAH_DEFAULT; - has_actions = TRUE; - } - } - else if (!(dwFlags & DIDBAM_PRESERVE)) - { - /* We must clear action data belonging to other devices */ - memset(&lpdiaf->rgoAction[i].guidInstance, 0, sizeof(GUID)); - lpdiaf->rgoAction[i].dwHow = DIAH_UNMAPPED; - } - } - - if (!has_actions) return DI_NOEFFECT; - - return IDirectInputDevice8WImpl_BuildActionMap(iface, lpdiaf, lpszUserName, dwFlags); -} - HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, LPCDIDATAFORMAT df) { IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface); @@ -986,7 +924,7 @@ HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, L dps.wsz[0] = '\0'; else lstrcpynW(dps.wsz, username, ARRAY_SIZE(dps.wsz)); - IDirectInputDevice8_SetProperty(iface, DIPROP_USERNAME, &dps.diph); + IDirectInputDevice2WImpl_SetProperty(iface, DIPROP_USERNAME, &dps.diph);
/* Save the settings to disk */ save_mapping_settings(iface, lpdiaf, username); @@ -1735,20 +1673,90 @@ HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W return DI_OK; }
-HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface, - LPDIACTIONFORMATW lpdiaf, - LPCWSTR lpszUserName, - DWORD dwFlags) +HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap( IDirectInputDevice8W *iface, DIACTIONFORMATW *format, + const WCHAR *username, DWORD flags ) { - IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface); - FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", This, lpdiaf, debugstr_w(lpszUserName), dwFlags); -#define X(x) if (dwFlags & x) FIXME("\tdwFlags =|"#x"\n"); - X(DIDBAM_DEFAULT) - X(DIDBAM_PRESERVE) - X(DIDBAM_INITIALIZE) - X(DIDBAM_HWDEFAULTS) -#undef X - + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); + BOOL load_success = FALSE, has_actions = FALSE; + DWORD genre, username_len = MAX_PATH; + WCHAR username_buf[MAX_PATH]; + const DIDATAFORMAT *df; + DWORD devMask; + int i; + + FIXME( "iface %p, format %p, username %s, flags %#x semi-stub!\n", iface, format, + debugstr_w(username), flags ); + + if (!format) return DIERR_INVALIDPARAM; + + switch (GET_DIDEVICE_TYPE( impl->instance.dwDevType )) + { + case DIDEVTYPE_KEYBOARD: + case DI8DEVTYPE_KEYBOARD: + devMask = DIKEYBOARD_MASK; + df = &c_dfDIKeyboard; + break; + case DIDEVTYPE_MOUSE: + case DI8DEVTYPE_MOUSE: + devMask = DIMOUSE_MASK; + df = &c_dfDIMouse2; + break; + default: + devMask = DIGENRE_ANY; + df = impl->data_format.wine_df; + break; + } + + /* Unless asked the contrary by these flags, try to load a previous mapping */ + if (!(flags & DIDBAM_HWDEFAULTS)) + { + /* Retrieve logged user name if necessary */ + if (username == NULL) GetUserNameW( username_buf, &username_len ); + else lstrcpynW( username_buf, username, MAX_PATH ); + load_success = load_mapping_settings( impl, format, username_buf ); + } + + if (load_success) return DI_OK; + + for (i = 0; i < format->dwNumActions; i++) + { + /* Don't touch a user configured action */ + if (format->rgoAction[i].dwHow == DIAH_USERCONFIG) continue; + + genre = format->rgoAction[i].dwSemantic & DIGENRE_ANY; + if (devMask == genre || (devMask == DIGENRE_ANY && genre != DIMOUSE_MASK && genre != DIKEYBOARD_MASK)) + { + DWORD obj_id = semantic_to_obj_id( impl, format->rgoAction[i].dwSemantic ); + DWORD type = DIDFT_GETTYPE( obj_id ); + DWORD inst = DIDFT_GETINSTANCE( obj_id ); + + LPDIOBJECTDATAFORMAT odf; + + if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON; + if (type == DIDFT_RELAXIS) type = DIDFT_AXIS; + + /* Make sure the object exists */ + odf = dataformat_to_odf_by_type( df, inst, type ); + + if (odf != NULL) + { + format->rgoAction[i].dwObjID = obj_id; + format->rgoAction[i].guidInstance = impl->guid; + format->rgoAction[i].dwHow = DIAH_DEFAULT; + has_actions = TRUE; + } + } + else if (!(flags & DIDBAM_PRESERVE)) + { + /* We must clear action data belonging to other devices */ + memset( &format->rgoAction[i].guidInstance, 0, sizeof(GUID) ); + format->rgoAction[i].dwHow = DIAH_UNMAPPED; + } + } + + if (!has_actions) return DI_NOEFFECT; + if (flags & (DIDBAM_DEFAULT|DIDBAM_PRESERVE|DIDBAM_INITIALIZE|DIDBAM_HWDEFAULTS)) + FIXME("Unimplemented flags %#x\n", flags); return DI_OK; }
diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 3fcb9240581..6aed93a130b 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -114,7 +114,6 @@ extern void _dump_OBJECTINSTANCEW(const DIDEVICEOBJECTINSTANCEW *ddoi) DECLSPEC extern void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) DECLSPEC_HIDDEN; extern const char *_dump_dinput_GUID(const GUID *guid) DECLSPEC_HIDDEN;
-extern HRESULT _build_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, DWORD devMask, LPCDIDATAFORMAT df) DECLSPEC_HIDDEN; extern HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, LPCDIDATAFORMAT df) DECLSPEC_HIDDEN;
/* And the stubs */ diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 65b9a809e5c..5921b473f3a 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -1385,16 +1385,6 @@ static HRESULT WINAPI hid_joystick_Poll( IDirectInputDevice8W *iface ) return hr; }
-static HRESULT WINAPI hid_joystick_BuildActionMap( IDirectInputDevice8W *iface, DIACTIONFORMATW *format, - const WCHAR *username, DWORD flags ) -{ - FIXME( "iface %p, format %p, username %s, flags %#x stub!\n", iface, format, debugstr_w(username), flags ); - - if (!format) return DIERR_INVALIDPARAM; - - return DIERR_UNSUPPORTED; -} - static HRESULT WINAPI hid_joystick_SetActionMap( IDirectInputDevice8W *iface, DIACTIONFORMATW *format, const WCHAR *username, DWORD flags ) { @@ -1443,7 +1433,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl = IDirectInputDevice7WImpl_EnumEffectsInFile, IDirectInputDevice7WImpl_WriteEffectToFile, /*** IDirectInputDevice8 methods ***/ - hid_joystick_BuildActionMap, + IDirectInputDevice8WImpl_BuildActionMap, hid_joystick_SetActionMap, IDirectInputDevice8WImpl_GetImageInfo, }; diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index 0a8c5b282ba..98fcf253afa 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -410,17 +410,6 @@ static HRESULT WINAPI SysKeyboardWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface) return res; }
-static HRESULT WINAPI SysKeyboardWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface, - LPDIACTIONFORMATW lpdiaf, - LPCWSTR lpszUserName, - DWORD dwFlags) -{ - SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface); - FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", This, lpdiaf, debugstr_w(lpszUserName), dwFlags); - - return _build_action_map(iface, lpdiaf, lpszUserName, dwFlags, DIKEYBOARD_MASK, &c_dfDIKeyboard); -} - static HRESULT WINAPI SysKeyboardWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, @@ -463,7 +452,7 @@ static const IDirectInputDevice8WVtbl SysKeyboardWvt = IDirectInputDevice2WImpl_SendDeviceData, IDirectInputDevice7WImpl_EnumEffectsInFile, IDirectInputDevice7WImpl_WriteEffectToFile, - SysKeyboardWImpl_BuildActionMap, + IDirectInputDevice8WImpl_BuildActionMap, SysKeyboardWImpl_SetActionMap, IDirectInputDevice8WImpl_GetImageInfo }; diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 6901cc09a31..92c8b110e57 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -676,16 +676,6 @@ static HRESULT WINAPI SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface, return res; }
-static HRESULT WINAPI SysMouseWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface, - LPDIACTIONFORMATW lpdiaf, - LPCWSTR lpszUserName, - DWORD dwFlags) -{ - FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags); - - return _build_action_map(iface, lpdiaf, lpszUserName, dwFlags, DIMOUSE_MASK, &c_dfDIMouse2); -} - static HRESULT WINAPI SysMouseWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, @@ -728,7 +718,7 @@ static const IDirectInputDevice8WVtbl SysMouseWvt = IDirectInputDevice2WImpl_SendDeviceData, IDirectInputDevice7WImpl_EnumEffectsInFile, IDirectInputDevice7WImpl_WriteEffectToFile, - SysMouseWImpl_BuildActionMap, + IDirectInputDevice8WImpl_BuildActionMap, SysMouseWImpl_SetActionMap, IDirectInputDevice8WImpl_GetImageInfo };
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 228 +++++++++++++++++++---------------- dlls/dinput/device_private.h | 4 +- dlls/dinput/joystick_hid.c | 14 +-- dlls/dinput/keyboard.c | 13 +- dlls/dinput/mouse.c | 13 +- 5 files changed, 128 insertions(+), 144 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 5528d3d328c..0f649ec59e8 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -827,111 +827,6 @@ static BOOL set_app_data(IDirectInputDeviceImpl *dev, int offset, UINT_PTR app_d return TRUE; }
-HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, LPCDIDATAFORMAT df) -{ - IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface); - DIDATAFORMAT data_format; - DIOBJECTDATAFORMAT *obj_df = NULL; - DIPROPDWORD dp; - DIPROPRANGE dpr; - DIPROPSTRING dps; - WCHAR username[MAX_PATH]; - DWORD username_size = MAX_PATH; - int i, action = 0, num_actions = 0; - unsigned int offset = 0; - ActionMap *action_map; - - if (This->acquired) return DIERR_ACQUIRED; - - data_format.dwSize = sizeof(data_format); - data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT); - data_format.dwFlags = DIDF_RELAXIS; - data_format.dwDataSize = lpdiaf->dwDataSize; - - /* Count the actions */ - for (i=0; i < lpdiaf->dwNumActions; i++) - if (IsEqualGUID(&This->guid, &lpdiaf->rgoAction[i].guidInstance)) - num_actions++; - - if (num_actions == 0) return DI_NOEFFECT; - - /* Construct the dataformat and actionmap */ - obj_df = malloc( sizeof(DIOBJECTDATAFORMAT) * num_actions ); - data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df; - data_format.dwNumObjs = num_actions; - - action_map = malloc( sizeof(ActionMap) * num_actions ); - - for (i = 0; i < lpdiaf->dwNumActions; i++) - { - if (IsEqualGUID(&This->guid, &lpdiaf->rgoAction[i].guidInstance)) - { - DWORD inst = DIDFT_GETINSTANCE(lpdiaf->rgoAction[i].dwObjID); - DWORD type = DIDFT_GETTYPE(lpdiaf->rgoAction[i].dwObjID); - LPDIOBJECTDATAFORMAT obj; - - if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON; - if (type == DIDFT_RELAXIS) type = DIDFT_AXIS; - - obj = dataformat_to_odf_by_type(df, inst, type); - - memcpy(&obj_df[action], obj, df->dwObjSize); - - action_map[action].uAppData = lpdiaf->rgoAction[i].uAppData; - action_map[action].offset = offset; - obj_df[action].dwOfs = offset; - offset += (type & DIDFT_BUTTON) ? 1 : 4; - - action++; - } - } - - IDirectInputDevice8_SetDataFormat(iface, &data_format); - - This->action_map = action_map; - This->num_actions = num_actions; - - free( obj_df ); - - /* Set the device properties according to the action format */ - dpr.diph.dwSize = sizeof(DIPROPRANGE); - dpr.lMin = lpdiaf->lAxisMin; - dpr.lMax = lpdiaf->lAxisMax; - dpr.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dpr.diph.dwHow = DIPH_DEVICE; - IDirectInputDevice8_SetProperty(iface, DIPROP_RANGE, &dpr.diph); - - if (lpdiaf->dwBufferSize > 0) - { - dp.diph.dwSize = sizeof(DIPROPDWORD); - dp.dwData = lpdiaf->dwBufferSize; - dp.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dp.diph.dwHow = DIPH_DEVICE; - IDirectInputDevice8_SetProperty(iface, DIPROP_BUFFERSIZE, &dp.diph); - } - - /* Retrieve logged user name if necessary */ - if (lpszUserName == NULL) - GetUserNameW(username, &username_size); - else - lstrcpynW(username, lpszUserName, MAX_PATH); - - dps.diph.dwSize = sizeof(dps); - dps.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dps.diph.dwObj = 0; - dps.diph.dwHow = DIPH_DEVICE; - if (dwFlags & DIDSAM_NOUSER) - dps.wsz[0] = '\0'; - else - lstrcpynW(dps.wsz, username, ARRAY_SIZE(dps.wsz)); - IDirectInputDevice2WImpl_SetProperty(iface, DIPROP_USERNAME, &dps.diph); - - /* Save the settings to disk */ - save_mapping_settings(iface, lpdiaf, username); - - return DI_OK; -} - /****************************************************************************** * queue_event - add new event to the ring queue */ @@ -1760,6 +1655,129 @@ HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap( IDirectInputDevice8W *if return DI_OK; }
+HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap( IDirectInputDevice8W *iface, DIACTIONFORMATW *format, + const WCHAR *username, DWORD flags ) +{ + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); + DIDATAFORMAT data_format; + DIOBJECTDATAFORMAT *obj_df = NULL; + DIPROPDWORD dp; + DIPROPRANGE dpr; + DIPROPSTRING dps; + WCHAR username_buf[MAX_PATH]; + DWORD username_len = MAX_PATH; + int i, action = 0, num_actions = 0; + unsigned int offset = 0; + const DIDATAFORMAT *df; + ActionMap *action_map; + + FIXME( "iface %p, format %p, username %s, flags %#x semi-stub!\n", iface, format, + debugstr_w(username), flags ); + + if (!format) return DIERR_INVALIDPARAM; + + switch (GET_DIDEVICE_TYPE( impl->instance.dwDevType )) + { + case DIDEVTYPE_KEYBOARD: + case DI8DEVTYPE_KEYBOARD: + df = &c_dfDIKeyboard; + break; + case DIDEVTYPE_MOUSE: + case DI8DEVTYPE_MOUSE: + df = &c_dfDIMouse2; + break; + default: + df = impl->data_format.wine_df; + break; + } + + if (impl->acquired) return DIERR_ACQUIRED; + + data_format.dwSize = sizeof(data_format); + data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT); + data_format.dwFlags = DIDF_RELAXIS; + data_format.dwDataSize = format->dwDataSize; + + /* Count the actions */ + for (i = 0; i < format->dwNumActions; i++) + if (IsEqualGUID( &impl->guid, &format->rgoAction[i].guidInstance )) + num_actions++; + + if (num_actions == 0) return DI_NOEFFECT; + + /* Construct the dataformat and actionmap */ + obj_df = malloc( sizeof(DIOBJECTDATAFORMAT) * num_actions ); + data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df; + data_format.dwNumObjs = num_actions; + + action_map = malloc( sizeof(ActionMap) * num_actions ); + + for (i = 0; i < format->dwNumActions; i++) + { + if (IsEqualGUID( &impl->guid, &format->rgoAction[i].guidInstance )) + { + DWORD inst = DIDFT_GETINSTANCE( format->rgoAction[i].dwObjID ); + DWORD type = DIDFT_GETTYPE( format->rgoAction[i].dwObjID ); + LPDIOBJECTDATAFORMAT obj; + + if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON; + if (type == DIDFT_RELAXIS) type = DIDFT_AXIS; + + obj = dataformat_to_odf_by_type( df, inst, type ); + + memcpy( &obj_df[action], obj, df->dwObjSize ); + + action_map[action].uAppData = format->rgoAction[i].uAppData; + action_map[action].offset = offset; + obj_df[action].dwOfs = offset; + offset += (type & DIDFT_BUTTON) ? 1 : 4; + + action++; + } + } + + IDirectInputDevice8_SetDataFormat( iface, &data_format ); + + impl->action_map = action_map; + impl->num_actions = num_actions; + + free( obj_df ); + + /* Set the device properties according to the action format */ + dpr.diph.dwSize = sizeof(DIPROPRANGE); + dpr.lMin = format->lAxisMin; + dpr.lMax = format->lAxisMax; + dpr.diph.dwHeaderSize = sizeof(DIPROPHEADER); + dpr.diph.dwHow = DIPH_DEVICE; + IDirectInputDevice8_SetProperty( iface, DIPROP_RANGE, &dpr.diph ); + + if (format->dwBufferSize > 0) + { + dp.diph.dwSize = sizeof(DIPROPDWORD); + dp.dwData = format->dwBufferSize; + dp.diph.dwHeaderSize = sizeof(DIPROPHEADER); + dp.diph.dwHow = DIPH_DEVICE; + IDirectInputDevice8_SetProperty( iface, DIPROP_BUFFERSIZE, &dp.diph ); + } + + /* Retrieve logged user name if necessary */ + if (username == NULL) GetUserNameW( username_buf, &username_len ); + else lstrcpynW( username_buf, username, MAX_PATH ); + + dps.diph.dwSize = sizeof(dps); + dps.diph.dwHeaderSize = sizeof(DIPROPHEADER); + dps.diph.dwObj = 0; + dps.diph.dwHow = DIPH_DEVICE; + if (flags & DIDSAM_NOUSER) dps.wsz[0] = '\0'; + else lstrcpynW( dps.wsz, username_buf, ARRAY_SIZE(dps.wsz) ); + IDirectInputDevice2WImpl_SetProperty( iface, DIPROP_USERNAME, &dps.diph ); + + /* Save the settings to disk */ + save_mapping_settings( iface, format, username_buf ); + + return DI_OK; +} + HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader) { diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 6aed93a130b..d61a0a3e6e8 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -114,8 +114,6 @@ extern void _dump_OBJECTINSTANCEW(const DIDEVICEOBJECTINSTANCEW *ddoi) DECLSPEC extern void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) DECLSPEC_HIDDEN; extern const char *_dump_dinput_GUID(const GUID *guid) DECLSPEC_HIDDEN;
-extern HRESULT _set_action_map(LPDIRECTINPUTDEVICE8W iface, LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags, LPCDIDATAFORMAT df) DECLSPEC_HIDDEN; - /* And the stubs */ extern HRESULT WINAPI IDirectInputDevice2WImpl_Acquire(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirectInputDevice2WImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface) DECLSPEC_HIDDEN; @@ -178,6 +176,8 @@ extern HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVIC LPDIACTIONFORMATW lpdiaf, LPCWSTR lpszUserName, DWORD dwFlags) DECLSPEC_HIDDEN; +extern HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap( IDirectInputDevice8W *iface, DIACTIONFORMATW *format, + const WCHAR *username, DWORD flags ); extern HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader) DECLSPEC_HIDDEN;
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 5921b473f3a..13083a6ac77 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -1385,18 +1385,6 @@ static HRESULT WINAPI hid_joystick_Poll( IDirectInputDevice8W *iface ) return hr; }
-static HRESULT WINAPI hid_joystick_SetActionMap( IDirectInputDevice8W *iface, DIACTIONFORMATW *format, - const WCHAR *username, DWORD flags ) -{ - struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface ); - - TRACE( "iface %p, format %p, username %s, flags %#x.\n", iface, format, debugstr_w(username), flags ); - - if (!format) return DIERR_INVALIDPARAM; - - return _set_action_map( iface, format, username, flags, impl->base.data_format.wine_df ); -} - static const IDirectInputDevice8WVtbl hid_joystick_vtbl = { /*** IUnknown methods ***/ @@ -1434,7 +1422,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl = IDirectInputDevice7WImpl_WriteEffectToFile, /*** IDirectInputDevice8 methods ***/ IDirectInputDevice8WImpl_BuildActionMap, - hid_joystick_SetActionMap, + IDirectInputDevice8WImpl_SetActionMap, IDirectInputDevice8WImpl_GetImageInfo, };
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index 98fcf253afa..c367162164a 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -410,17 +410,6 @@ static HRESULT WINAPI SysKeyboardWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface) return res; }
-static HRESULT WINAPI SysKeyboardWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface, - LPDIACTIONFORMATW lpdiaf, - LPCWSTR lpszUserName, - DWORD dwFlags) -{ - SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface); - FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", This, lpdiaf, debugstr_w(lpszUserName), dwFlags); - - return _set_action_map(iface, lpdiaf, lpszUserName, dwFlags, &c_dfDIKeyboard); -} - static const IDirectInputDevice8WVtbl SysKeyboardWvt = { IDirectInputDevice2WImpl_QueryInterface, @@ -453,6 +442,6 @@ static const IDirectInputDevice8WVtbl SysKeyboardWvt = IDirectInputDevice7WImpl_EnumEffectsInFile, IDirectInputDevice7WImpl_WriteEffectToFile, IDirectInputDevice8WImpl_BuildActionMap, - SysKeyboardWImpl_SetActionMap, + IDirectInputDevice8WImpl_SetActionMap, IDirectInputDevice8WImpl_GetImageInfo }; diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 92c8b110e57..e94cd4e7c50 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -676,17 +676,6 @@ static HRESULT WINAPI SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface, return res; }
-static HRESULT WINAPI SysMouseWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface, - LPDIACTIONFORMATW lpdiaf, - LPCWSTR lpszUserName, - DWORD dwFlags) -{ - SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface); - FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", This, lpdiaf, debugstr_w(lpszUserName), dwFlags); - - return _set_action_map(iface, lpdiaf, lpszUserName, dwFlags, &c_dfDIMouse2); -} - static const IDirectInputDevice8WVtbl SysMouseWvt = { IDirectInputDevice2WImpl_QueryInterface, @@ -719,6 +708,6 @@ static const IDirectInputDevice8WVtbl SysMouseWvt = IDirectInputDevice7WImpl_EnumEffectsInFile, IDirectInputDevice7WImpl_WriteEffectToFile, IDirectInputDevice8WImpl_BuildActionMap, - SysMouseWImpl_SetActionMap, + IDirectInputDevice8WImpl_SetActionMap, IDirectInputDevice8WImpl_GetImageInfo };
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/mouse.c | 152 +++++++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 78 deletions(-)
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index e94cd4e7c50..c1992a8557f 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -463,84 +463,6 @@ static void warp_check( SysMouseImpl* This, BOOL force ) }
-/****************************************************************************** - * Acquire : gets exclusive control of the mouse - */ -static HRESULT WINAPI SysMouseWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface) -{ - SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface); - POINT point; - HRESULT res; - - TRACE("(this=%p)\n",This); - - if ((res = IDirectInputDevice2WImpl_Acquire(iface)) != DI_OK) return res; - - /* Init the mouse state */ - GetCursorPos( &point ); - if (This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS) - { - This->m_state.lX = point.x; - This->m_state.lY = point.y; - } else { - This->m_state.lX = 0; - This->m_state.lY = 0; - This->org_coords = point; - } - This->m_state.lZ = 0; - This->m_state.rgbButtons[0] = GetKeyState(VK_LBUTTON) & 0x80; - This->m_state.rgbButtons[1] = GetKeyState(VK_RBUTTON) & 0x80; - This->m_state.rgbButtons[2] = GetKeyState(VK_MBUTTON) & 0x80; - - if (This->base.dwCoopLevel & DISCL_EXCLUSIVE) - { - ShowCursor(FALSE); /* hide cursor */ - warp_check( This, TRUE ); - } - else if (This->warp_override == WARP_FORCE_ON) - { - /* Need a window to warp mouse in. */ - if (!This->base.win) This->base.win = GetDesktopWindow(); - warp_check( This, TRUE ); - } - else if (This->clipped) - { - ClipCursor( NULL ); - This->clipped = FALSE; - } - - return DI_OK; -} - -/****************************************************************************** - * Unacquire : frees the mouse - */ -static HRESULT WINAPI SysMouseWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface) -{ - SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface); - HRESULT res; - - TRACE("(this=%p)\n",This); - - if ((res = IDirectInputDevice2WImpl_Unacquire(iface)) != DI_OK) return res; - - if (This->base.dwCoopLevel & DISCL_EXCLUSIVE) - { - ClipCursor(NULL); - ShowCursor(TRUE); /* show cursor */ - This->clipped = FALSE; - } - - /* And put the mouse cursor back where it was at acquire time */ - if (This->base.dwCoopLevel & DISCL_EXCLUSIVE || This->warp_override == WARP_FORCE_ON) - { - TRACE("warping mouse back to %s\n", wine_dbgstr_point(&This->org_coords)); - SetCursorPos(This->org_coords.x, This->org_coords.y); - } - - return DI_OK; -} - /****************************************************************************** * GetDeviceState : returns the "state" of the mouse. * @@ -676,6 +598,80 @@ static HRESULT WINAPI SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface, return res; }
+static HRESULT WINAPI SysMouseWImpl_Acquire( IDirectInputDevice8W *iface ) +{ + SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface ); + POINT point; + HRESULT res; + + TRACE( "iface %p\n", iface ); + + if ((res = IDirectInputDevice2WImpl_Acquire( iface )) != DI_OK) return res; + + /* Init the mouse state */ + GetCursorPos( &point ); + if (impl->base.data_format.user_df->dwFlags & DIDF_ABSAXIS) + { + impl->m_state.lX = point.x; + impl->m_state.lY = point.y; + } + else + { + impl->m_state.lX = 0; + impl->m_state.lY = 0; + impl->org_coords = point; + } + impl->m_state.lZ = 0; + impl->m_state.rgbButtons[0] = GetKeyState( VK_LBUTTON ) & 0x80; + impl->m_state.rgbButtons[1] = GetKeyState( VK_RBUTTON ) & 0x80; + impl->m_state.rgbButtons[2] = GetKeyState( VK_MBUTTON ) & 0x80; + + if (impl->base.dwCoopLevel & DISCL_EXCLUSIVE) + { + ShowCursor( FALSE ); /* hide cursor */ + warp_check( impl, TRUE ); + } + else if (impl->warp_override == WARP_FORCE_ON) + { + /* Need a window to warp mouse in. */ + if (!impl->base.win) impl->base.win = GetDesktopWindow(); + warp_check( impl, TRUE ); + } + else if (impl->clipped) + { + ClipCursor( NULL ); + impl->clipped = FALSE; + } + + return DI_OK; +} + +static HRESULT WINAPI SysMouseWImpl_Unacquire( IDirectInputDevice8W *iface ) +{ + SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface ); + HRESULT res; + + TRACE( "iface %p\n", iface ); + + if ((res = IDirectInputDevice2WImpl_Unacquire( iface )) != DI_OK) return res; + + if (impl->base.dwCoopLevel & DISCL_EXCLUSIVE) + { + ClipCursor( NULL ); + ShowCursor( TRUE ); /* show cursor */ + impl->clipped = FALSE; + } + + /* And put the mouse cursor back where it was at acquire time */ + if (impl->base.dwCoopLevel & DISCL_EXCLUSIVE || impl->warp_override == WARP_FORCE_ON) + { + TRACE( "warping mouse back to %s\n", wine_dbgstr_point( &impl->org_coords ) ); + SetCursorPos( impl->org_coords.x, impl->org_coords.y ); + } + + return DI_OK; +} + static const IDirectInputDevice8WVtbl SysMouseWvt = { IDirectInputDevice2WImpl_QueryInterface,
And introduce new internal acquire / unacquire callbacks.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 65 ++++++++++++++----------- dlls/dinput/device_private.h | 17 +++++-- dlls/dinput/dinput_main.c | 4 +- dlls/dinput/joystick_hid.c | 93 ++++++++++++------------------------ dlls/dinput/keyboard.c | 34 +++++++------ dlls/dinput/mouse.c | 30 ++++++------ 6 files changed, 114 insertions(+), 129 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 0f649ec59e8..8f57d32dee2 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -886,50 +886,56 @@ void queue_event( IDirectInputDevice8W *iface, int inst_id, DWORD data, DWORD ti * Acquire */
-HRESULT WINAPI IDirectInputDevice2WImpl_Acquire(LPDIRECTINPUTDEVICE8W iface) +HRESULT WINAPI IDirectInputDevice2WImpl_Acquire( IDirectInputDevice8W *iface ) { - IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface); - HRESULT res; - - TRACE("(%p)\n", This); + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); + HRESULT hr = DI_OK;
- if (!This->data_format.user_df) return DIERR_INVALIDPARAM; - if (This->dwCoopLevel & DISCL_FOREGROUND && This->win != GetForegroundWindow()) - return DIERR_OTHERAPPHASPRIO; + TRACE( "iface %p.\n", iface );
- EnterCriticalSection(&This->crit); - res = This->acquired ? S_FALSE : DI_OK; - This->acquired = 1; - LeaveCriticalSection(&This->crit); - if (res != DI_OK) return res; + EnterCriticalSection( &impl->crit ); + if (impl->acquired) + hr = DI_NOEFFECT; + else if (!impl->data_format.user_df) + hr = DIERR_INVALIDPARAM; + else if ((impl->dwCoopLevel & DISCL_FOREGROUND) && impl->win != GetForegroundWindow()) + hr = DIERR_OTHERAPPHASPRIO; + else + { + impl->acquired = TRUE; + if (FAILED(hr = impl->vtbl->acquire( iface ))) impl->acquired = FALSE; + } + LeaveCriticalSection( &impl->crit ); + if (hr != DI_OK) return hr;
- dinput_hooks_acquire_device(iface); - check_dinput_hooks(iface, TRUE); + dinput_hooks_acquire_device( iface ); + check_dinput_hooks( iface, TRUE );
- return res; + return hr; }
/****************************************************************************** * Unacquire */
-HRESULT WINAPI IDirectInputDevice2WImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface) +HRESULT WINAPI IDirectInputDevice2WImpl_Unacquire( IDirectInputDevice8W *iface ) { - IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface); - HRESULT res; + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); + HRESULT hr = DI_OK;
- TRACE("(%p)\n", This); + TRACE( "iface %p.\n", iface );
- EnterCriticalSection(&This->crit); - res = !This->acquired ? DI_NOEFFECT : DI_OK; - This->acquired = 0; - LeaveCriticalSection(&This->crit); - if (res != DI_OK) return res; + EnterCriticalSection( &impl->crit ); + if (!impl->acquired) hr = DI_NOEFFECT; + else hr = impl->vtbl->unacquire( iface ); + impl->acquired = FALSE; + LeaveCriticalSection( &impl->crit ); + if (hr != DI_OK) return hr;
- dinput_hooks_unacquire_device(iface); - check_dinput_hooks(iface, FALSE); + dinput_hooks_unacquire_device( iface ); + check_dinput_hooks( iface, FALSE );
- return res; + return hr; }
/****************************************************************************** @@ -1787,7 +1793,7 @@ HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface return DI_OK; }
-HRESULT direct_input_device_alloc( SIZE_T size, const IDirectInputDevice8WVtbl *vtbl, +HRESULT direct_input_device_alloc( SIZE_T size, const IDirectInputDevice8WVtbl *vtbl, const struct dinput_device_vtbl *internal_vtbl, const GUID *guid, IDirectInputImpl *dinput, void **out ) { IDirectInputDeviceImpl *This; @@ -1811,6 +1817,7 @@ HRESULT direct_input_device_alloc( SIZE_T size, const IDirectInputDevice8WVtbl * InitializeCriticalSection( &This->crit ); This->dinput = dinput; IDirectInput_AddRef( &dinput->IDirectInput7A_iface ); + This->vtbl = internal_vtbl;
*out = This; return DI_OK; diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index d61a0a3e6e8..7ae040744cb 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -55,6 +55,13 @@ typedef struct
typedef HRESULT dinput_device_read_state( IDirectInputDevice8W *iface );
+struct dinput_device_vtbl +{ + HRESULT (*read)(IDirectInputDevice8W *); + HRESULT (*acquire)(IDirectInputDevice8W *); + HRESULT (*unacquire)(IDirectInputDevice8W *); +}; + /* Device implementation */ typedef struct IDirectInputDeviceImpl IDirectInputDeviceImpl; struct IDirectInputDeviceImpl @@ -89,13 +96,13 @@ struct IDirectInputDeviceImpl int num_actions; /* number of actions mapped */ ActionMap *action_map; /* array of mappings */
- /* internal device file reading */ - HANDLE read_event; - dinput_device_read_state *read_callback; + /* internal device callbacks */ + HANDLE read_event; + const struct dinput_device_vtbl *vtbl; };
-extern HRESULT direct_input_device_alloc( SIZE_T size, const IDirectInputDevice8WVtbl *vtbl, const GUID *guid, - IDirectInputImpl *dinput, void **out ) DECLSPEC_HIDDEN; +extern HRESULT direct_input_device_alloc( SIZE_T size, const IDirectInputDevice8WVtbl *vtbl, const struct dinput_device_vtbl *internal_vtbl, + const GUID *guid, IDirectInputImpl *dinput, void **out ) DECLSPEC_HIDDEN; extern const IDirectInputDevice8AVtbl dinput_device_a_vtbl DECLSPEC_HIDDEN;
extern BOOL get_app_key(HKEY*, HKEY*) DECLSPEC_HIDDEN; diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index bc35d6d77b3..329cb738469 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -1308,7 +1308,7 @@ static DWORD WINAPI hook_thread_proc(void *param) { if (impl->read_event == events[ret]) { - hr = impl->read_callback( &impl->IDirectInputDevice8W_iface ); + hr = impl->vtbl->read( &impl->IDirectInputDevice8W_iface ); if (FAILED(hr)) list_remove( &impl->entry ); break; } @@ -1343,7 +1343,7 @@ static DWORD WINAPI hook_thread_proc(void *param) mice_cnt = list_count( &acquired_mouse_list ); LIST_FOR_EACH_ENTRY( impl, &acquired_device_list, IDirectInputDeviceImpl, entry ) { - if (!impl->read_event || !impl->read_callback) continue; + if (!impl->read_event || !impl->vtbl->read) continue; if (events_count >= ARRAY_SIZE(events)) break; events[events_count++] = impl->read_event; } diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 13083a6ac77..6454a4b7fd1 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -916,83 +916,46 @@ static HRESULT WINAPI hid_joystick_SetProperty( IDirectInputDevice8W *iface, con return DI_OK; }
-static HRESULT WINAPI hid_joystick_Acquire( IDirectInputDevice8W *iface ) +static HRESULT hid_joystick_internal_acquire( IDirectInputDevice8W *iface ) { struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface ); ULONG report_len = impl->caps.InputReportByteLength; - HRESULT hr = DI_OK; BOOL ret;
- TRACE( "iface %p.\n", iface ); - - EnterCriticalSection( &impl->base.crit ); - if (impl->base.acquired) - hr = DI_NOEFFECT; - else if (!impl->base.data_format.user_df) - hr = DIERR_INVALIDPARAM; - else if ((impl->base.dwCoopLevel & DISCL_FOREGROUND) && impl->base.win != GetForegroundWindow()) - hr = DIERR_OTHERAPPHASPRIO; - else if (impl->device == INVALID_HANDLE_VALUE) + if (impl->device == INVALID_HANDLE_VALUE) { impl->device = CreateFileW( impl->device_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING, 0 ); - if (impl->device == INVALID_HANDLE_VALUE) hr = DIERR_INPUTLOST; + if (impl->device == INVALID_HANDLE_VALUE) return DIERR_INPUTLOST; }
- if (hr == DI_OK) + memset( &impl->read_ovl, 0, sizeof(impl->read_ovl) ); + impl->read_ovl.hEvent = impl->base.read_event; + ret = ReadFile( impl->device, impl->input_report_buf, report_len, NULL, &impl->read_ovl ); + if (!ret && GetLastError() != ERROR_IO_PENDING) { - memset( &impl->read_ovl, 0, sizeof(impl->read_ovl) ); - impl->read_ovl.hEvent = impl->base.read_event; - ret = ReadFile( impl->device, impl->input_report_buf, report_len, NULL, &impl->read_ovl ); - if (!ret && GetLastError() != ERROR_IO_PENDING) - { - CloseHandle( impl->device ); - impl->device = INVALID_HANDLE_VALUE; - hr = DIERR_INPUTLOST; - } - else - { - impl->base.acquired = TRUE; - IDirectInputDevice8_SendForceFeedbackCommand( iface, DISFFC_RESET ); - } + CloseHandle( impl->device ); + impl->device = INVALID_HANDLE_VALUE; + return DIERR_INPUTLOST; } - LeaveCriticalSection( &impl->base.crit ); - if (hr != DI_OK) return hr;
- dinput_hooks_acquire_device( iface ); - check_dinput_hooks( iface, TRUE ); - - return hr; + IDirectInputDevice8_SendForceFeedbackCommand( iface, DISFFC_RESET ); + return DI_OK; }
-static HRESULT WINAPI hid_joystick_Unacquire( IDirectInputDevice8W *iface ) +static HRESULT hid_joystick_internal_unacquire( IDirectInputDevice8W *iface ) { struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface ); - HRESULT hr = DI_OK; BOOL ret;
- TRACE( "iface %p.\n", iface ); - - EnterCriticalSection( &impl->base.crit ); - if (!impl->base.acquired) hr = DI_NOEFFECT; - else - { - if (impl->device != INVALID_HANDLE_VALUE) - { - ret = CancelIoEx( impl->device, &impl->read_ovl ); - if (!ret) WARN( "CancelIoEx failed, last error %u\n", GetLastError() ); - else WaitForSingleObject( impl->base.read_event, INFINITE ); - } - IDirectInputDevice8_SendForceFeedbackCommand( iface, DISFFC_RESET ); - impl->base.acquired = FALSE; - } - LeaveCriticalSection( &impl->base.crit ); - if (hr != DI_OK) return hr; + if (impl->device == INVALID_HANDLE_VALUE) return DI_NOEFFECT;
- dinput_hooks_unacquire_device( iface ); - check_dinput_hooks( iface, FALSE ); + ret = CancelIoEx( impl->device, &impl->read_ovl ); + if (!ret) WARN( "CancelIoEx failed, last error %u\n", GetLastError() ); + else WaitForSingleObject( impl->base.read_event, INFINITE );
- return hr; + IDirectInputDevice8_SendForceFeedbackCommand( iface, DISFFC_RESET ); + return DI_OK; }
static HRESULT WINAPI hid_joystick_GetDeviceState( IDirectInputDevice8W *iface, DWORD len, void *ptr ) @@ -1396,8 +1359,8 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl = hid_joystick_EnumObjects, hid_joystick_GetProperty, hid_joystick_SetProperty, - hid_joystick_Acquire, - hid_joystick_Unacquire, + IDirectInputDevice2WImpl_Acquire, + IDirectInputDevice2WImpl_Unacquire, hid_joystick_GetDeviceState, IDirectInputDevice2WImpl_GetDeviceData, IDirectInputDevice2WImpl_SetDataFormat, @@ -1532,7 +1495,7 @@ static BOOL read_device_state_value( struct hid_joystick *impl, struct hid_value return DIENUM_CONTINUE; }
-static HRESULT hid_joystick_read_state( IDirectInputDevice8W *iface ) +static HRESULT hid_joystick_internal_read( IDirectInputDevice8W *iface ) { static const DIPROPHEADER filter = { @@ -1618,6 +1581,13 @@ static HRESULT hid_joystick_read_state( IDirectInputDevice8W *iface ) return hr; }
+static const struct dinput_device_vtbl hid_joystick_internal_vtbl = +{ + hid_joystick_internal_read, + hid_joystick_internal_acquire, + hid_joystick_internal_unacquire, +}; + static DWORD device_type_for_version( DWORD type, DWORD version ) { if (version >= 0x0800) return type; @@ -2211,13 +2181,12 @@ static HRESULT hid_joystick_create_device( IDirectInputImpl *dinput, const GUID else return DIERR_DEVICENOTREG;
- hr = direct_input_device_alloc( sizeof(struct hid_joystick), &hid_joystick_vtbl, guid, - dinput, (void **)&impl ); + hr = direct_input_device_alloc( sizeof(struct hid_joystick), &hid_joystick_vtbl, &hid_joystick_internal_vtbl, + guid, dinput, (void **)&impl ); if (FAILED(hr)) return hr; impl->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": hid_joystick.base.crit"); impl->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND; impl->base.read_event = CreateEventW( NULL, TRUE, FALSE, NULL ); - impl->base.read_callback = hid_joystick_read_state;
hr = hid_joystick_device_open( -1, &instance, impl->device_path, &impl->device, &impl->preparsed, &attrs, &impl->caps, dinput->dwVersion ); diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index c367162164a..138b8439374 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -37,6 +37,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(dinput); #define WINE_DINPUT_KEYBOARD_MAX_KEYS 256
static const IDirectInputDevice8WVtbl SysKeyboardWvt; +static const struct dinput_device_vtbl keyboard_internal_vtbl;
typedef struct SysKeyboardImpl SysKeyboardImpl; struct SysKeyboardImpl @@ -199,7 +200,8 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysKeyboar int i, idx = 0; HRESULT hr;
- if (FAILED(hr = direct_input_device_alloc( sizeof(SysKeyboardImpl), &SysKeyboardWvt, rguid, dinput, (void **)&newDevice ))) + if (FAILED(hr = direct_input_device_alloc( sizeof(SysKeyboardImpl), &SysKeyboardWvt, &keyboard_internal_vtbl, + rguid, dinput, (void **)&newDevice ))) return hr; df = newDevice->base.data_format.wine_df; newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysKeyboardImpl*->base.crit"); @@ -393,23 +395,25 @@ static HRESULT WINAPI SysKeyboardWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, return DI_OK; }
-static HRESULT WINAPI SysKeyboardWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface) +static HRESULT keyboard_internal_acquire( IDirectInputDevice8W *iface ) { - SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface); - HRESULT res; - - TRACE("(%p)\n", This); - - res = IDirectInputDevice2WImpl_Acquire(iface); - if (res == DI_OK) - { - TRACE("clearing keystate\n"); - memset(This->DInputKeyState, 0, sizeof(This->DInputKeyState)); - } + return DI_OK; +}
- return res; +static HRESULT keyboard_internal_unacquire( IDirectInputDevice8W *iface ) +{ + SysKeyboardImpl *This = impl_from_IDirectInputDevice8W( iface ); + memset( This->DInputKeyState, 0, sizeof(This->DInputKeyState) ); + return DI_OK; }
+static const struct dinput_device_vtbl keyboard_internal_vtbl = +{ + NULL, + keyboard_internal_acquire, + keyboard_internal_unacquire, +}; + static const IDirectInputDevice8WVtbl SysKeyboardWvt = { IDirectInputDevice2WImpl_QueryInterface, @@ -419,7 +423,7 @@ static const IDirectInputDevice8WVtbl SysKeyboardWvt = IDirectInputDevice2WImpl_EnumObjects, SysKeyboardWImpl_GetProperty, IDirectInputDevice2WImpl_SetProperty, - SysKeyboardWImpl_Acquire, + IDirectInputDevice2WImpl_Acquire, IDirectInputDevice2WImpl_Unacquire, SysKeyboardWImpl_GetDeviceState, IDirectInputDevice2WImpl_GetDeviceData, diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index c1992a8557f..20a4ab9af40 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -44,6 +44,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(dinput); #define WINE_MOUSE_BUTTONS_INSTANCE 3
static const IDirectInputDevice8WVtbl SysMouseWvt; +static const struct dinput_device_vtbl mouse_internal_vtbl;
typedef struct SysMouseImpl SysMouseImpl;
@@ -143,7 +144,8 @@ static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseIm HKEY hkey, appkey; HRESULT hr;
- if (FAILED(hr = direct_input_device_alloc( sizeof(SysMouseImpl), &SysMouseWvt, rguid, dinput, (void **)&newDevice ))) + if (FAILED(hr = direct_input_device_alloc( sizeof(SysMouseImpl), &SysMouseWvt, &mouse_internal_vtbl, + rguid, dinput, (void **)&newDevice ))) return hr; df = newDevice->base.data_format.wine_df; newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit"); @@ -462,7 +464,6 @@ static void warp_check( SysMouseImpl* This, BOOL force ) } }
- /****************************************************************************** * GetDeviceState : returns the "state" of the mouse. * @@ -598,15 +599,10 @@ static HRESULT WINAPI SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface, return res; }
-static HRESULT WINAPI SysMouseWImpl_Acquire( IDirectInputDevice8W *iface ) +static HRESULT mouse_internal_acquire( IDirectInputDevice8W *iface ) { SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface ); POINT point; - HRESULT res; - - TRACE( "iface %p\n", iface ); - - if ((res = IDirectInputDevice2WImpl_Acquire( iface )) != DI_OK) return res;
/* Init the mouse state */ GetCursorPos( &point ); @@ -646,14 +642,9 @@ static HRESULT WINAPI SysMouseWImpl_Acquire( IDirectInputDevice8W *iface ) return DI_OK; }
-static HRESULT WINAPI SysMouseWImpl_Unacquire( IDirectInputDevice8W *iface ) +static HRESULT mouse_internal_unacquire( IDirectInputDevice8W *iface ) { SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface ); - HRESULT res; - - TRACE( "iface %p\n", iface ); - - if ((res = IDirectInputDevice2WImpl_Unacquire( iface )) != DI_OK) return res;
if (impl->base.dwCoopLevel & DISCL_EXCLUSIVE) { @@ -672,6 +663,13 @@ static HRESULT WINAPI SysMouseWImpl_Unacquire( IDirectInputDevice8W *iface ) return DI_OK; }
+static const struct dinput_device_vtbl mouse_internal_vtbl = +{ + NULL, + mouse_internal_acquire, + mouse_internal_unacquire, +}; + static const IDirectInputDevice8WVtbl SysMouseWvt = { IDirectInputDevice2WImpl_QueryInterface, @@ -681,8 +679,8 @@ static const IDirectInputDevice8WVtbl SysMouseWvt = IDirectInputDevice2WImpl_EnumObjects, SysMouseWImpl_GetProperty, IDirectInputDevice2WImpl_SetProperty, - SysMouseWImpl_Acquire, - SysMouseWImpl_Unacquire, + IDirectInputDevice2WImpl_Acquire, + IDirectInputDevice2WImpl_Unacquire, SysMouseWImpl_GetDeviceState, SysMouseWImpl_GetDeviceData, IDirectInputDevice2WImpl_SetDataFormat,
And use it from within the internal hook critical section, to unacquire the device and remove it from the acquired device list directly.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/dinput_main.c | 26 +++++++++++++++++++++----- dlls/dinput/joystick_hid.c | 1 - 2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 329cb738469..46c18ed55dd 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -119,6 +119,22 @@ void dinput_hooks_unacquire_device(LPDIRECTINPUTDEVICE8W iface) LeaveCriticalSection( &dinput_hook_crit ); }
+static void dinput_device_internal_unacquire( IDirectInputDevice8W *iface ) +{ + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); + + TRACE( "iface %p.\n", iface ); + + EnterCriticalSection( &impl->crit ); + if (impl->acquired) + { + impl->vtbl->unacquire( iface ); + impl->acquired = FALSE; + list_remove( &impl->entry ); + } + LeaveCriticalSection( &impl->crit ); +} + static HRESULT create_directinput_instance(REFIID riid, LPVOID *ppDI, IDirectInputImpl **out) { IDirectInputImpl *This = calloc( 1, sizeof(IDirectInputImpl) ); @@ -1248,7 +1264,7 @@ static LRESULT CALLBACK callwndproc_proc( int code, WPARAM wparam, LPARAM lparam if (msg->hwnd == dev->win && msg->hwnd != foreground) { TRACE( "%p window is not foreground - unacquiring %p\n", dev->win, dev ); - IDirectInputDevice_Unacquire( &dev->IDirectInputDevice8W_iface ); + dinput_device_internal_unacquire( &dev->IDirectInputDevice8W_iface ); } } LIST_FOR_EACH_ENTRY_SAFE( dev, next, &acquired_mouse_list, IDirectInputDeviceImpl, entry ) @@ -1256,7 +1272,7 @@ static LRESULT CALLBACK callwndproc_proc( int code, WPARAM wparam, LPARAM lparam if (msg->hwnd == dev->win && msg->hwnd != foreground) { TRACE( "%p window is not foreground - unacquiring %p\n", dev->win, dev ); - IDirectInputDevice_Unacquire( &dev->IDirectInputDevice8W_iface ); + dinput_device_internal_unacquire( &dev->IDirectInputDevice8W_iface ); } } LIST_FOR_EACH_ENTRY_SAFE( dev, next, &acquired_rawmouse_list, IDirectInputDeviceImpl, entry ) @@ -1264,7 +1280,7 @@ static LRESULT CALLBACK callwndproc_proc( int code, WPARAM wparam, LPARAM lparam if (msg->hwnd == dev->win && msg->hwnd != foreground) { TRACE( "%p window is not foreground - unacquiring %p\n", dev->win, dev ); - IDirectInputDevice_Unacquire( &dev->IDirectInputDevice8W_iface ); + dinput_device_internal_unacquire( &dev->IDirectInputDevice8W_iface ); } } LIST_FOR_EACH_ENTRY_SAFE( dev, next, &acquired_keyboard_list, IDirectInputDeviceImpl, entry ) @@ -1272,7 +1288,7 @@ static LRESULT CALLBACK callwndproc_proc( int code, WPARAM wparam, LPARAM lparam if (msg->hwnd == dev->win && msg->hwnd != foreground) { TRACE( "%p window is not foreground - unacquiring %p\n", dev->win, dev ); - IDirectInputDevice_Unacquire( &dev->IDirectInputDevice8W_iface ); + dinput_device_internal_unacquire( &dev->IDirectInputDevice8W_iface ); } } LeaveCriticalSection( &dinput_hook_crit ); @@ -1309,7 +1325,7 @@ static DWORD WINAPI hook_thread_proc(void *param) if (impl->read_event == events[ret]) { hr = impl->vtbl->read( &impl->IDirectInputDevice8W_iface ); - if (FAILED(hr)) list_remove( &impl->entry ); + if (FAILED( hr )) dinput_device_internal_unacquire( &impl->IDirectInputDevice8W_iface ); break; } } diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 6454a4b7fd1..710e63185fb 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -1573,7 +1573,6 @@ static HRESULT hid_joystick_internal_read( IDirectInputDevice8W *iface ) WARN( "GetOverlappedResult/ReadFile failed, error %u\n", GetLastError() ); CloseHandle(impl->device); impl->device = INVALID_HANDLE_VALUE; - impl->base.acquired = FALSE; hr = DIERR_INPUTLOST; } LeaveCriticalSection( &impl->base.crit );
Otherwise we may close HID read event before it has finished removing it from the wait handles, causing MsgWaitForMultipleObjectsEx to return an error and terminate.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/dinput_main.c | 13 ++++--------- dlls/dinput8/tests/hid.c | 6 ------ 2 files changed, 4 insertions(+), 15 deletions(-)
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 46c18ed55dd..985dae1ab36 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -1381,8 +1381,7 @@ static DWORD WINAPI hook_thread_proc(void *param) mouse_hook = NULL; }
- if (finished_event) - SetEvent(finished_event); + SetEvent(finished_event); } }
@@ -1504,17 +1503,13 @@ void check_dinput_hooks(LPDIRECTINPUTDEVICE8W iface, BOOL acquired) WARN( "Unable to (un)register raw device %x:%x\n", dev->raw_device.usUsagePage, dev->raw_device.usUsage ); }
- if (acquired) - hook_change_finished_event = CreateEventW( NULL, FALSE, FALSE, NULL ); + hook_change_finished_event = CreateEventW( NULL, FALSE, FALSE, NULL ); PostThreadMessageW( hook_thread_id, WM_USER+0x10, 1, (LPARAM)hook_change_finished_event );
LeaveCriticalSection(&dinput_hook_crit);
- if (acquired) - { - WaitForSingleObject(hook_change_finished_event, INFINITE); - CloseHandle(hook_change_finished_event); - } + WaitForSingleObject(hook_change_finished_event, INFINITE); + CloseHandle(hook_change_finished_event); }
void check_dinput_events(void) diff --git a/dlls/dinput8/tests/hid.c b/dlls/dinput8/tests/hid.c index cf50dd32fb9..87a2a9a7a3c 100644 --- a/dlls/dinput8/tests/hid.c +++ b/dlls/dinput8/tests/hid.c @@ -4758,9 +4758,6 @@ static void test_simple_joystick(void) todo_wine ok( hr == DIERR_UNSUPPORTED, "Escape returned: %#x\n", hr );
- /* FIXME: we have to wait a bit because Wine DInput internal thread keeps a reference */ - Sleep( 100 ); - ref = IDirectInputDevice8_Release( device ); ok( ref == 0, "Release returned %d\n", ref );
@@ -7227,9 +7224,6 @@ static void test_force_feedback_joystick( void ) ok( hr == DI_OK, "Unacquire returned: %#x\n", hr ); set_hid_expect( file, NULL, 0 );
- /* FIXME: we have to wait a bit because Wine DInput internal thread keeps a reference */ - Sleep( 100 ); - ref = IDirectInputDevice8_Release( device ); ok( ref == 0, "Release returned %d\n", ref );
This should fix the last BuildActionMap / EnumDevicesBySemantics test failures when a joystick is plugged in.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 8f57d32dee2..e2d2e551d02 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -651,21 +651,20 @@ static int id_to_offset(const DataFormat *df, int id) static DWORD semantic_to_obj_id(IDirectInputDeviceImpl* This, DWORD dwSemantic) { DWORD type = (0x0000ff00 & dwSemantic) >> 8; - DWORD offset = 0x000000ff & dwSemantic; - DWORD obj_instance = 0; + BOOL byofs = (dwSemantic & 0x80000000) != 0; + DWORD value = (dwSemantic & 0x000000ff); BOOL found = FALSE; + DWORD instance; int i;
- for (i = 0; i < This->data_format.wine_df->dwNumObjs; i++) + for (i = 0; i < This->data_format.wine_df->dwNumObjs && !found; i++) { LPDIOBJECTDATAFORMAT odf = dataformat_to_odf(This->data_format.wine_df, i);
- if (odf->dwOfs == offset) - { - obj_instance = DIDFT_GETINSTANCE(odf->dwType); - found = TRUE; - break; - } + if (byofs && value != odf->dwOfs) continue; + if (!byofs && value != DIDFT_GETINSTANCE(odf->dwType)) continue; + instance = DIDFT_GETINSTANCE(odf->dwType); + found = TRUE; }
if (!found) return 0; @@ -673,7 +672,7 @@ static DWORD semantic_to_obj_id(IDirectInputDeviceImpl* This, DWORD dwSemantic) if (type & DIDFT_AXIS) type = DIDFT_RELAXIS; if (type & DIDFT_BUTTON) type = DIDFT_PSHBUTTON;
- return type | (0x0000ff00 & (obj_instance << 8)); + return type | (0x0000ff00 & (instance << 8)); }
/*