[Bf-blender-cvs] [65b1b1cd349] master: GHOST/Wayland: workaround inability to access window position

Campbell Barton noreply at git.blender.org
Thu Jun 16 07:57:55 CEST 2022


Commit: 65b1b1cd349f3bd813392e76eab5b610efba7428
Author: Campbell Barton
Date:   Thu Jun 16 15:16:04 2022 +1000
Branches: master
https://developer.blender.org/rB65b1b1cd349f3bd813392e76eab5b610efba7428

GHOST/Wayland: workaround inability to access window position

Wayland doesn't support accessing the position making functionality that
would map events to other windows fail, sometimes considering windows
overlapping when they weren't (as all window positions were zeroed).

Disable dragging between windows when accessing the window the position
isn't supported.

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

M	intern/ghost/GHOST_C-api.h
M	intern/ghost/GHOST_ISystem.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_System.cpp
M	intern/ghost/intern/GHOST_System.h
M	intern/ghost/intern/GHOST_SystemWayland.cpp
M	intern/ghost/intern/GHOST_SystemWayland.h
M	source/blender/windowmanager/intern/wm_event_system.cc

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

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 388d6eb96d2..c92e6ba78c1 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -906,6 +906,11 @@ extern int GHOST_UseNativePixels(void);
  */
 extern int GHOST_SupportsCursorWarp(void);
 
+/**
+ * Support positioning windows (when false `wmWindow.x,y` are meaningless).
+ */
+extern int GHOST_SupportsWindowPosition(void);
+
 /**
  * Assign the callback which generates a back-trace (may be NULL).
  */
diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h
index 436ff7a723e..d946d2d882a 100644
--- a/intern/ghost/GHOST_ISystem.h
+++ b/intern/ghost/GHOST_ISystem.h
@@ -312,6 +312,11 @@ class GHOST_ISystem {
    */
   virtual bool supportsCursorWarp() = 0;
 
+  /**
+   * Return true getting/setting the window position is supported.
+   */
+  virtual bool supportsWindowPosition() = 0;
+
   /**
    * Focus window after opening, or put them in the background.
    */
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 3bb7a7618c4..b1a15fdf4d7 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -835,6 +835,12 @@ int GHOST_SupportsCursorWarp(void)
   return system->supportsCursorWarp();
 }
 
+int GHOST_SupportsWindowPosition(void)
+{
+  GHOST_ISystem *system = GHOST_ISystem::getSystem();
+  return system->supportsWindowPosition();
+}
+
 void GHOST_SetBacktraceHandler(GHOST_TBacktraceFn backtrace_fn)
 {
   GHOST_ISystem::setBacktraceFn(backtrace_fn);
diff --git a/intern/ghost/intern/GHOST_System.cpp b/intern/ghost/intern/GHOST_System.cpp
index 2aad4f2ea29..c8308b3586b 100644
--- a/intern/ghost/intern/GHOST_System.cpp
+++ b/intern/ghost/intern/GHOST_System.cpp
@@ -395,6 +395,11 @@ bool GHOST_System::supportsCursorWarp()
   return true;
 }
 
+bool GHOST_System::supportsWindowPosition()
+{
+  return true;
+}
+
 void GHOST_System::initDebug(GHOST_Debug debug)
 {
   m_is_debug_enabled = debug.flags & GHOST_kDebugDefault;
diff --git a/intern/ghost/intern/GHOST_System.h b/intern/ghost/intern/GHOST_System.h
index 9f2fba1a2c6..b60ce09f743 100644
--- a/intern/ghost/intern/GHOST_System.h
+++ b/intern/ghost/intern/GHOST_System.h
@@ -152,6 +152,7 @@ class GHOST_System : public GHOST_ISystem {
   bool m_nativePixel;
 
   bool supportsCursorWarp(void);
+  bool supportsWindowPosition(void);
 
   /**
    * Focus window after opening, or put them in the background.
diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp
index 93d85f33dda..d8fbe875f67 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.cpp
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -2682,6 +2682,14 @@ GHOST_TSuccess GHOST_SystemWayland::setCursorVisibility(bool visible)
 
 bool GHOST_SystemWayland::supportsCursorWarp()
 {
+  /* WAYLAND doesn't support setting the cursor position directly,
+   * this is an intentional choice, forcing us to use a software cursor in this case. */
+  return false;
+}
+
+bool GHOST_SystemWayland::supportsWindowPosition()
+{
+  /* WAYLAND doesn't support accessing the window position. */
   return false;
 }
 
diff --git a/intern/ghost/intern/GHOST_SystemWayland.h b/intern/ghost/intern/GHOST_SystemWayland.h
index 3be108b1f88..762ceb80e38 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.h
+++ b/intern/ghost/intern/GHOST_SystemWayland.h
@@ -125,6 +125,7 @@ class GHOST_SystemWayland : public GHOST_System {
   GHOST_TSuccess setCursorVisibility(bool visible);
 
   bool supportsCursorWarp();
+  bool supportsWindowPosition();
 
   GHOST_TSuccess setCursorGrab(const GHOST_TGrabCursorMode mode,
                                const GHOST_TGrabCursorMode mode_current,
diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc
index 658e643508e..e44016948fc 100644
--- a/source/blender/windowmanager/intern/wm_event_system.cc
+++ b/source/blender/windowmanager/intern/wm_event_system.cc
@@ -4942,7 +4942,11 @@ static void attach_ndof_data(wmEvent *event, const GHOST_TEventNDOFMotionData *g
 /* Imperfect but probably usable... draw/enable drags to other windows. */
 static wmWindow *wm_event_cursor_other_windows(wmWindowManager *wm, wmWindow *win, wmEvent *event)
 {
-  int mval[2] = {event->xy[0], event->xy[1]};
+  /* If GHOST doesn't support window positioning, don't use this feature at all. */
+  const static int8_t supports_window_position = GHOST_SupportsWindowPosition();
+  if (!supports_window_position) {
+    return nullptr;
+  }
 
   if (wm->windows.first == wm->windows.last) {
     return nullptr;
@@ -4951,6 +4955,7 @@ static wmWindow *wm_event_cursor_other_windows(wmWindowManager *wm, wmWindow *wi
   /* In order to use window size and mouse position (pixels), we have to use a WM function. */
 
   /* Check if outside, include top window bar. */
+  int mval[2] = {event->xy[0], event->xy[1]};
   if (mval[0] < 0 || mval[1] < 0 || mval[0] > WM_window_pixels_x(win) ||
       mval[1] > WM_window_pixels_y(win) + 30) {
     /* Let's skip windows having modal handlers now. */



More information about the Bf-blender-cvs mailing list