In preparation to keep action map app data in there, for `SetActionMap`.
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/dinput.c | 6 ------ dlls/dinput/joystick_hid.c | 14 ++++++++------ dlls/dinput/keyboard.c | 9 +++++++-- dlls/dinput/mouse.c | 11 ++++++++--- 4 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/dlls/dinput/dinput.c b/dlls/dinput/dinput.c index db367e1f1ba..998573ad20d 100644 --- a/dlls/dinput/dinput.c +++ b/dlls/dinput/dinput.c @@ -299,12 +299,6 @@ static HRESULT WINAPI dinput7_CreateDeviceEx( IDirectInput7W *iface, const GUID
if (FAILED(hr)) return hr;
- if (FAILED(hr = dinput_device_init_device_format( device ))) - { - IDirectInputDevice8_Release( device ); - return hr; - } - hr = IDirectInputDevice8_QueryInterface( device, iid, out ); IDirectInputDevice8_Release( device ); return hr; diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index e8a554142f4..7efae608b5f 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -2022,12 +2022,6 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi list_init( &impl->effect_list );
hr = E_OUTOFMEMORY; - preparsed = (struct hid_preparsed_data *)impl->preparsed; - size = preparsed->input_caps_count * sizeof(struct object_properties); - if (!(object_properties = calloc( 1, size ))) goto failed; - impl->base.object_properties = object_properties; - enum_objects( impl, &filter, DIDFT_AXIS | DIDFT_POV, init_object_properties, NULL ); - size = impl->caps.InputReportByteLength; if (!(buffer = malloc( size ))) goto failed; impl->input_report_buf = buffer; @@ -2087,6 +2081,14 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi impl->base.caps.dwFFDriverVersion = 1; }
+ preparsed = (struct hid_preparsed_data *)impl->preparsed; + size = preparsed->input_caps_count * sizeof(struct object_properties); + if (!(object_properties = calloc( 1, size ))) goto failed; + impl->base.object_properties = object_properties; + enum_objects( impl, &filter, DIDFT_AXIS | DIDFT_POV, init_object_properties, NULL ); + + if (FAILED(hr = dinput_device_init_device_format( &impl->base.IDirectInputDevice8W_iface ))) goto failed; + *out = &impl->base.IDirectInputDevice8W_iface; return DI_OK;
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index 0dfc909585a..cbcbf94f0f6 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -188,6 +188,7 @@ HRESULT keyboard_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instan HRESULT keyboard_create_device( struct dinput *dinput, const GUID *guid, IDirectInputDevice8W **out ) { struct keyboard *impl; + HRESULT hr;
TRACE( "dinput %p, guid %s, out %p.\n", dinput, debugstr_guid( guid ), out );
@@ -202,12 +203,16 @@ HRESULT keyboard_create_device( struct dinput *dinput, const GUID *guid, IDirect impl->base.caps.dwDevType = impl->base.instance.dwDevType; impl->base.caps.dwFirmwareRevision = 100; impl->base.caps.dwHardwareRevision = 100; + if (dinput->dwVersion >= 0x0800) impl->base.use_raw_input = TRUE;
- if (dinput->dwVersion >= 0x0800) - impl->base.use_raw_input = TRUE; + if (FAILED(hr = dinput_device_init_device_format( &impl->base.IDirectInputDevice8W_iface ))) goto failed;
*out = &impl->base.IDirectInputDevice8W_iface; return DI_OK; + +failed: + IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface ); + return hr; }
static HRESULT keyboard_poll( IDirectInputDevice8W *iface ) diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 9b1bf74b8d5..1c2a66e1bfa 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -107,6 +107,7 @@ HRESULT mouse_create_device( struct dinput *dinput, const GUID *guid, IDirectInp struct mouse *impl; HKEY hkey, appkey; WCHAR buffer[20]; + HRESULT hr;
TRACE( "dinput %p, guid %s, out %p\n", dinput, debugstr_guid( guid ), out );
@@ -122,6 +123,7 @@ HRESULT mouse_create_device( struct dinput *dinput, const GUID *guid, IDirectInp impl->base.caps.dwFirmwareRevision = 100; impl->base.caps.dwHardwareRevision = 100; impl->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND; + if (dinput->dwVersion >= 0x0800) impl->base.use_raw_input = TRUE;
/* One object_properties per axis */ impl->base.object_properties = calloc( 3, sizeof(struct object_properties) ); @@ -132,6 +134,8 @@ HRESULT mouse_create_device( struct dinput *dinput, const GUID *guid, IDirectInp } IDirectInputDevice8_EnumObjects( &impl->base.IDirectInputDevice8W_iface, init_object_properties, impl, DIDFT_RELAXIS );
+ if (FAILED(hr = dinput_device_init_device_format( &impl->base.IDirectInputDevice8W_iface ))) goto failed; + get_app_key(&hkey, &appkey); if (!get_config_key( hkey, appkey, L"MouseWarpOverride", buffer, sizeof(buffer) )) { @@ -141,11 +145,12 @@ HRESULT mouse_create_device( struct dinput *dinput, const GUID *guid, IDirectInp if (appkey) RegCloseKey(appkey); if (hkey) RegCloseKey(hkey);
- if (dinput->dwVersion >= 0x0800) - impl->base.use_raw_input = TRUE; - *out = &impl->base.IDirectInputDevice8W_iface; return DI_OK; + +failed: + IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface ); + return hr; }
void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam, RAWINPUT *ri )
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/mouse.c | 102 ++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 51 deletions(-)
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 1c2a66e1bfa..cb19f5d1850 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -102,57 +102,6 @@ static BOOL CALLBACK init_object_properties( const DIDEVICEOBJECTINSTANCEW *inst return DIENUM_CONTINUE; }
-HRESULT mouse_create_device( struct dinput *dinput, const GUID *guid, IDirectInputDevice8W **out ) -{ - struct mouse *impl; - HKEY hkey, appkey; - WCHAR buffer[20]; - HRESULT hr; - - TRACE( "dinput %p, guid %s, out %p\n", dinput, debugstr_guid( guid ), out ); - - *out = NULL; - if (!IsEqualGUID( &GUID_SysMouse, guid )) return DIERR_DEVICENOTREG; - - if (!(impl = calloc( 1, sizeof(*impl) ))) return E_OUTOFMEMORY; - dinput_device_init( &impl->base, &mouse_vtbl, guid, dinput ); - impl->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": struct mouse*->base.crit"); - - mouse_enum_device( 0, 0, &impl->base.instance, dinput->dwVersion ); - impl->base.caps.dwDevType = impl->base.instance.dwDevType; - impl->base.caps.dwFirmwareRevision = 100; - impl->base.caps.dwHardwareRevision = 100; - impl->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND; - if (dinput->dwVersion >= 0x0800) impl->base.use_raw_input = TRUE; - - /* One object_properties per axis */ - impl->base.object_properties = calloc( 3, sizeof(struct object_properties) ); - if (!impl->base.object_properties) - { - IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface ); - return E_OUTOFMEMORY; - } - IDirectInputDevice8_EnumObjects( &impl->base.IDirectInputDevice8W_iface, init_object_properties, impl, DIDFT_RELAXIS ); - - if (FAILED(hr = dinput_device_init_device_format( &impl->base.IDirectInputDevice8W_iface ))) goto failed; - - get_app_key(&hkey, &appkey); - if (!get_config_key( hkey, appkey, L"MouseWarpOverride", buffer, sizeof(buffer) )) - { - if (!wcsnicmp( buffer, L"disable", -1 )) impl->warp_override = WARP_DISABLE; - else if (!wcsnicmp( buffer, L"force", -1 )) impl->warp_override = WARP_FORCE_ON; - } - if (appkey) RegCloseKey(appkey); - if (hkey) RegCloseKey(hkey); - - *out = &impl->base.IDirectInputDevice8W_iface; - return DI_OK; - -failed: - IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface ); - return hr; -} - void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam, RAWINPUT *ri ) { struct mouse *impl = impl_from_IDirectInputDevice8W( iface ); @@ -559,6 +508,57 @@ static HRESULT mouse_enum_objects( IDirectInputDevice8W *iface, const DIPROPHEAD return DIENUM_CONTINUE; }
+HRESULT mouse_create_device( struct dinput *dinput, const GUID *guid, IDirectInputDevice8W **out ) +{ + struct mouse *impl; + HKEY hkey, appkey; + WCHAR buffer[20]; + HRESULT hr; + + TRACE( "dinput %p, guid %s, out %p\n", dinput, debugstr_guid( guid ), out ); + + *out = NULL; + if (!IsEqualGUID( &GUID_SysMouse, guid )) return DIERR_DEVICENOTREG; + + if (!(impl = calloc( 1, sizeof(*impl) ))) return E_OUTOFMEMORY; + dinput_device_init( &impl->base, &mouse_vtbl, guid, dinput ); + impl->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": struct mouse*->base.crit"); + + mouse_enum_device( 0, 0, &impl->base.instance, dinput->dwVersion ); + impl->base.caps.dwDevType = impl->base.instance.dwDevType; + impl->base.caps.dwFirmwareRevision = 100; + impl->base.caps.dwHardwareRevision = 100; + impl->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND; + if (dinput->dwVersion >= 0x0800) impl->base.use_raw_input = TRUE; + + /* One object_properties per axis */ + impl->base.object_properties = calloc( 3, sizeof(struct object_properties) ); + if (!impl->base.object_properties) + { + IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface ); + return E_OUTOFMEMORY; + } + IDirectInputDevice8_EnumObjects( &impl->base.IDirectInputDevice8W_iface, init_object_properties, impl, DIDFT_RELAXIS ); + + if (FAILED(hr = dinput_device_init_device_format( &impl->base.IDirectInputDevice8W_iface ))) goto failed; + + get_app_key(&hkey, &appkey); + if (!get_config_key( hkey, appkey, L"MouseWarpOverride", buffer, sizeof(buffer) )) + { + if (!wcsnicmp( buffer, L"disable", -1 )) impl->warp_override = WARP_DISABLE; + else if (!wcsnicmp( buffer, L"force", -1 )) impl->warp_override = WARP_FORCE_ON; + } + if (appkey) RegCloseKey(appkey); + if (hkey) RegCloseKey(hkey); + + *out = &impl->base.IDirectInputDevice8W_iface; + return DI_OK; + +failed: + IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface ); + return hr; +} + static const struct dinput_device_vtbl mouse_vtbl = { NULL,
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/device.c | 44 ++++++++++++++++++++------------------ dlls/dinput/joystick_hid.c | 21 +++++++++--------- dlls/dinput/mouse.c | 32 +++++++++++---------------- 3 files changed, 47 insertions(+), 50 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 407e4f52a38..14b83311aac 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -1077,18 +1077,12 @@ struct get_object_property_params static BOOL get_object_property( struct dinput_device *device, UINT index, struct hid_value_caps *caps, const DIDEVICEOBJECTINSTANCEW *instance, void *data ) { - static const struct object_properties default_properties = - { - .range_min = DIPROPRANGE_NOMIN, - .range_max = DIPROPRANGE_NOMAX, - .granularity = 1, - }; struct get_object_property_params *params = data; struct dinput_device *impl = impl_from_IDirectInputDevice8W( params->iface ); - const struct object_properties *properties = NULL; + const struct object_properties *properties;
- if (!impl->object_properties) properties = &default_properties; - else properties = impl->object_properties + instance->dwOfs / sizeof(LONG); + if (index == -1) return DIENUM_STOP; + properties = impl->object_properties + index;
switch (params->property) { @@ -1257,10 +1251,10 @@ static BOOL set_object_property( struct dinput_device *device, UINT index, struc { struct set_object_property_params *params = data; struct dinput_device *impl = impl_from_IDirectInputDevice8W( params->iface ); - struct object_properties *properties = NULL; + struct object_properties *properties;
- if (!impl->object_properties) return DIENUM_STOP; - properties = impl->object_properties + instance->dwOfs / sizeof(LONG); + if (index == -1) return DIENUM_STOP; + properties = impl->object_properties + index;
switch (params->property) { @@ -1300,13 +1294,15 @@ static BOOL reset_object_value( struct dinput_device *impl, UINT index, struct h struct object_properties *properties; LONG tmp = -1;
- if (!impl->object_properties) return DIENUM_STOP; - properties = impl->object_properties + instance->dwOfs / sizeof(LONG); + if (index == -1) return DIENUM_STOP; + properties = impl->object_properties + index;
if (instance->dwType & DIDFT_AXIS) { - if (!properties->range_min) tmp = properties->range_max / 2; - else tmp = round( (properties->range_min + properties->range_max) / 2.0 ); + LONG range_min = 0, range_max = 0xfffe; + if (properties->range_min != DIPROPRANGE_NOMIN) range_min = properties->range_min; + if (properties->range_max != DIPROPRANGE_NOMAX) range_max = properties->range_max; + tmp = round( (range_min + range_max) / 2.0 ); }
*(LONG *)(impl->device_state + instance->dwOfs) = tmp; @@ -2210,6 +2206,12 @@ static BOOL enum_objects_count( struct dinput_device *impl, UINT index, struct h static BOOL enum_objects_init( struct dinput_device *impl, UINT index, struct hid_value_caps *caps, const DIDEVICEOBJECTINSTANCEW *instance, void *data ) { + static const struct object_properties default_properties = + { + .range_min = DIPROPRANGE_NOMIN, + .range_max = DIPROPRANGE_NOMAX, + .granularity = 1, + }; DIDATAFORMAT *format = &impl->device_format; DIOBJECTDATAFORMAT *object_format;
@@ -2222,8 +2224,8 @@ static BOOL enum_objects_init( struct dinput_device *impl, UINT index, struct hi object_format->dwType = instance->dwType; object_format->dwFlags = instance->dwFlags;
- if (impl->object_properties && (instance->dwType & (DIDFT_AXIS | DIDFT_POV))) - reset_object_value( impl, index, caps, instance, NULL ); + impl->object_properties[index] = default_properties; + if (instance->dwType & (DIDFT_AXIS | DIDFT_POV)) reset_object_value( impl, index, caps, instance, NULL );
return DIENUM_CONTINUE; } @@ -2238,8 +2240,8 @@ HRESULT dinput_device_init_device_format( IDirectInputDevice8W *iface ) }; struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface ); DIDATAFORMAT *format = &impl->device_format; - ULONG i, size; HRESULT hr; + ULONG i;
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_ALL, enum_objects_count, NULL ); if (FAILED(hr)) return hr; @@ -2250,8 +2252,8 @@ HRESULT dinput_device_init_device_format( IDirectInputDevice8W *iface ) return DIERR_OUTOFMEMORY; }
- size = format->dwNumObjs * sizeof(*format->rgodf); - if (!(format->rgodf = calloc( 1, size ))) return DIERR_OUTOFMEMORY; + if (!(impl->object_properties = calloc( format->dwNumObjs, sizeof(*impl->object_properties) ))) return DIERR_OUTOFMEMORY; + if (!(format->rgodf = calloc( format->dwNumObjs, sizeof(*format->rgodf) ))) return DIERR_OUTOFMEMORY;
format->dwSize = sizeof(*format); format->dwObjSize = sizeof(*format->rgodf); diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 7efae608b5f..42f58c52202 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -1176,14 +1176,17 @@ static BOOL read_device_state_value( struct dinput_device *device, UINT index, s const DIDEVICEOBJECTINSTANCEW *instance, void *data ) { struct hid_joystick *impl = CONTAINING_RECORD( device, struct hid_joystick, base ); - struct object_properties *properties = impl->base.object_properties + 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 object_properties *properties; LONG old_value, value; NTSTATUS status;
+ if (index == -1) return DIENUM_STOP; + properties = device->object_properties + index; + if (instance->wReportId != impl->base.device_state_report_id) return DIENUM_CONTINUE;
status = HidP_GetUsageValue( HidP_Input, instance->wUsagePage, 0, instance->wUsage, @@ -1645,14 +1648,19 @@ HRESULT hid_joystick_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *in static BOOL init_object_properties( struct dinput_device *device, UINT index, struct hid_value_caps *caps, const DIDEVICEOBJECTINSTANCEW *instance, void *data ) { - struct object_properties *properties = device->object_properties + instance->dwOfs / sizeof(LONG); + struct object_properties *properties; LONG tmp;
+ if (index == -1) return DIENUM_STOP; + properties = device->object_properties + index; + properties->bit_size = caps->bit_size; properties->physical_min = caps->physical_min; properties->physical_max = caps->physical_max; properties->logical_min = caps->logical_min; properties->logical_max = caps->logical_max; + properties->range_min = 0; + properties->range_max = 0;
if (instance->dwType & DIDFT_AXIS) properties->range_max = 65535; else @@ -1988,8 +1996,6 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi }, }; HIDD_ATTRIBUTES attrs = {.Size = sizeof(attrs)}; - struct object_properties *object_properties; - struct hid_preparsed_data *preparsed; struct hid_joystick *impl = NULL; USAGE_AND_PAGE *usages; char *buffer; @@ -2081,13 +2087,8 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi impl->base.caps.dwFFDriverVersion = 1; }
- preparsed = (struct hid_preparsed_data *)impl->preparsed; - size = preparsed->input_caps_count * sizeof(struct object_properties); - if (!(object_properties = calloc( 1, size ))) goto failed; - impl->base.object_properties = object_properties; - enum_objects( impl, &filter, DIDFT_AXIS | DIDFT_POV, init_object_properties, NULL ); - if (FAILED(hr = dinput_device_init_device_format( &impl->base.IDirectInputDevice8W_iface ))) goto failed; + enum_objects( impl, &filter, DIDFT_AXIS | DIDFT_POV, init_object_properties, NULL );
*out = &impl->base.IDirectInputDevice8W_iface; return DI_OK; diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index cb19f5d1850..ec30c825733 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -85,20 +85,16 @@ HRESULT mouse_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance, return DI_OK; }
-static BOOL CALLBACK init_object_properties( const DIDEVICEOBJECTINSTANCEW *instance, void *data ) +static BOOL init_object_properties( struct dinput_device *device, UINT index, struct hid_value_caps *caps, + const DIDEVICEOBJECTINSTANCEW *instance, void *data ) { - struct mouse *impl = (struct mouse *)data; - struct object_properties *properties = impl->base.object_properties + instance->dwOfs / sizeof(LONG); + struct object_properties *properties;
- properties->range_min = DIPROPRANGE_NOMIN; - properties->range_max = DIPROPRANGE_NOMAX; + if (index == -1) return DIENUM_STOP; + properties = device->object_properties + index;
/* The z-axis (wheel) has a different granularity */ - if (instance->dwOfs == DIMOFS_Z) - properties->granularity = WHEEL_DELTA; - else - properties->granularity = 1; - + if (instance->dwOfs == DIMOFS_Z) properties->granularity = WHEEL_DELTA; return DIENUM_CONTINUE; }
@@ -510,6 +506,12 @@ static HRESULT mouse_enum_objects( IDirectInputDevice8W *iface, const DIPROPHEAD
HRESULT mouse_create_device( struct dinput *dinput, const GUID *guid, IDirectInputDevice8W **out ) { + static const DIPROPHEADER filter = + { + .dwSize = sizeof(filter), + .dwHeaderSize = sizeof(filter), + .dwHow = DIPH_DEVICE, + }; struct mouse *impl; HKEY hkey, appkey; WCHAR buffer[20]; @@ -531,16 +533,8 @@ HRESULT mouse_create_device( struct dinput *dinput, const GUID *guid, IDirectInp impl->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND; if (dinput->dwVersion >= 0x0800) impl->base.use_raw_input = TRUE;
- /* One object_properties per axis */ - impl->base.object_properties = calloc( 3, sizeof(struct object_properties) ); - if (!impl->base.object_properties) - { - IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface ); - return E_OUTOFMEMORY; - } - IDirectInputDevice8_EnumObjects( &impl->base.IDirectInputDevice8W_iface, init_object_properties, impl, DIDFT_RELAXIS ); - if (FAILED(hr = dinput_device_init_device_format( &impl->base.IDirectInputDevice8W_iface ))) goto failed; + mouse_enum_objects( &impl->base.IDirectInputDevice8W_iface, &filter, DIDFT_AXIS, init_object_properties, NULL );
get_app_key(&hkey, &appkey); if (!get_config_key( hkey, appkey, L"MouseWarpOverride", buffer, sizeof(buffer) ))
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/device.c | 77 ++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 35 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 14b83311aac..3d0527cddb3 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -1975,11 +1975,40 @@ static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, D const WCHAR *username, DWORD flags ) { struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface ); - DIDATAFORMAT data_format; DIOBJECTDATAFORMAT *obj_df = NULL; - DIPROPDWORD dp; - DIPROPRANGE dpr; - DIPROPSTRING dps; + DIDATAFORMAT data_format = + { + .dwSize = sizeof(DIDATAFORMAT), + .dwObjSize = sizeof(DIOBJECTDATAFORMAT), + .dwFlags = DIDF_RELAXIS, + }; + DIPROPDWORD prop_buffer = + { + .diph = + { + .dwHeaderSize = sizeof(DIPROPHEADER), + .dwSize = sizeof(DIPROPDWORD), + .dwHow = DIPH_DEVICE, + } + }; + DIPROPRANGE prop_range = + { + .diph = + { + .dwHeaderSize = sizeof(DIPROPHEADER), + .dwSize = sizeof(DIPROPRANGE), + .dwHow = DIPH_DEVICE, + } + }; + DIPROPSTRING prop_username = + { + .diph = + { + .dwHeaderSize = sizeof(DIPROPHEADER), + .dwSize = sizeof(DIPROPSTRING), + .dwHow = DIPH_DEVICE, + } + }; WCHAR username_buf[MAX_PATH]; DWORD username_len = MAX_PATH; int i, action = 0, num_actions = 0; @@ -2009,11 +2038,6 @@ static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, D
if (impl->status == STATUS_ACQUIRED) return DIERR_ACQUIRED;
- data_format.dwSize = sizeof(data_format); - data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT); - data_format.dwFlags = DIDF_RELAXIS; - data_format.dwDataSize = format->dwDataSize; - /* Count the actions */ for (i = 0; i < format->dwNumActions; i++) if (IsEqualGUID( &impl->guid, &format->rgoAction[i].guidInstance )) @@ -2025,6 +2049,7 @@ static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, D obj_df = malloc( sizeof(DIOBJECTDATAFORMAT) * num_actions ); data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df; data_format.dwNumObjs = num_actions; + data_format.dwDataSize = format->dwDataSize;
action_map = malloc( sizeof(ActionMap) * num_actions );
@@ -2059,38 +2084,20 @@ static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, D
free( obj_df );
- /* Set the device properties according to the action format */ - dpr.diph.dwSize = sizeof(DIPROPRANGE); - dpr.lMin = format->lAxisMin; - dpr.lMax = format->lAxisMax; - dpr.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dpr.diph.dwObj = 0; - dpr.diph.dwHow = DIPH_DEVICE; - IDirectInputDevice8_SetProperty( iface, DIPROP_RANGE, &dpr.diph ); + prop_range.lMin = format->lAxisMin; + prop_range.lMax = format->lAxisMax; + IDirectInputDevice8_SetProperty( iface, DIPROP_RANGE, &prop_range.diph );
- if (format->dwBufferSize > 0) - { - dp.diph.dwSize = sizeof(DIPROPDWORD); - dp.dwData = format->dwBufferSize; - dp.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dp.diph.dwObj = 0; - dp.diph.dwHow = DIPH_DEVICE; - IDirectInputDevice8_SetProperty( iface, DIPROP_BUFFERSIZE, &dp.diph ); - } + if ((prop_buffer.dwData = format->dwBufferSize)) + IDirectInputDevice8_SetProperty( iface, DIPROP_BUFFERSIZE, &prop_buffer.diph );
- /* Retrieve logged user name if necessary */ if (username == NULL) GetUserNameW( username_buf, &username_len ); else lstrcpynW( username_buf, username, MAX_PATH );
- dps.diph.dwSize = sizeof(dps); - dps.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dps.diph.dwObj = 0; - dps.diph.dwHow = DIPH_DEVICE; - if (flags & DIDSAM_NOUSER) dps.wsz[0] = '\0'; - else lstrcpynW( dps.wsz, username_buf, ARRAY_SIZE(dps.wsz) ); - dinput_device_set_username( impl, &dps ); + if (flags & DIDSAM_NOUSER) prop_username.wsz[0] = '\0'; + else lstrcpynW( prop_username.wsz, username_buf, ARRAY_SIZE(prop_username.wsz) ); + dinput_device_set_username( impl, &prop_username );
- /* Save the settings to disk */ save_mapping_settings( iface, format, username_buf );
return DI_OK;
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/dinput/device.c | 4 ++-- dlls/dinput/tests/joystick8.c | 1 - 2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 3d0527cddb3..bdae9a4c93e 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -2088,8 +2088,8 @@ static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, D prop_range.lMax = format->lAxisMax; IDirectInputDevice8_SetProperty( iface, DIPROP_RANGE, &prop_range.diph );
- if ((prop_buffer.dwData = format->dwBufferSize)) - IDirectInputDevice8_SetProperty( iface, DIPROP_BUFFERSIZE, &prop_buffer.diph ); + prop_buffer.dwData = format->dwBufferSize; + IDirectInputDevice8_SetProperty( iface, DIPROP_BUFFERSIZE, &prop_buffer.diph );
if (username == NULL) GetUserNameW( username_buf, &username_len ); else lstrcpynW( username_buf, username, MAX_PATH ); diff --git a/dlls/dinput/tests/joystick8.c b/dlls/dinput/tests/joystick8.c index 5295ee6c169..0cc2ec7d681 100644 --- a/dlls/dinput/tests/joystick8.c +++ b/dlls/dinput/tests/joystick8.c @@ -941,7 +941,6 @@ static void test_action_map( IDirectInputDevice8W *device, HANDLE file, HANDLE e
hr = IDirectInputDevice8_GetProperty( device, DIPROP_BUFFERSIZE, &prop_dword.diph ); ok( hr == DI_OK, "GetProperty returned %#lx\n", hr ); - todo_wine ok( prop_dword.dwData == 0, "got dwData %#lx\n", prop_dword.dwData );