Peter Hutterer 4c175e
From 12aa6574fd87ec28186a75256a5111e9703d932e Mon Sep 17 00:00:00 2001
f76b04
From: Adam Jackson <ajax@redhat.com>
f76b04
Date: Tue, 28 Jul 2009 11:07:13 -0400
Peter Hutterer 4c175e
Subject: [PATCH 4/9] RANDR: right-of placement by default
f76b04
add10e
[Enhanced to add a new prefer clone option for drivers. This
add10e
allows for servers like RN50 where two heads are disjoint. - airlied]
f76b04
---
add10e
 hw/xfree86/common/xf86str.h |    9 ++++-
add10e
 hw/xfree86/modes/xf86Crtc.c |   74 ++++++++++++++++++++++++++++++++++++++----
add10e
 2 files changed, 74 insertions(+), 9 deletions(-)
f76b04
add10e
diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h
Peter Hutterer 379416
index 0493dc5..d66e373 100644
add10e
--- a/hw/xfree86/common/xf86str.h
add10e
+++ b/hw/xfree86/common/xf86str.h
Peter Hutterer 77cc64
@@ -496,10 +496,13 @@ typedef struct _confdrirec {
add10e
 } confDRIRec, *confDRIPtr;
add10e
 
add10e
 /* These values should be adjusted when new fields are added to ScrnInfoRec */
Peter Hutterer 77cc64
-#define NUM_RESERVED_INTS		16
Peter Hutterer 77cc64
+#define NUM_RESERVED_INTS		15
add10e
 #define NUM_RESERVED_POINTERS		14
Peter Hutterer 379416
 #define NUM_RESERVED_FUNCS		10
add10e
 
add10e
+/* let clients know they can use this */
add10e
+#define XF86_SCRN_HAS_PREFER_CLONE 1
add10e
+
add10e
 typedef pointer (*funcPointer)(void);
add10e
 
add10e
 /* flags for depth 24 pixmap options */
Peter Hutterer 379416
@@ -659,7 +662,6 @@ typedef void xf86ModeSetProc              (ScrnInfoPtr);
add10e
  * are to be dependent on compile-time defines.
add10e
  */
add10e
 
add10e
-
add10e
 typedef struct _ScrnInfoRec {
add10e
     int			driverVersion;
add10e
     char *		driverName;		/* canonical name used in */
Peter Hutterer 379416
@@ -761,6 +763,9 @@ typedef struct _ScrnInfoRec {
Peter Hutterer 77cc64
     ClockRangePtr	clockRanges;
Peter Hutterer 77cc64
     int			adjustFlags;
c22de5
 
add10e
+    /* initial rightof support disable */
add10e
+    int                 preferClone;
c22de5
+
add10e
     /*
add10e
      * These can be used when the minor ABI version is incremented.
c22de5
      * The NUM_* parameters must be reduced appropriately to keep the
f76b04
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
Peter Hutterer 4c175e
index c2814d4..b25876f 100644
f76b04
--- a/hw/xfree86/modes/xf86Crtc.c
f76b04
+++ b/hw/xfree86/modes/xf86Crtc.c
Peter Hutterer 4c175e
@@ -1139,6 +1139,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];
Peter Hutterer 4c175e
@@ -2030,6 +2039,57 @@ 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
+
add10e
+    if (scrn->preferClone)
add10e
+	return FALSE;
add10e
+
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,
Peter Hutterer 4c175e
@@ -2087,13 +2147,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;
Peter Hutterer 4c175e
@@ -2388,6 +2444,8 @@ xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow)
c22de5
     } else {
c22de5
 	if (xf86TargetUserpref(scrn, config, modes, enabled, width, height))
c22de5
 	    xf86DrvMsg(i, X_INFO, "Using user preference for initial modes\n");
c22de5
+	else if (xf86TargetRightOf(scrn, config, modes, enabled, width, height))
c22de5
+	    xf86DrvMsg(i, X_INFO, "Using spanning desktop for initial modes\n");
c22de5
 	else if (xf86TargetPreferred(scrn, config, modes, enabled, width, height))
c22de5
 	    xf86DrvMsg(i, X_INFO, "Using exact sizes for initial modes\n");
c22de5
 	else if (xf86TargetAspect(scrn, config, modes, enabled, width, height))
Peter Hutterer 4c175e
@@ -2405,8 +2463,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
-- 
Peter Hutterer 4c175e
1.7.4.4
f76b04