Add a current monitor function for window mode windows. (#1492)

This commit is contained in:
Jeffery Myers
2020-12-30 08:29:39 -08:00
committed by GitHub
parent 24b6dcf29f
commit 4c8bebc0d7

View File

@@ -1458,14 +1458,43 @@ int GetCurrentMonitor(void)
#if defined(PLATFORM_DESKTOP) #if defined(PLATFORM_DESKTOP)
int monitorCount; int monitorCount;
GLFWmonitor** monitors = glfwGetMonitors(&monitorCount); GLFWmonitor** monitors = glfwGetMonitors(&monitorCount);
GLFWmonitor* monitor = NULL;
GLFWmonitor* monitor = glfwGetWindowMonitor(CORE.Window.handle); if (monitorCount == 1) // easy out
return 0;
if (IsWindowFullscreen())
{
monitor = glfwGetWindowMonitor(CORE.Window.handle);
for (int i = 0; i < monitorCount; i++) for (int i = 0; i < monitorCount; i++)
{ {
if (monitors[i] == monitor) if (monitors[i] == monitor)
return i; return i;
} }
return 0; return 0;
}
else
{
int x = 0;
int y = 0;
glfwGetWindowPos(CORE.Window.handle, &x, &y);
for (int i = 0; i < monitorCount; i++)
{
int mx = 0;
int my = 0;
int width = 0;
int height = 0;
monitor = monitors[i];
glfwGetMonitorWorkarea(monitor, &mx, &my, &width, &height);
if (x >= mx && x <= (mx + width) && y >= my && y <= (my + height))
return i;
}
}
return 0;
#else #else
return 0; return 0;
#endif #endif