Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorGermano Cavalcante <germano.costa@ig.com.br>2022-03-02 00:09:28 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2022-03-02 00:25:12 +0300
commit9bd586a01e6813a615eab05871803730603e2152 (patch)
treea437902dcc606b7ea3b13d6d7e7ba1168a6428bd /intern
parent8e88af99348590e9879dcbfe97bbbc180fc5ec67 (diff)
Fix T95608: Mac issues with drag drop on multi-monitor
Mousemove events are sent to windows. In Windows OS, almost all mousemove events are sent to the window whose mouse cursor is over. On MacOS, the window with mousemove events is always the active window. It doesn't matter if the mouse cursor is inside or outside the window. So, in order for non-active windows to also have events, `WM_window_find_under_cursor` is called to find those windows and send the same events. The problem is that to find the window, `WM_window_find_under_cursor` only has the mouse coordinates available, it doesn't differentiate which monitor these coordinates came from. So the mouse on one monitor may incorrectly send events to a window on another monitor. The solution used is to use a native API on Mac to detect the window under the cursor. For Windows and Linux nothing has changed. Reviewed By: brecht Differential Revision: https://developer.blender.org/D14197
Diffstat (limited to 'intern')
-rw-r--r--intern/ghost/GHOST_C-api.h10
-rw-r--r--intern/ghost/GHOST_ISystem.h8
-rw-r--r--intern/ghost/intern/GHOST_C-api.cpp10
-rw-r--r--intern/ghost/intern/GHOST_System.cpp19
-rw-r--r--intern/ghost/intern/GHOST_System.h8
-rw-r--r--intern/ghost/intern/GHOST_SystemCocoa.h8
-rw-r--r--intern/ghost/intern/GHOST_SystemCocoa.mm14
-rw-r--r--intern/ghost/intern/GHOST_SystemNULL.h5
8 files changed, 82 insertions, 0 deletions
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 98094cc0669..a2eef91c704 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -265,6 +265,16 @@ extern GHOST_TSuccess GHOST_EndFullScreen(GHOST_SystemHandle systemhandle);
*/
extern int GHOST_GetFullScreen(GHOST_SystemHandle systemhandle);
+/**
+ * Get the Window under the cursor.
+ * \param x: The x-coordinate of the cursor.
+ * \param y: The y-coordinate of the cursor.
+ * @return The window under the cursor or nullptr in none.
+ */
+extern GHOST_WindowHandle GHOST_GetWindowUnderCursor(GHOST_SystemHandle systemhandle,
+ int32_t x,
+ int32_t y);
+
/***************************************************************************************
* Event management functionality
***************************************************************************************/
diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h
index 05c6c9d907f..4c568a0cc02 100644
--- a/intern/ghost/GHOST_ISystem.h
+++ b/intern/ghost/GHOST_ISystem.h
@@ -325,6 +325,14 @@ class GHOST_ISystem {
*/
virtual void useWindowFocus(const bool use_focus) = 0;
+ /**
+ * Get the Window under the cursor.
+ * \param x: The x-coordinate of the cursor.
+ * \param y: The y-coordinate of the cursor.
+ * @return The window under the cursor or nullptr if none.
+ */
+ virtual GHOST_IWindow *getWindowUnderCursor(int32_t x, int32_t y) = 0;
+
/***************************************************************************************
* Event management functionality
***************************************************************************************/
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index a21c3a90c06..3d8411a8268 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -249,6 +249,16 @@ int GHOST_GetFullScreen(GHOST_SystemHandle systemhandle)
return (int)system->getFullScreen();
}
+GHOST_WindowHandle GHOST_GetWindowUnderCursor(GHOST_SystemHandle systemhandle,
+ int32_t x,
+ int32_t y)
+{
+ GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
+ GHOST_IWindow *window = system->getWindowUnderCursor(x, y);
+
+ return (GHOST_WindowHandle)window;
+}
+
bool GHOST_ProcessEvents(GHOST_SystemHandle systemhandle, bool waitForEvent)
{
GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
diff --git a/intern/ghost/intern/GHOST_System.cpp b/intern/ghost/intern/GHOST_System.cpp
index d09c167cb95..17f74003805 100644
--- a/intern/ghost/intern/GHOST_System.cpp
+++ b/intern/ghost/intern/GHOST_System.cpp
@@ -205,6 +205,25 @@ bool GHOST_System::getFullScreen(void)
return fullScreen;
}
+GHOST_IWindow *GHOST_System::getWindowUnderCursor(int32_t x, int32_t y)
+{
+ /* TODO: This solution should follow the order of the activated windows (Z-order).
+ * It is imperfect but usable in most cases. */
+ for (GHOST_IWindow *iwindow : m_windowManager->getWindows()) {
+ if (iwindow->getState() == GHOST_kWindowStateMinimized) {
+ continue;
+ }
+
+ GHOST_Rect bounds;
+ iwindow->getClientBounds(bounds);
+ if (bounds.isInside(x, y)) {
+ return iwindow;
+ }
+ }
+
+ return NULL;
+}
+
void GHOST_System::dispatchEvents()
{
#ifdef WITH_INPUT_NDOF
diff --git a/intern/ghost/intern/GHOST_System.h b/intern/ghost/intern/GHOST_System.h
index 16c34ff1a6d..692e483be2a 100644
--- a/intern/ghost/intern/GHOST_System.h
+++ b/intern/ghost/intern/GHOST_System.h
@@ -173,6 +173,14 @@ class GHOST_System : public GHOST_ISystem {
void useWindowFocus(const bool use_focus);
bool m_windowFocus;
+ /**
+ * Get the Window under the cursor.
+ * \param x: The x-coordinate of the cursor.
+ * \param y: The y-coordinate of the cursor.
+ * @return The window under the cursor or nullptr if none.
+ */
+ GHOST_IWindow *getWindowUnderCursor(int32_t x, int32_t y);
+
/***************************************************************************************
* Event management functionality
***************************************************************************************/
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.h b/intern/ghost/intern/GHOST_SystemCocoa.h
index 5950da6813d..37cba8b8559 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.h
+++ b/intern/ghost/intern/GHOST_SystemCocoa.h
@@ -125,6 +125,14 @@ class GHOST_SystemCocoa : public GHOST_System {
*/
GHOST_TSuccess disposeContext(GHOST_IContext *context);
+ /**
+ * Get the Window under the cursor.
+ * \param x: The x-coordinate of the cursor.
+ * \param y: The y-coordinate of the cursor.
+ * @return The window under the cursor or nullptr if none.
+ */
+ GHOST_IWindow *getWindowUnderCursor(int32_t x, int32_t y);
+
/***************************************************************************************
* Event management functionality
***************************************************************************************/
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm
index a53c3d8f2ab..b54bfab5547 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.mm
+++ b/intern/ghost/intern/GHOST_SystemCocoa.mm
@@ -788,6 +788,20 @@ GHOST_TSuccess GHOST_SystemCocoa::disposeContext(GHOST_IContext *context)
return GHOST_kSuccess;
}
+GHOST_IWindow *GHOST_SystemCocoa::getWindowUnderCursor(int32_t x, int32_t y)
+{
+ NSPoint scr_co = NSMakePoint(x, y);
+
+ int windowNumberAtPoint = [NSWindow windowNumberAtPoint:scr_co belowWindowWithWindowNumber:0];
+ NSWindow *nswindow = [NSApp windowWithWindowNumber:windowNumberAtPoint];
+
+ if (nswindow == nil) {
+ return nil;
+ }
+
+ return m_windowManager->getWindowAssociatedWithOSWindow((void *)nswindow);
+}
+
/**
* \note : returns coordinates in Cocoa screen coordinates
*/
diff --git a/intern/ghost/intern/GHOST_SystemNULL.h b/intern/ghost/intern/GHOST_SystemNULL.h
index 5dbc42b53a2..43bbc788113 100644
--- a/intern/ghost/intern/GHOST_SystemNULL.h
+++ b/intern/ghost/intern/GHOST_SystemNULL.h
@@ -128,4 +128,9 @@ class GHOST_SystemNULL : public GHOST_System {
type,
((glSettings.flags & GHOST_glStereoVisual) != 0));
}
+
+ GHOST_IWindow *getWindowUnderCursor(int32_t x, int32_t y)
+ {
+ return NULL;
+ }
};