summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2020-06-02 19:44:57 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2020-06-02 19:44:57 +0200
commitf9a63b5ed5040f0c45b69ad06d2ffdeda8841e80 (patch)
treefe3c5d799f01489e3da746b180cdd5e08190824c
parent09ee1c0b9c41d4a4887b975d736063d3b5016278 (diff)
Fix for PR#86: mousewheel simultaneous X and Y scrolling under OS X .
Thanks to the OP for most of the fix.
-rw-r--r--src/Fl_cocoa.mm35
1 files changed, 12 insertions, 23 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index d964792bf..d7d7ec151 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -922,35 +922,24 @@ static void cocoaMouseWheelHandler(NSEvent *theEvent)
// to me why Apple changed the API on this even though the current API
// supports two wheels just fine. Matthias,
fl_lock_function();
-
Fl_Window *window = (Fl_Window*)[(FLWindow*)[theEvent window] getFl_Window];
- if ( !window->shown() ) {
- fl_unlock_function();
- return;
- }
Fl::first_window(window);
-
- // Under OSX, single mousewheel increments are 0.1,
- // so make sure they show up as at least 1..
- //
- float dx = [theEvent deltaX]; if ( fabs(dx) < 1.0 ) dx = (dx > 0) ? 1.0 : -1.0;
- float dy = [theEvent deltaY]; if ( fabs(dy) < 1.0 ) dy = (dy > 0) ? 1.0 : -1.0;
- if ([theEvent deltaX] != 0) {
- Fl::e_dx = (int)-dx;
+ // Under OSX, mousewheel deltas are floats, but fltk only supports ints.
+ float s = Fl::screen_driver()->scale(0);
+ int dx = roundf([theEvent deltaX] / s);
+ int dy = roundf([theEvent deltaY] / s);
+ // allow both horizontal and vertical movements to be processed by the widget
+ if (dx) {
+ Fl::e_dx = -dx;
Fl::e_dy = 0;
- if ( Fl::e_dx) Fl::handle( FL_MOUSEWHEEL, window );
- } else if ([theEvent deltaY] != 0) {
+ Fl::handle( FL_MOUSEWHEEL, window );
+ }
+ if (dy) {
Fl::e_dx = 0;
- Fl::e_dy = (int)-dy;
- if ( Fl::e_dy) Fl::handle( FL_MOUSEWHEEL, window );
- } else {
- fl_unlock_function();
- return;
+ Fl::e_dy = -dy;
+ Fl::handle( FL_MOUSEWHEEL, window );
}
-
fl_unlock_function();
-
- // return noErr;
}
/*