Commit 97d848aa authored by Raphael Junqueira's avatar Raphael Junqueira Committed by Alexandre Julliard

- use WINE_DINPUT_KEYBOARD_MAX_KEYS instead hard-coded 256 value

- better use of critical section - some cleanup to better understand code paths - logic correction on SetWindowsHookExA/UnhookWindowsHookEx on keyboard.
parent 10a605b0
...@@ -578,61 +578,61 @@ static void dinput_window_check(SysMouseImpl* This) { ...@@ -578,61 +578,61 @@ static void dinput_window_check(SysMouseImpl* This) {
static HRESULT WINAPI SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface) static HRESULT WINAPI SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
{ {
SysMouseImpl *This = (SysMouseImpl *)iface; SysMouseImpl *This = (SysMouseImpl *)iface;
RECT rect; RECT rect;
POINT point;
TRACE("(this=%p)\n",This); TRACE("(this=%p)\n",This);
if (This->acquired == 0) { if (This->acquired)
POINT point; return S_FALSE;
/* Store (in a global variable) the current lock */ This->acquired = 1;
current_lock = (IDirectInputDevice8A*)This;
/* Store (in a global variable) the current lock */
/* Init the mouse state */ current_lock = (IDirectInputDevice8A*)This;
GetCursorPos( &point );
if (This->absolute) { /* Init the mouse state */
This->m_state.lX = point.x; GetCursorPos( &point );
This->m_state.lY = point.y; if (This->absolute) {
This->prevX = point.x; This->m_state.lX = point.x;
This->prevY = point.y; This->m_state.lY = point.y;
} else { This->prevX = point.x;
This->m_state.lX = 0; This->prevY = point.y;
This->m_state.lY = 0; } else {
This->org_coords = point; This->m_state.lX = 0;
} This->m_state.lY = 0;
This->m_state.lZ = 0; This->org_coords = point;
This->m_state.rgbButtons[0] = ((GetKeyState(VK_LBUTTON) & 0x80) ? 0xFF : 0x00); }
This->m_state.rgbButtons[1] = ((GetKeyState(VK_RBUTTON) & 0x80) ? 0xFF : 0x00); This->m_state.lZ = 0;
This->m_state.rgbButtons[2] = ((GetKeyState(VK_MBUTTON) & 0x80) ? 0xFF : 0x00); This->m_state.rgbButtons[0] = ((GetKeyState(VK_LBUTTON) & 0x80) ? 0xFF : 0x00);
This->m_state.rgbButtons[1] = ((GetKeyState(VK_RBUTTON) & 0x80) ? 0xFF : 0x00);
/* Install our mouse hook */ This->m_state.rgbButtons[2] = ((GetKeyState(VK_MBUTTON) & 0x80) ? 0xFF : 0x00);
if (This->dwCoopLevel & DISCL_EXCLUSIVE)
ShowCursor(FALSE); /* hide cursor */ /* Install our mouse hook */
This->hook = SetWindowsHookExA( WH_MOUSE_LL, dinput_mouse_hook, DINPUT_instance, 0 ); if (This->dwCoopLevel & DISCL_EXCLUSIVE)
ShowCursor(FALSE); /* hide cursor */
/* Get the window dimension and find the center */ This->hook = SetWindowsHookExA( WH_MOUSE_LL, dinput_mouse_hook, DINPUT_instance, 0 );
GetWindowRect(This->win, &rect);
This->win_centerX = (rect.right - rect.left) / 2; /* Get the window dimension and find the center */
This->win_centerY = (rect.bottom - rect.top ) / 2; GetWindowRect(This->win, &rect);
This->win_centerX = (rect.right - rect.left) / 2;
/* Warp the mouse to the center of the window */ This->win_centerY = (rect.bottom - rect.top ) / 2;
if (This->absolute == 0) {
This->mapped_center.x = This->win_centerX; /* Warp the mouse to the center of the window */
This->mapped_center.y = This->win_centerY; if (This->absolute == 0) {
MapWindowPoints(This->win, HWND_DESKTOP, &This->mapped_center, 1); This->mapped_center.x = This->win_centerX;
TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y); This->mapped_center.y = This->win_centerY;
SetCursorPos( This->mapped_center.x, This->mapped_center.y ); MapWindowPoints(This->win, HWND_DESKTOP, &This->mapped_center, 1);
TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y);
SetCursorPos( This->mapped_center.x, This->mapped_center.y );
#ifdef MOUSE_HACK #ifdef MOUSE_HACK
This->need_warp = WARP_DONE; This->need_warp = WARP_DONE;
#else #else
This->need_warp = WARP_STARTED; This->need_warp = WARP_STARTED;
#endif #endif
}
This->acquired = 1;
return DI_OK;
} }
return S_FALSE;
return DI_OK;
} }
/****************************************************************************** /******************************************************************************
...@@ -644,29 +644,32 @@ static HRESULT WINAPI SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface) ...@@ -644,29 +644,32 @@ static HRESULT WINAPI SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
TRACE("(this=%p)\n",This); TRACE("(this=%p)\n",This);
if (This->acquired) { if (0 == This->acquired) {
/* Reinstall previous mouse event handler */ return DI_NOEFFECT;
if (This->hook) { }
UnhookWindowsHookEx( This->hook );
This->hook = 0;
if (This->dwCoopLevel & DISCL_EXCLUSIVE)
ShowCursor(TRUE); /* show cursor */
}
/* No more locks */ /* Reinstall previous mouse event handler */
current_lock = NULL; if (This->hook) {
UnhookWindowsHookEx( This->hook );
This->hook = 0;
if (This->dwCoopLevel & DISCL_EXCLUSIVE)
ShowCursor(TRUE); /* show cursor */
}
/* Unacquire device */ /* No more locks */
This->acquired = 0; if (current_lock == (IDirectInputDevice8A*) This)
current_lock = NULL;
else
ERR("this(%p) != current_lock(%p)\n", This, current_lock);
/* And put the mouse cursor back where it was at acquire time */ /* Unacquire device */
if (This->absolute == 0) { This->acquired = 0;
TRACE(" warping mouse back to (%ld , %ld)\n", This->org_coords.x, This->org_coords.y);
SetCursorPos(This->org_coords.x, This->org_coords.y); /* And put the mouse cursor back where it was at acquire time */
} if (This->absolute == 0) {
} else { TRACE(" warping mouse back to (%ld , %ld)\n", This->org_coords.x, This->org_coords.y);
return DI_NOEFFECT; SetCursorPos(This->org_coords.x, This->org_coords.y);
} }
return DI_OK; return DI_OK;
......
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