Przeglądaj źródła

Improved handling of primary monitor.

Camilla Berglund 13 lat temu
rodzic
commit
20a49a7eee
5 zmienionych plików z 31 dodań i 4 usunięć
  1. 2 2
      src/cocoa_monitor.m
  2. 4 0
      src/internal.h
  3. 21 1
      src/monitor.c
  4. 3 1
      src/win32_monitor.c
  5. 1 0
      src/x11_monitor.c

+ 2 - 2
src/cocoa_monitor.m

@@ -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);
 
 

+ 4 - 0
src/internal.h

@@ -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);

+ 21 - 1
src/monitor.c

@@ -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;
 }
 }
 
 
 
 

+ 3 - 1
src/win32_monitor.c

@@ -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,

+ 1 - 0
src/x11_monitor.c

@@ -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);