[Bf-blender-cvs] [843ad51d18c] master: Cleanup: use arguments for internal wayland cursor grabbing

Campbell Barton noreply at git.blender.org
Thu Jul 7 08:39:08 CEST 2022


Commit: 843ad51d18c80f4122baab47454d09383ae365c3
Author: Campbell Barton
Date:   Thu Jul 7 16:29:19 2022 +1000
Branches: master
https://developer.blender.org/rB843ad51d18c80f4122baab47454d09383ae365c3

Cleanup: use arguments for internal wayland cursor grabbing

Pass in arguments for internal grab logic instead of accessing
some values from the window and other values as arguments.
While more verbose it's simpler to reason about.

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

M	intern/ghost/intern/GHOST_SystemWayland.cpp
M	intern/ghost/intern/GHOST_SystemWayland.h
M	intern/ghost/intern/GHOST_WindowWayland.cpp

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

diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp
index 98526eb0bc6..164531f3847 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.cpp
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -3449,7 +3449,10 @@ void GHOST_SystemWayland::window_surface_unref(const wl_surface *surface)
 bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mode,
                                                  const GHOST_TGrabCursorMode mode_current,
                                                  int32_t init_grab_xy[2],
-                                                 wl_surface *surface)
+                                                 const GHOST_Rect *wrap_bounds,
+                                                 const GHOST_TAxisFlag wrap_axis,
+                                                 wl_surface *surface,
+                                                 const int scale)
 {
   /* Ignore, if the required protocols are not supported. */
   if (!d->relative_pointer_manager || !d->pointer_constraints) {
@@ -3502,31 +3505,22 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod
       if (mode_current == GHOST_kGrabWrap) {
         /* Since this call is initiated by Blender, we can be sure the window wasn't closed
          * by logic outside this function - as the window was needed to make this call. */
-        GHOST_WindowWayland *win = ghost_wl_surface_user_data(surface);
-        GHOST_ASSERT(win, "could not find window from surface when un-grabbing!");
-
-        GHOST_Rect bounds;
         int32_t xy_new[2] = {input->pointer.xy[0], input->pointer.xy[1]};
 
-        /* Fallback to window bounds. */
-        if (win->getCursorGrabBounds(bounds) == GHOST_kFailure) {
-          win->getClientBounds(bounds);
-        }
-
-        const int scale = win->scale();
+        GHOST_Rect bounds_scale;
 
-        bounds.m_l = wl_fixed_from_int(bounds.m_l) / scale;
-        bounds.m_t = wl_fixed_from_int(bounds.m_t) / scale;
-        bounds.m_r = wl_fixed_from_int(bounds.m_r) / scale;
-        bounds.m_b = wl_fixed_from_int(bounds.m_b) / scale;
+        bounds_scale.m_l = wl_fixed_from_int(wrap_bounds->m_l) / scale;
+        bounds_scale.m_t = wl_fixed_from_int(wrap_bounds->m_t) / scale;
+        bounds_scale.m_r = wl_fixed_from_int(wrap_bounds->m_r) / scale;
+        bounds_scale.m_b = wl_fixed_from_int(wrap_bounds->m_b) / scale;
 
-        bounds.wrapPoint(xy_new[0], xy_new[1], 0, win->getCursorGrabAxis());
+        bounds_scale.wrapPoint(xy_new[0], xy_new[1], 0, wrap_axis);
 
         /* Push an event so the new location is registered. */
         if ((xy_new[0] != input->pointer.xy[0]) || (xy_new[1] != input->pointer.xy[1])) {
           input->system->pushEvent(new GHOST_EventCursor(input->system->getMilliSeconds(),
                                                          GHOST_kEventCursorMove,
-                                                         win,
+                                                         ghost_wl_surface_user_data(surface),
                                                          wl_fixed_to_int(scale * xy_new[0]),
                                                          wl_fixed_to_int(scale * xy_new[1]),
                                                          GHOST_TABLET_DATA_NONE));
@@ -3541,8 +3535,6 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod
       else if (mode_current == GHOST_kGrabHide) {
         if ((init_grab_xy[0] != input->grab_lock_xy[0]) ||
             (init_grab_xy[1] != input->grab_lock_xy[1])) {
-          GHOST_WindowWayland *win = ghost_wl_surface_user_data(surface);
-          const int scale = win->scale();
           const wl_fixed_t xy_next[2] = {
               wl_fixed_from_int(init_grab_xy[0]) / scale,
               wl_fixed_from_int(init_grab_xy[1]) / scale,
@@ -3595,8 +3587,6 @@ bool GHOST_SystemWayland::window_cursor_grab_set(const GHOST_TGrabCursorMode mod
       if (mode == GHOST_kGrabHide) {
         /* Set the initial position to detect any changes when un-grabbing,
          * otherwise the unlocked cursor defaults to un-locking in-place. */
-        GHOST_WindowWayland *win = ghost_wl_surface_user_data(surface);
-        const int scale = win->scale();
         init_grab_xy[0] = wl_fixed_to_int(scale * input->pointer.xy[0]);
         init_grab_xy[1] = wl_fixed_to_int(scale * input->pointer.xy[1]);
         input->grab_lock_xy[0] = init_grab_xy[0];
diff --git a/intern/ghost/intern/GHOST_SystemWayland.h b/intern/ghost/intern/GHOST_SystemWayland.h
index e40448ff20b..0d51759aa2f 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.h
+++ b/intern/ghost/intern/GHOST_SystemWayland.h
@@ -179,7 +179,10 @@ class GHOST_SystemWayland : public GHOST_System {
   bool window_cursor_grab_set(const GHOST_TGrabCursorMode mode,
                               const GHOST_TGrabCursorMode mode_current,
                               int32_t init_grab_xy[2],
-                              wl_surface *surface);
+                              const GHOST_Rect *wrap_bounds,
+                              GHOST_TAxisFlag wrap_axis,
+                              wl_surface *surface,
+                              int scale);
 
  private:
   struct display_t *d;
diff --git a/intern/ghost/intern/GHOST_WindowWayland.cpp b/intern/ghost/intern/GHOST_WindowWayland.cpp
index 77eddbb13a5..a04ff23a1a1 100644
--- a/intern/ghost/intern/GHOST_WindowWayland.cpp
+++ b/intern/ghost/intern/GHOST_WindowWayland.cpp
@@ -501,7 +501,21 @@ GHOST_WindowWayland::GHOST_WindowWayland(GHOST_SystemWayland *system,
 
 GHOST_TSuccess GHOST_WindowWayland::setWindowCursorGrab(GHOST_TGrabCursorMode mode)
 {
-  if (m_system->window_cursor_grab_set(mode, m_cursorGrab, m_cursorGrabInitPos, w->wl_surface)) {
+  GHOST_Rect bounds_buf;
+  GHOST_Rect *bounds = nullptr;
+  if (m_cursorGrab == GHOST_kGrabWrap) {
+    if (getCursorGrabBounds(bounds_buf) == GHOST_kFailure) {
+      getClientBounds(bounds_buf);
+    }
+    bounds = &bounds_buf;
+  }
+  if (m_system->window_cursor_grab_set(mode,
+                                       m_cursorGrab,
+                                       m_cursorGrabInitPos,
+                                       bounds,
+                                       m_cursorGrabAxis,
+                                       w->wl_surface,
+                                       w->scale)) {
     return GHOST_kSuccess;
   }
   return GHOST_kFailure;



More information about the Bf-blender-cvs mailing list