Rémi Bernon : dinput: Reset axis and pov values on object property change.
Alexandre Julliard
julliard at winehq.org
Thu Nov 18 16:19:38 CST 2021
Module: wine
Branch: master
Commit: c918234f7125692fee4f559391e31d116339b71e
URL: https://source.winehq.org/git/wine.git/?a=commit;h=c918234f7125692fee4f559391e31d116339b71e
Author: Rémi Bernon <rbernon at codeweavers.com>
Date: Thu Nov 18 09:53:13 2021 +0100
dinput: Reset axis and pov values on object property change.
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
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;
}
}
More information about the wine-cvs
mailing list