windows.gaming.input: Acquire the device exclusively when creating ForceFeedbackMotor.

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-04-25 14:56:18 +02:00 committed by Alexandre Julliard
parent 69745cc12d
commit cd24005266
2 changed files with 12 additions and 3 deletions

View File

@ -5048,7 +5048,6 @@ static void test_windows_gaming_input(void)
.report_id = 1,
.report_len = 2,
.report_buf = {1, 0x01},
.todo = TRUE,
},
/* device gain */
{
@ -5056,7 +5055,6 @@ static void test_windows_gaming_input(void)
.report_id = 6,
.report_len = 2,
.report_buf = {6, 0xff},
.todo = TRUE,
},
};
static struct hid_expect expect_set_gain =
@ -5284,7 +5282,7 @@ static void test_windows_gaming_input(void)
set_hid_expect( file, expect_acquire, sizeof(expect_acquire) );
hr = IRawGameController_get_ForceFeedbackMotors( raw_controller, &motors_view );
ok( hr == S_OK, "get_ForceFeedbackMotors returned %#lx\n", hr );
wait_hid_expect_( __FILE__, __LINE__, file, 100, TRUE ); /* device gain reports are written asynchronously */
wait_hid_expect( file, 100 ); /* device gain reports are written asynchronously */
hr = IVectorView_ForceFeedbackMotor_get_Size( motors_view, &size );
ok( hr == S_OK, "get_Size returned %#lx\n", hr );

View File

@ -211,9 +211,14 @@ static const struct IForceFeedbackMotorVtbl motor_vtbl =
HRESULT force_feedback_motor_create( IDirectInputDevice8W *device, IForceFeedbackMotor **out )
{
struct motor *impl;
HRESULT hr;
TRACE( "device %p, out %p\n", device, out );
if (FAILED(hr = IDirectInputDevice8_Unacquire( device ))) goto failed;
if (FAILED(hr = IDirectInputDevice8_SetCooperativeLevel( device, GetDesktopWindow(), DISCL_BACKGROUND | DISCL_EXCLUSIVE ))) goto failed;
if (FAILED(hr = IDirectInputDevice8_Acquire( device ))) goto failed;
if (!(impl = calloc( 1, sizeof(*impl) ))) return E_OUTOFMEMORY;
impl->IForceFeedbackMotor_iface.lpVtbl = &motor_vtbl;
impl->ref = 1;
@ -224,4 +229,10 @@ HRESULT force_feedback_motor_create( IDirectInputDevice8W *device, IForceFeedbac
*out = &impl->IForceFeedbackMotor_iface;
TRACE( "created ForceFeedbackMotor %p\n", *out );
return S_OK;
failed:
IDirectInputDevice8_SetCooperativeLevel( device, 0, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE );
IDirectInputDevice8_Acquire( device );
WARN( "Failed to acquire device exclusively, hr %#lx\n", hr );
return hr;
}