[Bf-blender-cvs] [1a00134ab07] grab_walk_fix: Converted walk operator to use continuous grab. Mouse and tablet are now opaque to the operator handling.

Nicholas Rishel noreply at git.blender.org
Mon Sep 6 05:20:27 CEST 2021


Commit: 1a00134ab072047ba1c33921e08be23c6671d3ec
Author: Nicholas Rishel
Date:   Sat Sep 4 18:07:49 2021 -0700
Branches: grab_walk_fix
https://developer.blender.org/rB1a00134ab072047ba1c33921e08be23c6671d3ec

Converted walk operator to use continuous grab. Mouse and tablet are now opaque to the operator handling.

Continous grab has to be forced even if user has disabled it.

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

M	source/blender/editors/space_view3d/view3d_navigate_walk.c
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_event_system.c

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

diff --git a/source/blender/editors/space_view3d/view3d_navigate_walk.c b/source/blender/editors/space_view3d/view3d_navigate_walk.c
index 2d52f9e9ce6..254482ad975 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_walk.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_walk.c
@@ -284,9 +284,6 @@ typedef struct WalkInfo {
   bool is_reversed;
 
 #ifdef USE_TABLET_SUPPORT
-  /** Check if we had a cursor event before. */
-  bool is_cursor_first;
-
   /** Tablet devices (we can't relocate the cursor). */
   bool is_cursor_absolute;
 #endif
@@ -495,7 +492,7 @@ enum {
 static float base_speed = -1.0f;
 static float userdef_speed = -1.0f;
 
-static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op)
+static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op, wmEvent *event)
 {
   wmWindowManager *wm = CTX_wm_manager(C);
   wmWindow *win = CTX_wm_window(C);
@@ -537,6 +534,8 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op)
     userdef_speed = U.walk_navigation.walk_speed;
   }
 
+  walk->moffset[0] = 0;
+  walk->moffset[1] = 0;
   walk->speed = 0.0f;
   walk->is_fast = false;
   walk->is_slow = false;
@@ -573,8 +572,6 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op)
   walk->is_reversed = ((U.walk_navigation.flag & USER_WALK_MOUSE_REVERSE) != 0);
 
 #ifdef USE_TABLET_SUPPORT
-  walk->is_cursor_first = true;
-
   walk->is_cursor_absolute = false;
 #endif
 
@@ -622,11 +619,7 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op)
   walk->center_mval[1] -= walk->region->winrct.ymin;
 #endif
 
-  copy_v2_v2_int(walk->prev_mval, walk->center_mval);
-
-  WM_cursor_warp(win,
-                 walk->region->winrct.xmin + walk->center_mval[0],
-                 walk->region->winrct.ymin + walk->center_mval[1]);
+  copy_v2_v2_int(walk->prev_mval, event->mval);
 
   /* remove the mouse cursor temporarily */
   WM_cursor_modal_set(win, WM_CURSOR_NONE);
@@ -706,59 +699,13 @@ static void walkEvent(bContext *C, WalkInfo *walk, const wmEvent *event)
     walk->redraw = true;
   }
   else if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
-
-#ifdef USE_TABLET_SUPPORT
-    if (walk->is_cursor_first) {
-      /* wait until we get the 'warp' event */
-      if ((walk->center_mval[0] == event->mval[0]) && (walk->center_mval[1] == event->mval[1])) {
-        walk->is_cursor_first = false;
-      }
-      else {
-        /* NOTE: its possible the system isn't giving us the warp event
-         * ideally we shouldn't have to worry about this, see: T45361 */
-        wmWindow *win = CTX_wm_window(C);
-        WM_cursor_warp(win,
-                       walk->region->winrct.xmin + walk->center_mval[0],
-                       walk->region->winrct.ymin + walk->center_mval[1]);
-      }
-      return;
-    }
-
-    if ((walk->is_cursor_absolute == false) && event->tablet.is_motion_absolute) {
-      walk->is_cursor_absolute = true;
-      copy_v2_v2_int(walk->prev_mval, event->mval);
-      copy_v2_v2_int(walk->center_mval, event->mval);
-    }
-#endif /* USE_TABLET_SUPPORT */
-
     walk->moffset[0] += event->mval[0] - walk->prev_mval[0];
     walk->moffset[1] += event->mval[1] - walk->prev_mval[1];
 
     copy_v2_v2_int(walk->prev_mval, event->mval);
 
