From 4d743e815598610b10f6cb50da223d9d2685c260 Mon Sep 17 00:00:00 2001 From: Scr3amer Date: Tue, 26 Sep 2023 10:32:31 -0400 Subject: [PATCH 1/5] 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; From e8d244387fe7507b8636824cce31b5448e98de7d Mon Sep 17 00:00:00 2001 From: Scr3amer Date: Tue, 26 Sep 2023 14:43:45 -0400 Subject: [PATCH 2/5] Rename hosting to displaying and remove const pointer parameters --- include/GLFW/glfw3.h | 2 +- src/internal.h | 2 +- src/null_init.c | 2 +- src/null_platform.h | 2 +- src/null_window.c | 2 +- src/win32_init.c | 2 +- src/win32_platform.h | 2 +- src/win32_window.c | 2 +- src/window.c | 4 ++-- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 95747ffd..1aae0a55 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -3914,7 +3914,7 @@ GLFWAPI void glfwRequestWindowAttention(GLFWwindow* window); * * @ingroup window */ -GLFWAPI GLFWmonitor* glfwGetMonitorHostingWindow(GLFWwindow *const window); +GLFWAPI GLFWmonitor* glfwGetMonitorDisplayingWindow(GLFWwindow* window); /*! @brief Returns the monitor that the window uses for full screen mode. * diff --git a/src/internal.h b/src/internal.h index d626f97a..31992ed5 100644 --- a/src/internal.h +++ b/src/internal.h @@ -724,7 +724,7 @@ struct _GLFWplatform void (*showWindow)(_GLFWwindow*); void (*hideWindow)(_GLFWwindow*); void (*requestWindowAttention)(_GLFWwindow*); - _GLFWmonitor* (*getMonitorHostingWindow)(_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 0d015203..2cc1f2b4 100644 --- a/src/null_init.c +++ b/src/null_init.c @@ -89,7 +89,7 @@ GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform) _glfwShowWindowNull, _glfwHideWindowNull, _glfwRequestWindowAttentionNull, - _glfwGetMonitorHostingWindowNull, + _glfwGetMonitorDisplayingWindowNull, _glfwFocusWindowNull, _glfwSetWindowMonitorNull, _glfwWindowFocusedNull, diff --git a/src/null_platform.h b/src/null_platform.h index 1c5065c4..8ed01cd2 100644 --- a/src/null_platform.h +++ b/src/null_platform.h @@ -240,7 +240,7 @@ GLFWbool _glfwRawMouseMotionSupportedNull(void); void _glfwShowWindowNull(_GLFWwindow* window); void _glfwRequestWindowAttentionNull(_GLFWwindow* window); void _glfwRequestWindowAttentionNull(_GLFWwindow* window); -_GLFWmonitor* _glfwGetMonitorHostingWindoNull(_GLFWwindow* const window); +_GLFWmonitor* _glfwGetMonitorDisplayingWindoNull(_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 920ce0f2..90245579 100644 --- a/src/null_window.c +++ b/src/null_window.c @@ -436,7 +436,7 @@ void _glfwRequestWindowAttentionNull(_GLFWwindow* window) { } -_GLFWmonitor* _glfwGetMonitorHostingWindoNull(_GLFWwindow*const window) +_GLFWmonitor* _glfwGetMonitorDisplayingWindoNull(_GLFWwindow* window) { return NULL; } diff --git a/src/win32_init.c b/src/win32_init.c index 911577b1..20029e12 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -653,7 +653,7 @@ GLFWbool _glfwConnectWin32(int platformID, _GLFWplatform* platform) _glfwShowWindowWin32, _glfwHideWindowWin32, _glfwRequestWindowAttentionWin32, - _glfwGetMonitorHostingWindowWin32, + _glfwGetMonitorDisplayingWindowWin32, _glfwFocusWindowWin32, _glfwSetWindowMonitorWin32, _glfwWindowFocusedWin32, diff --git a/src/win32_platform.h b/src/win32_platform.h index 880757d0..79d65aaf 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -558,7 +558,7 @@ void _glfwMaximizeWindowWin32(_GLFWwindow* window); void _glfwShowWindowWin32(_GLFWwindow* window); void _glfwHideWindowWin32(_GLFWwindow* window); void _glfwRequestWindowAttentionWin32(_GLFWwindow* window); -_GLFWmonitor* _glfwGetMonitorHostingWindowWin32(_GLFWwindow* const 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 58a661d7..55d0ab9c 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1762,7 +1762,7 @@ void _glfwRequestWindowAttentionWin32(_GLFWwindow* window) FlashWindow(window->win32.handle, TRUE); } -_GLFWmonitor* _glfwGetMonitorHostingWindowWin32(_GLFWwindow* const window) +_GLFWmonitor* _glfwGetMonitorDisplayingWindowWin32(_GLFWwindow* window) { HMONITOR monitor = MonitorFromWindow(window->win32.handle, MONITOR_DEFAULTTONEAREST); diff --git a/src/window.c b/src/window.c index e45e2d13..9916e493 100644 --- a/src/window.c +++ b/src/window.c @@ -822,14 +822,14 @@ GLFWAPI void glfwRequestWindowAttention(GLFWwindow* handle) _glfw.platform.requestWindowAttention(window); } -GLFWAPI GLFWmonitor* glfwGetMonitorHostingWindow(GLFWwindow* const handle) +GLFWAPI GLFWmonitor* glfwGetMonitorDisplayingWindow(GLFWwindow* handle) { _GLFWwindow* const window = (_GLFWwindow*) handle; assert(handle != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - return (GLFWmonitor*)_glfw.platform.getMonitorHostingWindow(window); + return (GLFWmonitor*)_glfw.platform.getMonitorDisplayingWindow(window); } GLFWAPI void glfwHideWindow(GLFWwindow* handle) From a98b1877aaed1654cd008c6ddffe9c3ea10ebc52 Mon Sep 17 00:00:00 2001 From: Scr3amer Date: Tue, 26 Sep 2023 14:51:54 -0400 Subject: [PATCH 3/5] Return NULL if the monitor is not found --- include/GLFW/glfw3.h | 2 ++ src/win32_window.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 1aae0a55..6ef01bf9 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -3903,6 +3903,8 @@ GLFWAPI void glfwRequestWindowAttention(GLFWwindow* window); * 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. * diff --git a/src/win32_window.c b/src/win32_window.c index 55d0ab9c..f81999a2 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1772,7 +1772,7 @@ _GLFWmonitor* _glfwGetMonitorDisplayingWindowWin32(_GLFWwindow* window) return _glfw.monitors[i]; } - return _glfw.monitors[0]; + return NULL; } void _glfwFocusWindowWin32(_GLFWwindow* window) From d9b93315ba7280cf0b1ad3cd09b535cc12a1923c Mon Sep 17 00:00:00 2001 From: Scr3amer Date: Tue, 26 Sep 2023 14:56:35 -0400 Subject: [PATCH 4/5] Buildfix : Fix typo in function name --- src/null_platform.h | 2 +- src/null_window.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/null_platform.h b/src/null_platform.h index 8ed01cd2..46ca6742 100644 --- a/src/null_platform.h +++ b/src/null_platform.h @@ -240,7 +240,7 @@ GLFWbool _glfwRawMouseMotionSupportedNull(void); void _glfwShowWindowNull(_GLFWwindow* window); void _glfwRequestWindowAttentionNull(_GLFWwindow* window); void _glfwRequestWindowAttentionNull(_GLFWwindow* window); -_GLFWmonitor* _glfwGetMonitorDisplayingWindoNull(_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 90245579..dcf11ae4 100644 --- a/src/null_window.c +++ b/src/null_window.c @@ -436,7 +436,7 @@ void _glfwRequestWindowAttentionNull(_GLFWwindow* window) { } -_GLFWmonitor* _glfwGetMonitorDisplayingWindoNull(_GLFWwindow* window) +_GLFWmonitor* _glfwGetMonitorDisplayingWindowNull(_GLFWwindow* window) { return NULL; } From c6f67fb2dfc0974cb41796b7336bc2d47cf5dde4 Mon Sep 17 00:00:00 2001 From: Scr3amer Date: Tue, 26 Sep 2023 15:07:19 -0400 Subject: [PATCH 5/5] Buildfix - ISO C90 --- src/win32_window.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/win32_window.c b/src/win32_window.c index f81999a2..234ef1e4 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1764,9 +1764,10 @@ void _glfwRequestWindowAttentionWin32(_GLFWwindow* window) _GLFWmonitor* _glfwGetMonitorDisplayingWindowWin32(_GLFWwindow* window) { + int i; HMONITOR monitor = MonitorFromWindow(window->win32.handle, MONITOR_DEFAULTTONEAREST); - for(int i = 0; i < _glfw.monitorCount; ++i) + for(i = 0; i < _glfw.monitorCount; ++i) { if(_glfw.monitors[i]->win32.handle == monitor) return _glfw.monitors[i];