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