From 16a0c87d37d942ee807895a17e6d639e249d6285 Mon Sep 17 00:00:00 2001 From: Jan Zerebecki Date: Sun, 18 Jul 2010 12:26:06 +0200 Subject: [PATCH] dinput: option to force mouse warp when on the edge of the screen Set [HKCU\Software\Wine\DirectInput] "MouseWarpOverride" to "force_edge" to enable this hack. Based on patch http://bugs.winehq.org/attachment.cgi?id=15638 from bug http://bugs.winehq.org/show_bug.cgi?id=6971 . --- dlls/dinput/mouse.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index e05d9e2173b..731e7596d20 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -55,7 +55,8 @@ typedef enum { WARP_DEFAULT, WARP_DISABLE, - WARP_FORCE_ON + WARP_FORCE_ON, + WARP_FORCE_EDGE } WARP_MOUSE; struct SysMouseImpl @@ -205,6 +206,8 @@ static SysMouseImpl *alloc_device(REFGUID rguid, const void *mvt, IDirectInputIm newDevice->warp_override = WARP_DISABLE; else if (!strcasecmp(buffer, "force")) newDevice->warp_override = WARP_FORCE_ON; + else if (!strcasecmp(buffer, "force_edge")) + newDevice->warp_override = WARP_FORCE_EDGE; } if (appkey) RegCloseKey(appkey); if (hkey) RegCloseKey(hkey); @@ -331,8 +334,16 @@ static int dinput_mouse_hook( LPDIRECTINPUTDEVICE8A iface, WPARAM wparam, LPARAM } This->need_warp = This->warp_override != WARP_DISABLE && - (pt.x || pt.y) && - (dwCoop & DISCL_EXCLUSIVE || This->warp_override == WARP_FORCE_ON); + ( + ((pt.x || pt.y) && This->warp_override != WARP_FORCE_EDGE) || + ( + ( + hook->pt.x<2 || hook->pt.y<2 || + hook->pt.x>((2 * This->win_centerX)-2) || hook->pt.y>((2 * This->win_centerY)-2) + ) && This->warp_override == WARP_FORCE_EDGE + ) + ) && + (dwCoop & DISCL_EXCLUSIVE || This->warp_override >= WARP_FORCE_ON); break; } case WM_MOUSEWHEEL: @@ -453,7 +464,7 @@ static HRESULT WINAPI SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface) } /* Need a window to warp mouse in. */ - if (This->warp_override == WARP_FORCE_ON && !This->base.win) + if (This->warp_override >= WARP_FORCE_ON && !This->base.win) This->base.win = GetDesktopWindow(); /* Get the window dimension and find the center */ @@ -462,7 +473,7 @@ static HRESULT WINAPI SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface) This->win_centerY = (rect.bottom - rect.top ) / 2; /* Warp the mouse to the center of the window */ - if (This->base.dwCoopLevel & DISCL_EXCLUSIVE || This->warp_override == WARP_FORCE_ON) + if (This->base.dwCoopLevel & DISCL_EXCLUSIVE || This->warp_override >= WARP_FORCE_ON) { This->mapped_center.x = This->win_centerX; This->mapped_center.y = This->win_centerY; @@ -496,7 +507,7 @@ static HRESULT WINAPI SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface) } /* And put the mouse cursor back where it was at acquire time */ - if (This->base.dwCoopLevel & DISCL_EXCLUSIVE || This->warp_override == WARP_FORCE_ON) + if (This->base.dwCoopLevel & DISCL_EXCLUSIVE || This->warp_override >= WARP_FORCE_ON) { TRACE(" warping mouse back to (%d , %d)\n", This->org_coords.x, This->org_coords.y); SetCursorPos(This->org_coords.x, This->org_coords.y); -- 2.11.4.GIT