Commit 80a35fb4 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dinput: Always allocate and initialize the object_properties.

parent f2094069
...@@ -1077,18 +1077,12 @@ struct get_object_property_params ...@@ -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, static BOOL get_object_property( struct dinput_device *device, UINT index, struct hid_value_caps *caps,
const DIDEVICEOBJECTINSTANCEW *instance, void *data ) 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 get_object_property_params *params = data;
struct dinput_device *impl = impl_from_IDirectInputDevice8W( params->iface ); 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; if (index == -1) return DIENUM_STOP;
else properties = impl->object_properties + instance->dwOfs / sizeof(LONG); properties = impl->object_properties + index;
switch (params->property) switch (params->property)
{ {
...@@ -1257,10 +1251,10 @@ static BOOL set_object_property( struct dinput_device *device, UINT index, struc ...@@ -1257,10 +1251,10 @@ static BOOL set_object_property( struct dinput_device *device, UINT index, struc
{ {
struct set_object_property_params *params = data; struct set_object_property_params *params = data;
struct dinput_device *impl = impl_from_IDirectInputDevice8W( params->iface ); 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; if (index == -1) return DIENUM_STOP;
properties = impl->object_properties + instance->dwOfs / sizeof(LONG); properties = impl->object_properties + index;
switch (params->property) switch (params->property)
{ {
...@@ -1300,13 +1294,15 @@ static BOOL reset_object_value( struct dinput_device *impl, UINT index, struct h ...@@ -1300,13 +1294,15 @@ static BOOL reset_object_value( struct dinput_device *impl, UINT index, struct h
struct object_properties *properties; struct object_properties *properties;
LONG tmp = -1; LONG tmp = -1;
if (!impl->object_properties) return DIENUM_STOP; if (index == -1) return DIENUM_STOP;
properties = impl->object_properties + instance->dwOfs / sizeof(LONG); properties = impl->object_properties + index;
if (instance->dwType & DIDFT_AXIS) if (instance->dwType & DIDFT_AXIS)
{ {
if (!properties->range_min) tmp = properties->range_max / 2; LONG range_min = 0, range_max = 0xfffe;
else tmp = round( (properties->range_min + properties->range_max) / 2.0 ); 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; *(LONG *)(impl->device_state + instance->dwOfs) = tmp;
...@@ -2211,6 +2207,12 @@ static BOOL enum_objects_count( struct dinput_device *impl, UINT index, struct h ...@@ -2211,6 +2207,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, static BOOL enum_objects_init( struct dinput_device *impl, UINT index, struct hid_value_caps *caps,
const DIDEVICEOBJECTINSTANCEW *instance, void *data ) 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; DIDATAFORMAT *format = &impl->device_format;
DIOBJECTDATAFORMAT *object_format; DIOBJECTDATAFORMAT *object_format;
...@@ -2223,8 +2225,8 @@ static BOOL enum_objects_init( struct dinput_device *impl, UINT index, struct hi ...@@ -2223,8 +2225,8 @@ static BOOL enum_objects_init( struct dinput_device *impl, UINT index, struct hi
object_format->dwType = instance->dwType; object_format->dwType = instance->dwType;
object_format->dwFlags = instance->dwFlags; object_format->dwFlags = instance->dwFlags;
if (impl->object_properties && (instance->dwType & (DIDFT_AXIS | DIDFT_POV))) impl->object_properties[index] = default_properties;
reset_object_value( impl, index, caps, instance, NULL ); if (instance->dwType & (DIDFT_AXIS | DIDFT_POV)) reset_object_value( impl, index, caps, instance, NULL );
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
} }
...@@ -2239,8 +2241,8 @@ HRESULT dinput_device_init_device_format( IDirectInputDevice8W *iface ) ...@@ -2239,8 +2241,8 @@ HRESULT dinput_device_init_device_format( IDirectInputDevice8W *iface )
}; };
struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface ); struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface );
DIDATAFORMAT *format = &impl->device_format; DIDATAFORMAT *format = &impl->device_format;
ULONG i, size;
HRESULT hr; HRESULT hr;
ULONG i;
hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_ALL, enum_objects_count, NULL ); hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_ALL, enum_objects_count, NULL );
if (FAILED(hr)) return hr; if (FAILED(hr)) return hr;
...@@ -2251,8 +2253,8 @@ HRESULT dinput_device_init_device_format( IDirectInputDevice8W *iface ) ...@@ -2251,8 +2253,8 @@ HRESULT dinput_device_init_device_format( IDirectInputDevice8W *iface )
return DIERR_OUTOFMEMORY; return DIERR_OUTOFMEMORY;
} }
size = format->dwNumObjs * sizeof(*format->rgodf); if (!(impl->object_properties = calloc( format->dwNumObjs, sizeof(*impl->object_properties) ))) return DIERR_OUTOFMEMORY;
if (!(format->rgodf = calloc( 1, size ))) return DIERR_OUTOFMEMORY; if (!(format->rgodf = calloc( format->dwNumObjs, sizeof(*format->rgodf) ))) return DIERR_OUTOFMEMORY;
format->dwSize = sizeof(*format); format->dwSize = sizeof(*format);
format->dwObjSize = sizeof(*format->rgodf); format->dwObjSize = sizeof(*format->rgodf);
......
...@@ -1176,14 +1176,17 @@ static BOOL read_device_state_value( struct dinput_device *device, UINT index, s ...@@ -1176,14 +1176,17 @@ static BOOL read_device_state_value( struct dinput_device *device, UINT index, s
const DIDEVICEOBJECTINSTANCEW *instance, void *data ) const DIDEVICEOBJECTINSTANCEW *instance, void *data )
{ {
struct hid_joystick *impl = CONTAINING_RECORD( device, struct hid_joystick, base ); 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; IDirectInputDevice8W *iface = &impl->base.IDirectInputDevice8W_iface;
ULONG logical_value, report_len = impl->caps.InputReportByteLength; ULONG logical_value, report_len = impl->caps.InputReportByteLength;
struct parse_device_state_params *params = data; struct parse_device_state_params *params = data;
char *report_buf = impl->input_report_buf; char *report_buf = impl->input_report_buf;
struct object_properties *properties;
LONG old_value, value; LONG old_value, value;
NTSTATUS status; 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; if (instance->wReportId != impl->base.device_state_report_id) return DIENUM_CONTINUE;
status = HidP_GetUsageValue( HidP_Input, instance->wUsagePage, 0, instance->wUsage, 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 ...@@ -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, static BOOL init_object_properties( struct dinput_device *device, UINT index, struct hid_value_caps *caps,
const DIDEVICEOBJECTINSTANCEW *instance, void *data ) const DIDEVICEOBJECTINSTANCEW *instance, void *data )
{ {
struct object_properties *properties = device->object_properties + instance->dwOfs / sizeof(LONG); struct object_properties *properties;
LONG tmp; LONG tmp;
if (index == -1) return DIENUM_STOP;
properties = device->object_properties + index;
properties->bit_size = caps->bit_size; properties->bit_size = caps->bit_size;
properties->physical_min = caps->physical_min; properties->physical_min = caps->physical_min;
properties->physical_max = caps->physical_max; properties->physical_max = caps->physical_max;
properties->logical_min = caps->logical_min; properties->logical_min = caps->logical_min;
properties->logical_max = caps->logical_max; properties->logical_max = caps->logical_max;
properties->range_min = 0;
properties->range_max = 0;
if (instance->dwType & DIDFT_AXIS) properties->range_max = 65535; if (instance->dwType & DIDFT_AXIS) properties->range_max = 65535;
else else
...@@ -1988,8 +1996,6 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi ...@@ -1988,8 +1996,6 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi
}, },
}; };
HIDD_ATTRIBUTES attrs = {.Size = sizeof(attrs)}; HIDD_ATTRIBUTES attrs = {.Size = sizeof(attrs)};
struct object_properties *object_properties;
struct hid_preparsed_data *preparsed;
struct hid_joystick *impl = NULL; struct hid_joystick *impl = NULL;
USAGE_AND_PAGE *usages; USAGE_AND_PAGE *usages;
char *buffer; char *buffer;
...@@ -2081,13 +2087,8 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi ...@@ -2081,13 +2087,8 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi
impl->base.caps.dwFFDriverVersion = 1; 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; 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; *out = &impl->base.IDirectInputDevice8W_iface;
return DI_OK; return DI_OK;
......
...@@ -85,20 +85,16 @@ HRESULT mouse_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance, ...@@ -85,20 +85,16 @@ HRESULT mouse_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance,
return DI_OK; 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;
struct object_properties *properties = impl->base.object_properties + instance->dwOfs / sizeof(LONG);
properties->range_min = DIPROPRANGE_NOMIN; if (index == -1) return DIENUM_STOP;
properties->range_max = DIPROPRANGE_NOMAX; properties = device->object_properties + index;
/* The z-axis (wheel) has a different granularity */ /* The z-axis (wheel) has a different granularity */
if (instance->dwOfs == DIMOFS_Z) if (instance->dwOfs == DIMOFS_Z) properties->granularity = WHEEL_DELTA;
properties->granularity = WHEEL_DELTA;
else
properties->granularity = 1;
return DIENUM_CONTINUE; return DIENUM_CONTINUE;
} }
...@@ -510,6 +506,12 @@ static HRESULT mouse_enum_objects( IDirectInputDevice8W *iface, const DIPROPHEAD ...@@ -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 ) 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; struct mouse *impl;
HKEY hkey, appkey; HKEY hkey, appkey;
WCHAR buffer[20]; WCHAR buffer[20];
...@@ -531,16 +533,8 @@ HRESULT mouse_create_device( struct dinput *dinput, const GUID *guid, IDirectInp ...@@ -531,16 +533,8 @@ HRESULT mouse_create_device( struct dinput *dinput, const GUID *guid, IDirectInp
impl->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND; impl->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
if (dinput->dwVersion >= 0x0800) impl->base.use_raw_input = TRUE; 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; 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); get_app_key(&hkey, &appkey);
if (!get_config_key( hkey, appkey, L"MouseWarpOverride", buffer, sizeof(buffer) )) if (!get_config_key( hkey, appkey, L"MouseWarpOverride", buffer, sizeof(buffer) ))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment