summaryrefslogtreecommitdiff
path: root/src/Fl_win32.cxx
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2023-08-13 17:20:07 +0200
committerAlbrecht Schlosser <albrechts.fltk@online.de>2023-08-13 17:44:00 +0200
commit847901623a55d69fc8c0c4b7770ec33698402e3a (patch)
tree5d594b2b6041984fb7cd0d90a606d049f0276896 /src/Fl_win32.cxx
parent8c5c7aa7f43ac3ccbcee3c56629022a9643e2ab9 (diff)
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.
Diffstat (limited to 'src/Fl_win32.cxx')
-rw-r--r--src/Fl_win32.cxx38
1 files changed, 26 insertions, 12 deletions
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;
}