Signed-off-by: Rémi Bernon rbernon@codeweavers.com ---
v2: Fix keyboard test failure: check for acquired state before checking for data format in GetDeviceState.
dlls/dinput/device.c | 39 ++++++++++++++++++++++++++++++++------ dlls/dinput/joystick_hid.c | 26 +++++++------------------ dlls/dinput/keyboard.c | 19 ++----------------- dlls/dinput/mouse.c | 20 ++----------------- 4 files changed, 44 insertions(+), 60 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index cdaa76cd504..2b2c4646e31 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -1186,6 +1186,24 @@ HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects( IDirectInputDevice8W *iface return DI_OK; }
+static HRESULT enum_object_filter_init( IDirectInputDeviceImpl *impl, DIPROPHEADER *filter ) +{ + DIDATAFORMAT *format = impl->data_format.wine_df; + int i, *offsets = impl->data_format.offsets; + + if (filter->dwHow > DIPH_BYUSAGE) return DIERR_INVALIDPARAM; + if (filter->dwHow == DIPH_BYUSAGE && !(impl->instance.dwDevType & DIDEVTYPE_HID)) return DIERR_UNSUPPORTED; + if (filter->dwHow != DIPH_BYOFFSET) return DI_OK; + + if (!offsets) return DIERR_NOTFOUND; + + for (i = 0; i < format->dwNumObjs; ++i) if (offsets[i] == filter->dwObj) break; + if (i == format->dwNumObjs) return DIERR_NOTFOUND; + + filter->dwObj = format->rgodf[i].dwOfs; + return DI_OK; +} + static BOOL CALLBACK find_object( const DIDEVICEOBJECTINSTANCEW *instance, void *context ) { *(DIDEVICEOBJECTINSTANCEW *)context = *instance; @@ -1198,6 +1216,7 @@ HRESULT WINAPI IDirectInputDevice2WImpl_GetProperty( IDirectInputDevice8W *iface IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); DWORD object_mask = DIDFT_AXIS | DIDFT_BUTTON | DIDFT_POV; DIDEVICEOBJECTINSTANCEW instance; + DIPROPHEADER filter; HRESULT hr;
TRACE( "iface %p, guid %s, header %p\n", iface, debugstr_guid( guid ), header ); @@ -1206,6 +1225,9 @@ HRESULT WINAPI IDirectInputDevice2WImpl_GetProperty( IDirectInputDevice8W *iface if (header->dwHeaderSize != sizeof(DIPROPHEADER)) return DIERR_INVALIDPARAM; if (!IS_DIPROP( guid )) return DI_OK;
+ filter = *header; + if (FAILED(hr = enum_object_filter_init( impl, &filter ))) return hr; + switch (LOWORD( guid )) { case (DWORD_PTR)DIPROP_PRODUCTNAME: @@ -1228,7 +1250,7 @@ HRESULT WINAPI IDirectInputDevice2WImpl_GetProperty( IDirectInputDevice8W *iface case (DWORD_PTR)DIPROP_RANGE: if (header->dwSize != sizeof(DIPROPRANGE)) return DIERR_INVALIDPARAM; if (header->dwHow == DIPH_DEVICE) return DIERR_UNSUPPORTED; - hr = impl->vtbl->enum_objects( iface, header, object_mask, find_object, &instance ); + hr = impl->vtbl->enum_objects( iface, &filter, object_mask, find_object, &instance ); if (FAILED(hr)) return hr; if (hr == DIENUM_CONTINUE) return DIERR_NOTFOUND; if (!(instance.dwType & DIDFT_AXIS)) return DIERR_UNSUPPORTED; @@ -1239,7 +1261,7 @@ HRESULT WINAPI IDirectInputDevice2WImpl_GetProperty( IDirectInputDevice8W *iface case (DWORD_PTR)DIPROP_GRANULARITY: if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; if (header->dwHow == DIPH_DEVICE) return DIERR_UNSUPPORTED; - hr = impl->vtbl->enum_objects( iface, header, object_mask, find_object, &instance ); + hr = impl->vtbl->enum_objects( iface, &filter, object_mask, find_object, &instance ); if (FAILED(hr)) return hr; if (hr == DIENUM_CONTINUE) return DIERR_NOTFOUND; if (!(instance.dwType & DIDFT_AXIS)) return DIERR_UNSUPPORTED; @@ -1247,7 +1269,7 @@ HRESULT WINAPI IDirectInputDevice2WImpl_GetProperty( IDirectInputDevice8W *iface
case (DWORD_PTR)DIPROP_KEYNAME: if (header->dwSize != sizeof(DIPROPSTRING)) return DIERR_INVALIDPARAM; - hr = impl->vtbl->enum_objects( iface, header, object_mask, find_object, &instance ); + hr = impl->vtbl->enum_objects( iface, &filter, object_mask, find_object, &instance ); if (FAILED(hr)) return hr; if (hr == DIENUM_CONTINUE) return DIERR_NOTFOUND; if (!(instance.dwType & DIDFT_BUTTON)) return DIERR_UNSUPPORTED; @@ -1317,6 +1339,7 @@ HRESULT WINAPI IDirectInputDevice2WImpl_SetProperty( IDirectInputDevice8W *iface { struct set_object_property_params params = {.iface = iface, .header = header, .property = LOWORD( guid )}; IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); + DIPROPHEADER filter; HRESULT hr;
TRACE( "iface %p, guid %s, header %p\n", iface, debugstr_guid( guid ), header ); @@ -1325,6 +1348,9 @@ HRESULT WINAPI IDirectInputDevice2WImpl_SetProperty( IDirectInputDevice8W *iface if (header->dwHeaderSize != sizeof(DIPROPHEADER)) return DIERR_INVALIDPARAM; if (!IS_DIPROP( guid )) return DI_OK;
+ filter = *header; + if (FAILED(hr = enum_object_filter_init( impl, &filter ))) return hr; + switch (LOWORD( guid )) { case (DWORD_PTR)DIPROP_RANGE: @@ -1332,7 +1358,7 @@ HRESULT WINAPI IDirectInputDevice2WImpl_SetProperty( IDirectInputDevice8W *iface const DIPROPRANGE *value = (const DIPROPRANGE *)header; if (header->dwSize != sizeof(DIPROPRANGE)) return DIERR_INVALIDPARAM; if (value->lMin > value->lMax) return DIERR_INVALIDPARAM; - hr = impl->vtbl->enum_objects( iface, header, DIDFT_AXIS, set_object_property, ¶ms ); + hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_AXIS, set_object_property, ¶ms ); if (FAILED(hr)) return hr; return DI_OK; } @@ -1342,7 +1368,7 @@ HRESULT WINAPI IDirectInputDevice2WImpl_SetProperty( IDirectInputDevice8W *iface const DIPROPDWORD *value = (const DIPROPDWORD *)header; if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; if (value->dwData > 10000) return DIERR_INVALIDPARAM; - hr = impl->vtbl->enum_objects( iface, header, DIDFT_AXIS, set_object_property, ¶ms ); + hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_AXIS, set_object_property, ¶ms ); if (FAILED(hr)) return hr; return DI_OK; } @@ -1473,7 +1499,7 @@ HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo( IDirectInputDevice8W *ifa DWORD obj, DWORD how ) { IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); - const DIPROPHEADER filter = + DIPROPHEADER filter = { .dwSize = sizeof(filter), .dwHeaderSize = sizeof(filter), @@ -1488,6 +1514,7 @@ HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo( IDirectInputDevice8W *ifa if (instance->dwSize != sizeof(DIDEVICEOBJECTINSTANCE_DX3W) && instance->dwSize != sizeof(DIDEVICEOBJECTINSTANCEW)) return DIERR_INVALIDPARAM; if (how == DIPH_DEVICE) return DIERR_INVALIDPARAM; + if (FAILED(hr = enum_object_filter_init( impl, &filter ))) return hr;
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_ALL, get_object_info, instance ); if (FAILED(hr)) return hr; diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 3dc43c450e4..2dec33e3ccd 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -392,28 +392,16 @@ static void set_axis_type( DIDEVICEOBJECTINSTANCEW *instance, BOOL *seen, DWORD seen[i] = TRUE; }
-static BOOL enum_objects( struct hid_joystick *impl, const DIPROPHEADER *header, DWORD flags, +static BOOL enum_objects( struct hid_joystick *impl, const DIPROPHEADER *filter, DWORD flags, enum_object_callback callback, void *data ) { - DWORD collection = 0, object = 0, axis = 0, button = 0, pov = 0, value_ofs = 0, button_ofs = 0, i, j; + DWORD collection = 0, object = 0, axis = 0, button = 0, pov = 0, value_ofs = 0, button_ofs = 0, j; struct hid_preparsed_data *preparsed = (struct hid_preparsed_data *)impl->preparsed; DIDEVICEOBJECTINSTANCEW instance = {.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW)}; struct hid_value_caps *caps, *caps_end, *nary, *nary_end, *effect_caps; - DIDATAFORMAT *format = impl->base.data_format.wine_df; - int *offsets = impl->base.data_format.offsets; struct hid_collection_node *node, *node_end; - DIPROPHEADER filter = *header; BOOL ret, seen_axis[6] = {0};
- if (filter.dwHow == DIPH_BYOFFSET) - { - if (!offsets) return DIENUM_CONTINUE; - for (i = 0; i < format->dwNumObjs; ++i) - if (offsets[i] == filter.dwObj) break; - if (i == format->dwNumObjs) return DIENUM_CONTINUE; - filter.dwObj = format->rgodf[i].dwOfs; - } - button_ofs += impl->caps.NumberInputValueCaps * sizeof(LONG); button_ofs += impl->caps.NumberOutputValueCaps * sizeof(LONG); button_ofs += impl->caps.NumberFeatureValueCaps * sizeof(LONG); @@ -489,7 +477,7 @@ static BOOL enum_objects( struct hid_joystick *impl, const DIPROPHEADER *header, instance.dwDimension = caps->units; instance.wExponent = caps->units_exp; check_pid_effect_axis_caps( impl, &instance ); - ret = enum_object( impl, &filter, flags, callback, caps, &instance, data ); + ret = enum_object( impl, filter, flags, callback, caps, &instance, data ); if (ret != DIENUM_CONTINUE) return ret; value_ofs += sizeof(LONG); object++; @@ -532,7 +520,7 @@ static BOOL enum_objects( struct hid_joystick *impl, const DIPROPHEADER *header, instance.wCollectionNumber = caps->link_collection; instance.dwDimension = caps->units; instance.wExponent = caps->units_exp; - ret = enum_object( impl, &filter, flags, callback, caps, &instance, data ); + ret = enum_object( impl, filter, flags, callback, caps, &instance, data ); if (ret != DIENUM_CONTINUE) return ret; button_ofs++; object++; @@ -567,7 +555,7 @@ static BOOL enum_objects( struct hid_joystick *impl, const DIPROPHEADER *header, instance.wCollectionNumber = nary->link_collection; instance.dwDimension = caps->units; instance.wExponent = caps->units_exp; - ret = enum_object( impl, &filter, flags, callback, nary, &instance, data ); + ret = enum_object( impl, filter, flags, callback, nary, &instance, data ); if (ret != DIENUM_CONTINUE) return ret; button_ofs++; } @@ -586,7 +574,7 @@ static BOOL enum_objects( struct hid_joystick *impl, const DIPROPHEADER *header, instance.wCollectionNumber = caps->link_collection; instance.dwDimension = caps->units; instance.wExponent = caps->units_exp; - ret = enum_object( impl, &filter, flags, callback, caps, &instance, data ); + ret = enum_object( impl, filter, flags, callback, caps, &instance, data ); if (ret != DIENUM_CONTINUE) return ret;
if (caps->flags & HID_VALUE_CAPS_IS_BUTTON) button_ofs++; @@ -612,7 +600,7 @@ static BOOL enum_objects( struct hid_joystick *impl, const DIPROPHEADER *header, instance.wCollectionNumber = node->parent; instance.dwDimension = 0; instance.wExponent = 0; - ret = enum_object( impl, &filter, flags, callback, NULL, &instance, data ); + ret = enum_object( impl, filter, flags, callback, NULL, &instance, data ); if (ret != DIENUM_CONTINUE) return ret; } } diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index 0c2a1b839ff..ad91c948fbc 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -302,7 +302,7 @@ static BOOL try_enum_object( const DIPROPHEADER *filter, DWORD flags, LPDIENUMDE return DIENUM_CONTINUE; }
-static HRESULT keyboard_internal_enum_objects( IDirectInputDevice8W *iface, const DIPROPHEADER *header, DWORD flags, +static HRESULT keyboard_internal_enum_objects( IDirectInputDevice8W *iface, const DIPROPHEADER *filter, DWORD flags, LPDIENUMDEVICEOBJECTSCALLBACKW callback, void *context ) { SysKeyboardImpl *impl = impl_from_IDirectInputDevice8W( iface ); @@ -314,31 +314,16 @@ static HRESULT keyboard_internal_enum_objects( IDirectInputDevice8W *iface, cons .dwOfs = DIK_ESCAPE, .dwType = DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE( DIK_ESCAPE ), }; - DIDATAFORMAT *format = impl->base.data_format.wine_df; - int *offsets = impl->base.data_format.offsets; - DIPROPHEADER filter = *header; DWORD i, dik; BOOL ret;
- if (header->dwHow != DIPH_DEVICE && header->dwHow != DIPH_BYOFFSET && header->dwHow != DIPH_BYID) - return DIERR_UNSUPPORTED; - - if (filter.dwHow == DIPH_BYOFFSET) - { - if (!offsets) return DIENUM_CONTINUE; - for (i = 0; i < format->dwNumObjs; ++i) - if (offsets[i] == filter.dwObj) break; - if (i == format->dwNumObjs) return DIENUM_CONTINUE; - filter.dwObj = format->rgodf[i].dwOfs; - } - for (i = 0; i < 512; ++i) { if (!GetKeyNameTextW( i << 16, instance.tszName, ARRAY_SIZE(instance.tszName) )) continue; if (!(dik = map_dik_code( i, 0, subtype, impl->base.dinput->dwVersion ))) continue; instance.dwOfs = dik; instance.dwType = DIDFT_PSHBUTTON | DIDFT_MAKEINSTANCE( dik ); - ret = try_enum_object( &filter, flags, callback, &instance, context ); + ret = try_enum_object( filter, flags, callback, &instance, context ); if (ret != DIENUM_CONTINUE) return DIENUM_STOP; }
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 3553a5af94d..5b3ec2d1f20 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -575,7 +575,7 @@ static BOOL try_enum_object( const DIPROPHEADER *filter, DWORD flags, LPDIENUMDE return DIENUM_CONTINUE; }
-static HRESULT mouse_internal_enum_objects( IDirectInputDevice8W *iface, const DIPROPHEADER *header, DWORD flags, +static HRESULT mouse_internal_enum_objects( IDirectInputDevice8W *iface, const DIPROPHEADER *filter, DWORD flags, LPDIENUMDEVICEOBJECTSCALLBACKW callback, void *context ) { DIDEVICEOBJECTINSTANCEW instances[] = @@ -640,28 +640,12 @@ static HRESULT mouse_internal_enum_objects( IDirectInputDevice8W *iface, const D .tszName = L"Button 4", }, }; - SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface ); - DIDATAFORMAT *format = impl->base.data_format.wine_df; - int *offsets = impl->base.data_format.offsets; - DIPROPHEADER filter = *header; BOOL ret; DWORD i;
- if (header->dwHow != DIPH_DEVICE && header->dwHow != DIPH_BYOFFSET && header->dwHow != DIPH_BYID) - return DIERR_UNSUPPORTED; - - if (filter.dwHow == DIPH_BYOFFSET) - { - if (!offsets) return DIENUM_CONTINUE; - for (i = 0; i < format->dwNumObjs; ++i) - if (offsets[i] == filter.dwObj) break; - if (i == format->dwNumObjs) return DIENUM_CONTINUE; - filter.dwObj = format->rgodf[i].dwOfs; - } - for (i = 0; i < ARRAY_SIZE(instances); ++i) { - ret = try_enum_object( &filter, flags, callback, instances + i, context ); + ret = try_enum_object( filter, flags, callback, instances + i, context ); if (ret != DIENUM_CONTINUE) return DIENUM_STOP; }
With a new internal poll callback for mouse and keyboard Wine-specific message peeking behavior.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 12 ++++++++---- dlls/dinput/device_private.h | 1 + dlls/dinput/joystick_hid.c | 15 ++------------- dlls/dinput/keyboard.c | 7 +++++++ dlls/dinput/mouse.c | 7 +++++++ 5 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 2b2c4646e31..c31166b8248 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -1661,13 +1661,17 @@ HRESULT WINAPI IDirectInputDevice2WImpl_Escape(LPDIRECTINPUTDEVICE8W iface, LPDI return DI_OK; }
-HRESULT WINAPI IDirectInputDevice2WImpl_Poll(LPDIRECTINPUTDEVICE8W iface) +HRESULT WINAPI IDirectInputDevice2WImpl_Poll( IDirectInputDevice8W *iface ) { - IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface); + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); + HRESULT hr = DI_NOEFFECT;
- if (!This->acquired) return DIERR_NOTACQUIRED; + EnterCriticalSection( &impl->crit ); + if (!impl->acquired) hr = DIERR_NOTACQUIRED; + LeaveCriticalSection( &impl->crit ); + if (hr != DI_OK) return hr;
- check_dinput_events(); + if (impl->vtbl->poll) return impl->vtbl->poll( iface ); return DI_OK; }
diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index da1a90fda42..92b0320520b 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -57,6 +57,7 @@ typedef HRESULT dinput_device_read_state( IDirectInputDevice8W *iface );
struct dinput_device_vtbl { + HRESULT (*poll)( IDirectInputDevice8W *iface ); HRESULT (*read)( IDirectInputDevice8W *iface ); HRESULT (*acquire)( IDirectInputDevice8W *iface ); HRESULT (*unacquire)( IDirectInputDevice8W *iface ); diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 2dec33e3ccd..798243d85fc 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -1162,18 +1162,6 @@ static HRESULT WINAPI hid_joystick_EnumCreatedEffectObjects( IDirectInputDevice8 return DI_OK; }
-static HRESULT WINAPI hid_joystick_Poll( IDirectInputDevice8W *iface ) -{ - struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface ); - HRESULT hr = DI_NOEFFECT; - - EnterCriticalSection( &impl->base.crit ); - if (!impl->base.acquired) hr = DIERR_NOTACQUIRED; - LeaveCriticalSection( &impl->base.crit ); - - return hr; -} - static const IDirectInputDevice8WVtbl hid_joystick_vtbl = { /*** IUnknown methods ***/ @@ -1204,7 +1192,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl = hid_joystick_SendForceFeedbackCommand, hid_joystick_EnumCreatedEffectObjects, IDirectInputDevice2WImpl_Escape, - hid_joystick_Poll, + IDirectInputDevice2WImpl_Poll, IDirectInputDevice2WImpl_SendDeviceData, /*** IDirectInputDevice7 methods ***/ IDirectInputDevice7WImpl_EnumEffectsInFile, @@ -1432,6 +1420,7 @@ static HRESULT hid_joystick_internal_enum_objects( IDirectInputDevice8W *iface,
static const struct dinput_device_vtbl hid_joystick_internal_vtbl = { + NULL, hid_joystick_internal_read, hid_joystick_internal_acquire, hid_joystick_internal_unacquire, diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index ad91c948fbc..a8f831e7597 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -270,6 +270,12 @@ static HRESULT WINAPI SysKeyboardWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W ifac return DI_OK; }
+static HRESULT keyboard_internal_poll( IDirectInputDevice8W *iface ) +{ + check_dinput_events(); + return DI_OK; +} + static HRESULT keyboard_internal_acquire( IDirectInputDevice8W *iface ) { return DI_OK; @@ -353,6 +359,7 @@ static HRESULT keyboard_internal_set_property( IDirectInputDevice8W *iface, DWOR
static const struct dinput_device_vtbl keyboard_internal_vtbl = { + keyboard_internal_poll, NULL, keyboard_internal_acquire, keyboard_internal_unacquire, diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 5b3ec2d1f20..5933d7e5f0f 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -490,6 +490,12 @@ static HRESULT WINAPI SysMouseWImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface, return res; }
+static HRESULT mouse_internal_poll( IDirectInputDevice8W *iface ) +{ + check_dinput_events(); + return DI_OK; +} + static HRESULT mouse_internal_acquire( IDirectInputDevice8W *iface ) { SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface ); @@ -683,6 +689,7 @@ static HRESULT mouse_internal_set_property( IDirectInputDevice8W *iface, DWORD p
static const struct dinput_device_vtbl mouse_internal_vtbl = { + mouse_internal_poll, NULL, mouse_internal_acquire, mouse_internal_unacquire,
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/mouse.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-)
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 5933d7e5f0f..7b8402b2bf5 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -472,27 +472,14 @@ static HRESULT WINAPI SysMouseWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface, } LeaveCriticalSection(&This->base.crit);
- warp_check( This, FALSE ); return DI_OK; }
-/****************************************************************************** - * GetDeviceData : gets buffered input data. - */ -static HRESULT WINAPI SysMouseWImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface, - DWORD dodsize, LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags) -{ - SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface); - HRESULT res; - - res = IDirectInputDevice2WImpl_GetDeviceData(iface, dodsize, dod, entries, flags); - if (SUCCEEDED(res)) warp_check( This, FALSE ); - return res; -} - static HRESULT mouse_internal_poll( IDirectInputDevice8W *iface ) { + SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface ); check_dinput_events(); + warp_check( impl, FALSE ); return DI_OK; }
@@ -710,7 +697,7 @@ static const IDirectInputDevice8WVtbl SysMouseWvt = IDirectInputDevice2WImpl_Acquire, IDirectInputDevice2WImpl_Unacquire, SysMouseWImpl_GetDeviceState, - SysMouseWImpl_GetDeviceData, + IDirectInputDevice2WImpl_GetDeviceData, IDirectInputDevice2WImpl_SetDataFormat, IDirectInputDevice2WImpl_SetEventNotification, IDirectInputDevice2WImpl_SetCooperativeLevel,
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 41 ++++++++++++++++++++++++++++++++++++ dlls/dinput/device_private.h | 1 + dlls/dinput/joystick_hid.c | 18 +--------------- dlls/dinput/keyboard.c | 31 +-------------------------- dlls/dinput/mouse.c | 35 +----------------------------- 5 files changed, 45 insertions(+), 81 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index c31166b8248..ef77826ce25 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -1522,6 +1522,47 @@ HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo( IDirectInputDevice8W *ifa return DI_OK; }
+static BOOL CALLBACK reset_axis_data( const DIDEVICEOBJECTINSTANCEW *instance, void *data ) +{ + *(ULONG *)((char *)data + instance->dwOfs) = 0; + return DIENUM_CONTINUE; +} + +HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceState( IDirectInputDevice8W *iface, DWORD size, void *data ) +{ + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); + DIPROPHEADER filter = + { + .dwSize = sizeof(filter), + .dwHeaderSize = sizeof(filter), + .dwHow = DIPH_DEVICE, + .dwObj = 0, + }; + HRESULT hr; + + TRACE( "iface %p, size %u, data %p.\n", iface, size, data ); + + if (!data) return DIERR_INVALIDPARAM; + + IDirectInputDevice2_Poll( iface ); + + EnterCriticalSection( &impl->crit ); + if (!impl->acquired) + hr = DIERR_NOTACQUIRED; + else if (size != impl->data_format.user_df->dwDataSize) + hr = DIERR_INVALIDPARAM; + else + { + fill_DataFormat( data, size, impl->device_state, &impl->data_format ); + if (!(impl->data_format.user_df->dwFlags & DIDF_ABSAXIS)) + impl->vtbl->enum_objects( iface, &filter, DIDFT_RELAXIS, reset_axis_data, impl->device_state ); + hr = DI_OK; + } + LeaveCriticalSection( &impl->crit ); + + return hr; +} + HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags) { diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 92b0320520b..d918403ef67 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -157,6 +157,7 @@ extern HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(LPDIRECTINPUTDEVICE LPDIDEVICEOBJECTINSTANCEW pdidoi, DWORD dwObj, DWORD dwHow) DECLSPEC_HIDDEN; +extern HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceState( IDirectInputDevice8W *iface, DWORD len, void *ptr ); extern HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags) DECLSPEC_HIDDEN; extern HRESULT WINAPI IDirectInputDevice2WImpl_RunControlPanel(LPDIRECTINPUTDEVICE8W iface, HWND hwndOwner, DWORD dwFlags) DECLSPEC_HIDDEN; diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 798243d85fc..6dc44c5731e 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -818,22 +818,6 @@ static HRESULT hid_joystick_internal_unacquire( IDirectInputDevice8W *iface ) return DI_OK; }
-static HRESULT WINAPI hid_joystick_GetDeviceState( IDirectInputDevice8W *iface, DWORD len, void *ptr ) -{ - struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface ); - HRESULT hr = DI_OK; - - if (!ptr) return DIERR_INVALIDPARAM; - if (len != impl->base.data_format.user_df->dwDataSize) return DIERR_INVALIDPARAM; - - EnterCriticalSection( &impl->base.crit ); - if (!impl->base.acquired) hr = DIERR_NOTACQUIRED; - else fill_DataFormat( ptr, len, impl->base.device_state, &impl->base.data_format ); - LeaveCriticalSection( &impl->base.crit ); - - return hr; -} - static HRESULT hid_joystick_effect_create( struct hid_joystick *joystick, IDirectInputEffect **out );
static HRESULT WINAPI hid_joystick_CreateEffect( IDirectInputDevice8W *iface, const GUID *guid, @@ -1175,7 +1159,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl = IDirectInputDevice2WImpl_SetProperty, IDirectInputDevice2WImpl_Acquire, IDirectInputDevice2WImpl_Unacquire, - hid_joystick_GetDeviceState, + IDirectInputDevice2WImpl_GetDeviceState, IDirectInputDevice2WImpl_GetDeviceData, IDirectInputDevice2WImpl_SetDataFormat, IDirectInputDevice2WImpl_SetEventNotification, diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index a8f831e7597..75a2079f5fe 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -241,35 +241,6 @@ const struct dinput_device keyboard_device = { keyboarddev_create_device };
-static HRESULT WINAPI SysKeyboardWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface, DWORD len, LPVOID ptr) -{ - SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface); - DWORD i; - - TRACE("(%p)->(%d,%p)\n", This, len, ptr); - - if (!This->base.acquired) return DIERR_NOTACQUIRED; - - if (len != This->base.data_format.user_df->dwDataSize ) - return DIERR_INVALIDPARAM; - - check_dinput_events(); - - EnterCriticalSection(&This->base.crit); - - if (TRACE_ON(dinput)) - { - TRACE( "pressed keys:" ); - for (i = 0; i < len; i++) if (This->base.device_state[i]) TRACE( " %02x", i ); - TRACE( "\n" ); - } - - fill_DataFormat( ptr, len, This->base.device_state, &This->base.data_format ); - LeaveCriticalSection(&This->base.crit); - - return DI_OK; -} - static HRESULT keyboard_internal_poll( IDirectInputDevice8W *iface ) { check_dinput_events(); @@ -379,7 +350,7 @@ static const IDirectInputDevice8WVtbl SysKeyboardWvt = IDirectInputDevice2WImpl_SetProperty, IDirectInputDevice2WImpl_Acquire, IDirectInputDevice2WImpl_Unacquire, - SysKeyboardWImpl_GetDeviceState, + IDirectInputDevice2WImpl_GetDeviceState, IDirectInputDevice2WImpl_GetDeviceData, IDirectInputDevice2WImpl_SetDataFormat, IDirectInputDevice2WImpl_SetEventNotification, diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 7b8402b2bf5..69feb259d60 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -442,39 +442,6 @@ static void warp_check( SysMouseImpl* This, BOOL force ) } }
-/****************************************************************************** - * GetDeviceState : returns the "state" of the mouse. - * - * For the moment, only the "standard" return structure (DIMOUSESTATE) is - * supported. - */ -static HRESULT WINAPI SysMouseWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface, DWORD len, LPVOID ptr) -{ - SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface); - DIMOUSESTATE2 *state = (DIMOUSESTATE2 *)This->base.device_state; - TRACE("(%p)->(%u,%p)\n", This, len, ptr); - - if(This->base.acquired == 0) return DIERR_NOTACQUIRED; - - check_dinput_events(); - - EnterCriticalSection(&This->base.crit); - - /* Copy the current mouse state */ - fill_DataFormat( ptr, len, state, &This->base.data_format ); - - /* Initialize the buffer when in relative mode */ - if (!(This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS)) - { - state->lX = 0; - state->lY = 0; - state->lZ = 0; - } - LeaveCriticalSection(&This->base.crit); - - return DI_OK; -} - static HRESULT mouse_internal_poll( IDirectInputDevice8W *iface ) { SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface ); @@ -696,7 +663,7 @@ static const IDirectInputDevice8WVtbl SysMouseWvt = IDirectInputDevice2WImpl_SetProperty, IDirectInputDevice2WImpl_Acquire, IDirectInputDevice2WImpl_Unacquire, - SysMouseWImpl_GetDeviceState, + IDirectInputDevice2WImpl_GetDeviceState, IDirectInputDevice2WImpl_GetDeviceData, IDirectInputDevice2WImpl_SetDataFormat, IDirectInputDevice2WImpl_SetEventNotification,
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 30 +++++++++++------ dlls/dinput/device_private.h | 2 ++ dlls/dinput/joystick_hid.c | 62 ++++++++++++++---------------------- dlls/dinput/keyboard.c | 1 + dlls/dinput/mouse.c | 1 + 5 files changed, 48 insertions(+), 48 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index ef77826ce25..8858bfa26bb 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -1049,15 +1049,11 @@ HRESULT WINAPI IDirectInputDevice2WImpl_SetEventNotification(LPDIRECTINPUTDEVICE return DI_OK; }
- -ULONG WINAPI IDirectInputDevice2WImpl_Release(LPDIRECTINPUTDEVICE8W iface) +void direct_input_device_destroy( IDirectInputDevice8W *iface ) { IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface); - ULONG ref = InterlockedDecrement(&(This->ref)); - - TRACE("(%p) ref %d\n", This, ref);
- if (ref) return ref; + TRACE( "iface %p.\n", iface );
IDirectInputDevice_Unacquire(iface); /* Reset the FF state, free all effects, etc */ @@ -1078,6 +1074,20 @@ ULONG WINAPI IDirectInputDevice2WImpl_Release(LPDIRECTINPUTDEVICE8W iface) DeleteCriticalSection(&This->crit);
free( This ); +} + +ULONG WINAPI IDirectInputDevice2WImpl_Release( IDirectInputDevice8W *iface ) +{ + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + + TRACE( "iface %p, ref %u.\n", iface, ref ); + + if (!ref) + { + if (impl->vtbl->release) impl->vtbl->release( iface ); + else direct_input_device_destroy( iface ); + }
return ref; } @@ -1132,11 +1142,11 @@ HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(LPDIRECTINPUTDEVICE8W ifa return E_NOINTERFACE; }
-ULONG WINAPI IDirectInputDevice2WImpl_AddRef(LPDIRECTINPUTDEVICE8W iface) +ULONG WINAPI IDirectInputDevice2WImpl_AddRef( IDirectInputDevice8W *iface ) { - IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface); - ULONG ref = InterlockedIncrement(&This->ref); - TRACE( "(%p) ref %d\n", This, ref ); + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p, ref %u.\n", iface, ref ); return ref; }
diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index d918403ef67..bdac5b4a378 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -57,6 +57,7 @@ typedef HRESULT dinput_device_read_state( IDirectInputDevice8W *iface );
struct dinput_device_vtbl { + void (*release)( IDirectInputDevice8W *iface ); HRESULT (*poll)( IDirectInputDevice8W *iface ); HRESULT (*read)( IDirectInputDevice8W *iface ); HRESULT (*acquire)( IDirectInputDevice8W *iface ); @@ -116,6 +117,7 @@ struct IDirectInputDeviceImpl 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 HRESULT direct_input_device_init( IDirectInputDevice8W *iface ); +extern void direct_input_device_destroy( IDirectInputDevice8W *iface ); extern const IDirectInputDevice8AVtbl dinput_device_a_vtbl DECLSPEC_HIDDEN;
extern BOOL get_app_key(HKEY*, HKEY*) DECLSPEC_HIDDEN; diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 6dc44c5731e..bb75fa43efd 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -158,7 +158,7 @@ struct pid_set_ramp_force struct hid_joystick { IDirectInputDeviceImpl base; - LONG ref; + LONG internal_ref;
HANDLE device; OVERLAPPED read_ovl; @@ -608,45 +608,30 @@ static BOOL enum_objects( struct hid_joystick *impl, const DIPROPHEADER *filter, return DIENUM_CONTINUE; }
-static ULONG hid_joystick_private_incref( struct hid_joystick *impl ) +static void hid_joystick_internal_addref( IDirectInputDevice8W *iface ) { - return IDirectInputDevice2WImpl_AddRef( &impl->base.IDirectInputDevice8W_iface ); + struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface ); + ULONG ref = InterlockedIncrement( &impl->internal_ref ); + TRACE( "iface %p, internal ref %u.\n", iface, ref ); }
-static ULONG hid_joystick_private_decref( struct hid_joystick *impl ) +static void hid_joystick_internal_release( IDirectInputDevice8W *iface ) { - struct hid_joystick tmp = *impl; - ULONG ref; + struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface ); + ULONG ref = InterlockedDecrement( &impl->internal_ref ); + TRACE( "iface %p, internal ref %u.\n", iface, ref );
- if (!(ref = IDirectInputDevice2WImpl_Release( &impl->base.IDirectInputDevice8W_iface ))) + if (!ref) { - free( tmp.usages_buf ); - free( tmp.output_report_buf ); - free( tmp.input_report_buf ); - free( tmp.input_extra_caps ); - HidD_FreePreparsedData( tmp.preparsed ); - CloseHandle( tmp.base.read_event ); - CloseHandle( tmp.device ); + free( impl->usages_buf ); + free( impl->output_report_buf ); + free( impl->input_report_buf ); + free( impl->input_extra_caps ); + HidD_FreePreparsedData( impl->preparsed ); + CloseHandle( impl->base.read_event ); + CloseHandle( impl->device ); + direct_input_device_destroy( iface ); } - - return ref; -} - -static ULONG WINAPI hid_joystick_AddRef( IDirectInputDevice8W *iface ) -{ - struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface ); - ULONG ref = InterlockedIncrement( &impl->ref ); - TRACE( "iface %p, ref %u.\n", iface, ref ); - return ref; -} - -static ULONG WINAPI hid_joystick_Release( IDirectInputDevice8W *iface ) -{ - struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface ); - ULONG ref = InterlockedDecrement( &impl->ref ); - TRACE( "iface %p, ref %u.\n", iface, ref ); - if (!ref) hid_joystick_private_decref( impl ); - return ref; }
static HRESULT hid_joystick_internal_get_property( IDirectInputDevice8W *iface, DWORD property, DIPROPHEADER *header, @@ -1150,8 +1135,8 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl = { /*** IUnknown methods ***/ IDirectInputDevice2WImpl_QueryInterface, - hid_joystick_AddRef, - hid_joystick_Release, + IDirectInputDevice2WImpl_AddRef, + IDirectInputDevice2WImpl_Release, /*** IDirectInputDevice methods ***/ IDirectInputDevice2WImpl_GetCapabilities, IDirectInputDevice2WImpl_EnumObjects, @@ -1404,6 +1389,7 @@ static HRESULT hid_joystick_internal_enum_objects( IDirectInputDevice8W *iface,
static const struct dinput_device_vtbl hid_joystick_internal_vtbl = { + hid_joystick_internal_release, NULL, hid_joystick_internal_read, hid_joystick_internal_acquire, @@ -1979,7 +1965,7 @@ static HRESULT hid_joystick_create_device( IDirectInputImpl *dinput, const GUID &attrs, &impl->caps, dinput->dwVersion ); if (hr != DI_OK) goto failed;
- impl->ref = 1; + impl->internal_ref = 1; impl->base.instance = instance; impl->base.caps.dwDevType = instance.dwDevType; impl->attrs = attrs; @@ -2097,7 +2083,7 @@ static ULONG WINAPI hid_joystick_effect_Release( IDirectInputEffect *iface ) EnterCriticalSection( &impl->joystick->base.crit ); list_remove( &impl->entry ); LeaveCriticalSection( &impl->joystick->base.crit ); - hid_joystick_private_decref( impl->joystick ); + hid_joystick_internal_release( &impl->joystick->base.IDirectInputDevice8W_iface ); free( impl->type_specific_buf[1] ); free( impl->type_specific_buf[0] ); free( impl->effect_update_buf ); @@ -2934,7 +2920,7 @@ static HRESULT hid_joystick_effect_create( struct hid_joystick *joystick, IDirec impl->IDirectInputEffect_iface.lpVtbl = &hid_joystick_effect_vtbl; impl->ref = 1; impl->joystick = joystick; - hid_joystick_private_incref( joystick ); + hid_joystick_internal_addref( &joystick->base.IDirectInputDevice8W_iface );
EnterCriticalSection( &joystick->base.crit ); list_add_tail( &joystick->effect_list, &impl->entry ); diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index 75a2079f5fe..f17dc89ac16 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -330,6 +330,7 @@ static HRESULT keyboard_internal_set_property( IDirectInputDevice8W *iface, DWOR
static const struct dinput_device_vtbl keyboard_internal_vtbl = { + NULL, keyboard_internal_poll, NULL, keyboard_internal_acquire, diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 69feb259d60..7fafa7696a7 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -643,6 +643,7 @@ static HRESULT mouse_internal_set_property( IDirectInputDevice8W *iface, DWORD p
static const struct dinput_device_vtbl mouse_internal_vtbl = { + NULL, mouse_internal_poll, NULL, mouse_internal_acquire,