From 65e04b2c1dbd05ec66518bf8fe5809c91b7c3809 Mon Sep 17 00:00:00 2001 From: Taka Date: Mon, 12 Dec 2016 13:39:16 +1000 Subject: [PATCH] Only record mouse moves in the stroke history. --- MouseDll/core2.cpp | 63 ++++++++++++++++++++++++++------------------ MouseDll/event.cpp | 3 +-- MouseDll/globals.cpp | 3 +-- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/MouseDll/core2.cpp b/MouseDll/core2.cpp index ca62e56..6c82402 100644 --- a/MouseDll/core2.cpp +++ b/MouseDll/core2.cpp @@ -21,6 +21,16 @@ static void doRunMainLoop( int* pExitFlag ) ; static bool detectDirn( const MouseStrokeHistory* pStrokeHistory , eDirn* pDirn , int* pMagnitude ) ; static bool findDevice( InterceptionDevice hDevice , Device** ppDevice , DeviceConfig** ppDeviceConfig ) ; +// --- LOCAL DATA ------------------------------------------------------ + +enum eStrokeType { stMouseMove , stMouseWheel , stMouseHorzWheel } ; +static EnumStringInfo gStrokeTypeStringTable[] = { + { stMouseMove , "MOVE" } , + { stMouseWheel , "WHEEL" } , + { stMouseHorzWheel , "H-WHEEL" } , + { -1 , NULL } +} ; + // --------------------------------------------------------------------- void @@ -76,7 +86,7 @@ doRunMainLoop( int* pExitFlag ) ) ; // run the main loop - MouseStrokeHistoryTable strokeHistoryTable ; + MouseStrokeHistoryTable mouseMovesHistoryTable ; for ( ; ; ) { // wait for the next event @@ -99,6 +109,13 @@ doRunMainLoop( int* pExitFlag ) // get the event InterceptionMouseStroke* pStroke = (InterceptionMouseStroke*) &stroke ; DWORD strokeTimestamp = GetTickCount() ; + eStrokeType strokeType ; + if ( pStroke->state & INTERCEPTION_MOUSE_WHEEL ) + strokeType = stMouseWheel ; + else if ( pStroke->state & INTERCEPTION_MOUSE_HWHEEL ) + strokeType = stMouseHorzWheel ; + else + strokeType = stMouseMove ; int keyModifiers = 0 ; if ( GetAsyncKeyState(VK_CONTROL) < 0 ) keyModifiers |= Event::kmCtrl ; @@ -113,15 +130,9 @@ doRunMainLoop( int* pExitFlag ) stringstream buf ; if ( keyModifiers != 0 ) buf << " " << Event::keyModifiersString(keyModifiers) << " ;" ; - const char* pEventType ; - if ( pStroke->state & INTERCEPTION_MOUSE_WHEEL ) - pEventType = "WHEEL" ; - else if ( pStroke->state & INTERCEPTION_MOUSE_HWHEEL ) - pEventType = "HWHEEL" ; - else - pEventType = "MOVE" ; LOG_MSG( - pEventType << ":" << buf.str() << " hDevice=" << hDevice + enumString(gStrokeTypeStringTable,strokeType) << ": " << buf.str() + << " hDevice=" << hDevice << " ; state=0x" << hexString(pStroke->state) << " ; flags=0x" << hexString(pStroke->flags) << " ; rolling=" << pStroke->rolling @@ -161,24 +172,26 @@ doRunMainLoop( int* pExitFlag ) } // record the stroke - // FIXME! only record mouse moves - MouseStrokeHistory* pStrokeHistory = & strokeHistoryTable[hDevice] ; - int strokeHistoryResetInterval = pDeviceConfig->strokeHistoryResetInterval() ; - if ( strokeHistoryResetInterval <= 0 ) - strokeHistoryResetInterval = DEFAULT_STROKE_HISTORY_RESET_INTERVAL ; - if ( ! pStrokeHistory->empty() && (int)(strokeTimestamp-pStrokeHistory->back().first) >= strokeHistoryResetInterval ) + if ( strokeType == stMouseMove ) { - // we haven't seen a move event for a while - reset the history - pStrokeHistory->clear() ; + MouseStrokeHistory* pStrokeHistory = & mouseMovesHistoryTable[hDevice] ; + int strokeHistoryResetInterval = pDeviceConfig->strokeHistoryResetInterval() ; + if ( strokeHistoryResetInterval <= 0 ) + strokeHistoryResetInterval = DEFAULT_STROKE_HISTORY_RESET_INTERVAL ; + if ( ! pStrokeHistory->empty() && (int)(strokeTimestamp-pStrokeHistory->back().first) >= strokeHistoryResetInterval ) + { + // we haven't seen a move event for a while - reset the history + pStrokeHistory->clear() ; + } + pStrokeHistory->push_back( make_pair( strokeTimestamp , *pStroke ) ) ; + while ( pStrokeHistory->size() > MAX_STROKE_HISTORY ) + pStrokeHistory->pop_front() ; + + // figure out which way the mouse is moving + eDirn dirn ; + int dirnMagnitude ; + (void) detectDirn( pStrokeHistory , &dirn , &dirnMagnitude ) ; } - pStrokeHistory->push_back( make_pair( strokeTimestamp , *pStroke ) ) ; - while ( pStrokeHistory->size() > MAX_STROKE_HISTORY ) - pStrokeHistory->pop_front() ; - - // figure out which way the mouse is moving - eDirn dirn ; - int dirnMagnitude ; - (void) detectDirn( pStrokeHistory , &dirn , &dirnMagnitude ) ; // FIXME! handle the event interception_send( hContext , hDevice ,&stroke , 1 ) ; diff --git a/MouseDll/event.cpp b/MouseDll/event.cpp index 776acd3..8d3fd9a 100644 --- a/MouseDll/event.cpp +++ b/MouseDll/event.cpp @@ -38,8 +38,7 @@ Event::dumpEvent( ostream& os , const char* pPrefix ) const ostream& operator<<( ostream& os , const Event& evt ) { - static EnumStringInfo stringTable[] = - { + static EnumStringInfo stringTable[] = { { Event::etMouseLeft , "mouseLeft" } , { Event::etMouseRight , "mouseRight" } , { Event::etMouseUp , "mouseUp" } , diff --git a/MouseDll/globals.cpp b/MouseDll/globals.cpp index 6b2b01b..8c6a64f 100644 --- a/MouseDll/globals.cpp +++ b/MouseDll/globals.cpp @@ -94,8 +94,7 @@ makeLogMsg( const string& msg ) string toString( eDirn dirn ) { // return the eDirn as a string - static EnumStringInfo stringTable[] = - { + static EnumStringInfo stringTable[] = { { dUnknown , "UNKNOWN" } , { dLeft , "LEFT" } , { dRight , "RIGHT" } ,