From 4d743e815598610b10f6cb50da223d9d2685c260 Mon Sep 17 00:00:00 2001 From: Scr3amer Date: Tue, 26 Sep 2023 10:32:31 -0400 Subject: [PATCH] Initial commit --- include/GLFW/glfw3.h | 18 ++++++++++++++++++ src/internal.h | 1 + src/null_init.c | 1 + src/null_platform.h | 1 + src/null_window.c | 5 +++++ src/win32_init.c | 1 + src/win32_platform.h | 1 + src/win32_window.c | 13 +++++++++++++ src/window.c | 10 ++++++++++ 9 files changed, 51 insertions(+) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 58b395cd..95747ffd 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -3898,6 +3898,24 @@ 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. + * + * @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* glfwGetMonitorHostingWindow(GLFWwindow *const 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..d626f97a 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* (*getMonitorHostingWindow)(_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..0d015203 100644 --- a/src/null_init.c +++ b/src/null_init.c @@ -89,6 +89,7 @@ GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform) _glfwShowWindowNull, _glfwHideWindowNull, _glfwRequestWindowAttentionNull, + _glfwGetMonitorHostingWindowNull, _glfwFocusWindowNull, _glfwSetWindowMonitorNull, _glfwWindowFocusedNull, diff --git a/src/null_platform.h b/src/null_platform.h index 6d900111..1c5065c4 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* _glfwGetMonitorHostingWindoNull(_GLFWwindow* const 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..920ce0f2 100644 --- a/src/null_window.c +++ b/src/null_window.c @@ -436,6 +436,11 @@ void _glfwRequestWindowAttentionNull(_GLFWwindow* window) { } +_GLFWmonitor* _glfwGetMonitorHostingWindoNull(_GLFWwindow*const 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..911577b1 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -653,6 +653,7 @@ GLFWbool _glfwConnectWin32(int platformID, _GLFWplatform* platform) _glfwShowWindowWin32, _glfwHideWindowWin32, _glfwRequestWindowAttentionWin32, + _glfwGetMonitorHostingWindowWin32, _glfwFocusWindowWin32, _glfwSetWindowMonitorWin32, _glfwWindowFocusedWin32, diff --git a/src/win32_platform.h b/src/win32_platform.h index 82b34bb9..880757d0 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* _glfwGetMonitorHostingWindowWin32(_GLFWwindow* const 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 676640bf..58a661d7 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1762,6 +1762,19 @@ void _glfwRequestWindowAttentionWin32(_GLFWwindow* window) FlashWindow(window->win32.handle, TRUE); } +_GLFWmonitor* _glfwGetMonitorHostingWindowWin32(_GLFWwindow* const window) +{ + HMONITOR monitor = MonitorFromWindow(window->win32.handle, MONITOR_DEFAULTTONEAREST); + + for(int i = 0; i < _glfw.monitorCount; ++i) + { + if(_glfw.monitors[i]->win32.handle == monitor) + return _glfw.monitors[i]; + } + + return _glfw.monitors[0]; +} + void _glfwFocusWindowWin32(_GLFWwindow* window) { BringWindowToTop(window->win32.handle); diff --git a/src/window.c b/src/window.c index 1c8519ff..e45e2d13 100644 --- a/src/window.c +++ b/src/window.c @@ -822,6 +822,16 @@ GLFWAPI void glfwRequestWindowAttention(GLFWwindow* handle) _glfw.platform.requestWindowAttention(window); } +GLFWAPI GLFWmonitor* glfwGetMonitorHostingWindow(GLFWwindow* const handle) +{ + _GLFWwindow* const window = (_GLFWwindow*) handle; + assert(handle != NULL); + + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + + return (GLFWmonitor*)_glfw.platform.getMonitorHostingWindow(window); +} + GLFWAPI void glfwHideWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle;