Module: wine Branch: master Commit: f83b53c160fe194d48c5126b7e6ff1a4256f63c9 URL: http://source.winehq.org/git/wine.git/?a=commit;h=f83b53c160fe194d48c5126b7e...
Author: Vitaliy Margolen wine-patches@kievinfo.com Date: Sun Jun 3 09:09:35 2007 -0600
dinput: Acquire device only if specified window has focus in foreground coop level.
---
dlls/dinput/device.c | 2 ++ dlls/dinput/tests/mouse.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 5d8c954..b8fc781 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -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; diff --git a/dlls/dinput/tests/mouse.c b/dlls/dinput/tests/mouse.c index db95ab2..de6bff0 100644 --- a/dlls/dinput/tests/mouse.c +++ b/dlls/dinput/tests/mouse.c @@ -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); }