Blob Blame Raw
From 96794b48a3dd37bf0e74b566e5bcba00293836c7 Mon Sep 17 00:00:00 2001
From: Adam Jackson <ajax@redhat.com>
Date: Tue, 28 Jul 2009 11:07:13 -0400
Subject: [PATCH 12/16] RANDR: right-of placement by default

---
 hw/xfree86/modes/xf86Crtc.c |   71 ++++++++++++++++++++++++++++++++++++++----
 1 files changed, 64 insertions(+), 7 deletions(-)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 2ee109b..8f726fa 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -1141,6 +1141,15 @@ xf86InitialOutputPositions (ScrnInfoPtr scrn, DisplayModePtr *modes)
     int			o;
     int			min_x, min_y;
     
+    /* check for initial right-of heuristic */
+    for (o = 0; o < config->num_output; o++)
+    {
+	xf86OutputPtr	output = config->output[o];
+
+	if (output->initial_x || output->initial_y)
+            return TRUE;
+    }
+
     for (o = 0; o < config->num_output; o++)
     {
 	xf86OutputPtr	output = config->output[o];
@@ -2026,6 +2035,54 @@ bestModeForAspect(xf86CrtcConfigPtr config, Bool *enabled, float aspect)
     return match;
 }
 
+static int
+numEnabledOutputs(xf86CrtcConfigPtr config, Bool *enabled)
+{
+    int i = 0, p;
+
+    for (i = 0, p = -1; nextEnabledOutput(config, enabled, &p); i++) ;
+
+    return i;
+}
+
+static Bool
+xf86TargetRightOf(ScrnInfoPtr scrn, xf86CrtcConfigPtr config,
+		  DisplayModePtr *modes, Bool *enabled,
+		  int width, int height)
+{
+    int o;
+    int w = 0;
+
+    if (numEnabledOutputs(config, enabled) < 2)
+	return FALSE;
+
+    for (o = -1; nextEnabledOutput(config, enabled, &o); ) {
+	DisplayModePtr mode =
+	    xf86OutputHasPreferredMode(config->output[o], width, height);
+
+	if (!mode)
+	    return FALSE;
+
+	w += mode->HDisplay;
+    }
+
+    if (w > width)
+	return FALSE;
+
+    w = 0;
+    for (o = -1; nextEnabledOutput(config, enabled, &o); ) {
+	DisplayModePtr mode =
+	    xf86OutputHasPreferredMode(config->output[o], width, height);
+
+	config->output[o]->initial_x = w;
+	w += mode->HDisplay;
+
+	modes[o] = mode;
+    }
+
+    return TRUE;
+}
+
 static Bool
 xf86TargetPreferred(ScrnInfoPtr scrn, xf86CrtcConfigPtr config,
 		    DisplayModePtr *modes, Bool *enabled,
@@ -2083,13 +2140,9 @@ xf86TargetPreferred(ScrnInfoPtr scrn, xf86CrtcConfigPtr config,
      * biggest mode for its aspect ratio, assuming one exists.
      */
     if (!ret) do {
-	int i = 0;
 	float aspect = 0.0;
 
-	/* count the number of enabled outputs */
-	for (i = 0, p = -1; nextEnabledOutput(config, enabled, &p); i++) ;
-
-	if (i != 1)
+	if (numEnabledOutputs(config, enabled) != 1)
 	    break;
 
 	p = -1;
@@ -2376,6 +2429,8 @@ xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow)
 
     if (xf86TargetUserpref(scrn, config, modes, enabled, width, height))
 	xf86DrvMsg(i, X_INFO, "Using user preference for initial modes\n");
+    else if (xf86TargetRightOf(scrn, config, modes, enabled, width, height))
+	xf86DrvMsg(i, X_INFO, "Using spanning desktop for initial modes\n");
     else if (xf86TargetPreferred(scrn, config, modes, enabled, width, height))
 	xf86DrvMsg(i, X_INFO, "Using exact sizes for initial modes\n");
     else if (xf86TargetAspect(scrn, config, modes, enabled, width, height))
@@ -2392,8 +2447,10 @@ xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow)
 			config->output[o]->name);
 	else
 	    xf86DrvMsg (scrn->scrnIndex, X_INFO,
-			"Output %s using initial mode %s\n",
-			config->output[o]->name, modes[o]->name);
+			"Output %s using initial mode %s +%d+%d\n",
+			config->output[o]->name, modes[o]->name,
+                        config->output[o]->initial_x,
+                        config->output[o]->initial_y);
     }
 
     /*
-- 
1.6.4.2