From b53e80c5aa97fe2039e599646daf8977ce4aec28 Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Mon, 17 Jun 2019 00:57:06 +0200 Subject: [PATCH] Fix mouse scroll by releasing with a delay using timer(16ms) Also moved WM_MOUSEWHEEL to DisplayProc where it works fine now. --- Windows/MainWindow.cpp | 65 ++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index f52506da4a..c91112c0ca 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -103,8 +103,10 @@ extern ScreenManager *screenManager; #define TIMER_CURSORUPDATE 1 #define TIMER_CURSORMOVEUPDATE 2 +#define TIMER_WHEELRELEASE 3 #define CURSORUPDATE_INTERVAL_MS 1000 #define CURSORUPDATE_MOVE_TIMESPAN_MS 500 +#define WHEELRELEASE_DELAY_MS 16 namespace MainWindow { @@ -130,6 +132,7 @@ namespace MainWindow // gross hack bool noFocusPause = false; // TOGGLE_PAUSE state to override pause on lost focus bool trapMouse = true; // Handles some special cases(alt+tab, win menu) when game is running and mouse is confined + bool mouseScrollUsed = false; #define MAX_LOADSTRING 100 const TCHAR *szWindowClass = TEXT("PPSSPPWnd"); @@ -256,6 +259,20 @@ namespace MainWindow } } + void RelaseMouseWheel() { + if (mouseScrollUsed) { + // For simplicity release both wheel events + KeyInput key; + key.deviceId = DEVICE_ID_MOUSE; + key.flags = KEY_UP; + key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN; + NativeKey(key); + key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP; + NativeKey(key); + mouseScrollUsed = false; + } + } + static void HandleSizeChange(int newSizingType) { SavePosition(); Core_NotifyWindowHidden(false); @@ -657,6 +674,27 @@ namespace MainWindow } break; + case WM_MOUSEWHEEL: + { + int wheelDelta = (short)(wParam >> 16); + KeyInput key; + key.deviceId = DEVICE_ID_MOUSE; + + if (wheelDelta < 0) { + key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN; + wheelDelta = -wheelDelta; + } else { + key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP; + } + // There's no separate keyup event for mousewheel events, + // so we set mouseScrollUsed here and always release if it's true. + key.flags = KEY_DOWN | KEY_HASWHEELDELTA | (wheelDelta << 16); + mouseScrollUsed = true; + SetTimer(hwndMain, TIMER_WHEELRELEASE, WHEELRELEASE_DELAY_MS, 0); + NativeKey(key); + } + break; + case WM_TOUCH: { touchHandler.handleTouchEvent(hWnd, message, wParam, lParam); @@ -769,7 +807,7 @@ namespace MainWindow } break; - case WM_TIMER: + case WM_TIMER: // Hack: Take the opportunity to also show/hide the mouse cursor in fullscreen mode. switch (wParam) { case TIMER_CURSORUPDATE: @@ -780,26 +818,10 @@ namespace MainWindow hideCursor = true; KillTimer(hWnd, TIMER_CURSORMOVEUPDATE); return 0; - } - break; - - // For some reason, need to catch this here rather than in DisplayProc. - case WM_MOUSEWHEEL: - { - int wheelDelta = (short)(wParam >> 16); - KeyInput key; - key.deviceId = DEVICE_ID_MOUSE; - - if (wheelDelta < 0) { - key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN; - wheelDelta = -wheelDelta; - } else { - key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP; - } - // There's no separate keyup event for mousewheel events, let's pass them both together. - // This also means it really won't work great for key mapping :( Need to build a 1 frame delay or something. - key.flags = KEY_DOWN | KEY_UP | KEY_HASWHEELDELTA | (wheelDelta << 16); - NativeKey(key); + // Hack: need to release wheel event without waiting for another wheel event. + case TIMER_WHEELRELEASE: + RelaseMouseWheel(); + return 0; } break; @@ -888,6 +910,7 @@ namespace MainWindow case WM_DESTROY: KillTimer(hWnd, TIMER_CURSORUPDATE); KillTimer(hWnd, TIMER_CURSORMOVEUPDATE); + KillTimer(hWnd, TIMER_WHEELRELEASE); PostQuitMessage(0); break;