Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function to get the monitor on which a window is currently being displayed #2404

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions include/GLFW/glfw3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down
1 change: 1 addition & 0 deletions src/null_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform)
_glfwShowWindowNull,
_glfwHideWindowNull,
_glfwRequestWindowAttentionNull,
_glfwGetMonitorDisplayingWindowNull,
_glfwFocusWindowNull,
_glfwSetWindowMonitorNull,
_glfwWindowFocusedNull,
Expand Down
1 change: 1 addition & 0 deletions src/null_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/null_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,11 @@ void _glfwRequestWindowAttentionNull(_GLFWwindow* window)
{
}

_GLFWmonitor* _glfwGetMonitorDisplayingWindowNull(_GLFWwindow* window)
{
return NULL;
}

void _glfwHideWindowNull(_GLFWwindow* window)
{
if (_glfw.null.focusedWindow == window)
Expand Down
1 change: 1 addition & 0 deletions src/win32_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ GLFWbool _glfwConnectWin32(int platformID, _GLFWplatform* platform)
_glfwShowWindowWin32,
_glfwHideWindowWin32,
_glfwRequestWindowAttentionWin32,
_glfwGetMonitorDisplayingWindowWin32,
_glfwFocusWindowWin32,
_glfwSetWindowMonitorWin32,
_glfwWindowFocusedWin32,
Expand Down
1 change: 1 addition & 0 deletions src/win32_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions src/win32_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading