d62a092
From 96794b48a3dd37bf0e74b566e5bcba00293836c7 Mon Sep 17 00:00:00 2001
f76b04d
From: Adam Jackson <ajax@redhat.com>
f76b04d
Date: Tue, 28 Jul 2009 11:07:13 -0400
d62a092
Subject: [PATCH 12/16] RANDR: right-of placement by default
f76b04d
f76b04d
---
f76b04d
 hw/xfree86/modes/xf86Crtc.c |   71 ++++++++++++++++++++++++++++++++++++++----
f76b04d
 1 files changed, 64 insertions(+), 7 deletions(-)
f76b04d
f76b04d
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
d62a092
index 2ee109b..8f726fa 100644
f76b04d
--- a/hw/xfree86/modes/xf86Crtc.c
f76b04d
+++ b/hw/xfree86/modes/xf86Crtc.c
d62a092
@@ -1141,6 +1141,15 @@ xf86InitialOutputPositions (ScrnInfoPtr scrn, DisplayModePtr *modes)
f76b04d
     int			o;
f76b04d
     int			min_x, min_y;
f76b04d
     
f76b04d
+    /* check for initial right-of heuristic */
f76b04d
+    for (o = 0; o < config->num_output; o++)
f76b04d
+    {
f76b04d
+	xf86OutputPtr	output = config->output[o];
f76b04d
+
f76b04d
+	if (output->initial_x || output->initial_y)
f76b04d
+            return TRUE;
f76b04d
+    }
d62a092
+
f76b04d
     for (o = 0; o < config->num_output; o++)
f76b04d
     {
f76b04d
 	xf86OutputPtr	output = config->output[o];
d62a092
@@ -2026,6 +2035,54 @@ bestModeForAspect(xf86CrtcConfigPtr config, Bool *enabled, float aspect)
f76b04d
     return match;
f76b04d
 }
f76b04d
 
f76b04d
+static int
f76b04d
+numEnabledOutputs(xf86CrtcConfigPtr config, Bool *enabled)
f76b04d
+{
f76b04d
+    int i = 0, p;
f76b04d
+
f76b04d
+    for (i = 0, p = -1; nextEnabledOutput(config, enabled, &p); i++) ;
f76b04d
+
f76b04d
+    return i;
f76b04d
+}
f76b04d
+
f76b04d
+static Bool
f76b04d
+xf86TargetRightOf(ScrnInfoPtr scrn, xf86CrtcConfigPtr config,
f76b04d
+		  DisplayModePtr *modes, Bool *enabled,
f76b04d
+		  int width, int height)
f76b04d
+{
f76b04d
+    int o;
f76b04d
+    int w = 0;
f76b04d
+
f76b04d
+    if (numEnabledOutputs(config, enabled) < 2)
f76b04d
+	return FALSE;
d62a092
+
f76b04d
+    for (o = -1; nextEnabledOutput(config, enabled, &o); ) {
f76b04d
+	DisplayModePtr mode =
f76b04d
+	    xf86OutputHasPreferredMode(config->output[o], width, height);
f76b04d
+
f76b04d
+	if (!mode)
f76b04d
+	    return FALSE;
f76b04d
+
f76b04d
+	w += mode->HDisplay;
f76b04d
+    }
f76b04d
+
f76b04d
+    if (w > width)
f76b04d
+	return FALSE;
f76b04d
+
f76b04d
+    w = 0;
f76b04d
+    for (o = -1; nextEnabledOutput(config, enabled, &o); ) {
f76b04d
+	DisplayModePtr mode =
f76b04d
+	    xf86OutputHasPreferredMode(config->output[o], width, height);
f76b04d
+
f76b04d
+	config->output[o]->initial_x = w;
f76b04d
+	w += mode->HDisplay;
f76b04d
+
f76b04d
+	modes[o] = mode;
f76b04d
+    }
f76b04d
+
f76b04d
+    return TRUE;
f76b04d
+}
f76b04d
+
f76b04d
 static Bool
f76b04d
 xf86TargetPreferred(ScrnInfoPtr scrn, xf86CrtcConfigPtr config,
f76b04d
 		    DisplayModePtr *modes, Bool *enabled,
d62a092
@@ -2083,13 +2140,9 @@ xf86TargetPreferred(ScrnInfoPtr scrn, xf86CrtcConfigPtr config,
f76b04d
      * biggest mode for its aspect ratio, assuming one exists.
f76b04d
      */
f76b04d
     if (!ret) do {
f76b04d
-	int i = 0;
f76b04d
 	float aspect = 0.0;
f76b04d
 
f76b04d
-	/* count the number of enabled outputs */
f76b04d
-	for (i = 0, p = -1; nextEnabledOutput(config, enabled, &p); i++) ;
f76b04d
-
f76b04d
-	if (i != 1)
f76b04d
+	if (numEnabledOutputs(config, enabled) != 1)
f76b04d
 	    break;
f76b04d
 
f76b04d
 	p = -1;
d62a092
@@ -2376,6 +2429,8 @@ xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow)
f76b04d
 
f76b04d
     if (xf86TargetUserpref(scrn, config, modes, enabled, width, height))
f76b04d
 	xf86DrvMsg(i, X_INFO, "Using user preference for initial modes\n");
f76b04d
+    else if (xf86TargetRightOf(scrn, config, modes, enabled, width, height))
f76b04d
+	xf86DrvMsg(i, X_INFO, "Using spanning desktop for initial modes\n");
f76b04d
     else if (xf86TargetPreferred(scrn, config, modes, enabled, width, height))
f76b04d
 	xf86DrvMsg(i, X_INFO, "Using exact sizes for initial modes\n");
f76b04d
     else if (xf86TargetAspect(scrn, config, modes, enabled, width, height))
d62a092
@@ -2392,8 +2447,10 @@ xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow)
f76b04d
 			config->output[o]->name);
f76b04d
 	else
f76b04d
 	    xf86DrvMsg (scrn->scrnIndex, X_INFO,
f76b04d
-			"Output %s using initial mode %s\n",
f76b04d
-			config->output[o]->name, modes[o]->name);
f76b04d
+			"Output %s using initial mode %s +%d+%d\n",
f76b04d
+			config->output[o]->name, modes[o]->name,
f76b04d
+                        config->output[o]->initial_x,
f76b04d
+                        config->output[o]->initial_y);
f76b04d
     }
f76b04d
 
f76b04d
     /*
f76b04d
-- 
d62a092
1.6.4.2
f76b04d