[Bf-blender-cvs] [125b87844c9] temp_macos_coalesced_tablet: Support inbetween mouse/tablet moves on macOS.

Nicholas Rishel noreply at git.blender.org
Sat Nov 14 22:59:18 CET 2020


Commit: 125b87844c91c2fba0b821bbdd6d5dd3e90d6cc1
Author: Nicholas Rishel
Date:   Sat Nov 14 13:44:28 2020 -0800
Branches: temp_macos_coalesced_tablet
https://developer.blender.org/rB125b87844c91c2fba0b821bbdd6d5dd3e90d6cc1

Support inbetween mouse/tablet moves on macOS.

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.

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

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..8bd6829a967 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.mm
+++ b/intern/ghost/intern/GHOST_SystemCocoa.mm
@@ -535,6 +535,8 @@ GHOST_SystemCocoa::GHOST_SystemCocoa()
   m_ignoreWindowSizedMessages = false;
   m_ignoreMomentumScroll = false;
   m_multiTouchScroll = false;
+  
+  [NSEvent setMouseCoalescingEnabled:NO];
 }
 
 GHOST_SystemCocoa::~GHOST_SystemCocoa()
@@ -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..160e5017c72 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);
 }
 
+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)
@@ -4392,15 +4420,11 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void
       event.x = evt->x = pd->x;
       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. */



More information about the Bf-blender-cvs mailing list