[gtk+] Add heuristic for primary monitor



commit 53fae3247c2d283d45a0ecbad0425331b072983a
Author: Florian Scandella <flo chilicode com>
Date:   Fri Apr 9 17:22:51 2010 +0200

    Add heuristic for primary monitor
    
    Use the first monitor returned by RANDR as primary, if primary
    is not set and no LVDS is found.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=615128

 gdk/x11/gdkscreen-x11.c |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/gdk/x11/gdkscreen-x11.c b/gdk/x11/gdkscreen-x11.c
index 4a8fc68..3350162 100644
--- a/gdk/x11/gdkscreen-x11.c
+++ b/gdk/x11/gdkscreen-x11.c
@@ -748,6 +748,7 @@ init_randr13 (GdkScreen *screen)
   Display *dpy = GDK_SCREEN_XDISPLAY (screen);
   XRRScreenResources *resources;
   RROutput primary_output;
+  RROutput first_output = None;
   int i;
   GArray *monitors;
   gboolean randr12_compat = FALSE;
@@ -802,6 +803,9 @@ init_randr13 (GdkScreen *screen)
       XRRFreeOutputInfo (output);
     }
 
+  if (resources->noutput > 0)
+    first_output = resources->outputs[0];
+
   XRRFreeScreenResources (resources);
 
   /* non RandR 1.2 X driver doesn't return any usable multihead data */
@@ -828,12 +832,22 @@ init_randr13 (GdkScreen *screen)
   for (i = 0; i < screen_x11->n_monitors; ++i)
     {
       if (screen_x11->monitors[i].output == primary_output)
-        screen_x11->primary_monitor = i;
+	{
+	  screen_x11->primary_monitor = i;
+	  break;
+	}
 
       /* No RandR1.3+ available or no primary set, fall back to prefer LVDS as primary if present */
       if (primary_output == None &&
           g_ascii_strncasecmp (screen_x11->monitors[i].output_name, "LVDS", 4) == 0)
-        screen_x11->primary_monitor = i;
+	{
+	  screen_x11->primary_monitor = i;
+	  break;
+	}
+
+      /* No primary specified and no LVDS found */
+      if (screen_x11->monitors[i].output == first_output)
+	screen_x11->primary_monitor = i;
     }
 
   return screen_x11->n_monitors > 0;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]