Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mouse scroll for key mapping #12110

Merged
merged 1 commit into from
Jun 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 44 additions & 21 deletions Windows/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand All @@ -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;

Expand Down Expand Up @@ -888,6 +910,7 @@ namespace MainWindow
case WM_DESTROY:
KillTimer(hWnd, TIMER_CURSORUPDATE);
KillTimer(hWnd, TIMER_CURSORMOVEUPDATE);
KillTimer(hWnd, TIMER_WHEELRELEASE);
PostQuitMessage(0);
break;

Expand Down