Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 39 ++++++++++++++++++++++++++++++++++++++ dlls/dinput/joystick_hid.c | 9 +-------- 2 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index a3dde86f8be..c4d40e1278b 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -27,6 +27,7 @@
#include <stdarg.h> #include <string.h> +#include <math.h>
#include "windef.h" #include "winbase.h" @@ -1037,6 +1038,39 @@ static BOOL CALLBACK set_object_property( const DIDEVICEOBJECTINSTANCEW *instanc return DIENUM_CONTINUE; }
+static BOOL CALLBACK reset_object_value( const DIDEVICEOBJECTINSTANCEW *instance, void *context ) +{ + struct dinput_device *impl = context; + struct object_properties *properties; + LONG tmp = -1; + + if (!impl->object_properties) return DIENUM_STOP; + properties = impl->object_properties + instance->dwOfs / sizeof(LONG); + + 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 *)(impl->device_state + instance->dwOfs) = tmp; + return DIENUM_CONTINUE; +} + +static void reset_device_state( IDirectInputDevice8W *iface ) +{ + struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface ); + DIPROPHEADER filter = + { + .dwHeaderSize = sizeof(DIPROPHEADER), + .dwSize = sizeof(DIPROPHEADER), + .dwHow = DIPH_DEVICE, + .dwObj = 0, + }; + + impl->vtbl->enum_objects( iface, &filter, DIDFT_AXIS | DIDFT_POV, reset_object_value, impl ); +} + static HRESULT WINAPI dinput_device_SetProperty( IDirectInputDevice8W *iface, const GUID *guid, const DIPROPHEADER *header ) { @@ -1065,6 +1099,7 @@ static HRESULT WINAPI dinput_device_SetProperty( IDirectInputDevice8W *iface, co if (value->lMin > value->lMax) return DIERR_INVALIDPARAM; hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_AXIS, set_object_property, ¶ms ); if (FAILED(hr)) return hr; + reset_device_state( iface ); return DI_OK; } case (DWORD_PTR)DIPROP_DEADZONE: @@ -1075,6 +1110,7 @@ static HRESULT WINAPI dinput_device_SetProperty( IDirectInputDevice8W *iface, co if (value->dwData > 10000) return DIERR_INVALIDPARAM; hr = impl->vtbl->enum_objects( iface, &filter, DIDFT_AXIS, set_object_property, ¶ms ); if (FAILED(hr)) return hr; + reset_device_state( iface ); return DI_OK; } case (DWORD_PTR)DIPROP_AUTOCENTER: @@ -1922,6 +1958,9 @@ static BOOL CALLBACK enum_objects_init( const DIDEVICEOBJECTINSTANCEW *instance, obj_format->dwFlags = instance->dwFlags; }
+ if (impl->object_properties && (instance->dwType & (DIDFT_AXIS | DIDFT_POV))) + reset_object_value( instance, impl ); + format->dwNumObjs++; return DIENUM_CONTINUE; } diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 81b54ffe7a3..b252b9a13c9 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -789,17 +789,10 @@ static void set_extra_caps_range( struct hid_joystick *impl, const DIDEVICEOBJEC properties->range_min = min; properties->range_max = max;
- 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 *)(impl->base.device_state + instance->dwOfs) = tmp; - } - else if (instance->dwType & DIDFT_POV) + if (instance->dwType & DIDFT_POV) { tmp = properties->logical_max - properties->logical_min; if (tmp > 0) properties->range_max -= max / (tmp + 1); - *(LONG *)(impl->base.device_state + instance->dwOfs) = -1; } }