diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 58b395cd..6ef01bf9 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -3898,6 +3898,26 @@ GLFWAPI void glfwFocusWindow(GLFWwindow* window); */ GLFWAPI void glfwRequestWindowAttention(GLFWwindow* window); +/*! @brief Returns the monitor on which the window is being currently displayed. + * + * The window should not be NULL. + * + * @param[in] window The window to query. + * @return The monitor, or `NULL` if the window is NULL or an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @thread_safety This function must only be called from the main thread. + * + * @sa @ref window_monitor + * + * @since Added in version 3.4. + * + * @ingroup window + */ +GLFWAPI GLFWmonitor* glfwGetMonitorDisplayingWindow(GLFWwindow* window); + /*! @brief Returns the monitor that the window uses for full screen mode. * * This function returns the handle of the monitor that the specified window is diff --git a/src/internal.h b/src/internal.h index fe0369aa..31992ed5 100644 --- a/src/internal.h +++ b/src/internal.h @@ -724,6 +724,7 @@ struct _GLFWplatform void (*showWindow)(_GLFWwindow*); void (*hideWindow)(_GLFWwindow*); void (*requestWindowAttention)(_GLFWwindow*); + _GLFWmonitor* (*getMonitorDisplayingWindow)(_GLFWwindow*); void (*focusWindow)(_GLFWwindow*); void (*setWindowMonitor)(_GLFWwindow*,_GLFWmonitor*,int,int,int,int,int); GLFWbool (*windowFocused)(_GLFWwindow*); diff --git a/src/null_init.c b/src/null_init.c index 7236c98c..2cc1f2b4 100644 --- a/src/null_init.c +++ b/src/null_init.c @@ -89,6 +89,7 @@ GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform) _glfwShowWindowNull, _glfwHideWindowNull, _glfwRequestWindowAttentionNull, + _glfwGetMonitorDisplayingWindowNull, _glfwFocusWindowNull, _glfwSetWindowMonitorNull, _glfwWindowFocusedNull, diff --git a/src/null_platform.h b/src/null_platform.h index 6d900111..46ca6742 100644 --- a/src/null_platform.h +++ b/src/null_platform.h @@ -240,6 +240,7 @@ GLFWbool _glfwRawMouseMotionSupportedNull(void); void _glfwShowWindowNull(_GLFWwindow* window); void _glfwRequestWindowAttentionNull(_GLFWwindow* window); void _glfwRequestWindowAttentionNull(_GLFWwindow* window); +_GLFWmonitor* _glfwGetMonitorDisplayingWindowNull(_GLFWwindow* window); void _glfwHideWindowNull(_GLFWwindow* window); void _glfwFocusWindowNull(_GLFWwindow* window); GLFWbool _glfwWindowFocusedNull(_GLFWwindow* window); diff --git a/src/null_window.c b/src/null_window.c index e0bbb3b6..dcf11ae4 100644 --- a/src/null_window.c +++ b/src/null_window.c @@ -436,6 +436,11 @@ void _glfwRequestWindowAttentionNull(_GLFWwindow* window) { } +_GLFWmonitor* _glfwGetMonitorDisplayingWindowNull(_GLFWwindow* window) +{ + return NULL; +} + void _glfwHideWindowNull(_GLFWwindow* window) { if (_glfw.null.focusedWindow == window) diff --git a/src/win32_init.c b/src/win32_init.c index ef2615f1..20029e12 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -653,6 +653,7 @@ GLFWbool _glfwConnectWin32(int platformID, _GLFWplatform* platform) _glfwShowWindowWin32, _glfwHideWindowWin32, _glfwRequestWindowAttentionWin32, + _glfwGetMonitorDisplayingWindowWin32, _glfwFocusWindowWin32, _glfwSetWindowMonitorWin32, _glfwWindowFocusedWin32, diff --git a/src/win32_platform.h b/src/win32_platform.h index 82b34bb9..79d65aaf 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -558,6 +558,7 @@ void _glfwMaximizeWindowWin32(_GLFWwindow* window); void _glfwShowWindowWin32(_GLFWwindow* window); void _glfwHideWindowWin32(_GLFWwindow* window); void _glfwRequestWindowAttentionWin32(_GLFWwindow* window); +_GLFWmonitor* _glfwGetMonitorDisplayingWindowWin32(_GLFWwindow* window); void _glfwFocusWindowWin32(_GLFWwindow* window); void _glfwSetWindowMonitorWin32(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); GLFWbool _glfwWindowFocusedWin32(_GLFWwindow* window); diff --git a/src/win32_window.c b/src/win32_window.c index a4a18171..72ca2be5 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1762,6 +1762,20 @@ void _glfwRequestWindowAttentionWin32(_GLFWwindow* window) FlashWindow(window->win32.handle, TRUE); } +_GLFWmonitor* _glfwGetMonitorDisplayingWindowWin32(_GLFWwindow* window) +{ + int i; + HMONITOR monitor = MonitorFromWindow(window->win32.handle, MONITOR_DEFAULTTONEAREST); + + for(i = 0; i < _glfw.monitorCount; ++i) + { + if(_glfw.monitors[i]->win32.handle == monitor) + return _glfw.monitors[i]; + } + + return NULL; +} + void _glfwFocusWindowWin32(_GLFWwindow* window) { BringWindowToTop(window->win32.handle); diff --git a/src/window.c b/src/window.c index 1c8519ff..9916e493 100644 --- a/src/window.c +++ b/src/window.c @@ -822,6 +822,16 @@ GLFWAPI void glfwRequestWindowAttention(GLFWwindow* handle) _glfw.platform.requestWindowAttention(window); } +GLFWAPI GLFWmonitor* glfwGetMonitorDisplayingWindow(GLFWwindow* handle) +{ + _GLFWwindow* const window = (_GLFWwindow*) handle; + assert(handle != NULL); + + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + + return (GLFWmonitor*)_glfw.platform.getMonitorDisplayingWindow(window); +} + GLFWAPI void glfwHideWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle;