Commit: 96200110eb0f0c8d2d48b1f383927ab8bd6c4aff
Author: Nicholas Rishel
Date:   Sat Nov 14 17:17:12 2020 -0800
Branches: master
https://developer.blender.org/rB96200110eb0f0c8d2d48b1f383927ab8bd6c4aff

Fix T76699: Support macOS inbetween mouse/tablet.

Coalescing on macOS overwrites a singular unprocessed mouse event. To
receive all mouse and tablet events coalescing is disabled.

Disabling coalescing for macOS disables coalescing for trackpad
gestures. Repeat trackpad events are unnecessary and found to
negatively impact performance thus are re-coalesced in Window Manager.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D9574

===================================================================

M       intern/ghost/intern/GHOST_SystemCocoa.mm
M       source/blender/windowmanager/intern/wm_event_system.c

===================================================================

diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm 
b/intern/ghost/intern/GHOST_SystemCocoa.mm
index c12c09f1053..2a3f6e0b0b9 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.mm
+++ b/intern/ghost/intern/GHOST_SystemCocoa.mm
@@ -415,6 +415,8 @@ extern "C" int GHOST_HACK_getFirstFile(char 
buf[FIRSTFILEBUFLG])
     // with a frontmost window but an inactive application.
     [NSApp activateIgnoringOtherApps:YES];
   }
+
+  [NSEvent setMouseCoalescingEnabled:NO];
 }
 
 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString 
*)filename
@@ -892,7 +894,6 @@ bool GHOST_SystemCocoa::processEvents(bool waitForEvent)
   bool anyProcessed = false;
   NSEvent *event;
 
-  //  SetMouseCoalescingEnabled(false, NULL);
   // TODO : implement timer ??
 #if 0
   do {
diff --git a/source/blender/windowmanager/intern/wm_event_system.c 
b/source/blender/windowmanager/intern/wm_event_system.c
index bf970aa2034..1aaefeabd08 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -180,6 +180,14 @@ void wm_event_free(wmEvent *event)
   MEM_freeN(event);
 }
 
+static void wm_event_free_last(wmWindow *win)
+{
+  wmEvent *event = BLI_poptail(&win->queue);
+  if (event != NULL) {
+    wm_event_free(event);
+  }
+}
+
 void wm_event_free_all(wmWindow *win)
 {
   wmEvent *event;
@@ -4306,6 +4314,26 @@ static wmEvent *wm_event_add_mousemove(wmWindow *win, 
const wmEvent *event)
   return event_new;
 }
 
+static wmEvent *wm_event_add_trackpad(wmWindow *win, const wmEvent *event, int 
deltax, int deltay)
+{
+  /* Ignore in between trackpad events for performance, we only need high 
accuracy
+   * for painting with mouse moves, for navigation using the accumulated value 
is ok. */
+  wmEvent *event_last = win->queue.last;
+  if (event_last && event_last->type == event->type) {
+    deltax += event_last->x - event_last->prevx;
+    deltay += event_last->y - event_last->prevy;
+
+    wm_event_free_last(win);
+  }
+
+  /* Set prevx/prevy, the delta is computed from this in operators. */
+  wmEvent *event_new = wm_event_add(win, event);
+  event_new->prevx = event_new->x - deltax;
+  event_new->prevy = event_new->y - deltay;
+
+  return event_new;
+}
+
 /* Windows store own event queues, no bContext here. */
 /* Time is in 1000s of seconds, from Ghost. */
 void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, 
void *customdata)
@@ -4393,14 +4421,10 @@ void wm_event_add_ghostevent(wmWindowManager *wm, 
wmWindow *win, int type, void
       event.y = evt->y = pd->y;
       event.val = KM_NOTHING;
 
-      /* Use prevx/prevy so we can calculate the delta later. */
-      event.prevx = event.x - pd->deltaX;
-      event.prevy = event.y - (-pd->deltaY);
-
       /* The direction is inverted from the device due to system preferences. 
*/
       event.is_direction_inverted = pd->isDirectionInverted;
 
-      wm_event_add(win, &event);
+      wm_event_add_trackpad(win, &event, pd->deltaX, -pd->deltaY);
       break;
     }
     /* Mouse button. */

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to