From 692221cacb284b40cf3fe4944089eada69207611 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 22 Jan 2022 15:56:53 +0100 Subject: [PATCH] cocoadisplay: Invert direction of horizontal scroll Now behaves consistent with other applications (tested with Logitech MX Master 3 for Mac on macOS 10.13 in unnatural scrolling configuration). Set `cocoa-invert-wheel-x true` to revert to old behaviour. --- panda/src/cocoadisplay/cocoaGraphicsWindow.mm | 15 ++++++++++----- panda/src/cocoadisplay/config_cocoadisplay.h | 2 ++ panda/src/cocoadisplay/config_cocoadisplay.mm | 5 +++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm index 87a3c96777..0b973a0317 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm @@ -2021,8 +2021,10 @@ handle_mouse_moved_event(bool in_window, double x, double y, bool absolute) { */ void CocoaGraphicsWindow:: handle_wheel_event(double x, double y) { - cocoadisplay_cat.spam() - << "Wheel delta " << x << ", " << y << "\n"; + if (cocoadisplay_cat.is_spam()) { + cocoadisplay_cat.spam() + << "Wheel delta " << x << ", " << y << "\n"; + } if (y > 0.0) { _input->button_down(MouseButton::wheel_up()); @@ -2032,11 +2034,14 @@ handle_wheel_event(double x, double y) { _input->button_up(MouseButton::wheel_down()); } - // TODO: check if this is correct, I don't own a MacBook - if (x > 0.0) { + if (x != 0 && cocoa_invert_wheel_x) { + x = -x; + } + + if (x < 0.0) { _input->button_down(MouseButton::wheel_right()); _input->button_up(MouseButton::wheel_right()); - } else if (x < 0.0) { + } else if (x > 0.0) { _input->button_down(MouseButton::wheel_left()); _input->button_up(MouseButton::wheel_left()); } diff --git a/panda/src/cocoadisplay/config_cocoadisplay.h b/panda/src/cocoadisplay/config_cocoadisplay.h index 43a0e057c3..43051a67c5 100644 --- a/panda/src/cocoadisplay/config_cocoadisplay.h +++ b/panda/src/cocoadisplay/config_cocoadisplay.h @@ -20,6 +20,8 @@ NotifyCategoryDecl(cocoadisplay, EXPCL_PANDA_COCOADISPLAY, EXPTP_PANDA_COCOADISPLAY); +extern ConfigVariableBool cocoa_invert_wheel_x; + extern EXPCL_PANDA_COCOADISPLAY void init_libcocoadisplay(); #endif diff --git a/panda/src/cocoadisplay/config_cocoadisplay.mm b/panda/src/cocoadisplay/config_cocoadisplay.mm index 96662d6c9c..a79144769b 100644 --- a/panda/src/cocoadisplay/config_cocoadisplay.mm +++ b/panda/src/cocoadisplay/config_cocoadisplay.mm @@ -31,6 +31,11 @@ ConfigureFn(config_cocoadisplay) { init_libcocoadisplay(); } +ConfigVariableBool cocoa_invert_wheel_x +("cocoa-invert-wheel-x", false, + PRC_DESC("Set this to true to swap the wheel_left and wheel_right mouse " + "button events, to restore to the pre-1.10.12 behavior.")); + /** * Initializes the library. This must be called at least once before any of * the functions or classes in this library can be used. Normally it will be