dinput: Use an enumeration instead of BOOL for acquired status.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2022-01-24 12:02:46 +01:00 committed by Alexandre Julliard
parent fd46a5aac3
commit 3039fd6d5c
4 changed files with 23 additions and 17 deletions

View File

@ -84,7 +84,7 @@ static inline const char *debugstr_diobjectdataformat( const DIOBJECTDATAFORMAT
static inline BOOL is_exclusively_acquired( struct dinput_device *device ) 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 ); TRACE( "iface %p.\n", iface );
EnterCriticalSection( &impl->crit ); EnterCriticalSection( &impl->crit );
if (impl->acquired) if (impl->status == STATUS_ACQUIRED)
hr = DI_NOEFFECT; hr = DI_NOEFFECT;
else if (!impl->user_format) else if (!impl->user_format)
hr = DIERR_INVALIDPARAM; hr = DIERR_INVALIDPARAM;
@ -590,8 +590,8 @@ static HRESULT WINAPI dinput_device_Acquire( IDirectInputDevice8W *iface )
hr = DIERR_OTHERAPPHASPRIO; hr = DIERR_OTHERAPPHASPRIO;
else else
{ {
impl->acquired = TRUE; impl->status = STATUS_ACQUIRED;
if (FAILED(hr = impl->vtbl->acquire( iface ))) impl->acquired = FALSE; if (FAILED(hr = impl->vtbl->acquire( iface ))) impl->status = STATUS_UNACQUIRED;
} }
LeaveCriticalSection( &impl->crit ); LeaveCriticalSection( &impl->crit );
if (hr != DI_OK) return hr; if (hr != DI_OK) return hr;
@ -614,9 +614,9 @@ static HRESULT WINAPI dinput_device_Unacquire( IDirectInputDevice8W *iface )
TRACE( "iface %p.\n", iface ); TRACE( "iface %p.\n", iface );
EnterCriticalSection( &impl->crit ); EnterCriticalSection( &impl->crit );
if (!impl->acquired) hr = DI_NOEFFECT; if (impl->status != STATUS_ACQUIRED) hr = DI_NOEFFECT;
else hr = impl->vtbl->unacquire( iface ); else hr = impl->vtbl->unacquire( iface );
impl->acquired = FALSE; impl->status = STATUS_UNACQUIRED;
LeaveCriticalSection( &impl->crit ); LeaveCriticalSection( &impl->crit );
if (hr != DI_OK) return hr; 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->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM;
if (format->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) 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); EnterCriticalSection(&This->crit);
@ -696,7 +696,7 @@ static HRESULT WINAPI dinput_device_SetCooperativeLevel( IDirectInputDevice8W *i
/* Store the window which asks for the mouse */ /* Store the window which asks for the mouse */
EnterCriticalSection(&This->crit); EnterCriticalSection(&This->crit);
if (This->acquired) hr = DIERR_ACQUIRED; if (This->status == STATUS_ACQUIRED) hr = DIERR_ACQUIRED;
else else
{ {
This->win = hwnd; 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_BUFFERSIZE:
case (DWORD_PTR)DIPROP_PHYSICALRANGE: case (DWORD_PTR)DIPROP_PHYSICALRANGE:
case (DWORD_PTR)DIPROP_LOGICALRANGE: case (DWORD_PTR)DIPROP_LOGICALRANGE:
if (impl->acquired) return DIERR_ACQUIRED; if (impl->status == STATUS_ACQUIRED) return DIERR_ACQUIRED;
break; break;
case (DWORD_PTR)DIPROP_FFLOAD: case (DWORD_PTR)DIPROP_FFLOAD:
case (DWORD_PTR)DIPROP_GRANULARITY: case (DWORD_PTR)DIPROP_GRANULARITY:
@ -1553,7 +1553,7 @@ static HRESULT WINAPI dinput_device_GetDeviceState( IDirectInputDevice8W *iface,
IDirectInputDevice2_Poll( iface ); IDirectInputDevice2_Poll( iface );
EnterCriticalSection( &impl->crit ); EnterCriticalSection( &impl->crit );
if (!impl->acquired) if (impl->status != STATUS_ACQUIRED)
hr = DIERR_NOTACQUIRED; hr = DIERR_NOTACQUIRED;
else if (!(user_format = impl->user_format)) else if (!(user_format = impl->user_format))
hr = DIERR_INVALIDPARAM; 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->dinput->dwVersion == 0x0800 || size == sizeof(DIDEVICEOBJECTDATA_DX3))
{ {
if (!This->queue_len) return DIERR_NOTBUFFERED; 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) if (!This->queue_len)
@ -1857,7 +1857,7 @@ static HRESULT WINAPI dinput_device_Poll( IDirectInputDevice8W *iface )
HRESULT hr = DI_NOEFFECT; HRESULT hr = DI_NOEFFECT;
EnterCriticalSection( &impl->crit ); EnterCriticalSection( &impl->crit );
if (!impl->acquired) hr = DIERR_NOTACQUIRED; if (impl->status != STATUS_ACQUIRED) hr = DIERR_NOTACQUIRED;
LeaveCriticalSection( &impl->crit ); LeaveCriticalSection( &impl->crit );
if (FAILED(hr)) return hr; if (FAILED(hr)) return hr;
@ -2012,7 +2012,7 @@ static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, D
break; break;
} }
if (impl->acquired) return DIERR_ACQUIRED; if (impl->status == STATUS_ACQUIRED) return DIERR_ACQUIRED;
data_format.dwSize = sizeof(data_format); data_format.dwSize = sizeof(data_format);
data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT); data_format.dwObjSize = sizeof(DIOBJECTDATAFORMAT);

View File

@ -69,6 +69,12 @@ struct object_properties
DWORD calibration_mode; DWORD calibration_mode;
}; };
enum device_status
{
STATUS_UNACQUIRED,
STATUS_ACQUIRED,
};
/* Device implementation */ /* Device implementation */
struct dinput_device struct dinput_device
{ {
@ -84,7 +90,7 @@ struct dinput_device
DIDEVCAPS caps; DIDEVCAPS caps;
DWORD dwCoopLevel; DWORD dwCoopLevel;
HWND win; HWND win;
int acquired; enum device_status status;
BOOL use_raw_input; /* use raw input instead of low-level messages */ BOOL use_raw_input; /* use raw input instead of low-level messages */
RAWINPUTDEVICE raw_device; /* raw device to (un)register */ RAWINPUTDEVICE raw_device; /* raw device to (un)register */

View File

@ -128,10 +128,10 @@ static void dinput_device_internal_unacquire( IDirectInputDevice8W *iface )
TRACE( "iface %p.\n", iface ); TRACE( "iface %p.\n", iface );
EnterCriticalSection( &impl->crit ); EnterCriticalSection( &impl->crit );
if (impl->acquired) if (impl->status == STATUS_ACQUIRED)
{ {
impl->vtbl->unacquire( iface ); impl->vtbl->unacquire( iface );
impl->acquired = FALSE; impl->status = STATUS_UNACQUIRED;
list_remove( &impl->entry ); list_remove( &impl->entry );
} }
LeaveCriticalSection( &impl->crit ); LeaveCriticalSection( &impl->crit );

View File

@ -243,7 +243,7 @@ static inline struct hid_joystick_effect *impl_from_IDirectInputEffect( IDirectI
static inline BOOL is_exclusively_acquired( struct hid_joystick *joystick ) 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 ) static const GUID *object_usage_to_guid( USAGE usage_page, USAGE usage )