[X11] Obey DISPLAY environment variable when selecting screen (Steaphan Greene)
authorGabriel Jacobo <gabomdq@gmail.com>
Wed, 15 Oct 2014 18:33:43 -0300
changeset 9167 3d2c0f659ad3
parent 9166 e5a2e31d4bee
child 9168 b8e85a5ac99a
[X11] Obey DISPLAY environment variable when selecting screen (Steaphan Greene) Discussed in bug #2192, tested with Xvfb in dual head configuration.
src/video/x11/SDL_x11modes.c
--- a/src/video/x11/SDL_x11modes.c	Wed Oct 15 15:50:35 2014 -0400
+++ b/src/video/x11/SDL_x11modes.c	Wed Oct 15 18:33:43 2014 -0300
@@ -375,7 +375,7 @@
 X11_InitModes(_THIS)
 {
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
-    int screen, screencount;
+    int snum, screen, screencount;
 #if SDL_VIDEO_DRIVER_X11_XINERAMA
     int xinerama_major, xinerama_minor;
     int use_xinerama = 0;
@@ -423,7 +423,7 @@
     }
 #endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
 
-    for (screen = 0; screen < screencount; ++screen) {
+    for (snum = 0; snum < screencount; ++snum) {
         XVisualInfo vinfo;
         SDL_VideoDisplay display;
         SDL_DisplayData *displaydata;
@@ -433,6 +433,15 @@
         char display_name[128];
         int i, n;
 
+        /* Re-order screens to always put default screen first */
+        if (snum == 0) {
+            screen = DefaultScreen(data->display);
+        } else if (snum == DefaultScreen(data->display)) {
+            screen = 0;
+        } else {
+            screen = snum;
+        }
+
 #if SDL_VIDEO_DRIVER_X11_XINERAMA
         if (xinerama) {
             if (get_visualinfo(data->display, 0, &vinfo) < 0) {