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