mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 13:04:35 +00:00
Made glfwGetPrimaryMonitor always return a handle.
Replaced the primary flag with the convention of putting the primary monitor first in the returned array.
This commit is contained in:
parent
eb80266d89
commit
1961cecb7c
@ -244,6 +244,17 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
|
||||
|
||||
free(displays);
|
||||
|
||||
for (i = 0; i < monitorCount; i++)
|
||||
{
|
||||
if (CGDisplayIsMain(monitors[i]->ns.displayID))
|
||||
{
|
||||
_GLFWmonitor* temp = monitors[0];
|
||||
monitors[0] = monitors[i];
|
||||
monitors[i] = temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
*count = monitorCount;
|
||||
return monitors;
|
||||
}
|
||||
|
@ -257,8 +257,6 @@ struct _GLFWmonitor
|
||||
{
|
||||
char* name;
|
||||
|
||||
GLboolean primary;
|
||||
|
||||
// Physical dimensions in millimeters.
|
||||
int widthMM, heightMM;
|
||||
// Logical orientation of the screen on the desktop
|
||||
@ -686,7 +684,6 @@ GLboolean _glfwIsValidContext(_GLFWwndconfig* wndconfig);
|
||||
/*! @ingroup utility
|
||||
*/
|
||||
_GLFWmonitor* _glfwCreateMonitor(const char* name,
|
||||
GLboolean primary,
|
||||
int widthMM, int heightMM,
|
||||
int x, int y);
|
||||
|
||||
|
@ -156,7 +156,6 @@ void _glfwInputMonitorChange(void)
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
_GLFWmonitor* _glfwCreateMonitor(const char* name,
|
||||
GLboolean primary,
|
||||
int widthMM, int heightMM,
|
||||
int x, int y)
|
||||
{
|
||||
@ -168,7 +167,6 @@ _GLFWmonitor* _glfwCreateMonitor(const char* name,
|
||||
}
|
||||
|
||||
monitor->name = strdup(name);
|
||||
monitor->primary = primary;
|
||||
monitor->widthMM = widthMM;
|
||||
monitor->heightMM = heightMM;
|
||||
monitor->positionX = x;
|
||||
@ -280,31 +278,13 @@ GLFWAPI GLFWmonitor** glfwGetMonitors(int* count)
|
||||
|
||||
GLFWAPI GLFWmonitor* glfwGetPrimaryMonitor(void)
|
||||
{
|
||||
int i;
|
||||
_GLFWmonitor* primary = NULL;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwInputError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < _glfw.monitorCount; i++)
|
||||
{
|
||||
if (_glfw.monitors[i]->primary)
|
||||
{
|
||||
primary = _glfw.monitors[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!primary)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (GLFWmonitor*) primary;
|
||||
return (GLFWmonitor*) _glfw.monitors[0];
|
||||
}
|
||||
|
||||
GLFWAPI void glfwGetMonitorPos(GLFWmonitor* handle, int* xpos, int* ypos)
|
||||
|
@ -102,6 +102,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
|
||||
int size = 0, found = 0;
|
||||
_GLFWmonitor** monitors = NULL;
|
||||
DWORD adapterIndex = 0;
|
||||
int primaryIndex = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
@ -111,7 +112,6 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
|
||||
DEVMODE settings;
|
||||
char* name;
|
||||
HDC dc;
|
||||
GLboolean primary;
|
||||
|
||||
ZeroMemory(&adapter, sizeof(DISPLAY_DEVICE));
|
||||
adapter.cb = sizeof(DISPLAY_DEVICE);
|
||||
@ -156,7 +156,8 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
|
||||
EnumDisplayDevices(adapter.DeviceName, 0, &display, 0);
|
||||
dc = CreateDC(L"DISPLAY", display.DeviceString, NULL, NULL);
|
||||
|
||||
primary = adapter.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE;
|
||||
if (adapter.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
|
||||
primaryIndex = found;
|
||||
|
||||
name = _glfwCreateUTF8FromWideString(display.DeviceString);
|
||||
if (!name)
|
||||
@ -165,7 +166,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
monitors[found] = _glfwCreateMonitor(name, primary,
|
||||
monitors[found] = _glfwCreateMonitor(name,
|
||||
GetDeviceCaps(dc, HORZSIZE),
|
||||
GetDeviceCaps(dc, VERTSIZE),
|
||||
settings.dmPosition.x,
|
||||
@ -184,6 +185,13 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
|
||||
found++;
|
||||
}
|
||||
|
||||
if (primaryIndex > 0)
|
||||
{
|
||||
_GLFWmonitor* temp = monitors[0];
|
||||
monitors[0] = monitors[primaryIndex];
|
||||
monitors[primaryIndex] = temp;
|
||||
}
|
||||
|
||||
*count = found;
|
||||
return monitors;
|
||||
}
|
||||
|
@ -193,7 +193,6 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found)
|
||||
}
|
||||
|
||||
monitors[*found] = _glfwCreateMonitor(oi->name,
|
||||
output == primary,
|
||||
oi->mm_width, oi->mm_height,
|
||||
ci->x, ci->y);
|
||||
|
||||
@ -207,6 +206,17 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found)
|
||||
}
|
||||
|
||||
XRRFreeScreenResources(sr);
|
||||
|
||||
for (i = 0; i < *found; i++)
|
||||
{
|
||||
if (monitors[i]->x11.output == primary)
|
||||
{
|
||||
_GLFWmonitor* temp = monitors[0];
|
||||
monitors[0] = monitors[i];
|
||||
monitors[i] = temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -222,11 +232,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found)
|
||||
widthMM = DisplayWidthMM(_glfw.x11.display, _glfw.x11.screen);
|
||||
heightMM = DisplayHeightMM(_glfw.x11.display, _glfw.x11.screen);
|
||||
|
||||
monitors[0] = _glfwCreateMonitor("Display",
|
||||
GL_TRUE,
|
||||
widthMM, heightMM,
|
||||
0, 0);
|
||||
|
||||
monitors[0] = _glfwCreateMonitor("Display", widthMM, heightMM, 0, 0);
|
||||
*found = 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user