Value objects are always enumerated first, so offset / sizeof(LONG) can be safely used to index input_extra_caps array.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/joystick_hid.c | 89 ++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 37 deletions(-)
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index a6715463690..9c1f75ec9ee 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -73,6 +73,11 @@ static inline const char *debugstr_hid_collection_node( struct hid_collection_no
struct extra_caps { + LONG bit_size; + LONG logical_min; + LONG logical_max; + LONG range_min; + LONG range_max; LONG deadzone; LONG saturation; }; @@ -659,19 +664,18 @@ static ULONG WINAPI hid_joystick_Release( IDirectInputDevice8W *iface ) static BOOL get_property_prop_range( struct hid_joystick *impl, struct hid_value_caps *caps, DIDEVICEOBJECTINSTANCEW *instance, void *data ) { + struct extra_caps *extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG); DIPROPRANGE *value = data; - value->lMin = caps->physical_min; - value->lMax = caps->physical_max; + value->lMin = extra->range_min; + value->lMax = extra->range_max; return DIENUM_STOP; }
static BOOL get_property_prop_deadzone( struct hid_joystick *impl, struct hid_value_caps *caps, DIDEVICEOBJECTINSTANCEW *instance, void *data ) { - struct hid_preparsed_data *preparsed = (struct hid_preparsed_data *)impl->preparsed; - struct extra_caps *extra; + struct extra_caps *extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG); DIPROPDWORD *deadzone = data; - extra = impl->input_extra_caps + (caps - HID_INPUT_VALUE_CAPS( preparsed )); deadzone->dwData = extra->deadzone; return DIENUM_STOP; } @@ -679,10 +683,8 @@ static BOOL get_property_prop_deadzone( struct hid_joystick *impl, struct hid_va static BOOL get_property_prop_saturation( struct hid_joystick *impl, struct hid_value_caps *caps, DIDEVICEOBJECTINSTANCEW *instance, void *data ) { - struct hid_preparsed_data *preparsed = (struct hid_preparsed_data *)impl->preparsed; - struct extra_caps *extra; + struct extra_caps *extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG); DIPROPDWORD *saturation = data; - extra = impl->input_extra_caps + (caps - HID_INPUT_VALUE_CAPS( preparsed )); saturation->dwData = extra->saturation; return DIENUM_STOP; } @@ -781,22 +783,23 @@ static HRESULT WINAPI hid_joystick_GetProperty( IDirectInputDevice8W *iface, con static BOOL set_property_prop_range( struct hid_joystick *impl, struct hid_value_caps *caps, DIDEVICEOBJECTINSTANCEW *instance, void *data ) { + struct extra_caps *extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG); DIPROPRANGE *value = data; LONG tmp;
- caps->physical_min = value->lMin; - caps->physical_max = value->lMax; + extra->range_min = value->lMin; + extra->range_max = value->lMax;
if (instance->dwType & DIDFT_AXIS) { - if (!caps->physical_min) tmp = caps->physical_max / 2; - else tmp = round( (caps->physical_min + caps->physical_max) / 2.0 ); + if (!extra->range_min) tmp = extra->range_max / 2; + else tmp = round( (extra->range_min + extra->range_max) / 2.0 ); *(LONG *)(impl->base.device_state + instance->dwOfs) = tmp; } else if (instance->dwType & DIDFT_POV) { - tmp = caps->logical_max - caps->logical_min; - if (tmp > 0) caps->physical_max -= value->lMax / (tmp + 1); + tmp = extra->logical_max - extra->logical_min; + if (tmp > 0) extra->range_max -= value->lMax / (tmp + 1); *(LONG *)(impl->base.device_state + instance->dwOfs) = -1; } return DIENUM_CONTINUE; @@ -805,10 +808,8 @@ static BOOL set_property_prop_range( struct hid_joystick *impl, struct hid_value static BOOL set_property_prop_deadzone( struct hid_joystick *impl, struct hid_value_caps *caps, DIDEVICEOBJECTINSTANCEW *instance, void *data ) { - struct hid_preparsed_data *preparsed = (struct hid_preparsed_data *)impl->preparsed; - struct extra_caps *extra; + struct extra_caps *extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG); DIPROPDWORD *deadzone = data; - extra = impl->input_extra_caps + (caps - HID_INPUT_VALUE_CAPS( preparsed )); extra->deadzone = deadzone->dwData; return DIENUM_CONTINUE; } @@ -816,10 +817,8 @@ static BOOL set_property_prop_deadzone( struct hid_joystick *impl, struct hid_va static BOOL set_property_prop_saturation( struct hid_joystick *impl, struct hid_value_caps *caps, DIDEVICEOBJECTINSTANCEW *instance, void *data ) { - struct hid_preparsed_data *preparsed = (struct hid_preparsed_data *)impl->preparsed; - struct extra_caps *extra; + struct extra_caps *extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG); DIPROPDWORD *saturation = data; - extra = impl->input_extra_caps + (caps - HID_INPUT_VALUE_CAPS( preparsed )); extra->saturation = saturation->dwData; return DIENUM_CONTINUE; } @@ -1357,29 +1356,34 @@ static BOOL check_device_state_button( struct hid_joystick *impl, struct hid_val return DIENUM_CONTINUE; }
-static LONG sign_extend( ULONG value, struct hid_value_caps *caps ) +static LONG sign_extend( ULONG value, struct extra_caps *caps ) { UINT sign = 1 << (caps->bit_size - 1); if (sign <= 1 || caps->logical_min >= 0) return value; return value - ((value & sign) << 1); }
-static LONG scale_value( ULONG value, struct hid_value_caps *caps, LONG min, LONG max ) +static LONG scale_value( ULONG value, struct extra_caps *caps ) { - LONG tmp = sign_extend( value, caps ); - if (caps->logical_min > tmp || caps->logical_max < tmp) return -1; /* invalid / null value */ - return min + MulDiv( tmp - caps->logical_min, max - min, caps->logical_max - caps->logical_min ); + LONG tmp = sign_extend( value, caps ), log_min, log_max, phy_min, phy_max; + log_min = caps->logical_min; + log_max = caps->logical_max; + phy_min = caps->range_min; + phy_max = caps->range_max; + + if (log_min > tmp || log_max < tmp) return -1; /* invalid / null value */ + return phy_min + MulDiv( tmp - log_min, phy_max - phy_min, log_max - log_min ); }
-static LONG scale_axis_value( ULONG value, struct hid_value_caps *caps, struct extra_caps *extra ) +static LONG scale_axis_value( ULONG value, struct extra_caps *caps ) { LONG tmp = sign_extend( value, caps ), log_ctr, log_min, log_max, phy_ctr, phy_min, phy_max; ULONG bit_max = (1 << caps->bit_size) - 1;
log_min = caps->logical_min; log_max = caps->logical_max; - phy_min = caps->physical_min; - phy_max = caps->physical_max; + phy_min = caps->range_min; + phy_max = caps->range_max; /* xinput HID gamepad have bogus logical value range, let's use the bit range instead */ if (log_min == 0 && log_max == -1) log_max = bit_max;
@@ -1391,14 +1395,14 @@ static LONG scale_axis_value( ULONG value, struct hid_value_caps *caps, struct e tmp -= log_ctr; if (tmp <= 0) { - log_max = MulDiv( log_min - log_ctr, extra->deadzone, 10000 ); - log_min = MulDiv( log_min - log_ctr, extra->saturation, 10000 ); + log_max = MulDiv( log_min - log_ctr, caps->deadzone, 10000 ); + log_min = MulDiv( log_min - log_ctr, caps->saturation, 10000 ); phy_max = phy_ctr; } else { - log_min = MulDiv( log_max - log_ctr, extra->deadzone, 10000 ); - log_max = MulDiv( log_max - log_ctr, extra->saturation, 10000 ); + log_min = MulDiv( log_max - log_ctr, caps->deadzone, 10000 ); + log_max = MulDiv( log_max - log_ctr, caps->saturation, 10000 ); phy_min = phy_ctr; }
@@ -1410,24 +1414,22 @@ static LONG scale_axis_value( ULONG value, struct hid_value_caps *caps, struct e static BOOL read_device_state_value( struct hid_joystick *impl, struct hid_value_caps *caps, DIDEVICEOBJECTINSTANCEW *instance, void *data ) { - struct hid_preparsed_data *preparsed = (struct hid_preparsed_data *)impl->preparsed; + struct extra_caps *extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG); IDirectInputDevice8W *iface = &impl->base.IDirectInputDevice8W_iface; ULONG logical_value, report_len = impl->caps.InputReportByteLength; struct parse_device_state_params *params = data; char *report_buf = impl->input_report_buf; - struct extra_caps *extra; LONG old_value, value; NTSTATUS status;
if (instance->wReportId != impl->base.device_state_report_id) return DIENUM_CONTINUE;
- extra = impl->input_extra_caps + (caps - HID_INPUT_VALUE_CAPS( preparsed )); status = HidP_GetUsageValue( HidP_Input, instance->wUsagePage, 0, instance->wUsage, &logical_value, impl->preparsed, report_buf, report_len ); if (status != HIDP_STATUS_SUCCESS) WARN( "HidP_GetUsageValue %04x:%04x returned %#x\n", instance->wUsagePage, instance->wUsage, status ); - if (instance->dwType & DIDFT_AXIS) value = scale_axis_value( logical_value, caps, extra ); - else value = scale_value( logical_value, caps, caps->physical_min, caps->physical_max ); + if (instance->dwType & DIDFT_AXIS) value = scale_axis_value( logical_value, extra ); + else value = scale_value( logical_value, extra );
old_value = *(LONG *)(params->old_state + instance->dwOfs); *(LONG *)(impl->base.device_state + instance->dwOfs) = value; @@ -1807,6 +1809,18 @@ static HRESULT hid_joystick_enum_device( DWORD type, DWORD flags, DIDEVICEINSTAN return DI_OK; }
+static BOOL init_extra_caps( struct hid_joystick *impl, struct hid_value_caps *caps, + DIDEVICEOBJECTINSTANCEW *instance, void *data ) +{ + struct extra_caps *extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG); + extra->bit_size = caps->bit_size; + extra->logical_min = caps->logical_min; + extra->logical_max = caps->logical_max; + extra->range_min = caps->physical_min; + extra->range_max = caps->physical_max; + return DIENUM_CONTINUE; +} + static BOOL init_pid_reports( struct hid_joystick *impl, struct hid_value_caps *caps, DIDEVICEOBJECTINSTANCEW *instance, void *data ) { @@ -2124,6 +2138,7 @@ static HRESULT hid_joystick_create_device( IDirectInputImpl *dinput, const GUID size = preparsed->input_caps_count * sizeof(struct extra_caps); if (!(extra = calloc( 1, size ))) goto failed; impl->input_extra_caps = extra; + enum_objects( impl, &filter, DIDFT_AXIS | DIDFT_POV, init_extra_caps, NULL );
size = impl->caps.InputReportByteLength; if (!(buffer = malloc( size ))) goto failed;
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 128 ++++++++++++++++++++++++----------- dlls/dinput/device_private.h | 2 + dlls/dinput/joystick_hid.c | 105 ++++++++-------------------- dlls/dinput/keyboard.c | 58 +++++----------- dlls/dinput/mouse.c | 85 +++++++---------------- dlls/dinput8/tests/device.c | 35 ---------- dlls/dinput8/tests/hid.c | 1 - 7 files changed, 160 insertions(+), 254 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 7a8864a45d2..75ca6676bec 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -1186,59 +1186,105 @@ HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects( IDirectInputDevice8W *iface return DI_OK; }
-/****************************************************************************** - * GetProperty - */ +static BOOL CALLBACK find_object( const DIDEVICEOBJECTINSTANCEW *instance, void *context ) +{ + *(DIDEVICEOBJECTINSTANCEW *)context = *instance; + return DIENUM_STOP; +}
-HRESULT WINAPI IDirectInputDevice2WImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPDIPROPHEADER pdiph) +HRESULT WINAPI IDirectInputDevice2WImpl_GetProperty( IDirectInputDevice8W *iface, const GUID *guid, + DIPROPHEADER *header ) { - IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface); + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); + DWORD object_mask = DIDFT_AXIS | DIDFT_BUTTON | DIDFT_POV; + DIDEVICEOBJECTINSTANCEW instance; + HRESULT hr;
- TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(rguid), pdiph); - _dump_DIPROPHEADER(pdiph); + TRACE( "iface %p, guid %s, header %p\n", iface, debugstr_guid( guid ), header );
- if (!IS_DIPROP(rguid)) return DI_OK; + if (!header) return DIERR_INVALIDPARAM; + if (header->dwHeaderSize != sizeof(DIPROPHEADER)) return DIERR_INVALIDPARAM; + if (!IS_DIPROP( guid )) return DI_OK;
- switch (LOWORD(rguid)) + switch (LOWORD( guid )) { - case (DWORD_PTR) DIPROP_BUFFERSIZE: - { - LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph; - - if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; + case (DWORD_PTR)DIPROP_PRODUCTNAME: + case (DWORD_PTR)DIPROP_INSTANCENAME: + if (header->dwSize != sizeof(DIPROPSTRING)) return DIERR_INVALIDPARAM; + if (header->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED; + return impl->vtbl->get_property( iface, LOWORD( guid ), header, NULL ); + + case (DWORD_PTR)DIPROP_VIDPID: + case (DWORD_PTR)DIPROP_JOYSTICKID: + if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; + if (header->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED; + return impl->vtbl->get_property( iface, LOWORD( guid ), header, NULL ); + + case (DWORD_PTR)DIPROP_GUIDANDPATH: + if (header->dwSize != sizeof(DIPROPGUIDANDPATH)) return DIERR_INVALIDPARAM; + if (header->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED; + return impl->vtbl->get_property( iface, LOWORD( guid ), header, NULL ); + + 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 ); + if (FAILED(hr)) return hr; + if (hr == DIENUM_CONTINUE) return DIERR_NOTFOUND; + if (!(instance.dwType & DIDFT_AXIS)) return DIERR_UNSUPPORTED; + return impl->vtbl->get_property( iface, LOWORD( guid ), header, &instance ); + + case (DWORD_PTR)DIPROP_DEADZONE: + case (DWORD_PTR)DIPROP_SATURATION: + 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 ); + if (FAILED(hr)) return hr; + if (hr == DIENUM_CONTINUE) return DIERR_NOTFOUND; + if (!(instance.dwType & DIDFT_AXIS)) return DIERR_UNSUPPORTED; + return impl->vtbl->get_property( iface, LOWORD( guid ), header, &instance );
- pd->dwData = This->buffersize; - TRACE("buffersize = %d\n", pd->dwData); - break; - } - case (DWORD_PTR) DIPROP_USERNAME: - { - LPDIPROPSTRING ps = (LPDIPROPSTRING)pdiph; - struct DevicePlayer *device_player; + 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 ); + if (FAILED(hr)) return hr; + if (hr == DIENUM_CONTINUE) return DIERR_NOTFOUND; + if (!(instance.dwType & DIDFT_BUTTON)) return DIERR_UNSUPPORTED; + return impl->vtbl->get_property( iface, LOWORD( guid ), header, &instance );
- if (pdiph->dwSize != sizeof(DIPROPSTRING)) return DIERR_INVALIDPARAM; + case (DWORD_PTR)DIPROP_AUTOCENTER: + if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; + return DIERR_UNSUPPORTED;
- LIST_FOR_EACH_ENTRY(device_player, &This->dinput->device_players, - struct DevicePlayer, entry) + case (DWORD_PTR)DIPROP_BUFFERSIZE: + { + DIPROPDWORD *value = (DIPROPDWORD *)header; + if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; + value->dwData = impl->buffersize; + return DI_OK; + } + case (DWORD_PTR)DIPROP_USERNAME: + { + DIPROPSTRING *value = (DIPROPSTRING *)header; + struct DevicePlayer *device_player; + if (header->dwSize != sizeof(DIPROPSTRING)) return DIERR_INVALIDPARAM; + LIST_FOR_EACH_ENTRY( device_player, &impl->dinput->device_players, struct DevicePlayer, entry ) + { + if (IsEqualGUID( &device_player->instance_guid, &impl->guid )) { - if (IsEqualGUID(&device_player->instance_guid, &This->guid)) - { - if (*device_player->username) - { - lstrcpynW(ps->wsz, device_player->username, ARRAY_SIZE(ps->wsz)); - return DI_OK; - } - else break; - } + if (!*device_player->username) break; + lstrcpynW( value->wsz, device_player->username, ARRAY_SIZE(value->wsz) ); + return DI_OK; } - return S_FALSE; } - case (DWORD_PTR) DIPROP_VIDPID: - FIXME("DIPROP_VIDPID not implemented\n"); - return DIERR_UNSUPPORTED; - default: - FIXME("Unknown property %s\n", debugstr_guid(rguid)); - return DIERR_INVALIDPARAM; + return S_FALSE; + } + case (DWORD_PTR)DIPROP_CALIBRATION: + return DIERR_INVALIDPARAM; + default: + FIXME( "Unknown property %s\n", debugstr_guid( guid ) ); + return DIERR_UNSUPPORTED; }
return DI_OK; diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 8589eca41e3..e4290e5960b 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -62,6 +62,8 @@ struct dinput_device_vtbl HRESULT (*unacquire)( IDirectInputDevice8W *iface ); HRESULT (*enum_objects)( IDirectInputDevice8W *iface, const DIPROPHEADER *filter, DWORD flags, LPDIENUMDEVICEOBJECTSCALLBACKW callback, void *context ); + HRESULT (*get_property)( IDirectInputDevice8W *iface, DWORD property, DIPROPHEADER *header, + DIDEVICEOBJECTINSTANCEW *instance ); };
#define DEVICE_STATE_MAX_SIZE 1024 diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 9c1f75ec9ee..8c9218cd4e7 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -661,97 +661,56 @@ static ULONG WINAPI hid_joystick_Release( IDirectInputDevice8W *iface ) return ref; }
-static BOOL get_property_prop_range( struct hid_joystick *impl, struct hid_value_caps *caps, - DIDEVICEOBJECTINSTANCEW *instance, void *data ) -{ - struct extra_caps *extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG); - DIPROPRANGE *value = data; - value->lMin = extra->range_min; - value->lMax = extra->range_max; - return DIENUM_STOP; -} - -static BOOL get_property_prop_deadzone( struct hid_joystick *impl, struct hid_value_caps *caps, - DIDEVICEOBJECTINSTANCEW *instance, void *data ) -{ - struct extra_caps *extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG); - DIPROPDWORD *deadzone = data; - deadzone->dwData = extra->deadzone; - return DIENUM_STOP; -} - -static BOOL get_property_prop_saturation( struct hid_joystick *impl, struct hid_value_caps *caps, - DIDEVICEOBJECTINSTANCEW *instance, void *data ) -{ - struct extra_caps *extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG); - DIPROPDWORD *saturation = data; - saturation->dwData = extra->saturation; - return DIENUM_STOP; -} - -static BOOL get_property_prop_granularity( struct hid_joystick *impl, struct hid_value_caps *caps, - DIDEVICEOBJECTINSTANCEW *instance, void *data ) -{ - DIPROPDWORD *granularity = data; - granularity->dwData = 1; - return DIENUM_STOP; -} - -static HRESULT WINAPI hid_joystick_GetProperty( IDirectInputDevice8W *iface, const GUID *guid, - DIPROPHEADER *header ) +static HRESULT hid_joystick_internal_get_property( IDirectInputDevice8W *iface, DWORD property, DIPROPHEADER *header, + DIDEVICEOBJECTINSTANCEW *instance ) { struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface ); + struct extra_caps *extra = NULL;
- TRACE( "iface %p, guid %s, header %p\n", iface, debugstr_guid( guid ), header ); + if (instance) extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG);
- if (!header) return DIERR_INVALIDPARAM; - if (header->dwHeaderSize != sizeof(DIPROPHEADER)) return DIERR_INVALIDPARAM; - if (!IS_DIPROP( guid )) return DI_OK; - - switch (LOWORD( guid )) + switch (property) { case (DWORD_PTR)DIPROP_RANGE: - if (header->dwSize != sizeof(DIPROPRANGE)) return DIERR_INVALIDPARAM; - if (header->dwHow == DIPH_DEVICE) return DIERR_UNSUPPORTED; - if (enum_objects( impl, header, DIDFT_AXIS, get_property_prop_range, header ) == DIENUM_STOP) - return DI_OK; - return DIERR_NOTFOUND; + { + DIPROPRANGE *value = (DIPROPRANGE *)header; + value->lMin = extra->range_min; + value->lMax = extra->range_max; + return DI_OK; + } case (DWORD_PTR)DIPROP_DEADZONE: - if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; - if (header->dwHow == DIPH_DEVICE) return DIERR_UNSUPPORTED; - if (enum_objects( impl, header, DIDFT_AXIS, get_property_prop_deadzone, header ) == DIENUM_STOP) - return DI_OK; - return DIERR_NOTFOUND; + { + DIPROPDWORD *value = (DIPROPDWORD *)header; + value->dwData = extra->deadzone; + return DI_OK; + } case (DWORD_PTR)DIPROP_SATURATION: - if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; - if (header->dwHow == DIPH_DEVICE) return DIERR_UNSUPPORTED; - if (enum_objects( impl, header, DIDFT_AXIS, get_property_prop_saturation, header ) == DIENUM_STOP) - return DI_OK; - return DIERR_NOTFOUND; + { + DIPROPDWORD *value = (DIPROPDWORD *)header; + value->dwData = extra->saturation; + return DI_OK; + } case (DWORD_PTR)DIPROP_GRANULARITY: - if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; - if (header->dwHow == DIPH_DEVICE) return DIERR_UNSUPPORTED; - if (enum_objects( impl, header, DIDFT_AXIS, get_property_prop_granularity, header ) == DIENUM_STOP) - return DI_OK; - return DIERR_NOTFOUND; + { + DIPROPDWORD *value = (DIPROPDWORD *)header; + value->dwData = 1; + return DI_OK; + } case (DWORD_PTR)DIPROP_PRODUCTNAME: { DIPROPSTRING *value = (DIPROPSTRING *)header; - if (header->dwSize != sizeof(DIPROPSTRING)) return DIERR_INVALIDPARAM; 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->base.instance.tszInstanceName, MAX_PATH ); return DI_OK; } case (DWORD_PTR)DIPROP_VIDPID: { DIPROPDWORD *value = (DIPROPDWORD *)header; - if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; if (!impl->attrs.VendorID || !impl->attrs.ProductID) return DIERR_UNSUPPORTED; value->dwData = MAKELONG( impl->attrs.VendorID, impl->attrs.ProductID ); return DI_OK; @@ -759,25 +718,18 @@ static HRESULT WINAPI hid_joystick_GetProperty( IDirectInputDevice8W *iface, con case (DWORD_PTR)DIPROP_JOYSTICKID: { DIPROPDWORD *value = (DIPROPDWORD *)header; - if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; value->dwData = impl->base.instance.guidInstance.Data3; return DI_OK; } case (DWORD_PTR)DIPROP_GUIDANDPATH: { DIPROPGUIDANDPATH *value = (DIPROPGUIDANDPATH *)header; - if (header->dwSize != sizeof(DIPROPGUIDANDPATH)) return DIERR_INVALIDPARAM; lstrcpynW( value->wszPath, impl->device_path, MAX_PATH ); return DI_OK; } - case (DWORD_PTR)DIPROP_AUTOCENTER: - if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; - return DIERR_UNSUPPORTED; - default: - return IDirectInputDevice2WImpl_GetProperty( iface, guid, header ); }
- return DI_OK; + return DIERR_UNSUPPORTED; }
static BOOL set_property_prop_range( struct hid_joystick *impl, struct hid_value_caps *caps, @@ -1298,7 +1250,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl = /*** IDirectInputDevice methods ***/ IDirectInputDevice2WImpl_GetCapabilities, IDirectInputDevice2WImpl_EnumObjects, - hid_joystick_GetProperty, + IDirectInputDevice2WImpl_GetProperty, hid_joystick_SetProperty, IDirectInputDevice2WImpl_Acquire, IDirectInputDevice2WImpl_Unacquire, @@ -1551,6 +1503,7 @@ static const struct dinput_device_vtbl hid_joystick_internal_vtbl = hid_joystick_internal_acquire, hid_joystick_internal_unacquire, hid_joystick_internal_enum_objects, + hid_joystick_internal_get_property, };
static DWORD device_type_for_version( DWORD type, DWORD version ) diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index 0d1baec3807..bb1102e38eb 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -273,46 +273,6 @@ static HRESULT WINAPI SysKeyboardWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W ifac return DI_OK; }
-/****************************************************************************** - * GetProperty : Retrieves information about the input device. - */ -static HRESULT WINAPI SysKeyboardWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, - REFGUID rguid, LPDIPROPHEADER pdiph) -{ - SysKeyboardImpl *This = impl_from_IDirectInputDevice8W(iface); - - TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(rguid), pdiph); - _dump_DIPROPHEADER(pdiph); - - if (!IS_DIPROP(rguid)) return DI_OK; - - switch (LOWORD(rguid)) - { - case (DWORD_PTR)DIPROP_KEYNAME: - { - HRESULT hr; - LPDIPROPSTRING ps = (LPDIPROPSTRING)pdiph; - DIDEVICEOBJECTINSTANCEW didoi; - - if (pdiph->dwSize != sizeof(DIPROPSTRING)) - return DIERR_INVALIDPARAM; - - didoi.dwSize = sizeof(DIDEVICEOBJECTINSTANCEW); - - hr = IDirectInputDevice8_GetObjectInfo( iface, &didoi, ps->diph.dwObj, ps->diph.dwHow ); - if (hr == DI_OK) - memcpy(ps->wsz, didoi.tszName, sizeof(ps->wsz)); - return hr; - } - case (DWORD_PTR) DIPROP_VIDPID: - case (DWORD_PTR) DIPROP_RANGE: - return DIERR_UNSUPPORTED; - default: - return IDirectInputDevice2WImpl_GetProperty( iface, rguid, pdiph ); - } - return DI_OK; -} - static HRESULT keyboard_internal_acquire( IDirectInputDevice8W *iface ) { return DI_OK; @@ -388,12 +348,28 @@ static HRESULT keyboard_internal_enum_objects( IDirectInputDevice8W *iface, cons return DIENUM_CONTINUE; }
+static HRESULT keyboard_internal_get_property( IDirectInputDevice8W *iface, DWORD property, DIPROPHEADER *header, + DIDEVICEOBJECTINSTANCEW *instance ) +{ + switch (property) + { + case (DWORD_PTR)DIPROP_KEYNAME: + { + DIPROPSTRING *value = (DIPROPSTRING *)header; + lstrcpynW( value->wsz, instance->tszName, ARRAY_SIZE(value->wsz) ); + return DI_OK; + } + } + return DIERR_UNSUPPORTED; +} + static const struct dinput_device_vtbl keyboard_internal_vtbl = { NULL, keyboard_internal_acquire, keyboard_internal_unacquire, keyboard_internal_enum_objects, + keyboard_internal_get_property, };
static const IDirectInputDevice8WVtbl SysKeyboardWvt = @@ -403,7 +379,7 @@ static const IDirectInputDevice8WVtbl SysKeyboardWvt = IDirectInputDevice2WImpl_Release, IDirectInputDevice2WImpl_GetCapabilities, IDirectInputDevice2WImpl_EnumObjects, - SysKeyboardWImpl_GetProperty, + IDirectInputDevice2WImpl_GetProperty, IDirectInputDevice2WImpl_SetProperty, IDirectInputDevice2WImpl_Acquire, IDirectInputDevice2WImpl_Unacquire, diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 23570e1f906..f6aedda080a 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -495,65 +495,6 @@ static HRESULT WINAPI SysMouseWImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface, return res; }
-/****************************************************************************** - * GetProperty : get input device properties - */ -static HRESULT WINAPI SysMouseWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPDIPROPHEADER pdiph) -{ - SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface); - - TRACE("(%p) %s,%p\n", This, debugstr_guid(rguid), pdiph); - _dump_DIPROPHEADER(pdiph); - - if (IS_DIPROP(rguid)) { - switch (LOWORD(rguid)) { - case (DWORD_PTR) DIPROP_GRANULARITY: { - LPDIPROPDWORD pr = (LPDIPROPDWORD) pdiph; - - if ( - ((pdiph->dwHow == DIPH_BYOFFSET) && - ((pdiph->dwObj == DIMOFS_X) || - (pdiph->dwObj == DIMOFS_Y))) - || - ((pdiph->dwHow == DIPH_BYID) && - ((pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS)) || - (pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS)))) - ){ - /* Set granularity of X/Y Axis to 1. See MSDN on DIPROP_GRANULARITY */ - pr->dwData = 1; - } else { - /* We'll just assume that the app asks about the Z axis */ - pr->dwData = WHEEL_DELTA; - } - - break; - } - - case (DWORD_PTR) DIPROP_RANGE: { - LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph; - - if ((pdiph->dwHow == DIPH_BYID) && - ((pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS)) || - (pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS)))) { - /* Querying the range of either the X or the Y axis. As I do - not know the range, do as if the range were - unrestricted...*/ - pr->lMin = DIPROPRANGE_NOMIN; - pr->lMax = DIPROPRANGE_NOMAX; - } - - break; - } - case (DWORD_PTR) DIPROP_VIDPID: - return DIERR_UNSUPPORTED; - default: - return IDirectInputDevice2WImpl_GetProperty(iface, rguid, pdiph); - } - } - - return DI_OK; -} - static HRESULT mouse_internal_acquire( IDirectInputDevice8W *iface ) { SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface ); @@ -731,12 +672,36 @@ static HRESULT mouse_internal_enum_objects( IDirectInputDevice8W *iface, const D return DIENUM_CONTINUE; }
+static HRESULT mouse_internal_get_property( IDirectInputDevice8W *iface, DWORD property, DIPROPHEADER *header, + DIDEVICEOBJECTINSTANCEW *instance ) +{ + switch (property) + { + case (DWORD_PTR)DIPROP_RANGE: + { + DIPROPRANGE *range = (DIPROPRANGE *)header; + range->lMin = DIPROPRANGE_NOMIN; + range->lMax = DIPROPRANGE_NOMAX; + return DI_OK; + } + case (DWORD_PTR)DIPROP_GRANULARITY: + { + DIPROPDWORD *value = (DIPROPDWORD *)header; + if (instance->dwType == DIMOFS_Z) value->dwData = WHEEL_DELTA; + else value->dwData = 1; + return DI_OK; + } + } + return DIERR_UNSUPPORTED; +} + static const struct dinput_device_vtbl mouse_internal_vtbl = { NULL, mouse_internal_acquire, mouse_internal_unacquire, mouse_internal_enum_objects, + mouse_internal_get_property, };
static const IDirectInputDevice8WVtbl SysMouseWvt = @@ -746,7 +711,7 @@ static const IDirectInputDevice8WVtbl SysMouseWvt = IDirectInputDevice2WImpl_Release, IDirectInputDevice2WImpl_GetCapabilities, IDirectInputDevice2WImpl_EnumObjects, - SysMouseWImpl_GetProperty, + IDirectInputDevice2WImpl_GetProperty, IDirectInputDevice2WImpl_SetProperty, IDirectInputDevice2WImpl_Acquire, IDirectInputDevice2WImpl_Unacquire, diff --git a/dlls/dinput8/tests/device.c b/dlls/dinput8/tests/device.c index c6cf5867657..9f331c1b84c 100644 --- a/dlls/dinput8/tests/device.c +++ b/dlls/dinput8/tests/device.c @@ -1291,18 +1291,14 @@ static void test_mouse_info(void) prop_dword.diph.dwHow = DIPH_BYOFFSET; prop_dword.diph.dwObj = DIMOFS_X; hr = IDirectInputDevice8_GetProperty( device, DIPROP_GRANULARITY, &prop_dword.diph ); - todo_wine ok( hr == DIERR_NOTFOUND, "GetProperty DIPROP_GRANULARITY returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_DEADZONE, &prop_dword.diph ); - todo_wine ok( hr == DIERR_NOTFOUND, "GetProperty DIPROP_DEADZONE returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_SATURATION, &prop_dword.diph ); - todo_wine ok( hr == DIERR_NOTFOUND, "GetProperty DIPROP_SATURATION returned %#x\n", hr ); prop_range.diph.dwHow = DIPH_BYOFFSET; prop_range.diph.dwObj = DIMOFS_X; hr = IDirectInputDevice8_GetProperty( device, DIPROP_RANGE, &prop_range.diph ); - todo_wine ok( hr == DIERR_NOTFOUND, "GetProperty DIPROP_RANGE returned %#x\n", hr );
prop_dword.diph.dwHow = DIPH_DEVICE; @@ -1340,44 +1336,34 @@ static void test_mouse_info(void) hr = IDirectInputDevice8_GetProperty( device, DIPROP_VIDPID, &prop_dword.diph ); ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_VIDPID returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_GUIDANDPATH, &prop_guid_path.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_GUIDANDPATH returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_INSTANCENAME, &prop_string.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_INSTANCENAME returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_PRODUCTNAME, &prop_string.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_PRODUCTNAME returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_TYPENAME, &prop_string.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_TYPENAME returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_USERNAME, &prop_string.diph ); ok( hr == S_FALSE, "GetProperty DIPROP_USERNAME returned %#x\n", hr ); ok( !wcscmp( prop_string.wsz, L"" ), "got user %s\n", debugstr_w(prop_string.wsz) );
hr = IDirectInputDevice8_GetProperty( device, DIPROP_JOYSTICKID, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_VIDPID returned %#x\n", hr );
hr = IDirectInputDevice8_GetProperty( device, DIPROP_CALIBRATION, &prop_dword.diph ); ok( hr == DIERR_INVALIDPARAM, "GetProperty DIPROP_CALIBRATION returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_AUTOCENTER, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_AUTOCENTER returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_DEADZONE, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_DEADZONE returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_FFLOAD, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_FFLOAD returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_GRANULARITY, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_GRANULARITY returned %#x\n", hr );
prop_dword.diph.dwHow = DIPH_BYUSAGE; prop_dword.diph.dwObj = MAKELONG( HID_USAGE_GENERIC_X, HID_USAGE_PAGE_GENERIC ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_GRANULARITY, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_GRANULARITY returned %#x\n", hr );
prop_dword.diph.dwHow = DIPH_BYOFFSET; @@ -1387,18 +1373,14 @@ static void test_mouse_info(void) ok( hr == DI_OK, "GetProperty DIPROP_GRANULARITY returned %#x\n", hr ); ok( prop_dword.dwData == 1, "got %d expected 1\n", prop_dword.dwData ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_DEADZONE, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_DEADZONE returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_SATURATION, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_SATURATION returned %#x\n", hr ); prop_range.lMin = 0xdeadbeef; prop_range.lMax = 0xdeadbeef; hr = IDirectInputDevice8_GetProperty( device, DIPROP_RANGE, &prop_range.diph ); ok( hr == DI_OK, "GetProperty DIPROP_RANGE returned %#x\n", hr ); - todo_wine ok( prop_range.lMin == DIPROPRANGE_NOMIN, "got %d expected %d\n", prop_range.lMin, DIPROPRANGE_NOMIN ); - todo_wine ok( prop_range.lMax == DIPROPRANGE_NOMAX, "got %d expected %d\n", prop_range.lMax, DIPROPRANGE_NOMAX );
res = 0; @@ -1632,18 +1614,14 @@ static void test_keyboard_info(void) prop_dword.diph.dwHow = DIPH_BYOFFSET; prop_dword.diph.dwObj = 1; hr = IDirectInputDevice8_GetProperty( device, DIPROP_GRANULARITY, &prop_dword.diph ); - todo_wine ok( hr == DIERR_NOTFOUND, "GetProperty DIPROP_GRANULARITY returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_DEADZONE, &prop_dword.diph ); - todo_wine ok( hr == DIERR_NOTFOUND, "GetProperty DIPROP_DEADZONE returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_SATURATION, &prop_dword.diph ); - todo_wine ok( hr == DIERR_NOTFOUND, "GetProperty DIPROP_SATURATION returned %#x\n", hr ); prop_range.diph.dwHow = DIPH_BYOFFSET; prop_range.diph.dwObj = 1; hr = IDirectInputDevice8_GetProperty( device, DIPROP_RANGE, &prop_range.diph ); - todo_wine ok( hr == DIERR_NOTFOUND, "GetProperty DIPROP_RANGE returned %#x\n", hr );
prop_dword.diph.dwHow = DIPH_DEVICE; @@ -1681,56 +1659,43 @@ static void test_keyboard_info(void) hr = IDirectInputDevice8_GetProperty( device, DIPROP_VIDPID, &prop_dword.diph ); ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_VIDPID returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_GUIDANDPATH, &prop_guid_path.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_GUIDANDPATH returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_INSTANCENAME, &prop_string.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_INSTANCENAME returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_PRODUCTNAME, &prop_string.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_PRODUCTNAME returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_TYPENAME, &prop_string.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_TYPENAME returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_USERNAME, &prop_string.diph ); ok( hr == S_FALSE, "GetProperty DIPROP_USERNAME returned %#x\n", hr ); ok( !wcscmp( prop_string.wsz, L"" ), "got user %s\n", debugstr_w(prop_string.wsz) );
hr = IDirectInputDevice8_GetProperty( device, DIPROP_JOYSTICKID, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_VIDPID returned %#x\n", hr );
hr = IDirectInputDevice8_GetProperty( device, DIPROP_CALIBRATION, &prop_dword.diph ); ok( hr == DIERR_INVALIDPARAM, "GetProperty DIPROP_CALIBRATION returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_AUTOCENTER, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_AUTOCENTER returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_DEADZONE, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_DEADZONE returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_FFLOAD, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_FFLOAD returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_GRANULARITY, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_GRANULARITY returned %#x\n", hr );
prop_dword.diph.dwHow = DIPH_BYUSAGE; prop_dword.diph.dwObj = MAKELONG( HID_USAGE_KEYBOARD_LCTRL, HID_USAGE_PAGE_KEYBOARD ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_GRANULARITY, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_GRANULARITY returned %#x\n", hr );
prop_dword.diph.dwHow = DIPH_BYOFFSET; prop_dword.diph.dwObj = 1; hr = IDirectInputDevice8_GetProperty( device, DIPROP_GRANULARITY, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_GRANULARITY returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_DEADZONE, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_DEADZONE returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_SATURATION, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_SATURATION returned %#x\n", hr ); prop_range.diph.dwHow = DIPH_BYOFFSET; prop_range.diph.dwObj = 1; diff --git a/dlls/dinput8/tests/hid.c b/dlls/dinput8/tests/hid.c index 8fda1289843..8bb463b2fd7 100644 --- a/dlls/dinput8/tests/hid.c +++ b/dlls/dinput8/tests/hid.c @@ -4004,7 +4004,6 @@ static void test_simple_joystick(void) hr = IDirectInputDevice8_GetProperty( device, DIPROP_DEADZONE, &prop_dword.diph ); ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_DEADZONE returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_FFLOAD, &prop_dword.diph ); - todo_wine ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_FFLOAD returned %#x\n", hr ); hr = IDirectInputDevice8_GetProperty( device, DIPROP_GRANULARITY, &prop_dword.diph ); ok( hr == DIERR_UNSUPPORTED, "GetProperty DIPROP_GRANULARITY returned %#x\n", hr );
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 7 +++++++ dlls/dinput8/tests/device.c | 4 ---- dlls/dinput8/tests/hid.c | 4 ---- 3 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 75ca6676bec..54645fa995e 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -1280,6 +1280,13 @@ HRESULT WINAPI IDirectInputDevice2WImpl_GetProperty( IDirectInputDevice8W *iface } return S_FALSE; } + case (DWORD_PTR)DIPROP_FFGAIN: + { + DIPROPDWORD *value = (DIPROPDWORD *)header; + if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; + value->dwData = 10000; + return DI_OK; + } case (DWORD_PTR)DIPROP_CALIBRATION: return DIERR_INVALIDPARAM; default: diff --git a/dlls/dinput8/tests/device.c b/dlls/dinput8/tests/device.c index 9f331c1b84c..4492170673e 100644 --- a/dlls/dinput8/tests/device.c +++ b/dlls/dinput8/tests/device.c @@ -1315,9 +1315,7 @@ static void test_mouse_info(void) ok( prop_dword.dwData == 0, "got %#x expected %#x\n", prop_dword.dwData, 0 ); prop_dword.dwData = 0xdeadbeef; hr = IDirectInputDevice8_GetProperty( device, DIPROP_FFGAIN, &prop_dword.diph ); - todo_wine ok( hr == DI_OK, "GetProperty DIPROP_FFGAIN returned %#x\n", hr ); - todo_wine ok( prop_dword.dwData == 10000, "got %u expected %u\n", prop_dword.dwData, 10000 );
hr = IDirectInputDevice8_SetDataFormat( device, &c_dfDIMouse2 ); @@ -1638,9 +1636,7 @@ static void test_keyboard_info(void) ok( prop_dword.dwData == 0, "got %#x expected %#x\n", prop_dword.dwData, 0 ); prop_dword.dwData = 0xdeadbeef; hr = IDirectInputDevice8_GetProperty( device, DIPROP_FFGAIN, &prop_dword.diph ); - todo_wine ok( hr == DI_OK, "GetProperty DIPROP_FFGAIN returned %#x\n", hr ); - todo_wine ok( prop_dword.dwData == 10000, "got %u expected %u\n", prop_dword.dwData, 10000 );
hr = IDirectInputDevice8_SetDataFormat( device, &c_dfDIKeyboard ); diff --git a/dlls/dinput8/tests/hid.c b/dlls/dinput8/tests/hid.c index 8bb463b2fd7..b23d3a6bfd8 100644 --- a/dlls/dinput8/tests/hid.c +++ b/dlls/dinput8/tests/hid.c @@ -3992,9 +3992,7 @@ static void test_simple_joystick(void) ok( prop_dword.dwData == 0, "got %#x expected %#x\n", prop_dword.dwData, 0 ); prop_dword.dwData = 0xdeadbeef; hr = IDirectInputDevice8_GetProperty( device, DIPROP_FFGAIN, &prop_dword.diph ); - todo_wine ok( hr == DI_OK, "GetProperty DIPROP_FFGAIN returned %#x\n", hr ); - todo_wine ok( prop_dword.dwData == 10000, "got %u expected %u\n", prop_dword.dwData, 10000 );
hr = IDirectInputDevice8_GetProperty( device, DIPROP_CALIBRATION, &prop_dword.diph ); @@ -7143,9 +7141,7 @@ static void test_force_feedback_joystick( void )
prop_dword.dwData = 0xdeadbeef; hr = IDirectInputDevice8_GetProperty( device, DIPROP_FFGAIN, &prop_dword.diph ); - todo_wine ok( hr == DI_OK, "GetProperty DIPROP_FFGAIN returned %#x\n", hr ); - todo_wine ok( prop_dword.dwData == 10000, "got %u expected %u\n", prop_dword.dwData, 10000 );
hr = IDirectInputDevice8_GetProperty( device, DIPROP_FFLOAD, &prop_dword.diph );
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/mouse.c | 116 +++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 60 deletions(-)
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index f6aedda080a..b3a48baa3aa 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -68,9 +68,6 @@ struct SysMouseImpl BOOL need_warp; DWORD last_warped;
- /* This is for mouse reporting. */ - DIMOUSESTATE2 m_state; - WARP_MOUSE warp_override; };
@@ -79,17 +76,6 @@ static inline SysMouseImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface), SysMouseImpl, base); }
-static void _dump_mouse_state(const DIMOUSESTATE2 *m_state) -{ - int i; - - if (!TRACE_ON(dinput)) return; - - TRACE("(X: %d Y: %d Z: %d", m_state->lX, m_state->lY, m_state->lZ); - for (i = 0; i < 5; i++) TRACE(" B%d: %02x", i, m_state->rgbButtons[i]); - TRACE(")\n"); -} - static void fill_mouse_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version) { DWORD dwSize; DIDEVICEINSTANCEW ddi; @@ -213,6 +199,7 @@ const struct dinput_device mouse_device = { void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam, RAWINPUT *ri ) { SysMouseImpl *This = impl_from_IDirectInputDevice8W( iface ); + DIMOUSESTATE2 *state = (DIMOUSESTATE2 *)This->base.device_state; POINT rel, pt; DWORD seq; int i, wdata = 0; @@ -246,13 +233,13 @@ void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPA rel.y -= pt.y; }
- This->m_state.lX += rel.x; - This->m_state.lY += rel.y; + state->lX += rel.x; + state->lY += rel.y;
if (This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS) { - pt.x = This->m_state.lX; - pt.y = This->m_state.lY; + pt.x = state->lX; + pt.y = state->lY; } else { @@ -282,7 +269,7 @@ void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPA
if (ri->data.mouse.usButtonFlags & RI_MOUSE_WHEEL) { - This->m_state.lZ += (wdata = (SHORT)ri->data.mouse.usButtonData); + state->lZ += (wdata = (SHORT)ri->data.mouse.usButtonData); queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS, wdata, GetCurrentTime(), seq ); notify = TRUE; @@ -292,13 +279,17 @@ void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPA { if (ri->data.mouse.usButtonFlags & mouse_button_flags[i]) { - This->m_state.rgbButtons[i / 2] = 0x80 - (i % 2) * 0x80; - queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE +(i / 2) ) | DIDFT_PSHBUTTON, - This->m_state.rgbButtons[i / 2], GetCurrentTime(), seq ); + state->rgbButtons[i / 2] = 0x80 - (i % 2) * 0x80; + queue_event( iface, DIDFT_MAKEINSTANCE( WINE_MOUSE_BUTTONS_INSTANCE + (i / 2) ) | DIDFT_PSHBUTTON, + state->rgbButtons[i / 2], GetCurrentTime(), seq ); notify = TRUE; } }
+ TRACE( "buttons %02x %02x %02x %02x %02x, x %d, y %d, w %d\n", state->rgbButtons[0], + state->rgbButtons[1], state->rgbButtons[2], state->rgbButtons[3], state->rgbButtons[4], + state->lX, state->lY, state->lZ ); + if (notify && This->base.hEvent) SetEvent( This->base.hEvent ); LeaveCriticalSection( &This->base.crit ); } @@ -308,6 +299,7 @@ int dinput_mouse_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam { MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam; SysMouseImpl *This = impl_from_IDirectInputDevice8W( iface ); + DIMOUSESTATE2 *state = (DIMOUSESTATE2 *)This->base.device_state; int wdata = 0, inst_id = -1, ret = 0; BOOL notify = FALSE;
@@ -321,13 +313,13 @@ int dinput_mouse_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam POINT pt, pt1;
GetCursorPos(&pt); - This->m_state.lX += pt.x = hook->pt.x - pt.x; - This->m_state.lY += pt.y = hook->pt.y - pt.y; + state->lX += pt.x = hook->pt.x - pt.x; + state->lY += pt.y = hook->pt.y - pt.y;
if (This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS) { - pt1.x = This->m_state.lX; - pt1.y = This->m_state.lY; + pt1.x = state->lX; + pt1.y = state->lY; } else pt1 = pt;
@@ -359,54 +351,57 @@ int dinput_mouse_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam } case WM_MOUSEWHEEL: inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS; - This->m_state.lZ += wdata = (short)HIWORD(hook->mouseData); + state->lZ += wdata = (short)HIWORD( hook->mouseData ); /* FarCry crashes if it gets a mouse wheel message */ /* FIXME: should probably filter out other messages too */ ret = This->clipped; break; case WM_LBUTTONDOWN: inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 0) | DIDFT_PSHBUTTON; - This->m_state.rgbButtons[0] = wdata = 0x80; - break; - case WM_LBUTTONUP: + state->rgbButtons[0] = wdata = 0x80; + break; + case WM_LBUTTONUP: inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 0) | DIDFT_PSHBUTTON; - This->m_state.rgbButtons[0] = wdata = 0x00; - break; - case WM_RBUTTONDOWN: + state->rgbButtons[0] = wdata = 0x00; + break; + case WM_RBUTTONDOWN: inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 1) | DIDFT_PSHBUTTON; - This->m_state.rgbButtons[1] = wdata = 0x80; - break; - case WM_RBUTTONUP: + state->rgbButtons[1] = wdata = 0x80; + break; + case WM_RBUTTONUP: inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 1) | DIDFT_PSHBUTTON; - This->m_state.rgbButtons[1] = wdata = 0x00; - break; - case WM_MBUTTONDOWN: + state->rgbButtons[1] = wdata = 0x00; + break; + case WM_MBUTTONDOWN: inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2) | DIDFT_PSHBUTTON; - This->m_state.rgbButtons[2] = wdata = 0x80; - break; - case WM_MBUTTONUP: + state->rgbButtons[2] = wdata = 0x80; + break; + case WM_MBUTTONUP: inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2) | DIDFT_PSHBUTTON; - This->m_state.rgbButtons[2] = wdata = 0x00; - break; + state->rgbButtons[2] = wdata = 0x00; + break; case WM_XBUTTONDOWN: inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2 + HIWORD(hook->mouseData)) | DIDFT_PSHBUTTON; - This->m_state.rgbButtons[2 + HIWORD(hook->mouseData)] = wdata = 0x80; + state->rgbButtons[2 + HIWORD( hook->mouseData )] = wdata = 0x80; break; case WM_XBUTTONUP: inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2 + HIWORD(hook->mouseData)) | DIDFT_PSHBUTTON; - This->m_state.rgbButtons[2 + HIWORD(hook->mouseData)] = wdata = 0x00; + state->rgbButtons[2 + HIWORD( hook->mouseData )] = wdata = 0x00; break; }
if (inst_id != -1) { - _dump_mouse_state(&This->m_state); queue_event(iface, inst_id, wdata, GetCurrentTime(), This->base.dinput->evsequence++); notify = TRUE; }
+ TRACE( "buttons %02x %02x %02x %02x %02x, x %d, y %d, w %d\n", state->rgbButtons[0], + state->rgbButtons[1], state->rgbButtons[2], state->rgbButtons[3], state->rgbButtons[4], + state->lX, state->lY, state->lZ ); + if (notify && This->base.hEvent) SetEvent( This->base.hEvent ); LeaveCriticalSection(&This->base.crit); return ret; @@ -456,6 +451,7 @@ static void warp_check( SysMouseImpl* This, BOOL force ) 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; @@ -463,17 +459,16 @@ static HRESULT WINAPI SysMouseWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface, check_dinput_events();
EnterCriticalSection(&This->base.crit); - _dump_mouse_state(&This->m_state);
/* Copy the current mouse state */ - fill_DataFormat(ptr, len, &This->m_state, &This->base.data_format); + 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)) { - This->m_state.lX = 0; - This->m_state.lY = 0; - This->m_state.lZ = 0; + state->lX = 0; + state->lY = 0; + state->lZ = 0; } LeaveCriticalSection(&This->base.crit);
@@ -498,25 +493,26 @@ static HRESULT WINAPI SysMouseWImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface, static HRESULT mouse_internal_acquire( IDirectInputDevice8W *iface ) { SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface ); + DIMOUSESTATE2 *state = (DIMOUSESTATE2 *)impl->base.device_state; POINT point;
/* 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; + state->lX = point.x; + state->lY = point.y; } else { - impl->m_state.lX = 0; - impl->m_state.lY = 0; + state->lX = 0; + 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; + state->lZ = 0; + state->rgbButtons[0] = GetKeyState( VK_LBUTTON ) & 0x80; + state->rgbButtons[1] = GetKeyState( VK_RBUTTON ) & 0x80; + state->rgbButtons[2] = GetKeyState( VK_MBUTTON ) & 0x80;
if (impl->base.dwCoopLevel & DISCL_EXCLUSIVE) {
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/keyboard.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index bb1102e38eb..a1764eb64c0 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -34,8 +34,6 @@
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;
@@ -43,7 +41,6 @@ typedef struct SysKeyboardImpl SysKeyboardImpl; struct SysKeyboardImpl { struct IDirectInputDeviceImpl base; - BYTE DInputKeyState[WINE_DINPUT_KEYBOARD_MAX_KEYS]; };
static inline SysKeyboardImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface) @@ -115,11 +112,10 @@ int dinput_keyboard_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lpa new_diks = hook->flags & LLKHF_UP ? 0 : 0x80;
/* returns now if key event already known */ - if (new_diks == This->DInputKeyState[dik_code]) - return ret; + if (new_diks == This->base.device_state[dik_code]) return ret;
- This->DInputKeyState[dik_code] = new_diks; - TRACE(" setting %02X to %02X\n", dik_code, This->DInputKeyState[dik_code]); + This->base.device_state[dik_code] = new_diks; + TRACE( " setting key %02x to %02x\n", dik_code, This->base.device_state[dik_code] );
EnterCriticalSection(&This->base.crit); queue_event(iface, DIDFT_MAKEINSTANCE(dik_code) | DIDFT_PSHBUTTON, @@ -248,6 +244,8 @@ const struct dinput_device keyboard_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; @@ -259,15 +257,14 @@ static HRESULT WINAPI SysKeyboardWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W ifac
EnterCriticalSection(&This->base.crit);
- if (TRACE_ON(dinput)) { - int i; - for (i = 0; i < WINE_DINPUT_KEYBOARD_MAX_KEYS; i++) { - if (This->DInputKeyState[i] != 0x00) - TRACE(" - %02X: %02x\n", i, This->DInputKeyState[i]); - } + 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->DInputKeyState, &This->base.data_format); + fill_DataFormat( ptr, len, This->base.device_state, &This->base.data_format ); LeaveCriticalSection(&This->base.crit);
return DI_OK; @@ -281,7 +278,7 @@ static HRESULT keyboard_internal_acquire( IDirectInputDevice8W *iface ) static HRESULT keyboard_internal_unacquire( IDirectInputDevice8W *iface ) { SysKeyboardImpl *This = impl_from_IDirectInputDevice8W( iface ); - memset( This->DInputKeyState, 0, sizeof(This->DInputKeyState) ); + memset( This->base.device_state, 0, sizeof(This->base.device_state) ); return DI_OK; }
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 229 +++++++++++++++++++++-------------- dlls/dinput/device_private.h | 2 + dlls/dinput/joystick_hid.c | 113 ++++------------- dlls/dinput/keyboard.c | 7 ++ dlls/dinput/mouse.c | 7 ++ 5 files changed, 179 insertions(+), 179 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 54645fa995e..cdaa76cd504 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -1297,112 +1297,165 @@ HRESULT WINAPI IDirectInputDevice2WImpl_GetProperty( IDirectInputDevice8W *iface return DI_OK; }
-/****************************************************************************** - * SetProperty - */ +struct set_object_property_params +{ + IDirectInputDevice8W *iface; + const DIPROPHEADER *header; + DWORD property; +};
-HRESULT WINAPI IDirectInputDevice2WImpl_SetProperty( - LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPCDIPROPHEADER pdiph) +static BOOL CALLBACK set_object_property( const DIDEVICEOBJECTINSTANCEW *instance, void *context ) { - IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface); + struct set_object_property_params *params = context; + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( params->iface ); + impl->vtbl->set_property( params->iface, params->property, params->header, instance ); + return DIENUM_CONTINUE; +} + +HRESULT WINAPI IDirectInputDevice2WImpl_SetProperty( IDirectInputDevice8W *iface, const GUID *guid, + const DIPROPHEADER *header ) +{ + struct set_object_property_params params = {.iface = iface, .header = header, .property = LOWORD( guid )}; + IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface ); + HRESULT hr;
- TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(rguid), pdiph); - _dump_DIPROPHEADER(pdiph); + TRACE( "iface %p, guid %s, header %p\n", iface, debugstr_guid( guid ), header );
- if (!IS_DIPROP(rguid)) return DI_OK; + if (!header) return DIERR_INVALIDPARAM; + if (header->dwHeaderSize != sizeof(DIPROPHEADER)) return DIERR_INVALIDPARAM; + if (!IS_DIPROP( guid )) return DI_OK;
- switch (LOWORD(rguid)) + switch (LOWORD( guid )) + { + case (DWORD_PTR)DIPROP_RANGE: + { + 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 ); + if (FAILED(hr)) return hr; + return DI_OK; + } + case (DWORD_PTR)DIPROP_DEADZONE: + case (DWORD_PTR)DIPROP_SATURATION: + { + 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 ); + if (FAILED(hr)) return hr; + return DI_OK; + } + case (DWORD_PTR)DIPROP_AUTOCENTER: + { + const DIPROPDWORD *value = (const DIPROPDWORD *)header; + if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; + EnterCriticalSection( &impl->crit ); + if (impl->acquired) hr = DIERR_ACQUIRED; + else if (value->dwData > DIPROPAUTOCENTER_ON) hr = DIERR_INVALIDPARAM; + else hr = DIERR_UNSUPPORTED; + LeaveCriticalSection( &impl->crit ); + return hr; + } + case (DWORD_PTR)DIPROP_FFLOAD: + case (DWORD_PTR)DIPROP_GRANULARITY: + case (DWORD_PTR)DIPROP_VIDPID: + if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; + return DIERR_READONLY; + case (DWORD_PTR)DIPROP_TYPENAME: + case (DWORD_PTR)DIPROP_USERNAME: + if (header->dwSize != sizeof(DIPROPSTRING)) return DIERR_INVALIDPARAM; + return DIERR_READONLY; + case (DWORD_PTR)DIPROP_GUIDANDPATH: + if (header->dwSize != sizeof(DIPROPGUIDANDPATH)) return DIERR_INVALIDPARAM; + return DIERR_READONLY; + case (DWORD_PTR)DIPROP_AXISMODE: { - case (DWORD_PTR) DIPROP_AXISMODE: + const DIPROPDWORD *value = (const DIPROPDWORD *)header; + if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; + if (header->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED; + if (header->dwHow == DIPH_DEVICE && header->dwObj) return DIERR_INVALIDPARAM; + + TRACE( "Axis mode: %s\n", value->dwData == DIPROPAXISMODE_ABS ? "absolute" : "relative" ); + EnterCriticalSection( &impl->crit ); + if (impl->acquired) hr = DIERR_ACQUIRED; + else if (!impl->data_format.user_df) hr = DI_OK; + else { - LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph; - - if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; - if (pdiph->dwHow == DIPH_DEVICE && pdiph->dwObj) return DIERR_INVALIDPARAM; - if (This->acquired) return DIERR_ACQUIRED; - if (pdiph->dwHow != DIPH_DEVICE) return DIERR_UNSUPPORTED; - if (!This->data_format.user_df) return DI_OK; - - TRACE("Axis mode: %s\n", pd->dwData == DIPROPAXISMODE_ABS ? "absolute" : - "relative"); - - EnterCriticalSection(&This->crit); - This->data_format.user_df->dwFlags &= ~DIDFT_AXIS; - This->data_format.user_df->dwFlags |= pd->dwData == DIPROPAXISMODE_ABS ? - DIDF_ABSAXIS : DIDF_RELAXIS; - LeaveCriticalSection(&This->crit); - break; + impl->data_format.user_df->dwFlags &= ~DIDFT_AXIS; + impl->data_format.user_df->dwFlags |= value->dwData == DIPROPAXISMODE_ABS ? DIDF_ABSAXIS : DIDF_RELAXIS; + hr = DI_OK; } - case (DWORD_PTR) DIPROP_BUFFERSIZE: - { - LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph; - - if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; - if (This->acquired) return DIERR_ACQUIRED; + LeaveCriticalSection( &impl->crit ); + return hr; + } + case (DWORD_PTR)DIPROP_BUFFERSIZE: + { + const DIPROPDWORD *value = (const DIPROPDWORD *)header; + if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
- TRACE("buffersize = %d\n", pd->dwData); + TRACE( "buffersize = %d\n", value->dwData );
- EnterCriticalSection(&This->crit); + EnterCriticalSection( &impl->crit ); + if (impl->acquired) hr = DIERR_ACQUIRED; + else + { + impl->buffersize = value->dwData; + impl->queue_len = min( impl->buffersize, 1024 ); + free( impl->data_queue );
- This->buffersize = pd->dwData; - This->queue_len = min(This->buffersize, 1024); - free( This->data_queue ); + impl->data_queue = impl->queue_len ? malloc( impl->queue_len * sizeof(DIDEVICEOBJECTDATA) ) : NULL; + impl->queue_head = impl->queue_tail = impl->overflow = 0; + hr = DI_OK; + } + LeaveCriticalSection( &impl->crit ); + return hr; + } + case (DWORD_PTR)DIPROP_APPDATA: + { + const DIPROPPOINTER *value = (const DIPROPPOINTER *)header; + int offset = -1; + if (header->dwSize != sizeof(DIPROPPOINTER)) return DIERR_INVALIDPARAM; + + if (header->dwHow == DIPH_BYID) + offset = id_to_offset( &impl->data_format, header->dwObj ); + else if (header->dwHow == DIPH_BYOFFSET) + offset = verify_offset( &impl->data_format, header->dwObj ); + else + return DIERR_UNSUPPORTED;
- This->data_queue = This->queue_len ? malloc( This->queue_len * sizeof(DIDEVICEOBJECTDATA) ) : NULL; - This->queue_head = This->queue_tail = This->overflow = 0; + if (offset == -1) return DIERR_OBJECTNOTFOUND; + if (!set_app_data( impl, offset, value->uData )) return DIERR_OUTOFMEMORY; + return DI_OK; + } + default: + FIXME( "Unknown property %s\n", debugstr_guid( guid ) ); + return DIERR_UNSUPPORTED; + }
- LeaveCriticalSection(&This->crit); - break; - } - case (DWORD_PTR) DIPROP_USERNAME: - { - LPCDIPROPSTRING ps = (LPCDIPROPSTRING)pdiph; - struct DevicePlayer *device_player; - BOOL found = FALSE; + return DI_OK; +}
- if (pdiph->dwSize != sizeof(DIPROPSTRING)) return DIERR_INVALIDPARAM; +static void dinput_device_set_username( IDirectInputDeviceImpl *impl, const DIPROPSTRING *value ) +{ + struct DevicePlayer *device_player; + BOOL found = FALSE;
- LIST_FOR_EACH_ENTRY(device_player, &This->dinput->device_players, - struct DevicePlayer, entry) - { - if (IsEqualGUID(&device_player->instance_guid, &This->guid)) - { - found = TRUE; - break; - } - } - if (!found && (device_player = malloc( sizeof(struct DevicePlayer) ))) - { - list_add_tail(&This->dinput->device_players, &device_player->entry); - device_player->instance_guid = This->guid; - } - if (device_player) - lstrcpynW(device_player->username, ps->wsz, ARRAY_SIZE(device_player->username)); - break; - } - case (DWORD_PTR) DIPROP_APPDATA: + LIST_FOR_EACH_ENTRY( device_player, &impl->dinput->device_players, struct DevicePlayer, entry ) + { + if (IsEqualGUID( &device_player->instance_guid, &impl->guid )) { - int offset = -1; - LPCDIPROPPOINTER pp = (LPCDIPROPPOINTER)pdiph; - if (pdiph->dwSize != sizeof(DIPROPPOINTER)) return DIERR_INVALIDPARAM; - - if (pdiph->dwHow == DIPH_BYID) - offset = id_to_offset(&This->data_format, pdiph->dwObj); - else if (pdiph->dwHow == DIPH_BYOFFSET) - offset = verify_offset(&This->data_format, pdiph->dwObj); - else - return DIERR_UNSUPPORTED; - - if (offset == -1) return DIERR_OBJECTNOTFOUND; - if (!set_app_data(This, offset, pp->uData)) return DIERR_OUTOFMEMORY; + found = TRUE; break; } - default: - WARN("Unknown property %s\n", debugstr_guid(rguid)); - return DIERR_UNSUPPORTED; } - - return DI_OK; + if (!found && (device_player = malloc( sizeof(struct DevicePlayer) ))) + { + list_add_tail( &impl->dinput->device_players, &device_player->entry ); + device_player->instance_guid = impl->guid; + } + if (device_player) + lstrcpynW( device_player->username, value->wsz, ARRAY_SIZE(device_player->username) ); }
static BOOL CALLBACK get_object_info( const DIDEVICEOBJECTINSTANCEW *instance, void *data ) @@ -1827,7 +1880,7 @@ HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap( IDirectInputDevice8W *ifac 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 ); + dinput_device_set_username( impl, &dps );
/* Save the settings to disk */ save_mapping_settings( iface, format, username_buf ); diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index e4290e5960b..da1a90fda42 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -64,6 +64,8 @@ struct dinput_device_vtbl LPDIENUMDEVICEOBJECTSCALLBACKW callback, void *context ); HRESULT (*get_property)( IDirectInputDevice8W *iface, DWORD property, DIPROPHEADER *header, DIDEVICEOBJECTINSTANCEW *instance ); + HRESULT (*set_property)( IDirectInputDevice8W *iface, DWORD property, const DIPROPHEADER *header, + const DIDEVICEOBJECTINSTANCEW *instance ); };
#define DEVICE_STATE_MAX_SIZE 1024 diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 8c9218cd4e7..3dc43c450e4 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -732,15 +732,14 @@ static HRESULT hid_joystick_internal_get_property( IDirectInputDevice8W *iface, return DIERR_UNSUPPORTED; }
-static BOOL set_property_prop_range( struct hid_joystick *impl, struct hid_value_caps *caps, - DIDEVICEOBJECTINSTANCEW *instance, void *data ) +static void set_extra_caps_range( struct hid_joystick *impl, const DIDEVICEOBJECTINSTANCEW *instance, + LONG min, LONG max ) { struct extra_caps *extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG); - DIPROPRANGE *value = data; LONG tmp;
- extra->range_min = value->lMin; - extra->range_max = value->lMax; + extra->range_min = min; + extra->range_max = max;
if (instance->dwType & DIDFT_AXIS) { @@ -751,96 +750,42 @@ static BOOL set_property_prop_range( struct hid_joystick *impl, struct hid_value else if (instance->dwType & DIDFT_POV) { tmp = extra->logical_max - extra->logical_min; - if (tmp > 0) extra->range_max -= value->lMax / (tmp + 1); + if (tmp > 0) extra->range_max -= max / (tmp + 1); *(LONG *)(impl->base.device_state + instance->dwOfs) = -1; } - return DIENUM_CONTINUE; -} - -static BOOL set_property_prop_deadzone( struct hid_joystick *impl, struct hid_value_caps *caps, - DIDEVICEOBJECTINSTANCEW *instance, void *data ) -{ - struct extra_caps *extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG); - DIPROPDWORD *deadzone = data; - extra->deadzone = deadzone->dwData; - return DIENUM_CONTINUE; -} - -static BOOL set_property_prop_saturation( struct hid_joystick *impl, struct hid_value_caps *caps, - DIDEVICEOBJECTINSTANCEW *instance, void *data ) -{ - struct extra_caps *extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG); - DIPROPDWORD *saturation = data; - extra->saturation = saturation->dwData; - return DIENUM_CONTINUE; }
-static HRESULT WINAPI hid_joystick_SetProperty( IDirectInputDevice8W *iface, const GUID *guid, - const DIPROPHEADER *header ) +static HRESULT hid_joystick_internal_set_property( IDirectInputDevice8W *iface, DWORD property, const DIPROPHEADER *header, + const DIDEVICEOBJECTINSTANCEW *instance ) { struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface ); - HRESULT hr; - - TRACE( "iface %p, guid %s, header %p\n", iface, debugstr_guid( guid ), header ); + struct extra_caps *extra = NULL;
- if (!header) return DIERR_INVALIDPARAM; - if (header->dwHeaderSize != sizeof(DIPROPHEADER)) return DIERR_INVALIDPARAM; - if (!IS_DIPROP( guid )) return DI_OK; + if (instance) extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG);
- switch (LOWORD( guid )) + switch (property) { case (DWORD_PTR)DIPROP_RANGE: { - DIPROPRANGE *value = (DIPROPRANGE *)header; - if (header->dwSize != sizeof(DIPROPRANGE)) return DIERR_INVALIDPARAM; - if (value->lMin > value->lMax) return DIERR_INVALIDPARAM; - enum_objects( impl, header, DIDFT_AXIS, set_property_prop_range, (void *)header ); + const DIPROPRANGE *value = (const DIPROPRANGE *)header; + set_extra_caps_range( impl, instance, value->lMin, value->lMax ); return DI_OK; } case (DWORD_PTR)DIPROP_DEADZONE: { - DIPROPDWORD *value = (DIPROPDWORD *)header; - if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; - if (value->dwData > 10000) return DIERR_INVALIDPARAM; - enum_objects( impl, header, DIDFT_AXIS, set_property_prop_deadzone, (void *)header ); + const DIPROPDWORD *value = (const DIPROPDWORD *)header; + extra->deadzone = value->dwData; return DI_OK; } case (DWORD_PTR)DIPROP_SATURATION: { - DIPROPDWORD *value = (DIPROPDWORD *)header; - if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; - if (value->dwData > 10000) return DIERR_INVALIDPARAM; - enum_objects( impl, header, DIDFT_AXIS, set_property_prop_saturation, (void *)header ); + const DIPROPDWORD *value = (const DIPROPDWORD *)header; + extra->saturation = value->dwData; return DI_OK; } - case (DWORD_PTR)DIPROP_AUTOCENTER: - { - DIPROPDWORD *value = (DIPROPDWORD *)header; - if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; - EnterCriticalSection( &impl->base.crit ); - if (impl->base.acquired) hr = DIERR_ACQUIRED; - else if (value->dwData > DIPROPAUTOCENTER_ON) hr = DIERR_INVALIDPARAM; - else hr = DIERR_UNSUPPORTED; - LeaveCriticalSection( &impl->base.crit ); - return hr; - } - case (DWORD_PTR)DIPROP_FFLOAD: - case (DWORD_PTR)DIPROP_GRANULARITY: - case (DWORD_PTR)DIPROP_VIDPID: - if (header->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM; - return DIERR_READONLY; - case (DWORD_PTR)DIPROP_TYPENAME: - case (DWORD_PTR)DIPROP_USERNAME: - if (header->dwSize != sizeof(DIPROPSTRING)) return DIERR_INVALIDPARAM; - return DIERR_READONLY; - case (DWORD_PTR)DIPROP_GUIDANDPATH: - if (header->dwSize != sizeof(DIPROPGUIDANDPATH)) return DIERR_INVALIDPARAM; - return DIERR_READONLY; - default: - return IDirectInputDevice2WImpl_SetProperty( iface, guid, header ); }
- return DI_OK; + return DIERR_UNSUPPORTED; }
static HRESULT hid_joystick_internal_acquire( IDirectInputDevice8W *iface ) @@ -1251,7 +1196,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl = IDirectInputDevice2WImpl_GetCapabilities, IDirectInputDevice2WImpl_EnumObjects, IDirectInputDevice2WImpl_GetProperty, - hid_joystick_SetProperty, + IDirectInputDevice2WImpl_SetProperty, IDirectInputDevice2WImpl_Acquire, IDirectInputDevice2WImpl_Unacquire, hid_joystick_GetDeviceState, @@ -1504,6 +1449,7 @@ static const struct dinput_device_vtbl hid_joystick_internal_vtbl = hid_joystick_internal_unacquire, hid_joystick_internal_enum_objects, hid_joystick_internal_get_property, + hid_joystick_internal_set_property, };
static DWORD device_type_for_version( DWORD type, DWORD version ) @@ -1766,11 +1712,12 @@ static BOOL init_extra_caps( struct hid_joystick *impl, struct hid_value_caps *c DIDEVICEOBJECTINSTANCEW *instance, void *data ) { struct extra_caps *extra = impl->input_extra_caps + instance->dwOfs / sizeof(LONG); + LONG range_max = (instance->dwType & DIDFT_AXIS) ? 65535 : 36000; extra->bit_size = caps->bit_size; extra->logical_min = caps->logical_min; extra->logical_max = caps->logical_max; - extra->range_min = caps->physical_min; - extra->range_max = caps->physical_max; + set_extra_caps_range( impl, instance, 0, range_max ); + extra->saturation = 10000; return DIENUM_CONTINUE; }
@@ -2039,15 +1986,6 @@ static HRESULT hid_joystick_create_device( IDirectInputImpl *dinput, const GUID .dwHow = DIPH_DEVICE, }, }; - DIPROPDWORD saturation = - { - .diph = - { - .dwSize = sizeof(DIPROPDWORD), - .dwHeaderSize = sizeof(DIPROPHEADER), - .dwHow = DIPH_DEVICE, - }, - }; HIDD_ATTRIBUTES attrs = {.Size = sizeof(attrs)}; struct hid_preparsed_data *preparsed; struct hid_joystick *impl = NULL; @@ -2147,13 +2085,6 @@ static HRESULT hid_joystick_create_device( IDirectInputImpl *dinput, const GUID if (FAILED(hr = direct_input_device_init( &impl->base.IDirectInputDevice8W_iface ))) goto failed;
- range.lMax = 65535; - enum_objects( impl, &range.diph, DIDFT_AXIS, set_property_prop_range, &range ); - range.lMax = 36000; - enum_objects( impl, &range.diph, DIDFT_POV, set_property_prop_range, &range ); - saturation.dwData = 10000; - enum_objects( impl, &range.diph, DIDFT_AXIS, set_property_prop_saturation, &saturation ); - *out = &impl->base.IDirectInputDevice8W_iface; return DI_OK;
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index a1764eb64c0..0c2a1b839ff 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -360,6 +360,12 @@ static HRESULT keyboard_internal_get_property( IDirectInputDevice8W *iface, DWOR return DIERR_UNSUPPORTED; }
+static HRESULT keyboard_internal_set_property( IDirectInputDevice8W *iface, DWORD property, const DIPROPHEADER *header, + const DIDEVICEOBJECTINSTANCEW *instance ) +{ + return DIERR_UNSUPPORTED; +} + static const struct dinput_device_vtbl keyboard_internal_vtbl = { NULL, @@ -367,6 +373,7 @@ static const struct dinput_device_vtbl keyboard_internal_vtbl = keyboard_internal_unacquire, keyboard_internal_enum_objects, keyboard_internal_get_property, + keyboard_internal_set_property, };
static const IDirectInputDevice8WVtbl SysKeyboardWvt = diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index b3a48baa3aa..3553a5af94d 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -691,6 +691,12 @@ static HRESULT mouse_internal_get_property( IDirectInputDevice8W *iface, DWORD p return DIERR_UNSUPPORTED; }
+static HRESULT mouse_internal_set_property( IDirectInputDevice8W *iface, DWORD property, const DIPROPHEADER *header, + const DIDEVICEOBJECTINSTANCEW *instance ) +{ + return DIERR_UNSUPPORTED; +} + static const struct dinput_device_vtbl mouse_internal_vtbl = { NULL, @@ -698,6 +704,7 @@ static const struct dinput_device_vtbl mouse_internal_vtbl = mouse_internal_unacquire, mouse_internal_enum_objects, mouse_internal_get_property, + mouse_internal_set_property, };
static const IDirectInputDevice8WVtbl SysMouseWvt =