changeset 3505:a1bf34bc2a58

Ensure that the main display is picked up first
author Sam Lantinga <slouken@libsdl.org>
date Tue, 01 Dec 2009 10:41:58 +0000
parents 919d88c202cf
children e829b6098435
files src/video/cocoa/SDL_cocoamodes.m
diffstat 1 files changed, 39 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/cocoa/SDL_cocoamodes.m	Tue Dec 01 10:34:01 2009 +0000
+++ b/src/video/cocoa/SDL_cocoamodes.m	Tue Dec 01 10:41:58 2009 +0000
@@ -139,7 +139,7 @@
     CGDisplayErr result;
     CGDirectDisplayID *displays;
     CGDisplayCount numDisplays;
-    int i;
+    int pass, i;
 
     result = CGGetOnlineDisplayList(0, NULL, &numDisplays);
     if (result != kCGErrorSuccess) {
@@ -154,35 +154,48 @@
         return;
     }
 
-    for (i = 0; i < numDisplays; ++i) {
-        SDL_VideoDisplay display;
-        SDL_DisplayData *displaydata;
-        SDL_DisplayMode mode;
-        CFDictionaryRef moderef;
+    /* Pick up the primary display in the first pass, then get the rest */
+    for (pass = 0; pass < 2; ++pass) {
+        for (i = 0; i < numDisplays; ++i) {
+            SDL_VideoDisplay display;
+            SDL_DisplayData *displaydata;
+            SDL_DisplayMode mode;
+            CFDictionaryRef moderef;
 
-        if (CGDisplayMirrorsDisplay(displays[i]) != kCGNullDirectDisplay) {
-            continue;
-        }
-        moderef = CGDisplayCurrentMode(displays[i]);
-        if (!moderef) {
-            continue;
-        }
+            if (pass == 0) {
+                if (!CGDisplayIsMain(displays[i])) {
+                    continue;
+                }
+            } else {
+                if (CGDisplayIsMain(displays[i])) {
+                    continue;
+                }
+            }
 
-        displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata));
-        if (!displaydata) {
-            continue;
-        }
-        displaydata->display = displays[i];
+            if (CGDisplayMirrorsDisplay(displays[i]) != kCGNullDirectDisplay) {
+                continue;
+            }
+            moderef = CGDisplayCurrentMode(displays[i]);
+            if (!moderef) {
+                continue;
+            }
 
-        SDL_zero(display);
-        if (!GetDisplayMode (moderef, &mode)) {
-            SDL_free(displaydata);
-            continue;
+            displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata));
+            if (!displaydata) {
+                continue;
+            }
+            displaydata->display = displays[i];
+
+            SDL_zero(display);
+            if (!GetDisplayMode (moderef, &mode)) {
+                SDL_free(displaydata);
+                continue;
+            }
+            display.desktop_mode = mode;
+            display.current_mode = mode;
+            display.driverdata = displaydata;
+            SDL_AddVideoDisplay(&display);
         }
-        display.desktop_mode = mode;
-        display.current_mode = mode;
-        display.driverdata = displaydata;
-        SDL_AddVideoDisplay(&display);
     }
     SDL_stack_free(displays);
 }