dinput: Add a helper function for mouse warping.
This commit is contained in:
parent
8578f9c375
commit
5f2daff124
|
@ -427,6 +427,21 @@ static BOOL dinput_window_check(SysMouseImpl* This) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HRESULT warp_check( SysMouseImpl* This, BOOL force )
|
||||||
|
{
|
||||||
|
DWORD now = GetCurrentTime();
|
||||||
|
|
||||||
|
if (force || (This->need_warp && (now - This->last_warped > 10)))
|
||||||
|
{
|
||||||
|
This->last_warped = now;
|
||||||
|
This->need_warp = FALSE;
|
||||||
|
if (!dinput_window_check(This)) return DIERR_GENERIC;
|
||||||
|
TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y);
|
||||||
|
SetCursorPos( This->mapped_center.x, This->mapped_center.y );
|
||||||
|
}
|
||||||
|
return DI_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Acquire : gets exclusive control of the mouse
|
* Acquire : gets exclusive control of the mouse
|
||||||
|
@ -434,7 +449,6 @@ static BOOL dinput_window_check(SysMouseImpl* This) {
|
||||||
static HRESULT WINAPI SysMouseWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
|
static HRESULT WINAPI SysMouseWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
|
||||||
{
|
{
|
||||||
SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
|
SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
|
||||||
RECT rect;
|
|
||||||
POINT point;
|
POINT point;
|
||||||
HRESULT res;
|
HRESULT res;
|
||||||
|
|
||||||
|
@ -473,23 +487,12 @@ static HRESULT WINAPI SysMouseWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
|
||||||
ERR("Failed to get RECT: %d\n", GetLastError());
|
ERR("Failed to get RECT: %d\n", GetLastError());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Need a window to warp mouse in. */
|
|
||||||
if (This->warp_override == WARP_FORCE_ON && !This->base.win)
|
|
||||||
This->base.win = GetDesktopWindow();
|
|
||||||
|
|
||||||
/* Get the window dimension and find the center */
|
|
||||||
GetWindowRect(This->base.win, &rect);
|
|
||||||
This->mapped_center.x = (rect.left + rect.right) / 2;
|
|
||||||
This->mapped_center.y = (rect.top + rect.bottom) / 2;
|
|
||||||
|
|
||||||
/* Warp the mouse to the center of the window */
|
/* 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)
|
||||||
{
|
{
|
||||||
TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y);
|
/* Need a window to warp mouse in. */
|
||||||
SetCursorPos( This->mapped_center.x, This->mapped_center.y );
|
if (!This->base.win) This->base.win = GetDesktopWindow();
|
||||||
This->last_warped = GetCurrentTime();
|
warp_check( This, TRUE );
|
||||||
|
|
||||||
This->need_warp = FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return DI_OK;
|
return DI_OK;
|
||||||
|
@ -563,19 +566,7 @@ static HRESULT WINAPI SysMouseWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface,
|
||||||
}
|
}
|
||||||
LeaveCriticalSection(&This->base.crit);
|
LeaveCriticalSection(&This->base.crit);
|
||||||
|
|
||||||
/* Check if we need to do a mouse warping */
|
return warp_check( This, FALSE );
|
||||||
if (This->need_warp && (GetCurrentTime() - This->last_warped > 10))
|
|
||||||
{
|
|
||||||
if(!dinput_window_check(This))
|
|
||||||
return DIERR_GENERIC;
|
|
||||||
TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y);
|
|
||||||
SetCursorPos( This->mapped_center.x, This->mapped_center.y );
|
|
||||||
This->last_warped = GetCurrentTime();
|
|
||||||
|
|
||||||
This->need_warp = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return DI_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT WINAPI SysMouseAImpl_GetDeviceState(LPDIRECTINPUTDEVICE8A iface, DWORD len, LPVOID ptr)
|
static HRESULT WINAPI SysMouseAImpl_GetDeviceState(LPDIRECTINPUTDEVICE8A iface, DWORD len, LPVOID ptr)
|
||||||
|
@ -594,19 +585,7 @@ static HRESULT WINAPI SysMouseWImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface,
|
||||||
HRESULT res;
|
HRESULT res;
|
||||||
|
|
||||||
res = IDirectInputDevice2WImpl_GetDeviceData(iface, dodsize, dod, entries, flags);
|
res = IDirectInputDevice2WImpl_GetDeviceData(iface, dodsize, dod, entries, flags);
|
||||||
if (FAILED(res)) return res;
|
if (SUCCEEDED(res)) res = warp_check( This, FALSE );
|
||||||
|
|
||||||
/* Check if we need to do a mouse warping */
|
|
||||||
if (This->need_warp && (GetCurrentTime() - This->last_warped > 10))
|
|
||||||
{
|
|
||||||
if(!dinput_window_check(This))
|
|
||||||
return DIERR_GENERIC;
|
|
||||||
TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y);
|
|
||||||
SetCursorPos( This->mapped_center.x, This->mapped_center.y );
|
|
||||||
This->last_warped = GetCurrentTime();
|
|
||||||
|
|
||||||
This->need_warp = FALSE;
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue