1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-26 20:28:49 -05:00

Improved handling of primary monitor.

This commit is contained in:
Camilla Berglund 2012-09-13 17:46:40 +02:00
parent d21e79642b
commit 20a49a7eee
5 changed files with 31 additions and 4 deletions

View File

@ -263,9 +263,9 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
{ {
const CGSize size = CGDisplayScreenSize(displays[i]); const CGSize size = CGDisplayScreenSize(displays[i]);
const CGRect bounds = CGDisplayBounds(displays[i]); const CGRect bounds = CGDisplayBounds(displays[i]);
const char* name = getDisplayName(displays[i]);
monitors[found] = _glfwCreateMonitor(name, monitors[found] = _glfwCreateMonitor(getDisplayName(displays[i]),
CGDisplayIsMain(displays[i]),
size.width, size.height, size.width, size.height,
bounds.origin.x, bounds.origin.y); bounds.origin.x, bounds.origin.y);

View File

@ -209,6 +209,9 @@ struct _GLFWmonitor
void* userPointer; void* userPointer;
char* name; char* name;
GLboolean primary;
// physical dimensions in millimeters. // physical dimensions in millimeters.
int physicalWidth; int physicalWidth;
int physicalHeight; int physicalHeight;
@ -393,6 +396,7 @@ GLboolean _glfwIsValidContext(_GLFWwndconfig* wndconfig);
// Monitor management (monitor.c) // Monitor management (monitor.c)
_GLFWmonitor* _glfwCreateMonitor(const char* name, _GLFWmonitor* _glfwCreateMonitor(const char* name,
GLboolean primary,
int physicalWidth, int physicalHeight, int physicalWidth, int physicalHeight,
int screenX, int screenY); int screenX, int screenY);
void _glfwDestroyMonitor(_GLFWmonitor* monitor); void _glfwDestroyMonitor(_GLFWmonitor* monitor);

View File

@ -78,6 +78,7 @@ static int compareVideoModes(const void* firstPtr, const void* secondPtr)
//======================================================================== //========================================================================
_GLFWmonitor* _glfwCreateMonitor(const char* name, _GLFWmonitor* _glfwCreateMonitor(const char* name,
GLboolean primary,
int physicalWidth, int physicalHeight, int physicalWidth, int physicalHeight,
int screenX, int screenY) int screenX, int screenY)
{ {
@ -89,6 +90,7 @@ _GLFWmonitor* _glfwCreateMonitor(const char* name,
} }
monitor->name = strdup(name); monitor->name = strdup(name);
monitor->primary = primary;
monitor->physicalWidth = physicalWidth; monitor->physicalWidth = physicalWidth;
monitor->physicalHeight = physicalHeight; monitor->physicalHeight = physicalHeight;
monitor->screenX = screenX; monitor->screenX = screenX;
@ -253,13 +255,31 @@ GLFWAPI GLFWmonitor* glfwGetMonitors(int* count)
GLFWAPI GLFWmonitor glfwGetPrimaryMonitor(void) GLFWAPI GLFWmonitor glfwGetPrimaryMonitor(void)
{ {
int i;
GLFWmonitor handle = NULL;
if (!_glfwInitialized) if (!_glfwInitialized)
{ {
_glfwSetError(GLFW_NOT_INITIALIZED, NULL); _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return NULL; return NULL;
} }
return _glfwLibrary.monitors[0]; for (i = 0; i < _glfwLibrary.monitorCount; i++)
{
if (_glfwLibrary.monitors[i]->primary)
{
handle = _glfwLibrary.monitors[i];
break;
}
}
if (!handle)
{
_glfwSetError(GLFW_PLATFORM_ERROR, NULL);
return NULL;
}
return handle;
} }

View File

@ -257,7 +257,9 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
EnumDisplayDevices(adapter.DeviceName, 0, &monitor, 0); EnumDisplayDevices(adapter.DeviceName, 0, &monitor, 0);
dc = CreateDC(L"DISPLAY", monitor.DeviceString, NULL, NULL); dc = CreateDC(L"DISPLAY", monitor.DeviceString, NULL, NULL);
monitors[found] = _glfwCreateMonitor(name, const GLboolean primary = adapter.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE;
monitors[found] = _glfwCreateMonitor(name, primary,
GetDeviceCaps(dc, HORZSIZE), GetDeviceCaps(dc, HORZSIZE),
GetDeviceCaps(dc, VERTSIZE), GetDeviceCaps(dc, VERTSIZE),
settings.dmPosition.x, settings.dmPosition.x,

View File

@ -465,6 +465,7 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
ci = XRRGetCrtcInfo(_glfwLibrary.X11.display, sr, oi->crtc); ci = XRRGetCrtcInfo(_glfwLibrary.X11.display, sr, oi->crtc);
monitors[found] = _glfwCreateMonitor(oi->name, monitors[found] = _glfwCreateMonitor(oi->name,
i == 0,
oi->mm_width, oi->mm_height, oi->mm_width, oi->mm_height,
ci->x, ci->y); ci->x, ci->y);