--- wine-git-bak/dlls/dinput/mouse.c 2006-09-13 10:29:53.000000000 +0200 +++ wine-git/dlls/dinput/mouse.c 2006-09-15 17:25:51.000000000 +0200 @@ -37,8 +37,6 @@ #include "wine/debug.h" #include "wine/unicode.h" -#define MOUSE_HACK - WINE_DEFAULT_DEBUG_CHANNEL(dinput); /* Wine mouse driver object instances */ @@ -103,7 +101,6 @@ typedef enum { WARP_DONE, /* Warping has been done */ WARP_NEEDED, /* Warping is needed */ - WARP_STARTED /* Warping has been done, waiting for the warp event */ } WARP_STATUS; struct SysMouseImpl @@ -136,7 +133,6 @@ /* warping: whether we need to move mouse back to middle once we * reach window borders (for e.g. shooters, "surface movement" games) */ WARP_STATUS need_warp; - DWORD last_warped; int acquired; HANDLE hEvent; CRITICAL_SECTION crit; @@ -412,6 +408,9 @@ return DI_OK; } +#define MIN 50 +#define MAX 200 + /* low-level mouse hook */ static LRESULT CALLBACK dinput_mouse_hook( int code, WPARAM wparam, LPARAM lparam ) { @@ -434,53 +433,48 @@ if (hook->pt.y != This->prevY) GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y, hook->time, This->dinput->evsequence); + + This->m_state.lX = hook->pt.x; + This->m_state.lY = hook->pt.y; } else { /* Now, warp handling */ - if ((This->need_warp == WARP_STARTED) && - (hook->pt.x == This->mapped_center.x) && (hook->pt.y == This->mapped_center.y)) { - /* Warp has been done... */ + if (This->need_warp == WARP_NEEDED) { + /* If warp was needed, we check if it has been done, ie if the pointer is back in the center zone */ + if ( (hook->pt.x > This->mapped_center.x-MIN) && + (hook->pt.x < This->mapped_center.x+MIN) && + (hook->pt.y > This->mapped_center.y-MIN) && + (hook->pt.y < This->mapped_center.y+MIN) ) { This->need_warp = WARP_DONE; - goto end; + This->prevX = This->mapped_center.x; + This->prevY = This->mapped_center.y; + } + } + else { + /* Otherwise, we make sure the pointer doesn't go too far. If it does, then warp is needed */ + if ( (hook->pt.x < This->mapped_center.x-MAX) || + (hook->pt.x > This->mapped_center.x+MAX) || + (hook->pt.y < This->mapped_center.y-MAX) || + (hook->pt.y > This->mapped_center.y+MAX) ) { + This->need_warp = WARP_NEEDED; + } } - /* Relative mouse input with absolute mouse event : the real fun starts here... */ - if ((This->need_warp == WARP_NEEDED) || - (This->need_warp == WARP_STARTED)) { if (hook->pt.x != This->prevX) GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->prevX, hook->time, This->dinput->evsequence); if (hook->pt.y != This->prevY) GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->prevY, hook->time, This->dinput->evsequence); - } else { - /* This is the first time the event handler has been called after a - GetDeviceData or GetDeviceState. */ - if (hook->pt.x != This->mapped_center.x) { - GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->mapped_center.x, - hook->time, This->dinput->evsequence); - This->need_warp = WARP_NEEDED; - } - if (hook->pt.y != This->mapped_center.y) { - GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->mapped_center.y, - hook->time, This->dinput->evsequence); - This->need_warp = WARP_NEEDED; - } - } + This->m_state.lX = hook->pt.x - This->mapped_center.x; + This->m_state.lY = hook->pt.y - This->mapped_center.y; } This->prevX = hook->pt.x; This->prevY = hook->pt.y; - - if (This->absolute) { - This->m_state.lX = hook->pt.x; - This->m_state.lY = hook->pt.y; - } else { - This->m_state.lX = hook->pt.x - This->mapped_center.x; - This->m_state.lY = hook->pt.y - This->mapped_center.y; - } } + TRACE(" msg %x pt %ld %ld (W=%d)\n", wparam, hook->pt.x, hook->pt.y, (!This->absolute) && This->need_warp ); @@ -529,7 +523,6 @@ This->dinput->evsequence++; - end: /* Mouse moved -> send event if asked */ if (This->hEvent) SetEvent(This->hEvent); @@ -616,13 +609,8 @@ 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 ); - This->last_warped = GetCurrentTime(); -#ifdef MOUSE_HACK This->need_warp = WARP_DONE; -#else - This->need_warp = WARP_STARTED; -#endif } return DI_OK; @@ -693,17 +681,10 @@ } /* 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) { dinput_window_check(This); TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y); SetCursorPos( This->mapped_center.x, This->mapped_center.y ); - This->last_warped = GetCurrentTime(); - -#ifdef MOUSE_HACK - This->need_warp = WARP_DONE; -#else - This->need_warp = WARP_STARTED; -#endif } LeaveCriticalSection(&(This->crit)); @@ -787,17 +768,10 @@ LeaveCriticalSection(&(This->crit)); /* 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) { dinput_window_check(This); TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y); SetCursorPos( This->mapped_center.x, This->mapped_center.y ); - This->last_warped = GetCurrentTime(); - -#ifdef MOUSE_HACK - This->need_warp = WARP_DONE; -#else - This->need_warp = WARP_STARTED; -#endif } return DI_OK; }