From f9a63b5ed5040f0c45b69ad06d2ffdeda8841e80 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Tue, 2 Jun 2020 19:44:57 +0200 Subject: [PATCH] Fix for PR#86: mousewheel simultaneous X and Y scrolling under OS X . Thanks to the OP for most of the fix. --- src/Fl_cocoa.mm | 35 ++++++++++++----------------------- 1 file 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; } /* -- GitLab