[Bf-blender-cvs] [da9e14b0b91] master: Fix GHOST_kGrabHide in Wayland

Campbell Barton noreply at git.blender.org
Fri May 27 08:49:29 CEST 2022


Commit: da9e14b0b91c81d29c4e44f40ac299ae847367de
Author: Campbell Barton
Date:   Fri May 27 16:29:45 2022 +1000
Branches: master
https://developer.blender.org/rBda9e14b0b91c81d29c4e44f40ac299ae847367de

Fix GHOST_kGrabHide in Wayland

Dragging number buttons wasn't grabbing the cursor and would stop
when the pointer reached the screen edge & wasn't setting the cursor
visible on completion.

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

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 4a25b8bb9bb..24d3f525c97 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.cpp
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -1920,6 +1920,8 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorVisibility(bool visible)
 }
 
 GHOST_TSuccess GHOST_SystemWayland::setCursorGrab(const GHOST_TGrabCursorMode mode,
+                                                  const GHOST_TGrabCursorMode mode_current,
+
                                                   wl_surface *surface)
 {
   /* ignore, if the required protocols are not supported */
@@ -1933,36 +1935,37 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorGrab(const GHOST_TGrabCursorMode mo
 
   input_t *input = d->inputs[0];
 
-  switch (mode) {
-    case GHOST_kGrabDisable:
-      if (input->relative_pointer) {
-        zwp_relative_pointer_v1_destroy(input->relative_pointer);
-        input->relative_pointer = nullptr;
-      }
-      if (input->locked_pointer) {
-        zwp_locked_pointer_v1_destroy(input->locked_pointer);
-        input->locked_pointer = nullptr;
-      }
-      break;
-
-    case GHOST_kGrabNormal:
-      break;
-    case GHOST_kGrabWrap:
-      input->relative_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer(
-          d->relative_pointer_manager, input->pointer);
-      zwp_relative_pointer_v1_add_listener(
-          input->relative_pointer, &relative_pointer_listener, input);
-      input->locked_pointer = zwp_pointer_constraints_v1_lock_pointer(
-          d->pointer_constraints,
-          surface,
-          input->pointer,
-          nullptr,
-          ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
-      break;
+  if (mode != GHOST_kGrabDisable) {
+    /* TODO(@campbellbarton): Support #GHOST_kGrabWrap,
+     * where the cursor moves but is constrained to a region. */
+    input->relative_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer(
+        d->relative_pointer_manager, input->pointer);
+    zwp_relative_pointer_v1_add_listener(
+        input->relative_pointer, &relative_pointer_listener, input);
+    input->locked_pointer = zwp_pointer_constraints_v1_lock_pointer(
+        d->pointer_constraints,
+        surface,
+        input->pointer,
+        nullptr,
+        ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
+
+    if (mode == GHOST_kGrabHide) {
+      setCursorVisibility(false);
+    }
+  }
+  else {
+    if (input->relative_pointer) {
+      zwp_relative_pointer_v1_destroy(input->relative_pointer);
+      input->relative_pointer = nullptr;
+    }
+    if (input->locked_pointer) {
+      zwp_locked_pointer_v1_destroy(input->locked_pointer);
+      input->locked_pointer = nullptr;
+    }
 
-    case GHOST_kGrabHide:
+    if (mode_current == GHOST_kGrabHide) {
       setCursorVisibility(false);
-      break;
+    }
   }
 
   return GHOST_kSuccess;
diff --git a/intern/ghost/intern/GHOST_SystemWayland.h b/intern/ghost/intern/GHOST_SystemWayland.h
index 1f664915ad3..01b47358618 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.h
+++ b/intern/ghost/intern/GHOST_SystemWayland.h
@@ -103,7 +103,9 @@ class GHOST_SystemWayland : public GHOST_System {
 
   GHOST_TSuccess setCursorVisibility(bool visible);
 
-  GHOST_TSuccess setCursorGrab(const GHOST_TGrabCursorMode mode, wl_surface *surface);
+  GHOST_TSuccess setCursorGrab(const GHOST_TGrabCursorMode mode,
+                               const GHOST_TGrabCursorMode mode_current,
+                               wl_surface *surface);
 
  private:
   struct display_t *d;
diff --git a/intern/ghost/intern/GHOST_WindowWayland.cpp b/intern/ghost/intern/GHOST_WindowWayland.cpp
index 7ae06623c91..7f2a2c992d9 100644
--- a/intern/ghost/intern/GHOST_WindowWayland.cpp
+++ b/intern/ghost/intern/GHOST_WindowWayland.cpp
@@ -320,7 +320,7 @@ int &GHOST_WindowWayland::scale()
 
 GHOST_TSuccess GHOST_WindowWayland::setWindowCursorGrab(GHOST_TGrabCursorMode mode)
 {
-  return m_system->setCursorGrab(mode, w->surface);
+  return m_system->setCursorGrab(mode, m_cursorGrab, w->surface);
 }
 
 GHOST_TSuccess GHOST_WindowWayland::setWindowCursorShape(GHOST_TStandardCursor shape)



More information about the Bf-blender-cvs mailing list