diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index d828dc58..4e8816e7 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -305,6 +305,11 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) return monitors; } +GLboolean _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second) +{ + return first->ns.displayID == second->ns.displayID; +} + void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) { const CGRect bounds = CGDisplayBounds(monitor->ns.displayID); diff --git a/src/internal.h b/src/internal.h index 61b6f64e..28fd37f2 100644 --- a/src/internal.h +++ b/src/internal.h @@ -363,6 +363,16 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode); */ _GLFWmonitor** _glfwPlatformGetMonitors(int* count); +/*! @brief Checks whether two monitor objects represent the same monitor. + * + * @param[in] first The first monitor. + * @param[in] second The second monitor. + * @return @c GL_TRUE if the monitor objects represent the same monitor, or @c + * GL_FALSE otherwise. + * @ingroup platform + */ +GLboolean _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second); + /*! @copydoc glfwGetMonitorPos * @ingroup platform */ diff --git a/src/monitor.c b/src/monitor.c index 20b6fde6..c4bc404f 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -106,7 +106,7 @@ void _glfwInputMonitorChange(void) if (_glfw.monitors[j] == NULL) continue; - if (strcmp(monitors[i]->name, _glfw.monitors[j]->name) == 0) + if (_glfwPlatformIsSameMonitor(monitors[i], _glfw.monitors[j])) { // This monitor was connected before, so re-use the existing // monitor object to preserve its address and user pointer diff --git a/src/win32_monitor.c b/src/win32_monitor.c index ecc4cddb..57d905ec 100644 --- a/src/win32_monitor.c +++ b/src/win32_monitor.c @@ -174,6 +174,11 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count) return monitors; } +GLboolean _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second) +{ + return wcscmp(first->win32.name, second->win32.name); +} + void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) { DEVMODE settings; diff --git a/src/x11_monitor.c b/src/x11_monitor.c index da0e7ad3..c3122f48 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -224,6 +224,11 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found) return monitors; } +GLboolean _glfwPlatformIsSameMonitor(_GLFWmonitor* first, _GLFWmonitor* second) +{ + return first->x11.crtc == second->x11.crtc; +} + void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) { if (_glfw.x11.randr.available)