-    if ((walk->center_mval[0] != event->mval[0]) || (walk->center_mval[1] != event->mval[1])) {
+    if (walk->moffset[0] != 0 || walk->moffset[1] != 0) {
       walk->redraw = true;
-
-#ifdef USE_TABLET_SUPPORT
-      if (walk->is_cursor_absolute) {
-        /* pass */
-      }
-      else
-#endif
-          if (WM_event_is_last_mousemove(event)) {
-        wmWindow *win = CTX_wm_window(C);
-
-#ifdef __APPLE__
-        if ((abs(walk->prev_mval[0] - walk->center_mval[0]) > walk->center_mval[0] / 2) ||
-            (abs(walk->prev_mval[1] - walk->center_mval[1]) > walk->center_mval[1] / 2))
-#endif
-        {
-          WM_cursor_warp(win,
-                         walk->region->winrct.xmin + walk->center_mval[0],
-                         walk->region->winrct.ymin + walk->center_mval[1]);
-          copy_v2_v2_int(walk->prev_mval, walk->center_mval);
-        }
-      }
     }
   }
 #ifdef WITH_INPUT_NDOF
@@ -1095,16 +1042,7 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
           y = (float)moffset[1];
 
           /* Speed factor. */
-#ifdef USE_TABLET_SUPPORT
-          if (walk->is_cursor_absolute) {
-            y /= region->winy;
-            y *= walk_rotate_tablet_factor;
-          }
-          else
-#endif
-          {
-            y *= walk_rotate_constant_factor;
-          }
+          y *= walk_rotate_constant_factor;
 
           /* user adjustment factor */
           y *= walk->mouse_speed;
@@ -1144,16 +1082,7 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm)
           x = (float)moffset[0];
 
           /* Speed factor. */
-#ifdef USE_TABLET_SUPPORT
-          if (walk->is_cursor_absolute) {
-            x /= region->winx;
-            x *= walk_rotate_tablet_factor;
-          }
-          else
-#endif
-          {
-            x *= walk_rotate_constant_factor;
-          }
+          x *= walk_rotate_constant_factor;
 
           /* user adjustment factor */
           x *= walk->mouse_speed;
@@ -1442,7 +1371,7 @@ static int walk_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
   op->customdata = walk;
 
-  if (initWalkInfo(C, walk, op) == false) {
+  if (initWalkInfo(C, walk, op, event) == false) {
     MEM_freeN(op->customdata);
     return OPERATOR_CANCELLED;
   }
@@ -1521,7 +1450,7 @@ void VIEW3D_OT_walk(wmOperatorType *ot)
   ot->poll = ED_operator_region_view3d_active;
 
   /* flags */
-  ot->flag = OPTYPE_BLOCKING;
+  ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY | OPTYPE_GRAB_CURSOR_FORCE;
 }
 
 /** \} */
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 8a1ff67b37c..32e575400bb 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -184,6 +184,9 @@ enum {
   OPTYPE_LOCK_BYPASS = (1 << 9),
   /** Special type of undo which doesn't store itself multiple times. */
   OPTYPE_UNDO_GROUPED = (1 << 10),
+
+  /** Force cursor warp. */
+  OPTYPE_GRAB_CURSOR_FORCE = (1 << 11),
 };
 
 /** For #WM_cursor_grab_enable wrap axis. */
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 1f47b152a2b..8c0f345fdb2 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -1397,7 +1397,7 @@ static int wm_operator_invoke(bContext *C,
         int bounds[4] = {-1, -1, -1, -1};
         int wrap = WM_CURSOR_WRAP_NONE;
 
-        if (event && (U.uiflag & USER_CONTINUOUS_MOUSE)) {
+        if (event && (U.uiflag & USER_CONTINUOUS_MOUSE || op->flag & OPTYPE_GRAB_CURSOR_FORCE)) {
           const wmOperator *op_test = op->opm ? op->opm : op;
           const wmOperatorType *ot_test = op_test->type;
           if ((ot_test->flag & OPTYPE_GRAB_CURSOR_XY) ||



More information about the Bf-blender-cvs mailing list