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