dinput: Move mouse event queue into base device class.
This commit is contained in:
parent
564ad7da8c
commit
fb5884203b
|
@ -126,9 +126,6 @@ struct SysMouseImpl
|
||||||
POINT org_coords;
|
POINT org_coords;
|
||||||
POINT mapped_center;
|
POINT mapped_center;
|
||||||
DWORD win_centerX, win_centerY;
|
DWORD win_centerX, win_centerY;
|
||||||
LPDIDEVICEOBJECTDATA data_queue;
|
|
||||||
int queue_head, queue_tail, queue_len;
|
|
||||||
BOOL overflow;
|
|
||||||
/* warping: whether we need to move mouse back to middle once we
|
/* warping: whether we need to move mouse back to middle once we
|
||||||
* reach window borders (for e.g. shooters, "surface movement" games) */
|
* reach window borders (for e.g. shooters, "surface movement" games) */
|
||||||
WARP_STATUS need_warp;
|
WARP_STATUS need_warp;
|
||||||
|
@ -327,7 +324,7 @@ static ULONG WINAPI SysMouseAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
|
||||||
set_dinput_hook(WH_MOUSE_LL, NULL);
|
set_dinput_hook(WH_MOUSE_LL, NULL);
|
||||||
|
|
||||||
/* Free the data queue */
|
/* Free the data queue */
|
||||||
HeapFree(GetProcessHeap(),0,This->data_queue);
|
HeapFree(GetProcessHeap(), 0, This->base.data_queue);
|
||||||
DeleteCriticalSection(&This->base.crit);
|
DeleteCriticalSection(&This->base.crit);
|
||||||
|
|
||||||
/* Free the DataFormat */
|
/* Free the DataFormat */
|
||||||
|
@ -390,11 +387,11 @@ static LRESULT CALLBACK dinput_mouse_hook( int code, WPARAM wparam, LPARAM lpara
|
||||||
if (wparam == WM_MOUSEMOVE) {
|
if (wparam == WM_MOUSEMOVE) {
|
||||||
if (This->absolute) {
|
if (This->absolute) {
|
||||||
if (hook->pt.x != This->prevX)
|
if (hook->pt.x != This->prevX)
|
||||||
GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x,
|
queue_event((LPDIRECTINPUTDEVICE8A)This, This->offset_array[WINE_MOUSE_X_POSITION],
|
||||||
hook->time, This->dinput->evsequence);
|
hook->pt.x, hook->time, This->dinput->evsequence);
|
||||||
if (hook->pt.y != This->prevY)
|
if (hook->pt.y != This->prevY)
|
||||||
GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y,
|
queue_event((LPDIRECTINPUTDEVICE8A)This, This->offset_array[WINE_MOUSE_Y_POSITION],
|
||||||
hook->time, This->dinput->evsequence);
|
hook->pt.y, hook->time, This->dinput->evsequence);
|
||||||
} else {
|
} else {
|
||||||
/* Now, warp handling */
|
/* Now, warp handling */
|
||||||
if ((This->need_warp == WARP_STARTED) &&
|
if ((This->need_warp == WARP_STARTED) &&
|
||||||
|
@ -408,23 +405,23 @@ static LRESULT CALLBACK dinput_mouse_hook( int code, WPARAM wparam, LPARAM lpara
|
||||||
if ((This->need_warp == WARP_NEEDED) ||
|
if ((This->need_warp == WARP_NEEDED) ||
|
||||||
(This->need_warp == WARP_STARTED)) {
|
(This->need_warp == WARP_STARTED)) {
|
||||||
if (hook->pt.x != This->prevX)
|
if (hook->pt.x != This->prevX)
|
||||||
GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->prevX,
|
queue_event((LPDIRECTINPUTDEVICE8A)This, This->offset_array[WINE_MOUSE_X_POSITION],
|
||||||
hook->time, This->dinput->evsequence);
|
hook->pt.x - This->prevX, hook->time, This->dinput->evsequence);
|
||||||
if (hook->pt.y != This->prevY)
|
if (hook->pt.y != This->prevY)
|
||||||
GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->prevY,
|
queue_event((LPDIRECTINPUTDEVICE8A)This, This->offset_array[WINE_MOUSE_Y_POSITION],
|
||||||
hook->time, This->dinput->evsequence);
|
hook->pt.y - This->prevY, hook->time, This->dinput->evsequence);
|
||||||
} else {
|
} else {
|
||||||
/* This is the first time the event handler has been called after a
|
/* This is the first time the event handler has been called after a
|
||||||
GetDeviceData or GetDeviceState. */
|
GetDeviceData or GetDeviceState. */
|
||||||
if (hook->pt.x != This->mapped_center.x) {
|
if (hook->pt.x != This->mapped_center.x) {
|
||||||
GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->mapped_center.x,
|
queue_event((LPDIRECTINPUTDEVICE8A)This, This->offset_array[WINE_MOUSE_X_POSITION],
|
||||||
hook->time, This->dinput->evsequence);
|
hook->pt.x - This->mapped_center.x, hook->time, This->dinput->evsequence);
|
||||||
This->need_warp = WARP_NEEDED;
|
This->need_warp = WARP_NEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hook->pt.y != This->mapped_center.y) {
|
if (hook->pt.y != This->mapped_center.y) {
|
||||||
GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->mapped_center.y,
|
queue_event((LPDIRECTINPUTDEVICE8A)This, This->offset_array[WINE_MOUSE_Y_POSITION],
|
||||||
hook->time, This->dinput->evsequence);
|
hook->pt.y - This->mapped_center.y, hook->time, This->dinput->evsequence);
|
||||||
This->need_warp = WARP_NEEDED;
|
This->need_warp = WARP_NEEDED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -447,39 +444,39 @@ static LRESULT CALLBACK dinput_mouse_hook( int code, WPARAM wparam, LPARAM lpara
|
||||||
|
|
||||||
switch(wparam) {
|
switch(wparam) {
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
GEN_EVENT(This->offset_array[WINE_MOUSE_L_POSITION], 0x80,
|
queue_event((LPDIRECTINPUTDEVICE8A)This, This->offset_array[WINE_MOUSE_L_POSITION],
|
||||||
hook->time, This->dinput->evsequence);
|
0x80, hook->time, This->dinput->evsequence);
|
||||||
This->m_state.rgbButtons[0] = 0x80;
|
This->m_state.rgbButtons[0] = 0x80;
|
||||||
break;
|
break;
|
||||||
case WM_LBUTTONUP:
|
case WM_LBUTTONUP:
|
||||||
GEN_EVENT(This->offset_array[WINE_MOUSE_L_POSITION], 0x00,
|
queue_event((LPDIRECTINPUTDEVICE8A)This, This->offset_array[WINE_MOUSE_L_POSITION],
|
||||||
hook->time, This->dinput->evsequence);
|
0x00, hook->time, This->dinput->evsequence);
|
||||||
This->m_state.rgbButtons[0] = 0x00;
|
This->m_state.rgbButtons[0] = 0x00;
|
||||||
break;
|
break;
|
||||||
case WM_RBUTTONDOWN:
|
case WM_RBUTTONDOWN:
|
||||||
GEN_EVENT(This->offset_array[WINE_MOUSE_R_POSITION], 0x80,
|
queue_event((LPDIRECTINPUTDEVICE8A)This, This->offset_array[WINE_MOUSE_R_POSITION],
|
||||||
hook->time, This->dinput->evsequence);
|
0x80, hook->time, This->dinput->evsequence);
|
||||||
This->m_state.rgbButtons[1] = 0x80;
|
This->m_state.rgbButtons[1] = 0x80;
|
||||||
break;
|
break;
|
||||||
case WM_RBUTTONUP:
|
case WM_RBUTTONUP:
|
||||||
GEN_EVENT(This->offset_array[WINE_MOUSE_R_POSITION], 0x00,
|
queue_event((LPDIRECTINPUTDEVICE8A)This, This->offset_array[WINE_MOUSE_R_POSITION],
|
||||||
hook->time, This->dinput->evsequence);
|
0x00, hook->time, This->dinput->evsequence);
|
||||||
This->m_state.rgbButtons[1] = 0x00;
|
This->m_state.rgbButtons[1] = 0x00;
|
||||||
break;
|
break;
|
||||||
case WM_MBUTTONDOWN:
|
case WM_MBUTTONDOWN:
|
||||||
GEN_EVENT(This->offset_array[WINE_MOUSE_M_POSITION], 0x80,
|
queue_event((LPDIRECTINPUTDEVICE8A)This, This->offset_array[WINE_MOUSE_M_POSITION],
|
||||||
hook->time, This->dinput->evsequence);
|
0x80, hook->time, This->dinput->evsequence);
|
||||||
This->m_state.rgbButtons[2] = 0x80;
|
This->m_state.rgbButtons[2] = 0x80;
|
||||||
break;
|
break;
|
||||||
case WM_MBUTTONUP:
|
case WM_MBUTTONUP:
|
||||||
GEN_EVENT(This->offset_array[WINE_MOUSE_M_POSITION], 0x00,
|
queue_event((LPDIRECTINPUTDEVICE8A)This, This->offset_array[WINE_MOUSE_M_POSITION],
|
||||||
hook->time, This->dinput->evsequence);
|
0x00, hook->time, This->dinput->evsequence);
|
||||||
This->m_state.rgbButtons[2] = 0x00;
|
This->m_state.rgbButtons[2] = 0x00;
|
||||||
break;
|
break;
|
||||||
case WM_MOUSEWHEEL:
|
case WM_MOUSEWHEEL:
|
||||||
wdata = (short)HIWORD(hook->mouseData);
|
wdata = (short)HIWORD(hook->mouseData);
|
||||||
GEN_EVENT(This->offset_array[WINE_MOUSE_Z_POSITION], wdata,
|
queue_event((LPDIRECTINPUTDEVICE8A)This, This->offset_array[WINE_MOUSE_Z_POSITION],
|
||||||
hook->time, This->dinput->evsequence);
|
wdata, hook->time, This->dinput->evsequence);
|
||||||
This->m_state.lZ += wdata;
|
This->m_state.lZ += wdata;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -673,76 +670,13 @@ static HRESULT WINAPI SysMouseAImpl_GetDeviceState(
|
||||||
* GetDeviceData : gets buffered input data.
|
* GetDeviceData : gets buffered input data.
|
||||||
*/
|
*/
|
||||||
static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
|
static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
|
||||||
DWORD dodsize,
|
DWORD dodsize, LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
|
||||||
LPDIDEVICEOBJECTDATA dod,
|
{
|
||||||
LPDWORD entries,
|
|
||||||
DWORD flags
|
|
||||||
) {
|
|
||||||
SysMouseImpl *This = (SysMouseImpl *)iface;
|
SysMouseImpl *This = (SysMouseImpl *)iface;
|
||||||
DWORD len;
|
HRESULT res;
|
||||||
int nqtail = 0;
|
|
||||||
|
|
||||||
TRACE("(%p)->(dods=%d,dod=%p,entries=%p (%d)%s,fl=0x%08x%s)\n",This,dodsize,dod,
|
|
||||||
entries, *entries,*entries == INFINITE ? " (INFINITE)" : "",
|
|
||||||
flags, (flags & DIGDD_PEEK) ? " (DIGDD_PEEK)": "" );
|
|
||||||
|
|
||||||
if (This->base.acquired == 0) {
|
|
||||||
WARN(" application tries to get data from an unacquired device !\n");
|
|
||||||
return DIERR_NOTACQUIRED;
|
|
||||||
}
|
|
||||||
|
|
||||||
EnterCriticalSection(&This->base.crit);
|
|
||||||
|
|
||||||
len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0)
|
res = IDirectInputDevice2AImpl_GetDeviceData(iface, dodsize, dod, entries, flags);
|
||||||
+ (This->queue_head - This->queue_tail);
|
if (FAILED(res)) return res;
|
||||||
if ((*entries != INFINITE) && (len > *entries)) len = *entries;
|
|
||||||
|
|
||||||
if (dod == NULL) {
|
|
||||||
*entries = len;
|
|
||||||
|
|
||||||
if (!(flags & DIGDD_PEEK)) {
|
|
||||||
if (len)
|
|
||||||
TRACE("Application discarding %d event(s).\n", len);
|
|
||||||
|
|
||||||
nqtail = This->queue_tail + len;
|
|
||||||
while (nqtail >= This->queue_len) nqtail -= This->queue_len;
|
|
||||||
} else {
|
|
||||||
TRACE("Telling application that %d event(s) are in the queue.\n", len);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) {
|
|
||||||
ERR("Wrong structure size !\n");
|
|
||||||
LeaveCriticalSection(&This->base.crit);
|
|
||||||
return DIERR_INVALIDPARAM;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len)
|
|
||||||
TRACE("Application retrieving %d event(s):\n", len);
|
|
||||||
|
|
||||||
*entries = 0;
|
|
||||||
nqtail = This->queue_tail;
|
|
||||||
while (len) {
|
|
||||||
/* Copy the buffered data into the application queue */
|
|
||||||
TRACE(" - queuing Offs:%2d Data:%5d TS:%8d Seq:%8d at address %p from queue tail %4d\n",
|
|
||||||
(This->data_queue)->dwOfs,
|
|
||||||
(This->data_queue)->dwData,
|
|
||||||
(This->data_queue)->dwTimeStamp,
|
|
||||||
(This->data_queue)->dwSequence,
|
|
||||||
(char *)dod + *entries * dodsize,
|
|
||||||
nqtail);
|
|
||||||
memcpy((char *)dod + *entries * dodsize, This->data_queue + nqtail, dodsize);
|
|
||||||
/* Advance position */
|
|
||||||
nqtail++;
|
|
||||||
if (nqtail >= This->queue_len)
|
|
||||||
nqtail -= This->queue_len;
|
|
||||||
(*entries)++;
|
|
||||||
len--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!(flags & DIGDD_PEEK))
|
|
||||||
This->queue_tail = nqtail;
|
|
||||||
|
|
||||||
LeaveCriticalSection(&This->base.crit);
|
|
||||||
|
|
||||||
/* Check if we need to do a mouse warping */
|
/* Check if we need to do a mouse warping */
|
||||||
if (This->need_warp == WARP_NEEDED && (GetCurrentTime() - This->last_warped > 10)) {
|
if (This->need_warp == WARP_NEEDED && (GetCurrentTime() - This->last_warped > 10)) {
|
||||||
|
@ -758,7 +692,7 @@ static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
|
||||||
This->need_warp = WARP_STARTED;
|
This->need_warp = WARP_STARTED;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return DI_OK;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
|
@ -774,17 +708,6 @@ static HRESULT WINAPI SysMouseAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
|
||||||
|
|
||||||
if (!HIWORD(rguid)) {
|
if (!HIWORD(rguid)) {
|
||||||
switch (LOWORD(rguid)) {
|
switch (LOWORD(rguid)) {
|
||||||
case (DWORD) DIPROP_BUFFERSIZE: {
|
|
||||||
LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
|
|
||||||
|
|
||||||
TRACE("buffersize = %d\n", pd->dwData);
|
|
||||||
|
|
||||||
This->data_queue = HeapAlloc(GetProcessHeap(),0, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
|
|
||||||
This->queue_head = 0;
|
|
||||||
This->queue_tail = 0;
|
|
||||||
This->queue_len = pd->dwData;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case (DWORD) DIPROP_AXISMODE: {
|
case (DWORD) DIPROP_AXISMODE: {
|
||||||
LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
|
LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
|
||||||
This->absolute = !(pd->dwData);
|
This->absolute = !(pd->dwData);
|
||||||
|
@ -792,8 +715,7 @@ static HRESULT WINAPI SysMouseAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
FIXME("Unknown type %p (%s)\n",rguid,debugstr_guid(rguid));
|
return IDirectInputDevice2AImpl_SetProperty(iface, rguid, ph);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -809,22 +731,11 @@ static HRESULT WINAPI SysMouseAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
|
||||||
{
|
{
|
||||||
SysMouseImpl *This = (SysMouseImpl *)iface;
|
SysMouseImpl *This = (SysMouseImpl *)iface;
|
||||||
|
|
||||||
TRACE("(this=%p,%s,%p)\n",
|
TRACE("(%p) %s,%p\n", This, debugstr_guid(rguid), pdiph);
|
||||||
iface, debugstr_guid(rguid), pdiph);
|
_dump_DIPROPHEADER(pdiph);
|
||||||
|
|
||||||
if (TRACE_ON(dinput))
|
|
||||||
_dump_DIPROPHEADER(pdiph);
|
|
||||||
|
|
||||||
if (!HIWORD(rguid)) {
|
if (!HIWORD(rguid)) {
|
||||||
switch (LOWORD(rguid)) {
|
switch (LOWORD(rguid)) {
|
||||||
case (DWORD) DIPROP_BUFFERSIZE: {
|
|
||||||
LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
|
|
||||||
|
|
||||||
TRACE(" return buffersize = %d\n",This->queue_len);
|
|
||||||
pd->dwData = This->queue_len;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case (DWORD) DIPROP_GRANULARITY: {
|
case (DWORD) DIPROP_GRANULARITY: {
|
||||||
LPDIPROPDWORD pr = (LPDIPROPDWORD) pdiph;
|
LPDIPROPDWORD pr = (LPDIPROPDWORD) pdiph;
|
||||||
|
|
||||||
|
@ -849,12 +760,11 @@ static HRESULT WINAPI SysMouseAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
FIXME("Unknown type %p (%s)\n",rguid,debugstr_guid(rguid));
|
return IDirectInputDevice2AImpl_GetProperty(iface, rguid, pdiph);
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return DI_OK;
|
return DI_OK;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue