From 847901623a55d69fc8c0c4b7770ec33698402e3a Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Sun, 13 Aug 2023 17:20:07 +0200 Subject: Handle shift + mousewheel event on Windows (STR 3521) Pressing the shift key while using the mousewheel changes horizontal to vertical scrolling and vice versa. This allows users with a standard mouse with only one scrollwheel to use it for both scrolling directions. Note: other mice that have either two buttons or a scroll ball can generate both horizontal and vertical scrolling in one action. This commit does not affect such behavior. This patch is different than the one in file 'scroll.patch' (STR 3521). It takes care of distinct mousewheel delta calculation for vertical and horizontal mousewheels and avoids the "fallthrough" case. Note: macOS takes care of this, there's no special handling required. To do: the Wayland platform still needs to be updated. --- src/Fl_win32.cxx | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index 8579e0ccd..0895ca417 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -1531,24 +1531,38 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar } // case WM_DEADCHAR ... WM_SYSCHAR case WM_MOUSEWHEEL: { - static int delta = 0; // running total of all motion + static int delta = 0; // running total of all vertical mousewheel motion delta += (SHORT)(HIWORD(wParam)); - Fl::e_dx = 0; - Fl::e_dy = -delta / WHEEL_DELTA; - delta += Fl::e_dy * WHEEL_DELTA; - if (Fl::e_dy) - Fl::handle(FL_MOUSEWHEEL, window); + int dy = -delta / WHEEL_DELTA; + delta += dy * WHEEL_DELTA; + if (dy == 0) // nothing to do + return 0; + if (Fl::event_shift()) { // shift key pressed: send horizontal mousewheel event + Fl::e_dx = dy; + Fl::e_dy = 0; + } else { // shift key not pressed (normal behavior): send vertical mousewheel event + Fl::e_dx = 0; + Fl::e_dy = dy; + } + Fl::handle(FL_MOUSEWHEEL, window); return 0; } case WM_MOUSEHWHEEL: { - static int delta = 0; // running total of all motion + static int delta = 0; // running total of all horizontal mousewheel motion delta += (SHORT)(HIWORD(wParam)); - Fl::e_dy = 0; - Fl::e_dx = delta / WHEEL_DELTA; - delta -= Fl::e_dx * WHEEL_DELTA; - if (Fl::e_dx) - Fl::handle(FL_MOUSEWHEEL, window); + int dx = delta / WHEEL_DELTA; + delta -= dx * WHEEL_DELTA; + if (dx == 0) // nothing to do + return 0; + if (Fl::event_shift()) { // shift key pressed: send *vertical* mousewheel event + Fl::e_dx = 0; + Fl::e_dy = dx; + } else { // shift key not pressed (normal behavior): send horizontal mousewheel event + Fl::e_dx = dx; + Fl::e_dy = 0; + } + Fl::handle(FL_MOUSEWHEEL, window); return 0; } -- cgit v1.2.3