Browse Source

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.
rdb 3 years ago
parent
commit
692221cacb

+ 10 - 5
panda/src/cocoadisplay/cocoaGraphicsWindow.mm

@@ -2021,8 +2021,10 @@ handle_mouse_moved_event(bool in_window, double x, double y, bool absolute) {
  */
  */
 void CocoaGraphicsWindow::
 void CocoaGraphicsWindow::
 handle_wheel_event(double x, double y) {
 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) {
   if (y > 0.0) {
     _input->button_down(MouseButton::wheel_up());
     _input->button_down(MouseButton::wheel_up());
@@ -2032,11 +2034,14 @@ handle_wheel_event(double x, double y) {
     _input->button_up(MouseButton::wheel_down());
     _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_down(MouseButton::wheel_right());
     _input->button_up(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_down(MouseButton::wheel_left());
     _input->button_up(MouseButton::wheel_left());
     _input->button_up(MouseButton::wheel_left());
   }
   }

+ 2 - 0
panda/src/cocoadisplay/config_cocoadisplay.h

@@ -20,6 +20,8 @@
 
 
 NotifyCategoryDecl(cocoadisplay, EXPCL_PANDA_COCOADISPLAY, EXPTP_PANDA_COCOADISPLAY);
 NotifyCategoryDecl(cocoadisplay, EXPCL_PANDA_COCOADISPLAY, EXPTP_PANDA_COCOADISPLAY);
 
 
+extern ConfigVariableBool cocoa_invert_wheel_x;
+
 extern EXPCL_PANDA_COCOADISPLAY void init_libcocoadisplay();
 extern EXPCL_PANDA_COCOADISPLAY void init_libcocoadisplay();
 
 
 #endif
 #endif

+ 5 - 0
panda/src/cocoadisplay/config_cocoadisplay.mm

@@ -31,6 +31,11 @@ ConfigureFn(config_cocoadisplay) {
   init_libcocoadisplay();
   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
  * 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
  * the functions or classes in this library can be used.  Normally it will be