Commit f83b53c1 authored by Vitaliy Margolen's avatar Vitaliy Margolen Committed by Alexandre Julliard

dinput: Acquire device only if specified window has focus in foreground coop level.

parent 6a8bf96d
......@@ -556,6 +556,8 @@ HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
HRESULT res;
if (!This->data_format.user_df) return DIERR_INVALIDPARAM;
if (This->dwCoopLevel & DISCL_FOREGROUND && This->win != GetForegroundWindow())
return DIERR_OTHERAPPHASPRIO;
EnterCriticalSection(&This->crit);
res = This->acquired ? S_FALSE : DI_OK;
......
......@@ -72,11 +72,15 @@ static void test_acquire(LPDIRECTINPUT pDI, HWND hwnd)
{
HRESULT hr;
LPDIRECTINPUTDEVICE pMouse = NULL;
DIMOUSESTATE2 m_state;
hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pMouse, NULL);
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %s\n", DXGetErrorString8(hr));
if (FAILED(hr)) return;
hr = IDirectInputDevice_SetCooperativeLevel(pMouse, hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
ok(hr == S_OK, "SetCooperativeLevel: %s\n", DXGetErrorString8(hr));
hr = IDirectInputDevice_SetDataFormat(pMouse, &c_dfDIMouse);
ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %s\n", DXGetErrorString8(hr));
hr = IDirectInputDevice_Unacquire(pMouse);
......@@ -86,6 +90,23 @@ static void test_acquire(LPDIRECTINPUT pDI, HWND hwnd)
hr = IDirectInputDevice_Acquire(pMouse);
ok(hr == S_FALSE, "IDirectInputDevice_Acquire() should have failed: %s\n", DXGetErrorString8(hr));
/* Foreground coop level requires window to have focus */
/* This should make dinput loose mouse input */
SetActiveWindow( 0 );
hr = IDirectInputDevice_GetDeviceState(pMouse, sizeof(m_state), &m_state);
todo_wine
ok(hr == DIERR_NOTACQUIRED, "GetDeviceState() should have failed: %s\n", DXGetErrorString8(hr));
/* Workaround so we can test other things. Remove when Wine is fixed */
IDirectInputDevice_Unacquire(pMouse);
hr = IDirectInputDevice_Acquire(pMouse);
ok(hr == DIERR_OTHERAPPHASPRIO, "Acquire() should have failed: %s\n", DXGetErrorString8(hr));
SetActiveWindow( hwnd );
hr = IDirectInputDevice_Acquire(pMouse);
ok(hr == S_OK, "Acquire() failed: %s\n", DXGetErrorString8(hr));
if (pMouse) IUnknown_Release(pMouse);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment