Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 26 +++++++++++++------------- dlls/dinput/device_private.h | 8 +++++++- dlls/dinput/dinput_main.c | 4 ++-- dlls/dinput/joystick_hid.c | 2 +- 4 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 5f8227acd0c..47cf4d72dc3 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -84,7 +84,7 @@ static inline const char *debugstr_diobjectdataformat( const DIOBJECTDATAFORMAT
static inline BOOL is_exclusively_acquired( struct dinput_device *device ) { - return device->acquired && (device->dwCoopLevel & DISCL_EXCLUSIVE); + return device->status == STATUS_ACQUIRED && (device->dwCoopLevel & DISCL_EXCLUSIVE); }
/****************************************************************************** @@ -582,7 +582,7 @@ static HRESULT WINAPI dinput_device_Acquire( IDirectInputDevice8W *iface ) TRACE( "iface %p.\n", iface );
EnterCriticalSection( &impl->crit ); - if (impl->acquired) + if (impl->status == STATUS_ACQUIRED) hr = DI_NOEFFECT; else if (!impl->user_format) hr = DIERR_INVALIDPARAM; @@ -590,8 +590,8 @@ static HRESULT WINAPI dinput_device_Acquire( IDirectInputDevice8W *iface ) hr = DIERR_OTHERAPPHASPRIO; else { - impl->acquired = TRUE; - if (FAILED(hr = impl->vtbl->acquire( iface ))) impl->acquired = FALSE; + impl->status = STATUS_ACQUIRED; + if (FAILED(hr = impl->vtbl->acquire( iface ))) impl->status = STATUS_UNACQUIRED; } LeaveCriticalSection( &impl->crit ); if (hr != DI_OK) return hr; @@ -614,9 +614,9 @@ static HRESULT WINAPI dinput_device_Unacquire( IDirectInputDevice8W *iface ) TRACE( "iface %p.\n", iface );
EnterCriticalSection( &impl->crit ); - if (!impl->acquired) hr = DI_NOEFFECT; + if (impl->status != STATUS_ACQUIRED) hr = DI_NOEFFECT; else hr = impl->vtbl->unacquire( iface ); - impl->acquired = FALSE; + impl->status = STATUS_UNACQUIRED; LeaveCriticalSection( &impl->crit ); if (hr != DI_OK) return hr;
@@ -647,7 +647,7 @@ static HRESULT WINAPI dinput_device_SetDataFormat( IDirectInputDevice8W *iface,
if (format->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM; if (format->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) return DIERR_INVALIDPARAM; - if (This->acquired) return DIERR_ACQUIRED; + if (This->status == STATUS_ACQUIRED) return DIERR_ACQUIRED;
EnterCriticalSection(&This->crit);
@@ -696,7 +696,7 @@ static HRESULT WINAPI dinput_device_SetCooperativeLevel( IDirectInputDevice8W *i
/* Store the window which asks for the mouse */ EnterCriticalSection(&This->crit); - if (This->acquired) hr = DIERR_ACQUIRED; + if (This->status == STATUS_ACQUIRED) hr = DIERR_ACQUIRED; else { This->win = hwnd; @@ -1014,7 +1014,7 @@ static HRESULT check_property( struct dinput_device *impl, const GUID *guid, con case (DWORD_PTR)DIPROP_BUFFERSIZE: case (DWORD_PTR)DIPROP_PHYSICALRANGE: case (DWORD_PTR)DIPROP_LOGICALRANGE: - if (impl->acquired) return DIERR_ACQUIRED; + if (impl->status == STATUS_ACQUIRED) return DIERR_ACQUIRED; break; case (DWORD_PTR)DIPROP_FFLOAD: case (DWORD_PTR)DIPROP_GRANULARITY: @@ -1553,7 +1553,7 @@ static HRESULT WINAPI dinput_device_GetDeviceState( IDirectInputDevice8W *iface, IDirectInputDevice2_Poll( iface );
EnterCriticalSection( &impl->crit ); - if (!impl->acquired) + if (impl->status != STATUS_ACQUIRED) hr = DIERR_NOTACQUIRED; else if (!(user_format = impl->user_format)) hr = DIERR_INVALIDPARAM; @@ -1605,7 +1605,7 @@ static HRESULT WINAPI dinput_device_GetDeviceData( IDirectInputDevice8W *iface, if (This->dinput->dwVersion == 0x0800 || size == sizeof(DIDEVICEOBJECTDATA_DX3)) { if (!This->queue_len) return DIERR_NOTBUFFERED; - if (!This->acquired) return DIERR_NOTACQUIRED; + if (This->status != STATUS_ACQUIRED) return DIERR_NOTACQUIRED; }
if (!This->queue_len) @@ -1857,7 +1857,7 @@ static HRESULT WINAPI dinput_device_Poll( IDirectInputDevice8W *iface ) HRESULT hr = DI_NOEFFECT;
EnterCriticalSection( &impl->crit ); - if (!impl->acquired) hr = DIERR_NOTACQUIRED; + if (impl->status != STATUS_ACQUIRED) hr = DIERR_NOTACQUIRED; LeaveCriticalSection( &impl->crit ); if (FAILED(hr)) return hr;
@@ -2012,7 +2012,7 @@ static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, D break; }
- if (impl->acquired) return DIERR_ACQUIRED; + if (impl->status == STATUS_ACQUIRED) return DIERR_ACQUIRED;
data_format.dwSize = sizeof(data_format); data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT); diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 00a80b16590..7865c3a15a9 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -69,6 +69,12 @@ struct object_properties DWORD calibration_mode; };
+enum device_status +{ + STATUS_UNACQUIRED, + STATUS_ACQUIRED, +}; + /* Device implementation */ struct dinput_device { @@ -84,7 +90,7 @@ struct dinput_device DIDEVCAPS caps; DWORD dwCoopLevel; HWND win; - int acquired; + enum device_status status;
BOOL use_raw_input; /* use raw input instead of low-level messages */ RAWINPUTDEVICE raw_device; /* raw device to (un)register */ diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 8347e3aa586..664311b7a31 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -128,10 +128,10 @@ static void dinput_device_internal_unacquire( IDirectInputDevice8W *iface ) TRACE( "iface %p.\n", iface );
EnterCriticalSection( &impl->crit ); - if (impl->acquired) + if (impl->status == STATUS_ACQUIRED) { impl->vtbl->unacquire( iface ); - impl->acquired = FALSE; + impl->status = STATUS_UNACQUIRED; list_remove( &impl->entry ); } LeaveCriticalSection( &impl->crit ); diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 16fcc06b6e8..558a7373000 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -243,7 +243,7 @@ static inline struct hid_joystick_effect *impl_from_IDirectInputEffect( IDirectI
static inline BOOL is_exclusively_acquired( struct hid_joystick *joystick ) { - return joystick->base.acquired && (joystick->base.dwCoopLevel & DISCL_EXCLUSIVE); + return joystick->base.status == STATUS_ACQUIRED && (joystick->base.dwCoopLevel & DISCL_EXCLUSIVE); }
static const GUID *object_usage_to_guid( USAGE usage_page, USAGE usage )