Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 19 +++++++++++-------- dlls/dinput/joystick_hid.c | 17 +++++++++++------ 2 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index a4c85351648..5f8227acd0c 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -82,6 +82,11 @@ static inline const char *debugstr_diobjectdataformat( const DIOBJECTDATAFORMAT debugstr_guid( data->pguid ), data->dwOfs, data->dwType, data->dwFlags ); }
+static inline BOOL is_exclusively_acquired( struct dinput_device *device ) +{ + return device->acquired && (device->dwCoopLevel & DISCL_EXCLUSIVE); +} + /****************************************************************************** * Various debugging tools */ @@ -1073,7 +1078,7 @@ static HRESULT check_property( struct dinput_device *impl, const GUID *guid, con
case (DWORD_PTR)DIPROP_FFLOAD: if (!(impl->caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_UNSUPPORTED; - if (!impl->acquired || !(impl->dwCoopLevel & DISCL_EXCLUSIVE)) return DIERR_NOTEXCLUSIVEACQUIRED; + if (!is_exclusively_acquired( impl )) return DIERR_NOTEXCLUSIVEACQUIRED; /* fallthrough */ case (DWORD_PTR)DIPROP_PRODUCTNAME: case (DWORD_PTR)DIPROP_INSTANCENAME: @@ -1399,7 +1404,7 @@ static HRESULT WINAPI dinput_device_set_property( IDirectInputDevice8W *iface, c const DIPROPDWORD *value = (const DIPROPDWORD *)header; if (!impl->vtbl->send_device_gain) return DIERR_UNSUPPORTED; impl->device_gain = value->dwData; - if (!impl->acquired || !(impl->dwCoopLevel & DISCL_EXCLUSIVE)) return DI_OK; + if (!is_exclusively_acquired( impl )) return DI_OK; return impl->vtbl->send_device_gain( iface, impl->device_gain ); } case (DWORD_PTR)DIPROP_AXISMODE: @@ -1679,7 +1684,7 @@ static HRESULT WINAPI dinput_device_CreateEffect( IDirectInputDevice8W *iface, c if (!params) return DI_OK;
flags = params->dwSize == sizeof(DIEFFECT_DX6) ? DIEP_ALLPARAMS : DIEP_ALLPARAMS_DX5; - if (!impl->acquired || !(impl->dwCoopLevel & DISCL_EXCLUSIVE)) flags |= DIEP_NODOWNLOAD; + if (!is_exclusively_acquired( impl )) flags |= DIEP_NODOWNLOAD; hr = IDirectInputEffect_SetParameters( *out, params, flags ); if (FAILED(hr)) goto failed; return DI_OK; @@ -1788,10 +1793,8 @@ static HRESULT WINAPI dinput_device_GetForceFeedbackState( IDirectInputDevice8W if (!(impl->caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_UNSUPPORTED;
EnterCriticalSection( &impl->crit ); - if (!impl->acquired || !(impl->dwCoopLevel & DISCL_EXCLUSIVE)) - hr = DIERR_NOTEXCLUSIVEACQUIRED; - else - *out = impl->force_feedback_state; + if (!is_exclusively_acquired( impl )) hr = DIERR_NOTEXCLUSIVEACQUIRED; + else *out = impl->force_feedback_state; LeaveCriticalSection( &impl->crit );
return hr; @@ -1819,7 +1822,7 @@ static HRESULT WINAPI dinput_device_SendForceFeedbackCommand( IDirectInputDevice if (!impl->vtbl->send_force_feedback_command) return DIERR_UNSUPPORTED;
EnterCriticalSection( &impl->crit ); - if (!impl->acquired || !(impl->dwCoopLevel & DISCL_EXCLUSIVE)) hr = DIERR_NOTEXCLUSIVEACQUIRED; + if (!is_exclusively_acquired( impl )) hr = DIERR_NOTEXCLUSIVEACQUIRED; else hr = impl->vtbl->send_force_feedback_command( iface, command, FALSE ); LeaveCriticalSection( &impl->crit );
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index ccf205e275b..7a365137271 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -241,6 +241,11 @@ static inline struct hid_joystick_effect *impl_from_IDirectInputEffect( IDirectI return CONTAINING_RECORD( iface, struct hid_joystick_effect, IDirectInputEffect_iface ); }
+static inline BOOL is_exclusively_acquired( struct hid_joystick *joystick ) +{ + return joystick->base.acquired && (joystick->base.dwCoopLevel & DISCL_EXCLUSIVE); +} + static const GUID *object_usage_to_guid( USAGE usage_page, USAGE usage ) { switch (usage_page) @@ -827,7 +832,7 @@ static HRESULT hid_joystick_get_property( IDirectInputDevice8W *iface, DWORD pro { DIPROPDWORD *value = (DIPROPDWORD *)header; if (!(impl->base.caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_UNSUPPORTED; - if (!impl->base.acquired || !(impl->base.dwCoopLevel & DISCL_EXCLUSIVE)) return DIERR_NOTEXCLUSIVEACQUIRED; + if (!is_exclusively_acquired( impl )) return DIERR_NOTEXCLUSIVEACQUIRED; value->dwData = 0; return DI_OK; } @@ -898,7 +903,7 @@ static HRESULT hid_joystick_unacquire( IDirectInputDevice8W *iface ) else WaitForSingleObject( impl->base.read_event, INFINITE );
if (!(impl->base.caps.dwFlags & DIDC_FORCEFEEDBACK)) return DI_OK; - if (!impl->base.acquired || !(impl->base.dwCoopLevel & DISCL_EXCLUSIVE)) return DI_OK; + if (!is_exclusively_acquired( impl )) return DI_OK; hid_joystick_send_force_feedback_command( iface, DISFFC_RESET, TRUE ); return DI_OK; } @@ -2682,7 +2687,7 @@ static HRESULT WINAPI hid_joystick_effect_Start( IDirectInputEffect *iface, DWOR else control = PID_USAGE_OP_EFFECT_START;
EnterCriticalSection( &impl->joystick->base.crit ); - if (!impl->joystick->base.acquired || !(impl->joystick->base.dwCoopLevel & DISCL_EXCLUSIVE)) + if (!is_exclusively_acquired( impl->joystick )) hr = DIERR_NOTEXCLUSIVEACQUIRED; else if ((flags & DIES_NODOWNLOAD) && !impl->index) hr = DIERR_NOTDOWNLOADED; @@ -2730,7 +2735,7 @@ static HRESULT WINAPI hid_joystick_effect_Stop( IDirectInputEffect *iface ) TRACE( "iface %p.\n", iface );
EnterCriticalSection( &impl->joystick->base.crit ); - if (!impl->joystick->base.acquired || !(impl->joystick->base.dwCoopLevel & DISCL_EXCLUSIVE)) + if (!is_exclusively_acquired( impl->joystick )) hr = DIERR_NOTEXCLUSIVEACQUIRED; else if (!impl->index) hr = DIERR_NOTDOWNLOADED; @@ -2775,7 +2780,7 @@ static HRESULT WINAPI hid_joystick_effect_GetEffectStatus( IDirectInputEffect *i *status = 0;
EnterCriticalSection( &impl->joystick->base.crit ); - if (!impl->joystick->base.acquired || !(impl->joystick->base.dwCoopLevel & DISCL_EXCLUSIVE)) + if (!is_exclusively_acquired( impl->joystick )) hr = DIERR_NOTEXCLUSIVEACQUIRED; else if (!impl->index) hr = DIERR_NOTDOWNLOADED; @@ -2850,7 +2855,7 @@ static HRESULT WINAPI hid_joystick_effect_Download( IDirectInputEffect *iface ) if (impl->modified) hr = DI_OK; else hr = DI_NOEFFECT;
- if (!impl->joystick->base.acquired || !(impl->joystick->base.dwCoopLevel & DISCL_EXCLUSIVE)) + if (!is_exclusively_acquired( impl->joystick )) hr = DIERR_NOTEXCLUSIVEACQUIRED; else if ((impl->flags & complete_mask) != complete_mask) hr = DIERR_INCOMPLETEEFFECT;