diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h index 028fa2cc263..e767da45940 100644 --- a/intern/ghost/GHOST_C-api.h +++ b/intern/ghost/GHOST_C-api.h @@ -256,7 +256,10 @@ extern GHOST_TSuccess GHOST_EndFullScreen(GHOST_SystemHandle systemhandle); extern bool GHOST_GetFullScreen(GHOST_SystemHandle systemhandle); /** - * Get the Window under the cursor. + * Get the Window under the cursor. Although coordinates of the mouse are supplied, platform- + * specific implementations are free to ignore these and query the mouse location themselves, due + * to them possibly being incorrect under certain conditions, for example when using multiple + * monitors that vary in scale and/or DPI. * \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. diff --git a/intern/ghost/GHOST_ISystem.hh b/intern/ghost/GHOST_ISystem.hh index 0e145c9eac6..59df6208da6 100644 --- a/intern/ghost/GHOST_ISystem.hh +++ b/intern/ghost/GHOST_ISystem.hh @@ -332,7 +332,10 @@ class GHOST_ISystem { virtual void setAutoFocus(const bool auto_focus) = 0; /** - * Get the Window under the cursor. + * Get the Window under the cursor. Although coordinates of the mouse are supplied, platform- + * specific implementations are free to ignore these and query the mouse location themselves, due + * to them possibly being incorrect under certain conditions, for example when using multiple + * monitors that vary in scale and/or DPI. * \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. diff --git a/intern/ghost/intern/GHOST_SystemWin32.cc b/intern/ghost/intern/GHOST_SystemWin32.cc index 9d13e73c28a..bfaa3ac00ff 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cc +++ b/intern/ghost/intern/GHOST_SystemWin32.cc @@ -473,6 +473,23 @@ GHOST_TSuccess GHOST_SystemWin32::getPixelAtCursor(float r_color[3]) const return GHOST_kSuccess; } +GHOST_IWindow *GHOST_SystemWin32::getWindowUnderCursor(int32_t /*x*/, int32_t /*y*/) +{ + /* Get cursor position from the OS. Do not use the supplied positions as those + * could be incorrect, especially if using multiple windows of differing OS scale. */ + POINT point; + if (!GetCursorPos(&point)) { + return nullptr; + } + + HWND win = WindowFromPoint(point); + if (win == NULL) { + return nullptr; + } + + return m_windowManager->getWindowAssociatedWithOSWindow((void *)win); +} + GHOST_TSuccess GHOST_SystemWin32::getModifierKeys(GHOST_ModifierKeys &keys) const { /* `GetAsyncKeyState` returns the current interrupt-level state of the hardware, which is needed diff --git a/intern/ghost/intern/GHOST_SystemWin32.hh b/intern/ghost/intern/GHOST_SystemWin32.hh index 8fa578f7cd3..68672946145 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.hh +++ b/intern/ghost/intern/GHOST_SystemWin32.hh @@ -151,6 +151,12 @@ class GHOST_SystemWin32 : public GHOST_System { */ static GHOST_TSuccess disposeContextD3D(GHOST_ContextD3D *context); + /** + * Get the Window under the mouse cursor. Location obtained from the OS. + * \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_WindowWin32.cc b/intern/ghost/intern/GHOST_WindowWin32.cc index 882648e9da7..3ea3412717b 100644 --- a/intern/ghost/intern/GHOST_WindowWin32.cc +++ b/intern/ghost/intern/GHOST_WindowWin32.cc @@ -361,6 +361,11 @@ HWND GHOST_WindowWin32::getHWND() const return m_hWnd; } +void *GHOST_WindowWin32::getOSWindow() const +{ + return (void *)m_hWnd; +} + void GHOST_WindowWin32::setTitle(const char *title) { wchar_t *title_16 = alloc_utf16_from_8((char *)title, 0); diff --git a/intern/ghost/intern/GHOST_WindowWin32.hh b/intern/ghost/intern/GHOST_WindowWin32.hh index 665f3fbfc73..aeb64514784 100644 --- a/intern/ghost/intern/GHOST_WindowWin32.hh +++ b/intern/ghost/intern/GHOST_WindowWin32.hh @@ -107,6 +107,12 @@ class GHOST_WindowWin32 : public GHOST_Window { */ HWND getHWND() const; + /** + * Returns the handle of the window. + * \return The handle of the window. + */ + void *getOSWindow() const; + /** * Sets the title displayed in the title bar. * \param title: The title to display in the title bar.