[Xquartz-changes] xserver: Branch 'master' - 58 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Mon Jan 11 17:39:19 PST 2010


 Xi/stubs.c                           |    3 
 config/Makefile.am                   |   20 +
 config/config-backends.h             |   21 +-
 config/config.c                      |   77 +++++++
 config/dbus.c                        |    2 
 config/hal.c                         |   88 ++------
 config/udev.c                        |  260 +++++++++++++++++++++++++
 configure.ac                         |   49 ++++
 cpprules.in                          |    3 
 dix/devices.c                        |    6 
 dix/getevents.c                      |    7 
 dix/ptrveloc.c                       |   28 ++
 exa/exa.c                            |    6 
 exa/exa_accel.c                      |   35 +--
 exa/exa_migration_classic.c          |    3 
 exa/exa_migration_mixed.c            |   58 ++---
 exa/exa_mixed.c                      |   18 +
 exa/exa_priv.h                       |   15 +
 exa/exa_unaccel.c                    |  347 +++++++++++++++++++++++++++-------
 hw/dmx/dmxinput.c                    |    3 
 hw/kdrive/ephyr/.gitignore           |    1 
 hw/kdrive/ephyr/ephyr.c              |  137 ++++++-------
 hw/kdrive/ephyr/ephyr.h              |    7 
 hw/kdrive/ephyr/ephyr_draw.c         |    7 
 hw/kdrive/ephyr/ephyrdriext.c        |   21 --
 hw/kdrive/ephyr/ephyrglxext.c        |   28 +-
 hw/kdrive/ephyr/ephyrhostvideo.c     |    6 
 hw/kdrive/ephyr/ephyrinit.c          |   15 -
 hw/kdrive/ephyr/ephyrvideo.c         |   21 --
 hw/kdrive/fake/fake.c                |   89 ++++----
 hw/kdrive/fake/fake.h                |    5 
 hw/kdrive/fake/fakeinit.c            |    4 
 hw/kdrive/fbdev/fbdev.c              |  228 +++++++++++-----------
 hw/kdrive/fbdev/fbdev.h              |   47 ----
 hw/kdrive/fbdev/fbinit.c             |   14 -
 hw/kdrive/linux/Makefile.am          |   31 +--
 hw/kdrive/linux/bus.c                |  133 -------------
 hw/kdrive/linux/evdev.c              |   24 +-
 hw/kdrive/linux/keyboard.c           |   14 -
 hw/kdrive/linux/linux.c              |   44 +++-
 hw/kdrive/linux/mouse.c              |   48 ++--
 hw/kdrive/linux/ms.c                 |    6 
 hw/kdrive/linux/ps2.c                |    4 
 hw/kdrive/linux/tslib.c              |   14 -
 hw/kdrive/sdl/.gitignore             |    2 
 hw/kdrive/src/Makefile.am            |    2 
 hw/kdrive/src/kcmap.c                |  145 ++++----------
 hw/kdrive/src/kcurscol.c             |   94 ---------
 hw/kdrive/src/kdrive.c               |  217 ++++++++-------------
 hw/kdrive/src/kdrive.h               |  110 +---------
 hw/kdrive/src/kinfo.c                |   38 +--
 hw/kdrive/src/kinput.c               |   85 ++++----
 hw/kdrive/src/kmap.c                 |  172 ----------------
 hw/kdrive/src/kmode.c                |   38 +--
 hw/kdrive/src/kshadow.c              |   34 +--
 hw/kdrive/src/kxv.c                  |  303 ++++++++++++++---------------
 hw/kdrive/src/kxv.h                  |   38 +--
 hw/xfree86/common/xf86AutoConfig.c   |    3 
 hw/xfree86/common/xf86Config.c       |  172 +++++++++++-----
 hw/xfree86/common/xf86Globals.c      |    3 
 hw/xfree86/common/xf86Init.c         |   15 +
 hw/xfree86/common/xf86Mode.c         |   14 -
 hw/xfree86/common/xf86Module.h       |    2 
 hw/xfree86/common/xf86Option.c       |   25 --
 hw/xfree86/common/xf86Priv.h         |    1 
 hw/xfree86/common/xf86Xinput.c       |  181 ++++++++++++++---
 hw/xfree86/common/xf86str.h          |   16 -
 hw/xfree86/doc/man/Xorg.man.pre      |   34 +++
 hw/xfree86/doc/man/xorg.conf.man.pre |  221 ++++++++++++++++++++-
 hw/xfree86/exa/examodule.c           |   37 +--
 hw/xfree86/parser/Configint.h        |    2 
 hw/xfree86/parser/InputClass.c       |  232 ++++++++++++++++++++++
 hw/xfree86/parser/Layout.c           |   79 ++++++-
 hw/xfree86/parser/Makefile.am        |    1 
 hw/xfree86/parser/configProcs.h      |    4 
 hw/xfree86/parser/read.c             |    8 
 hw/xfree86/parser/scan.c             |  356 ++++++++++++++++++++++++++---------
 hw/xfree86/parser/write.c            |    2 
 hw/xfree86/parser/xf86Parser.h       |   47 +++-
 hw/xfree86/parser/xf86tokens.h       |   13 +
 hw/xfree86/x86emu/Makefile.am        |    2 
 hw/xfree86/x86emu/sys.c              |  181 +++++++++++++++++
 hw/xquartz/darwinXinput.c            |    3 
 hw/xwin/.gitignore                   |    3 
 hw/xwin/InitOutput.c                 |    3 
 hw/xwin/winconfig.c                  |   40 +++
 hw/xwin/winconfig.h                  |    1 
 hw/xwin/winprocarg.c                 |   18 +
 include/dix-config.h.in              |    6 
 include/eventstr.h                   |    4 
 include/input.h                      |   16 +
 include/kdrive-config.h.in           |    9 
 include/ptrveloc.h                   |    3 
 include/xorg-config.h.in             |    3 
 os/utils.c                           |    4 
 xorg-server.m4                       |    3 
 96 files changed, 3103 insertions(+), 1939 deletions(-)

New commits:
commit 032f97808c65771a07bac748212cf6457a5d1660
Author: Simon Thum <simon.thum at gmx.de>
Date:   Wed Jan 6 17:32:24 2010 +0100

    xfree86: init pointer feedback controls from options
    
    With InputClass support, it makes more sense to cover all
    aspects of acceleration in options. Previously, one could only set the
    default on the command line.
    
    Signed-off-by: Simon Thum <simon.thum at gmx.de>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 920b940..df774a1 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -196,12 +196,12 @@ ProcessVelocityConfiguration(DeviceIntPtr pDev, char* devname, pointer list,
 
 static void
 ApplyAccelerationSettings(DeviceIntPtr dev){
-    int scheme;
+    int scheme, i;
     DeviceVelocityPtr pVel;
     LocalDevicePtr local = (LocalDevicePtr)dev->public.devicePrivate;
     char* schemeStr;
 
-    if(dev->valuator){
+    if (dev->valuator && dev->ptrfeed) {
 	schemeStr = xf86SetStrOption(local->options, "AccelerationScheme", "");
 
 	scheme = dev->valuator->accelScheme.number;
@@ -244,6 +244,30 @@ ApplyAccelerationSettings(DeviceIntPtr dev){
                                               pVel);
                 break;
         }
+
+        i = xf86SetIntOption(local->options, "AccelerationNumerator",
+                             dev->ptrfeed->ctrl.num);
+        if (i >= 0)
+            dev->ptrfeed->ctrl.num = i;
+
+        i = xf86SetIntOption(local->options, "AccelerationDenominator",
+                             dev->ptrfeed->ctrl.den);
+        if (i > 0)
+            dev->ptrfeed->ctrl.den = i;
+
+        i = xf86SetIntOption(local->options, "AccelerationThreshold",
+                             dev->ptrfeed->ctrl.threshold);
+        if (i >= 0)
+            dev->ptrfeed->ctrl.threshold = i;
+
+        /* mostly a no-op anyway */
+        (*dev->ptrfeed->CtrlProc)(dev, &dev->ptrfeed->ctrl);
+
+        xf86Msg(X_CONFIG, "%s: (accel) acceleration factor: %.3f\n",
+                            local->name, ((float)dev->ptrfeed->ctrl.num)/
+                                         ((float)dev->ptrfeed->ctrl.den));
+        xf86Msg(X_CONFIG, "%s: (accel) acceleration threshold: %i\n",
+                local->name, dev->ptrfeed->ctrl.threshold);
     }
 }
 
diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre
index be0c676..222530b 100644
--- a/hw/xfree86/doc/man/xorg.conf.man.pre
+++ b/hw/xfree86/doc/man/xorg.conf.man.pre
@@ -959,6 +959,26 @@ Selects the scheme, which is the underlying algorithm.
 .B  "predictable   default algorithm (behaving more predictable)"
 .B  "lightweight   old acceleration code (as specified in the X protocol spec)"
 .B  "none          no acceleration or deceleration"
+.fi
+.RE
+.TP 7
+.BI "Option \*qAccelerationNumerator\*q  \*q" integer \*q
+.TP 7
+.BI "Option \*qAccelerationDenominator\*q  \*q" integer \*q
+Set numerator and denominator of the acceleration factor. The acceleration
+factor is a rational which, together with threshold, can be used to tweak
+profiles to suit the users needs. The
+.B simple
+and
+.B limited
+profiles use it directly (i.e. they accelerate by the factor), for other
+profiles it should hold that a higher acceleration factor leads to a faster
+pointer. Typically, 1 is unaccelerated and values up to 5 are sensible.
+.TP 7
+.BI "Option \*qAccelerationThreshold\*q  \*q" integer \*q
+Set the threshold, which is roughly the velocity (usually device units per 10
+ms) required for acceleration to become effective. The precise effect varies
+with the profile however.
 
 .SH "INPUTCLASS SECTION"
 The config file may have multiple
commit 0722c287a4c8a6cdedca9756192547bfcf77ade5
Author: Simon Thum <simon.thum at gmx.de>
Date:   Wed Jan 6 19:43:59 2010 +0100

    xfree86: document pointer acceleration in xorg.conf.man
    
    Signed-off-by: Simon Thum <simon.thum at gmx.de>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Fernando Carrijo <fcarrijo at yahoo.com.br>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre
index 9420dfe..be0c676 100644
--- a/hw/xfree86/doc/man/xorg.conf.man.pre
+++ b/hw/xfree86/doc/man/xorg.conf.man.pre
@@ -915,6 +915,51 @@ may be reattached or set floating at runtime.
 .TP 7
 .BI "Option \*qSendDragEvents\*q  \*q" boolean \*q
 Send core events while dragging. Enabled by default.
+.PP
+For pointing devices, the following options control how the pointer
+is accelerated or decelerated with respect to physical device motion. Most of
+these can be adjusted at runtime, see the xinput(1) man page for details. Only
+the most important acceleration options are discussed here.
+.TP 7
+.BI "Option \*qAccelerationProfile\*q  \*q" integer \*q
+Select the profile. In layman's terms, the profile constitutes the "feeling" of
+the acceleration. More formally, it defines how the transfer function (actual
+acceleration as a function of current device velocity and acceleration controls)
+is constructed. This is mainly a matter of personal preference.
+.PP
+.RS 6
+.nf
+.B  " 0      classic (mostly compatible)"
+.B  "-1      none (only constant deceleration is applied)"
+.B  " 1      device-dependent"
+.B  " 2      polynomial (polynomial function)"
+.B  " 3      smooth linear (soft knee, then linear)"
+.B  " 4      simple (normal when slow, otherwise accelerated)"
+.B  " 5      power (power function)"
+.B  " 6      linear (more speed, more acceleration)"
+.B  " 7      limited (like linear, but maxes out at threshold)"
+.fi
+.RE
+.TP 7
+.BI "Option \*qConstantDeceleration\*q  \*q" real \*q
+Makes the pointer go
+.B deceleration
+times slower than normal. Most useful for high-resolution devices.
+.TP 7
+.BI "Option \*qAdaptiveDeceleration\*q  \*q" real \*q
+Allows to actually decelerate the pointer when going slow. At most, it will be
+.B adaptive deceleration
+times slower. Enables precise pointer placement without sacrificing speed.
+.TP 7
+.BI "Option \*qAccelerationScheme\*q  \*q" string \*q
+Selects the scheme, which is the underlying algorithm.
+.PP
+.RS 7
+.nf
+.B  "predictable   default algorithm (behaving more predictable)"
+.B  "lightweight   old acceleration code (as specified in the X protocol spec)"
+.B  "none          no acceleration or deceleration"
+
 .SH "INPUTCLASS SECTION"
 The config file may have multiple
 .B InputClass
commit 1aca2d757534879eb55faaee421cb972a9546712
Author: Simon Thum <simon.thum at gmx.de>
Date:   Wed Jan 6 19:13:36 2010 +0100

    whitespace fixes
    
    Signed-off-by: Simon Thum <simon.thum at gmx.de>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 57db056..920b940 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -121,7 +121,7 @@ ProcessVelocityConfiguration(DeviceIntPtr pDev, char* devname, pointer list,
 
     /* common settings (available via device properties) */
     tempf = xf86SetRealOption(list, "ConstantDeceleration", 1.0);
-    if(tempf > 1.0){
+    if (tempf > 1.0) {
         xf86Msg(X_CONFIG, "%s: (accel) constant deceleration by %.1f\n",
                 devname, tempf);
         prop = XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION);
@@ -130,7 +130,7 @@ ProcessVelocityConfiguration(DeviceIntPtr pDev, char* devname, pointer list,
     }
 
     tempf = xf86SetRealOption(list, "AdaptiveDeceleration", 1.0);
-    if(tempf > 1.0){
+    if (tempf > 1.0) {
         xf86Msg(X_CONFIG, "%s: (accel) adaptive deceleration by %.1f\n",
                 devname, tempf);
         prop = XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION);
@@ -144,8 +144,7 @@ ProcessVelocityConfiguration(DeviceIntPtr pDev, char* devname, pointer list,
 
     prop = XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER);
     if (XIChangeDeviceProperty(pDev, prop, XA_INTEGER, 32,
-                               PropModeReplace, 1, &tempi, FALSE) == Success)
-    {
+                               PropModeReplace, 1, &tempi, FALSE) == Success) {
         xf86Msg(X_CONFIG, "%s: (accel) acceleration profile %i\n", devname,
                 tempi);
     } else {
@@ -156,20 +155,19 @@ ProcessVelocityConfiguration(DeviceIntPtr pDev, char* devname, pointer list,
     /* set scaling */
     tempf = xf86SetRealOption(list, "ExpectedRate", 0);
     prop = XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING);
-    if(tempf > 0){
+    if (tempf > 0) {
         tempf = 1000.0 / tempf;
         XIChangeDeviceProperty(pDev, prop, float_prop, 32,
                                PropModeReplace, 1, &tempf, FALSE);
-    }else{
+    } else {
         tempf = xf86SetRealOption(list, "VelocityScale", s->corr_mul);
         XIChangeDeviceProperty(pDev, prop, float_prop, 32,
                                PropModeReplace, 1, &tempf, FALSE);
     }
 
     tempi = xf86SetIntOption(list, "VelocityTrackerCount", -1);
-    if(tempi > 1){
+    if (tempi > 1)
 	InitTrackers(s, tempi);
-    }
 
     s->initial_range = xf86SetIntOption(list, "VelocityInitialRange",
                                         s->initial_range);
@@ -177,7 +175,7 @@ ProcessVelocityConfiguration(DeviceIntPtr pDev, char* devname, pointer list,
     s->max_diff = xf86SetRealOption(list, "VelocityAbsDiff", s->max_diff);
 
     tempf = xf86SetRealOption(list, "VelocityRelDiff", -1);
-    if(tempf >= 0){
+    if (tempf >= 0) {
 	xf86Msg(X_CONFIG, "%s: (accel) max rel. velocity difference: %.1f%%\n",
 	        devname, tempf*100.0);
 	s->max_rel_diff = tempf;
@@ -208,30 +206,30 @@ ApplyAccelerationSettings(DeviceIntPtr dev){
 
 	scheme = dev->valuator->accelScheme.number;
 
-	if(!xf86NameCmp(schemeStr, "predictable"))
+	if (!xf86NameCmp(schemeStr, "predictable"))
 	    scheme = PtrAccelPredictable;
 
-	if(!xf86NameCmp(schemeStr, "lightweight"))
+	if (!xf86NameCmp(schemeStr, "lightweight"))
 	    scheme = PtrAccelLightweight;
 
-	if(!xf86NameCmp(schemeStr, "none"))
+	if (!xf86NameCmp(schemeStr, "none"))
 	    scheme = PtrAccelNoOp;
 
         /* reinit scheme if needed */
-        if(dev->valuator->accelScheme.number != scheme){
-            if(dev->valuator->accelScheme.AccelCleanupProc){
+        if (dev->valuator->accelScheme.number != scheme) {
+            if (dev->valuator->accelScheme.AccelCleanupProc) {
                 dev->valuator->accelScheme.AccelCleanupProc(dev);
             }
 
-            if(InitPointerAccelerationScheme(dev, scheme)){
+            if (InitPointerAccelerationScheme(dev, scheme)) {
 		xf86Msg(X_CONFIG, "%s: (accel) selected scheme %s/%i\n",
 		        local->name, schemeStr, scheme);
-	    }else{
+	    } else {
         	xf86Msg(X_CONFIG, "%s: (accel) could not init scheme %s\n",
         	        local->name, schemeStr);
         	scheme = dev->valuator->accelScheme.number;
             }
-        }else{
+        } else {
             xf86Msg(X_CONFIG, "%s: (accel) keeping acceleration scheme %i\n",
                     local->name, scheme);
         }
@@ -239,7 +237,7 @@ ApplyAccelerationSettings(DeviceIntPtr dev){
         xfree(schemeStr);
 
         /* process special configuration */
-        switch(scheme){
+        switch (scheme) {
             case PtrAccelPredictable:
                 pVel = GetDevicePredictableAccelData(dev);
                 ProcessVelocityConfiguration (dev, local->name, local->options,
commit 14039b5a7982fbf8130501bb00766176a4e9bccb
Author: Simon Thum <simon.thum at gmx.de>
Date:   Wed Jan 6 18:16:20 2010 +0100

    doc: actually document SendDragEvents
    
    Signed-off-by: Simon Thum <simon.thum at gmx.de>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre
index 5b98bda..9420dfe 100644
--- a/hw/xfree86/doc/man/xorg.conf.man.pre
+++ b/hw/xfree86/doc/man/xorg.conf.man.pre
@@ -914,7 +914,7 @@ X Input extension. This option controls the startup behavior only, a device
 may be reattached or set floating at runtime.
 .TP 7
 .BI "Option \*qSendDragEvents\*q  \*q" boolean \*q
-???
+Send core events while dragging. Enabled by default.
 .SH "INPUTCLASS SECTION"
 The config file may have multiple
 .B InputClass
commit 14e4e4a294e648e0bdcb70c34748e1b81c5bb64f
Author: Simon Thum <simon.thum at gmx.de>
Date:   Wed Jan 6 18:13:27 2010 +0100

    os: state effect of -a and -t options more precisely
    
    Signed-off-by: Simon Thum <simon.thum at gmx.de>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/os/utils.c b/os/utils.c
index 3718b17..d7c8388 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -472,7 +472,7 @@ AdjustWaitForDelay (pointer waitTime, unsigned long newdelay)
 void UseMsg(void)
 {
     ErrorF("use: X [:<display>] [option]\n");
-    ErrorF("-a #                   mouse acceleration (pixels)\n");
+    ErrorF("-a #                   default pointer acceleration (factor)\n");
     ErrorF("-ac                    disable access control restrictions\n");
     ErrorF("-audit int             set audit trail level\n");	
     ErrorF("-auth file             select authorization file\n");	
@@ -524,7 +524,7 @@ void UseMsg(void)
 #endif
     ErrorF("-retro                 start with classic stipple and cursor\n");
     ErrorF("-s #                   screen-saver timeout (minutes)\n");
-    ErrorF("-t #                   mouse threshold (pixels)\n");
+    ErrorF("-t #                   default pointer threshold (pixels/t)\n");
     ErrorF("-terminate             terminate at server reset\n");
     ErrorF("-to #                  connection time out\n");
     ErrorF("-tst                   disable testing extensions\n");
commit d727ddb91a549d23f6bf323e91db4b8916c1b7a0
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sat Jan 9 16:28:32 2010 -0500

    kdrive: klinux.h breaks make dist
    
    This file is no longer part of the source code
    and must be removed from distribution.
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/linux/Makefile.am b/hw/kdrive/linux/Makefile.am
index fe4a3d1..93e5d2f 100644
--- a/hw/kdrive/linux/Makefile.am
+++ b/hw/kdrive/linux/Makefile.am
@@ -8,7 +8,7 @@ noinst_LTLIBRARIES = liblinux.la
 
 liblinux_la_SOURCES =
 
-liblinux_la_SOURCES += linux.c klinux.h
+liblinux_la_SOURCES += linux.c
 
 if KDRIVE_KBD
 liblinux_la_SOURCES += keyboard.c
commit 6313d2da6c6910827d68cf31fe00b46a34c5bfc7
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Fri Jan 8 19:04:25 2010 -0500

    configure: use backticks rather than $() for commands
    
    This patch to xserver configure.ac is to increase code portability to
    non POSIX system by using backticks rather than $() for command
    substitution for BUILD_DATE and BUILD_TIME.
    
    Reviewed-by: Rémi Cardona <remi at gentoo.org>
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index e0ddd48..92dd8a4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2112,9 +2112,9 @@ AC_TRY_COMPILE([
 
 AC_DEFINE_DIR(PROJECTROOT, prefix, [Overall prefix])
 
-BUILD_DATE="$(date +'%Y%m%d')"
+BUILD_DATE="`date +'%Y%m%d'`"
 AC_SUBST([BUILD_DATE])
-BUILD_TIME="$(date +'1%H%M%S')"
+BUILD_TIME="`date +'1%H%M%S'`"
 AC_SUBST([BUILD_TIME])
 
 DIX_CFLAGS="-DHAVE_DIX_CONFIG_H $XSERVER_CFLAGS"
commit 74ab27f64a747ee45810f99cdc6e29b82cf8035e
Author: Tiago Vignatti <tiago.vignatti at nokia.com>
Date:   Mon Dec 28 18:00:28 2009 +0200

    Revert "Make sys.c use unaligned access functions provided in compiler."
    
    This reverts commit da923d0bc15e99a8ed1986bd6f5df37f7af7284b.
    
    Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/x86emu/Makefile.am b/hw/xfree86/x86emu/Makefile.am
index e7368f5..df96977 100644
--- a/hw/xfree86/x86emu/Makefile.am
+++ b/hw/xfree86/x86emu/Makefile.am
@@ -11,7 +11,7 @@ libx86emu_la_SOURCES = debug.c \
                       sys.c \
                       x86emu.h
 
-INCLUDES = $(XORG_INCS)
+INCLUDES = 
 
 AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS)
 
diff --git a/hw/xfree86/x86emu/sys.c b/hw/xfree86/x86emu/sys.c
index 2ebf6f1..e15fb09 100644
--- a/hw/xfree86/x86emu/sys.c
+++ b/hw/xfree86/x86emu/sys.c
@@ -48,13 +48,168 @@
 #ifndef NO_SYS_HEADERS
 #include <string.h>
 #endif                                                                                           
-#include "compiler.h" /* for unaligned access functions */
 /*------------------------- Global Variables ------------------------------*/
 
 X86EMU_sysEnv		_X86EMU_env;		/* Global emulator machine state */
 X86EMU_intrFuncs	_X86EMU_intrTab[256];
 
 /*----------------------------- Implementation ----------------------------*/
+#if defined(__alpha__) || defined(__alpha)
+/* to cope with broken egcs-1.1.2 :-(((( */
+
+#define ALPHA_UALOADS
+/*
+ * inline functions to do unaligned accesses
+ * from linux/include/asm-alpha/unaligned.h
+ */
+
+/*
+ * EGCS 1.1 knows about arbitrary unaligned loads.  Define some
+ * packed structures to talk about such things with.
+ */
+
+#if defined(__GNUC__)
+struct __una_u64 { unsigned long  x __attribute__((packed)); };
+struct __una_u32 { unsigned int   x __attribute__((packed)); };
+struct __una_u16 { unsigned short x __attribute__((packed)); };
+#endif
+
+static __inline__ unsigned long ldq_u(unsigned long * r11)
+{
+#if defined(__GNUC__)
+	const struct __una_u64 *ptr = (const struct __una_u64 *) r11;
+	return ptr->x;
+#else
+	unsigned long r1,r2;
+	__asm__("ldq_u %0,%3\n\t"
+		"ldq_u %1,%4\n\t"
+		"extql %0,%2,%0\n\t"
+		"extqh %1,%2,%1"
+		:"=&r" (r1), "=&r" (r2)
+		:"r" (r11),
+		 "m" (*r11),
+		 "m" (*(const unsigned long *)(7+(char *) r11)));
+	return r1 | r2;
+#endif
+}
+
+static __inline__ unsigned long ldl_u(unsigned int * r11)
+{
+#if defined(__GNUC__)
+	const struct __una_u32 *ptr = (const struct __una_u32 *) r11;
+	return ptr->x;
+#else
+	unsigned long r1,r2;
+	__asm__("ldq_u %0,%3\n\t"
+		"ldq_u %1,%4\n\t"
+		"extll %0,%2,%0\n\t"
+		"extlh %1,%2,%1"
+		:"=&r" (r1), "=&r" (r2)
+		:"r" (r11),
+		 "m" (*r11),
+		 "m" (*(const unsigned long *)(3+(char *) r11)));
+	return r1 | r2;
+#endif
+}
+
+static __inline__ unsigned long ldw_u(unsigned short * r11)
+{
+#if defined(__GNUC__)
+	const struct __una_u16 *ptr = (const struct __una_u16 *) r11;
+	return ptr->x;
+#else
+	unsigned long r1,r2;
+	__asm__("ldq_u %0,%3\n\t"
+		"ldq_u %1,%4\n\t"
+		"extwl %0,%2,%0\n\t"
+		"extwh %1,%2,%1"
+		:"=&r" (r1), "=&r" (r2)
+		:"r" (r11),
+		 "m" (*r11),
+		 "m" (*(const unsigned long *)(1+(char *) r11)));
+	return r1 | r2;
+#endif
+}
+
+/*
+ * Elemental unaligned stores 
+ */
+
+static __inline__ void stq_u(unsigned long r5, unsigned long * r11)
+{
+#if defined(__GNUC__)
+	struct __una_u64 *ptr = (struct __una_u64 *) r11;
+	ptr->x = r5;
+#else
+	unsigned long r1,r2,r3,r4;
+
+	__asm__("ldq_u %3,%1\n\t"
+		"ldq_u %2,%0\n\t"
+		"insqh %6,%7,%5\n\t"
+		"insql %6,%7,%4\n\t"
+		"mskqh %3,%7,%3\n\t"
+		"mskql %2,%7,%2\n\t"
+		"bis %3,%5,%3\n\t"
+		"bis %2,%4,%2\n\t"
+		"stq_u %3,%1\n\t"
+		"stq_u %2,%0"
+		:"=m" (*r11),
+		 "=m" (*(unsigned long *)(7+(char *) r11)),
+		 "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4)
+		:"r" (r5), "r" (r11));
+#endif
+}
+
+static __inline__ void stl_u(unsigned long r5, unsigned int * r11)
+{
+#if defined(__GNUC__)
+	struct __una_u32 *ptr = (struct __una_u32 *) r11;
+	ptr->x = r5;
+#else
+	unsigned long r1,r2,r3,r4;
+
+	__asm__("ldq_u %3,%1\n\t"
+		"ldq_u %2,%0\n\t"
+		"inslh %6,%7,%5\n\t"
+		"insll %6,%7,%4\n\t"
+		"msklh %3,%7,%3\n\t"
+		"mskll %2,%7,%2\n\t"
+		"bis %3,%5,%3\n\t"
+		"bis %2,%4,%2\n\t"
+		"stq_u %3,%1\n\t"
+		"stq_u %2,%0"
+		:"=m" (*r11),
+		 "=m" (*(unsigned long *)(3+(char *) r11)),
+		 "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4)
+		:"r" (r5), "r" (r11));
+#endif
+}
+
+static __inline__ void stw_u(unsigned long r5, unsigned short * r11)
+{
+#if defined(__GNUC__)
+	struct __una_u16 *ptr = (struct __una_u16 *) r11;
+	ptr->x = r5;
+#else
+	unsigned long r1,r2,r3,r4;
+
+	__asm__("ldq_u %3,%1\n\t"
+		"ldq_u %2,%0\n\t"
+		"inswh %6,%7,%5\n\t"
+		"inswl %6,%7,%4\n\t"
+		"mskwh %3,%7,%3\n\t"
+		"mskwl %2,%7,%2\n\t"
+		"bis %3,%5,%3\n\t"
+		"bis %2,%4,%2\n\t"
+		"stq_u %3,%1\n\t"
+		"stq_u %2,%0"
+		:"=m" (*r11),
+		 "=m" (*(unsigned long *)(1+(char *) r11)),
+		 "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4)
+		:"r" (r5), "r" (r11));
+#endif
+}
+#endif
 
 /****************************************************************************
 PARAMETERS:
@@ -107,7 +262,13 @@ u16 X86API rdw(
 		}
 	else
 #endif
+#if defined(ALPHA_UALOADS)
 		val = ldw_u((u16*)(M.mem_base + addr));
+#elif  defined(IA64_UALOADS)
+      val = uldw((u16*)(M.mem_base + addr));
+#else
+		val = *(u16*)(M.mem_base + addr);
+#endif
 		DB(	if (DEBUG_MEM_TRACE())
 		printk("%#08x 2 -> %#x\n", addr, val);)
     return val;
@@ -140,7 +301,13 @@ u32 X86API rdl(
 		}
 	else
 #endif
+#if defined(ALPHA_UALOADS)
 		val = ldl_u((u32*)(M.mem_base + addr));
+#elif  defined(IA64_UALOADS)
+        val = uldl((u32*)(M.mem_base + addr));
+#else
+		val = *(u32*)(M.mem_base + addr);
+#endif
 DB(	if (DEBUG_MEM_TRACE())
 		printk("%#08x 4 -> %#x\n", addr, val);)
 	return val;
@@ -192,7 +359,13 @@ DB(	if (DEBUG_MEM_TRACE())
 		}
 	else
 #endif
+#if defined(ALPHA_UALOADS)
 	 stw_u(val,(u16*)(M.mem_base + addr));
+#elif defined(IA64_UALOADS)
+     ustw(val,(u16*)(M.mem_base + addr));
+#else
+	 *(u16*)(M.mem_base + addr) = val;
+#endif
 }
 
 /****************************************************************************
@@ -222,7 +395,13 @@ DB(	if (DEBUG_MEM_TRACE())
 		}
 	else
 #endif
+#if defined(ALPHA_UALOADS)
 	 stl_u(val,(u32*)(M.mem_base + addr));
+#elif defined(IA64_UALOADS)
+     ustl(val,(u32*)(M.mem_base + addr));
+#else
+	 *(u32*)(M.mem_base + addr) = val;
+#endif
 }
 
 /****************************************************************************
commit 6a2a57832709798d99d19ff4c587e22f3b3c150d
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Thu Jan 7 15:23:34 2010 -0500

    macros: use PKG_CONFIG variable rather than executable name
    
    User can defined alternate location for pkg-config.
    Once option in place, all instances of pkg-config must be converted.
    
    Acked-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/xorg-server.m4 b/xorg-server.m4
index 2d16438..bdecf62 100644
--- a/xorg-server.m4
+++ b/xorg-server.m4
@@ -29,8 +29,9 @@ dnl
 # is defined, then add $1 to $REQUIRED_MODULES.
 
 AC_DEFUN([XORG_DRIVER_CHECK_EXT],[
+	AC_REQUIRE([PKG_PROG_PKG_CONFIG])
 	SAVE_CFLAGS="$CFLAGS"
-	CFLAGS="$CFLAGS -I`pkg-config --variable=sdkdir xorg-server`"
+	CFLAGS="$CFLAGS -I`$PKG_CONFIG --variable=sdkdir xorg-server`"
 	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 #include "xorg-server.h"
 #if !defined $1
commit 1b3132f5e981b3398e08263742332cc966bebc07
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Thu Jan 7 14:12:34 2010 -0500

    xwin: ignore intermediate .man file
    
    Only detectable on a Cygwin build
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xwin/.gitignore b/hw/xwin/.gitignore
index a996950..a8c3a28 100644
--- a/hw/xwin/.gitignore
+++ b/hw/xwin/.gitignore
@@ -2,4 +2,5 @@
 winprefslex.c
 winprefsyacc.c
 winprefsyacc.h
-
+XWin.man
+XWinrc.man
commit 8ab4749aaefb3727b9fc58bb37b50a2d07eb1531
Merge: 8d53d84... 9437504...
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jan 7 10:32:21 2010 -0800

    Merge remote branch 'dottedmag/for-keithp'

commit 8d53d84485fdce8ea9686e6f300a69f7ddebd467
Author: Adam Tkac <atkac at redhat.com>
Date:   Thu Jan 7 15:34:52 2010 +0100

    Do not define members of include/eventstr.h:EventType enum conditionally.
    
    Main problem is that EventType enumeration members can be different in
    module and in server, which obviously causes problems.
    
    Signed-off-by: Adam Tkac <atkac at redhat.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/include/eventstr.h b/include/eventstr.h
index 0d5b1c6..79685c1 100644
--- a/include/eventstr.h
+++ b/include/eventstr.h
@@ -58,17 +58,13 @@ enum EventType {
     ET_ProximityOut,
     ET_DeviceChanged,
     ET_Hierarchy,
-#if XFreeXDGA
     ET_DGAEvent,
-#endif
     ET_RawKeyPress,
     ET_RawKeyRelease,
     ET_RawButtonPress,
     ET_RawButtonRelease,
     ET_RawMotion,
-#ifdef XQUARTZ
     ET_XQuartz,
-#endif
     ET_Internal = 0xFF /* First byte */
 };
 
commit 9437504b21dfdb509ab8b3a00f64403e1e4026dd
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Mon Jan 4 05:42:02 2010 +0600

    kdrive: Remove unused kdNoopOps external variable declaration
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 8616035..35ce036 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -359,9 +359,6 @@ extern KdOsFuncs	*kdOsFuncs;
     dixSetPrivate(&(pScreen)->devPrivates, kdScreenPrivateKey, v)
 #define KdScreenPriv(pScreen) KdPrivScreenPtr pScreenPriv = KdGetScreenPriv(pScreen)
 
-/* knoop.c */
-extern GCOps		kdNoopOps;
-
 /* kcmap.c */
 void
 KdSetColormap (ScreenPtr pScreen);
commit aa6e0936be15488455e6a4236806a58496da2979
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Mon Jan 4 05:30:22 2010 +0600

    kdrive: Remove unused kmap.c
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/src/Makefile.am b/hw/kdrive/src/Makefile.am
index 9aa8e5e..51375b9 100644
--- a/hw/kdrive/src/Makefile.am
+++ b/hw/kdrive/src/Makefile.am
@@ -19,7 +19,6 @@ libkdrive_la_SOURCES =	\
 	kdrive.h	\
 	kinfo.c		\
 	kinput.c	\
-	kmap.c		\
 	kmode.c		\
 	kshadow.c	\
 	$(KDRIVE_XV_SOURCES) \
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 8a62faf..8616035 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -582,23 +582,6 @@ KdRingBell (KdKeyboardInfo      *ki,
             int                 pitch,
             int                 duration);
 
-/* kmap.c */
-
-#define KD_MAPPED_MODE_REGISTERS    0
-#define KD_MAPPED_MODE_FRAMEBUFFER  1
-
-void *
-KdMapDevice (CARD32 addr, CARD32 size);
-
-void
-KdUnmapDevice (void *addr, CARD32 size);
-
-void
-KdSetMappedMode (CARD32 addr, CARD32 size, int mode);
-
-void
-KdResetMappedMode (CARD32 addr, CARD32 size, int mode);
-
 /* kmode.c */
 const KdMonitorTiming *
 KdFindMode (KdScreenInfo    *screen,
diff --git a/hw/kdrive/src/kmap.c b/hw/kdrive/src/kmap.c
deleted file mode 100644
index 2bf0840..0000000
--- a/hw/kdrive/src/kmap.c
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Copyright © 1999 Keith Packard
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Keith Packard not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  Keith Packard makes no
- * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.
- *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <kdrive-config.h>
-#include "kdrive.h"
-
-#include <errno.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#ifdef HAVE_ASM_MTRR_H
-#include <asm/mtrr.h>
-#endif
-
-#include <sys/ioctl.h>
-
-void *
-KdMapDevice (CARD32 addr, CARD32 size)
-{
-#ifdef WINDOWS
-    void    *a;
-    void    *d;
-
-    d = VirtualAlloc (NULL, size, MEM_RESERVE, PAGE_NOACCESS);
-    if (!d)
-	return NULL;
-    DRAW_DEBUG ((DEBUG_S3INIT, "Virtual address of 0x%x is 0x%x", addr, d));
-    a = VirtualCopyAddr (addr);
-    DRAW_DEBUG ((DEBUG_S3INIT, "Translated address is 0x%x", a));
-    if (!VirtualCopy (d, a, size,
-		      PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL))
-    {
-	DRAW_DEBUG ((DEBUG_FAILURE, "VirtualCopy failed %d",
-		    GetLastError ()));
-	return NULL;
-    }
-    DRAW_DEBUG ((DEBUG_S3INIT, "Device mapped successfully"));
-    return d;
-#endif
-#ifdef linux
-    void    *a;
-    int	    fd;
-
-#ifdef __arm__
-    fd = open ("/dev/mem", O_RDWR|O_SYNC);
-#else
-    fd = open ("/dev/mem", O_RDWR);
-#endif
-    if (fd < 0)
-	FatalError ("KdMapDevice: failed to open /dev/mem (%s)\n",
-		    strerror (errno));
-
-    a = mmap ((caddr_t) 0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, addr);
-    close (fd);
-    if ((long) a == -1)
-	FatalError ("KdMapDevice: failed to map frame buffer (%s)\n",
-		    strerror (errno));
-    return a;
-#endif
-}
-
-void
-KdUnmapDevice (void *addr, CARD32 size)
-{
-#ifdef WINDOWS
-    VirtualFree (addr, size, MEM_DECOMMIT);
-    VirtualFree (addr, 0, MEM_RELEASE);
-#endif
-#ifdef linux
-    munmap (addr, size);
-#endif
-}
-
-#ifdef HAVE_ASM_MTRR_H
-static int  mtrr;
-#endif
-
-void
-KdSetMappedMode (CARD32 addr, CARD32 size, int mode)
-{
-#ifdef HAVE_ASM_MTRR_H
-    struct mtrr_sentry  sentry;
-    unsigned long    	base, bound;
-    unsigned int	type = MTRR_TYPE_WRBACK;
-
-    if (addr < 0x100000)
-	return;
-    if (!mtrr)
-	mtrr = open ("/proc/mtrr", 2);
-    if (mtrr > 0)
-    {
-	unsigned long nsize;
-	base = addr & ~((1<<22)-1);
-	bound = ((addr + size) + ((1<<22) - 1)) & ~((1<<22) - 1);
-	nsize = 1;
-	while (nsize < (bound - base))
-	    nsize <<= 1;
-	switch (mode) {
-	case KD_MAPPED_MODE_REGISTERS:
-	    type = MTRR_TYPE_UNCACHABLE;
-	    break;
-	case KD_MAPPED_MODE_FRAMEBUFFER:
-	    type = MTRR_TYPE_WRCOMB;
-	    break;
-	}
-	sentry.base = base;
-	sentry.size = nsize;
-	sentry.type = type;
-
-	if (ioctl (mtrr, MTRRIOC_ADD_ENTRY, &sentry) < 0)
-	    ErrorF ("MTRRIOC_ADD_ENTRY failed 0x%x 0x%x %d (%s)\n",
-		    base, bound - base, type, strerror(errno));
-    }
-#endif
-}
-
-void
-KdResetMappedMode (CARD32 addr, CARD32 size, int mode)
-{
-#ifdef HAVE_ASM_MTRR_H
-    struct mtrr_sentry  sentry;
-    unsigned long    	base, bound;
-    unsigned int	type = MTRR_TYPE_WRBACK;
-
-    if (addr < 0x100000)
-	return;
-    if (!mtrr)
-	mtrr = open ("/proc/mtrr", 2);
-    if (mtrr > 0)
-    {
-	unsigned long	nsize;
-	base = addr & ~((1<<22)-1);
-	bound = ((addr + size) + ((1<<22) - 1)) & ~((1<<22) - 1);
-	nsize = 1;
-	while (nsize < (bound - base))
-	    nsize <<= 1;
-	switch (mode) {
-	case KD_MAPPED_MODE_REGISTERS:
-	    type = MTRR_TYPE_UNCACHABLE;
-	    break;
-	case KD_MAPPED_MODE_FRAMEBUFFER:
-	    type = MTRR_TYPE_WRCOMB;
-	    break;
-	}
-	sentry.base = base;
-	sentry.size = nsize;
-	sentry.type = type;
-
-	if (ioctl (mtrr, MTRRIOC_DEL_ENTRY, &sentry) < 0)
-	    ErrorF ("MTRRIOC_DEL_ENTRY failed 0x%x 0x%x %d (%s)\n",
-		    base, bound - base, type, strerror(errno));
-    }
-#endif
-}
commit f78ac5c6e273f575af29746e08e7c182ff7b93b3
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Mon Jan 4 02:36:30 2010 +0600

    kdrive: Make internal functions static
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/fbdev/fbdev.c b/hw/kdrive/fbdev/fbdev.c
index b9c2b96..d4604ad 100644
--- a/hw/kdrive/fbdev/fbdev.c
+++ b/hw/kdrive/fbdev/fbdev.c
@@ -32,7 +32,7 @@ extern int KdTsPhyScreen;
 
 char *fbdevDevicePath = NULL;
 
-Bool
+static Bool
 fbdevInitialize (KdCardInfo *card, FbdevPriv *priv)
 {
     unsigned long   off;
@@ -147,7 +147,7 @@ fbdevConvertMonitorTiming (const KdMonitorTiming *t, struct fb_var_screeninfo *v
       var->sync |= FB_SYNC_VERT_HIGH_ACT;
 }
 
-Bool
+static Bool
 fbdevScreenInitialize (KdScreenInfo *screen, FbdevScrPriv *scrpriv)
 {
     FbdevPriv	*priv = screen->card->driver;
@@ -309,7 +309,7 @@ fbdevScreenInit (KdScreenInfo *screen)
     return TRUE;
 }
 
-void *
+static void *
 fbdevWindowLinear (ScreenPtr	pScreen,
 		   CARD32	row,
 		   CARD32	offset,
@@ -362,7 +362,7 @@ fbdevMapFramebuffer (KdScreenInfo *screen)
     return TRUE;
 }
 
-void
+static void
 fbdevSetScreenSizes (ScreenPtr pScreen)
 {
     KdScreenPriv(pScreen);
@@ -386,14 +386,14 @@ fbdevSetScreenSizes (ScreenPtr pScreen)
     }
 }
 
-Bool
+static Bool
 fbdevUnmapFramebuffer (KdScreenInfo *screen)
 {
     KdShadowFbFree (screen);
     return TRUE;
 }
 
-Bool
+static Bool
 fbdevSetShadow (ScreenPtr pScreen)
 {
     KdScreenPriv(pScreen);
@@ -444,7 +444,7 @@ fbdevSetShadow (ScreenPtr pScreen)
 
 
 #ifdef RANDR
-Bool
+static Bool
 fbdevRandRGetInfo (ScreenPtr pScreen, Rotation *rotations)
 {
     KdScreenPriv(pScreen);
@@ -475,7 +475,7 @@ fbdevRandRGetInfo (ScreenPtr pScreen, Rotation *rotations)
     return TRUE;
 }
 
-Bool
+static Bool
 fbdevRandRSetConfig (ScreenPtr		pScreen,
 		     Rotation		randr,
 		     int		rate,
@@ -564,7 +564,7 @@ bail4:
     return FALSE;
 }
 
-Bool
+static Bool
 fbdevRandRInit (ScreenPtr pScreen)
 {
     rrScrPrivPtr    pScrPriv;
@@ -579,7 +579,7 @@ fbdevRandRInit (ScreenPtr pScreen)
 }
 #endif
 
-Bool
+static Bool
 fbdevCreateColormap (ColormapPtr pmap)
 {
     ScreenPtr		pScreen = pmap->pScreen;
diff --git a/hw/kdrive/fbdev/fbdev.h b/hw/kdrive/fbdev/fbdev.h
index 4d4f7a9..ebac6ad 100644
--- a/hw/kdrive/fbdev/fbdev.h
+++ b/hw/kdrive/fbdev/fbdev.h
@@ -52,18 +52,12 @@ extern KdCardFuncs  fbdevFuncs;
 extern char*        fbdevDevicePath;
 
 Bool
-fbdevInitialize (KdCardInfo *card, FbdevPriv *priv);
-
-Bool
 fbdevCardInit (KdCardInfo *card);
 
 Bool
 fbdevScreenInit (KdScreenInfo *screen);
 
 Bool
-fbdevScreenInitialize (KdScreenInfo *screen, FbdevScrPriv *scrpriv);
-
-Bool
 fbdevInitScreen (ScreenPtr pScreen);
 
 Bool
@@ -102,38 +96,4 @@ fbdevPutColors (ScreenPtr pScreen, int n, xColorItem *pdefs);
 Bool
 fbdevMapFramebuffer (KdScreenInfo *screen);
 
-void *
-fbdevWindowLinear (ScreenPtr	pScreen,
-		   CARD32	row,
-		   CARD32	offset,
-		   int		mode,
-		   CARD32	*size,
-		   void		*closure);
-
-void
-fbdevSetScreenSizes (ScreenPtr pScreen);
-
-Bool
-fbdevUnmapFramebuffer (KdScreenInfo *screen);
-
-Bool
-fbdevSetShadow (ScreenPtr pScreen);
-
-Bool
-fbdevCreateColormap (ColormapPtr pmap);
-
-#ifdef RANDR
-Bool
-fbdevRandRGetInfo (ScreenPtr pScreen, Rotation *rotations);
-
-Bool
-fbdevRandRSetConfig (ScreenPtr		pScreen,
-		     Rotation		randr,
-		     int		rate,
-		     RRScreenSizePtr	pSize);
-Bool
-fbdevRandRInit (ScreenPtr pScreen);
-
-#endif
-
 #endif /* _FBDEV_H_ */
commit 37a8ddc0dbf3fb7f059b689038979bace206dccf
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Mon Jan 4 02:28:37 2010 +0600

    kdrive: Remove unused 'k' variable
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/fbdev/fbdev.c b/hw/kdrive/fbdev/fbdev.c
index cd90487..b9c2b96 100644
--- a/hw/kdrive/fbdev/fbdev.c
+++ b/hw/kdrive/fbdev/fbdev.c
@@ -35,7 +35,6 @@ char *fbdevDevicePath = NULL;
 Bool
 fbdevInitialize (KdCardInfo *card, FbdevPriv *priv)
 {
-    int		    k;
     unsigned long   off;
 
     if (fbdevDevicePath == NULL)
@@ -50,14 +49,14 @@ fbdevInitialize (KdCardInfo *card, FbdevPriv *priv)
 
     /* quiet valgrind */
     memset (&priv->fix, '\0', sizeof (priv->fix));
-    if ((k=ioctl(priv->fd, FBIOGET_FSCREENINFO, &priv->fix)) < 0) {
+    if (ioctl(priv->fd, FBIOGET_FSCREENINFO, &priv->fix) < 0) {
 	perror("Error with /dev/fb ioctl FIOGET_FSCREENINFO");
 	close (priv->fd);
 	return FALSE;
     }
     /* quiet valgrind */
     memset (&priv->var, '\0', sizeof (priv->var));
-    if ((k=ioctl(priv->fd, FBIOGET_VSCREENINFO, &priv->var)) < 0) {
+    if (ioctl(priv->fd, FBIOGET_VSCREENINFO, &priv->var) < 0) {
 	perror("Error with /dev/fb ioctl FIOGET_VSCREENINFO");
 	close (priv->fd);
 	return FALSE;
commit af1f1a05e1aa9ec921f1288818a66766c301f8b0
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Mon Jan 4 01:50:04 2010 +0600

    kdrive: Remove bus mouse driver
    
    Bus mice aren't used anymore, do not keep dead code around.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/linux/Makefile.am b/hw/kdrive/linux/Makefile.am
index 2f89b8f..fe4a3d1 100644
--- a/hw/kdrive/linux/Makefile.am
+++ b/hw/kdrive/linux/Makefile.am
@@ -19,7 +19,7 @@ liblinux_la_SOURCES += evdev.c
 endif
 
 if KDRIVE_MOUSE
-liblinux_la_SOURCES += mouse.c bus.c ms.c ps2.c
+liblinux_la_SOURCES += mouse.c ms.c ps2.c
 endif
 
 if TSLIB
diff --git a/hw/kdrive/linux/bus.c b/hw/kdrive/linux/bus.c
deleted file mode 100644
index de9b90f..0000000
--- a/hw/kdrive/linux/bus.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright © 2000 Keith Packard
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Keith Packard not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  Keith Packard makes no
- * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.
- *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <kdrive-config.h>
-#endif
-#include <X11/X.h>
-#include <X11/Xproto.h>
-#include <X11/Xpoll.h>
-#include "inputstr.h"
-#include "scrnintstr.h"
-#include "kdrive.h"
-
-/* /dev/adbmouse is a busmouse */
-
-static void
-BusRead (int adbPort, void *closure)
-{
-    unsigned char   buf[3];
-    int		    n;
-    int		    dx, dy;
-    unsigned long   flags;
-
-    n = read (adbPort, buf, 3);
-    if (n == 3)
-    {
-	flags = KD_MOUSE_DELTA;
-	dx = (char) buf[1];
-	dy = -(char) buf[2];
-	if ((buf[0] & 4) == 0)
-	    flags |= KD_BUTTON_1;
-	if ((buf[0] & 2) == 0)
-	    flags |= KD_BUTTON_2;
-	if ((buf[0] & 1) == 0)
-	    flags |= KD_BUTTON_3;
-        KdEnqueuePointerEvent (closure, flags, dx, dy, 0);
-    }
-}
-
-char	*BusNames[] = {
-    "/dev/adbmouse",
-    "/dev/mouse",
-};
-
-#define NUM_BUS_NAMES	(sizeof (BusNames) / sizeof (BusNames[0]))
-
-static int
-BusInit (KdPointerInfo *pi)
-{
-    int	    i, fd = 0;
-
-    if (!pi->path || (strcmp(pi->path, "auto") == 0))
-    {
-        for (i = 0; i < NUM_BUS_NAMES; i++)
-        {
-            if ((fd = open (BusNames[i], 0)) >= 0)
-            {
-                close(fd);
-                xfree(pi->path);
-                pi->path = strdup(BusNames[i]);
-                return Success;
-            }
-        }
-    }
-    else
-    {
-        if ((fd = open(pi->path, 0)) >= 0)
-        {
-            close(fd);
-            return Success;
-        }
-    }
-
-    return !Success;
-}
-
-static int
-BusEnable (KdPointerInfo *pi)
-{
-    int fd = open(pi->path, 0);
-
-    if (fd >= 0)
-    {
-        KdRegisterFd(fd, BusRead, pi);
-        pi->driverPrivate = (void *)fd;
-        return Success;
-    }
-    else
-    {
-        return !Success;
-    }
-}
-
-static void
-BusDisable (KdPointerInfo *pi)
-{
-    KdUnregisterFd(pi, (int)pi->driverPrivate, TRUE);
-}
-
-static void
-BusFini (KdPointerInfo *pi)
-{
-    return;
-}
-
-KdPointerDriver BusMouseDriver = {
-    "bus",
-    BusInit,
-    BusEnable,
-    BusDisable,
-    BusFini,
-    NULL
-};
commit a3cc3af186b55ac80abd6859ffe491f4ae936596
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Sat Jan 2 23:31:28 2010 +0600

    kdrive: Adjust kdrive usage message as shadow overlay support has been dropped
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c
index d481d50..7675c1e 100644
--- a/hw/kdrive/src/kdrive.c
+++ b/hw/kdrive/src/kdrive.c
@@ -529,7 +529,7 @@ void
 KdUseMsg (void)
 {
     ErrorF("\nTinyX Device Dependent Usage:\n");
-    ErrorF("-screen WIDTH[/WIDTHMM]xHEIGHT[/HEIGHTMM][@ROTATION][X][Y][xDEPTH/BPP{,DEPTH/BPP}[xFREQ]]  Specify screen characteristics\n");
+    ErrorF("-screen WIDTH[/WIDTHMM]xHEIGHT[/HEIGHTMM][@ROTATION][X][Y][xDEPTH/BPP[xFREQ]]  Specify screen characteristics\n");
     ErrorF("-rgba rgb/bgr/vrgb/vbgr/none   Specify subpixel ordering for LCD panels\n");
     ErrorF("-mouse driver [,n,,options]    Specify the pointer driver and its options (n is the number of buttons)\n");
     ErrorF("-keybd driver [,,options]      Specify the keyboard driver and its options\n");
commit c40b9f959175057fac726fcdfff9641ae0681cf6
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Mon Jan 4 14:07:37 2010 +0600

    kdrive: Remove unused VxWorks* variable declarations
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 30d74f9..8a62faf 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -582,10 +582,6 @@ KdRingBell (KdKeyboardInfo      *ki,
             int                 pitch,
             int                 duration);
 
-extern KdPointerDriver	VxWorksMouseDriver;
-extern KdKeyboardDriver	VxWorksKeyboardDriver;
-extern KdOsFuncs	VxWorksFuncs;
-
 /* kmap.c */
 
 #define KD_MAPPED_MODE_REGISTERS    0
commit 4e0d580d5ac00d8d87c8e0080a02868c87a31caa
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Sat Jan 2 15:04:03 2010 +0600

    kdrive: Remove unused KdCardInfo::lastMarker field
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 78d6414..30d74f9 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -62,8 +62,6 @@ typedef struct _KdCardInfo {
     struct _KdScreenInfo    *screenList;
     int			    selected;
     struct _KdCardInfo	    *next;
-
-    int			    lastMarker;
 } KdCardInfo;
 
 extern KdCardInfo	*kdCardInfo;
commit dbaab9759ba31edf63cf73eda86ba931d88e8cce
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Sat Jan 2 16:18:29 2010 +0600

    kdrive: Extract common part of fbdevPutColors and fbdevEnable
    
    Put framebuffer colormap updating code in separate function
    for brevity.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/fbdev/fbdev.c b/hw/kdrive/fbdev/fbdev.c
index 37bda17..cd90487 100644
--- a/hw/kdrive/fbdev/fbdev.c
+++ b/hw/kdrive/fbdev/fbdev.c
@@ -651,6 +651,21 @@ fbdevPreserve (KdCardInfo *card)
 {
 }
 
+static int
+fbdevUpdateFbColormap(FbdevPriv *priv, int minidx, int maxidx)
+{
+    struct fb_cmap cmap;
+
+    cmap.start = minidx;
+    cmap.len = maxidx - minidx + 1;
+    cmap.red = &priv->red[minidx];
+    cmap.green = &priv->green[minidx];
+    cmap.blue = &priv->blue[minidx];
+    cmap.transp = 0;
+
+    return ioctl(priv->fd, FBIOPUTCMAP, &cmap);
+}
+
 Bool
 fbdevEnable (ScreenPtr pScreen)
 {
@@ -670,7 +685,6 @@ fbdevEnable (ScreenPtr pScreen)
 
     if (priv->fix.visual == FB_VISUAL_DIRECTCOLOR)
     {
-	struct fb_cmap	cmap;
 	int		i;
 
 	for (i = 0;
@@ -682,13 +696,8 @@ fbdevEnable (ScreenPtr pScreen)
 	    priv->green[i] = i * 65535 / ((1 << priv->var.green.length) - 1);
 	    priv->blue[i] = i * 65535 / ((1 << priv->var.blue.length) - 1);
 	}
-	cmap.start = 0;
-	cmap.len = i;
-	cmap.red = &priv->red[0];
-	cmap.green = &priv->green[0];
-	cmap.blue = &priv->blue[0];
-	cmap.transp = 0;
-	ioctl (priv->fd, FBIOPUTCMAP, &cmap);
+
+	fbdevUpdateFbColormap(priv, 0, i);
     }
     return TRUE;
 }
@@ -744,6 +753,9 @@ fbdevCardFini (KdCardInfo *card)
     xfree (priv);
 }
 
+/*
+ * Retrieve actual colormap and return selected n entries in pdefs.
+ */
 void
 fbdevGetColors (ScreenPtr pScreen, int n, xColorItem *pdefs)
 {
@@ -785,12 +797,14 @@ fbdevGetColors (ScreenPtr pScreen, int n, xColorItem *pdefs)
     }
 }
 
+/*
+ * Change colormap by updating n entries described in pdefs.
+ */
 void
 fbdevPutColors (ScreenPtr pScreen, int n, xColorItem *pdefs)
 {
     KdScreenPriv(pScreen);
     FbdevPriv	*priv = pScreenPriv->card->driver;
-    struct fb_cmap  cmap;
     int		    p;
     int		    min, max;
 
@@ -808,11 +822,6 @@ fbdevPutColors (ScreenPtr pScreen, int n, xColorItem *pdefs)
 	    max = p;
 	pdefs++;
     }
-    cmap.start = min;
-    cmap.len = max - min + 1;
-    cmap.red = &priv->red[min];
-    cmap.green = &priv->green[min];
-    cmap.blue = &priv->blue[min];
-    cmap.transp = 0;
-    ioctl (priv->fd, FBIOPUTCMAP, &cmap);
+
+    fbdevUpdateFbColormap(priv, min, max);
 }
commit 7ee14154b230b931d294288e1291c4fc617b1354
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Sat Jan 2 15:42:53 2010 +0600

    kdrive: Remove unused overlay fb support
    
    Xfbdev, Xephyr and Xfake all use only one framebuffer, so simplify
    implementation by removing overlay support.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 93118a8..b21559b 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -101,77 +101,77 @@ ephyrScreenInitialize (KdScreenInfo *screen, EphyrScrPriv *scrpriv)
     }
 
   if (EphyrWantGrayScale)
-    screen->fb[0].depth = 8;
+    screen->fb.depth = 8;
 
-  if (screen->fb[0].depth && screen->fb[0].depth != hostx_get_depth())
+  if (screen->fb.depth && screen->fb.depth != hostx_get_depth())
     {
-      if (screen->fb[0].depth < hostx_get_depth()
-	  && (screen->fb[0].depth == 24 || screen->fb[0].depth == 16
-	      || screen->fb[0].depth == 8))
+      if (screen->fb.depth < hostx_get_depth()
+	  && (screen->fb.depth == 24 || screen->fb.depth == 16
+	      || screen->fb.depth == 8))
 	{
-	  hostx_set_server_depth(screen, screen->fb[0].depth);
+	  hostx_set_server_depth(screen, screen->fb.depth);
 	}
       else
 	ErrorF("\nXephyr: requested screen depth not supported, setting to match hosts.\n");
     }
   
-  screen->fb[0].depth = hostx_get_server_depth(screen);
+  screen->fb.depth = hostx_get_server_depth(screen);
   screen->rate = 72;
   
-  if (screen->fb[0].depth <= 8)
+  if (screen->fb.depth <= 8)
     {
       if (EphyrWantGrayScale)
-	screen->fb[0].visuals = ((1 << StaticGray) | (1 << GrayScale));
+	screen->fb.visuals = ((1 << StaticGray) | (1 << GrayScale));
       else
-	screen->fb[0].visuals = ((1 << StaticGray) |
-				 (1 << GrayScale) |
-				 (1 << StaticColor) |
-				 (1 << PseudoColor) |
-				 (1 << TrueColor) |
-				 (1 << DirectColor));
+	screen->fb.visuals = ((1 << StaticGray) |
+			      (1 << GrayScale) |
+			      (1 << StaticColor) |
+			      (1 << PseudoColor) |
+			      (1 << TrueColor) |
+			      (1 << DirectColor));
       
-      screen->fb[0].redMask   = 0x00;
-      screen->fb[0].greenMask = 0x00;
-      screen->fb[0].blueMask  = 0x00;
-      screen->fb[0].depth        = 8;
-      screen->fb[0].bitsPerPixel = 8;
+      screen->fb.redMask   = 0x00;
+      screen->fb.greenMask = 0x00;
+      screen->fb.blueMask  = 0x00;
+      screen->fb.depth        = 8;
+      screen->fb.bitsPerPixel = 8;
     }
   else 
     {
-      screen->fb[0].visuals = (1 << TrueColor);
+      screen->fb.visuals = (1 << TrueColor);
       
-      if (screen->fb[0].depth <= 15)
+      if (screen->fb.depth <= 15)
 	{
-	  screen->fb[0].depth = 15;
-	  screen->fb[0].bitsPerPixel = 16;
+	  screen->fb.depth = 15;
+	  screen->fb.bitsPerPixel = 16;
 	}
-      else if (screen->fb[0].depth <= 16)
+      else if (screen->fb.depth <= 16)
 	{
-	  screen->fb[0].depth = 16;
-	  screen->fb[0].bitsPerPixel = 16;
+	  screen->fb.depth = 16;
+	  screen->fb.bitsPerPixel = 16;
 	}
-      else if (screen->fb[0].depth <= 24)
+      else if (screen->fb.depth <= 24)
 	{
-	  screen->fb[0].depth = 24;
-	  screen->fb[0].bitsPerPixel = 32;
+	  screen->fb.depth = 24;
+	  screen->fb.bitsPerPixel = 32;
 	}
-      else if (screen->fb[0].depth <= 30)
+      else if (screen->fb.depth <= 30)
 	{
-	  screen->fb[0].depth = 30;
-	  screen->fb[0].bitsPerPixel = 32;
+	  screen->fb.depth = 30;
+	  screen->fb.bitsPerPixel = 32;
 	}
       else
 	{
 	  ErrorF("\nXephyr: Unsupported screen depth %d\n",
-	         screen->fb[0].depth);
+	         screen->fb.depth);
 	  return FALSE;
 	}
 
       hostx_get_visual_masks (screen, &redMask, &greenMask, &blueMask);
 
-      screen->fb[0].redMask = (Pixel) redMask;
-      screen->fb[0].greenMask = (Pixel) greenMask;
-      screen->fb[0].blueMask = (Pixel) blueMask;
+      screen->fb.redMask = (Pixel) redMask;
+      screen->fb.greenMask = (Pixel) greenMask;
+      screen->fb.blueMask = (Pixel) blueMask;
 
     }
   
@@ -250,7 +250,7 @@ ephyrMapFramebuffer (KdScreenInfo *screen)
   KdComputePointerMatrix (&m, scrpriv->randr, screen->width, screen->height);
   KdSetPointerMatrix (&m);
   
-  priv->bytes_per_line = ((screen->width * screen->fb[0].bitsPerPixel + 31) >> 5) << 2;
+  priv->bytes_per_line = ((screen->width * screen->fb.bitsPerPixel + 31) >> 5) << 2;
 
   buffer_height = ephyrBufferHeight(screen);
 
@@ -260,9 +260,9 @@ ephyrMapFramebuffer (KdScreenInfo *screen)
     {
       scrpriv->shadow = FALSE;
       
-      screen->fb[0].byteStride = priv->bytes_per_line;
-      screen->fb[0].pixelStride = screen->width;
-      screen->fb[0].frameBuffer = (CARD8 *) (priv->base);
+      screen->fb.byteStride = priv->bytes_per_line;
+      screen->fb.pixelStride = screen->width;
+      screen->fb.frameBuffer = (CARD8 *) (priv->base);
     }
   else
     {
@@ -271,7 +271,7 @@ ephyrMapFramebuffer (KdScreenInfo *screen)
       
       EPHYR_LOG("allocing shadow");
       
-      KdShadowFbAlloc (screen, 0, 
+      KdShadowFbAlloc (screen,
 		       scrpriv->randr & (RR_Rotate_90|RR_Rotate_270));
     }
   
@@ -307,7 +307,7 @@ ephyrUnmapFramebuffer (KdScreenInfo *screen)
   EphyrScrPriv  *scrpriv = screen->driver;
   
   if (scrpriv->shadow)
-    KdShadowFbFree (screen, 0);
+    KdShadowFbFree (screen);
   
   /* Note, priv->base will get freed when XImage recreated */
   
@@ -571,10 +571,10 @@ ephyrRandRSetConfig (ScreenPtr		pScreen,
   (*pScreen->ModifyPixmapHeader) (fbGetScreenPixmap (pScreen),
 				  pScreen->width,
 				  pScreen->height,
-				  screen->fb[0].depth,
-				  screen->fb[0].bitsPerPixel,
-				  screen->fb[0].byteStride,
-				  screen->fb[0].frameBuffer);
+				  screen->fb.depth,
+				  screen->fb.bitsPerPixel,
+				  screen->fb.byteStride,
+				  screen->fb.frameBuffer);
   
   /* set the subpixel order */
   
@@ -735,7 +735,7 @@ ephyrScreenFini (KdScreenInfo *screen)
 {
     EphyrScrPriv  *scrpriv = screen->driver;
     if (scrpriv->shadow) {
-        KdShadowFbFree (screen, 0);
+        KdShadowFbFree (screen);
     }
     xfree(screen->driver);
     screen->driver = NULL;
@@ -1027,7 +1027,7 @@ ephyrCardFini (KdCardInfo *card)
 }
 
 void
-ephyrGetColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
+ephyrGetColors (ScreenPtr pScreen, int n, xColorItem *pdefs)
 {
   /* XXX Not sure if this is right */
   
@@ -1044,7 +1044,7 @@ ephyrGetColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
 }
 
 void
-ephyrPutColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
+ephyrPutColors (ScreenPtr pScreen, int n, xColorItem *pdefs)
 {
   int min, max, p;
 
diff --git a/hw/kdrive/ephyr/ephyr.h b/hw/kdrive/ephyr/ephyr.h
index cb5e4b5..41a82bf 100644
--- a/hw/kdrive/ephyr/ephyr.h
+++ b/hw/kdrive/ephyr/ephyr.h
@@ -116,10 +116,10 @@ void
 ephyrCardFini (KdCardInfo *card);
 
 void
-ephyrGetColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs);
+ephyrGetColors (ScreenPtr pScreen, int n, xColorItem *pdefs);
 
 void
-ephyrPutColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs);
+ephyrPutColors (ScreenPtr pScreen, int n, xColorItem *pdefs);
 
 Bool
 ephyrMapFramebuffer (KdScreenInfo *screen);
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index bb2ee10..6624ab9 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -302,7 +302,7 @@ ephyrInitVideo (ScreenPtr pScreen)
 
     EPHYR_LOG ("enter\n") ;
 
-    if (screen->fb[0].bitsPerPixel == 8) {
+    if (screen->fb.bitsPerPixel == 8) {
         EPHYR_LOG_ERROR ("8 bits depth not supported\n") ;
         return FALSE ;
     }
diff --git a/hw/kdrive/fake/fake.c b/hw/kdrive/fake/fake.c
index a4044b6..809e309 100644
--- a/hw/kdrive/fake/fake.c
+++ b/hw/kdrive/fake/fake.c
@@ -69,45 +69,45 @@ fakeScreenInitialize (KdScreenInfo *screen, FakeScrPriv *scrpriv)
     if (screen->height <= 0)
 	screen->height = 1;
     
-    if (!screen->fb[0].depth)
-	screen->fb[0].depth = 16;
+    if (!screen->fb.depth)
+	screen->fb.depth = 16;
 
-    if (screen->fb[0].depth <= 8)
+    if (screen->fb.depth <= 8)
     {
-	screen->fb[0].visuals = ((1 << StaticGray) |
-				 (1 << GrayScale) |
-				 (1 << StaticColor) |
-				 (1 << PseudoColor) |
-				 (1 << TrueColor) |
-				 (1 << DirectColor));
+	screen->fb.visuals = ((1 << StaticGray) |
+			      (1 << GrayScale) |
+			      (1 << StaticColor) |
+			      (1 << PseudoColor) |
+			      (1 << TrueColor) |
+			      (1 << DirectColor));
     }
     else 
     {
-	screen->fb[0].visuals = (1 << TrueColor);
+	screen->fb.visuals = (1 << TrueColor);
 #define Mask(o,l)   (((1 << l) - 1) << o)
-	if (screen->fb[0].depth <= 15)
+	if (screen->fb.depth <= 15)
 	{
-	    screen->fb[0].depth = 15;
-	    screen->fb[0].bitsPerPixel = 16;
-	    screen->fb[0].redMask = Mask (10, 5);
-	    screen->fb[0].greenMask = Mask (5, 5);
-	    screen->fb[0].blueMask = Mask (0, 5);
+	    screen->fb.depth = 15;
+	    screen->fb.bitsPerPixel = 16;
+	    screen->fb.redMask = Mask (10, 5);
+	    screen->fb.greenMask = Mask (5, 5);
+	    screen->fb.blueMask = Mask (0, 5);
 	}
-	else if (screen->fb[0].depth <= 16)
+	else if (screen->fb.depth <= 16)
 	{
-	    screen->fb[0].depth = 16;
-	    screen->fb[0].bitsPerPixel = 16;
-	    screen->fb[0].redMask = Mask (11, 5);
-	    screen->fb[0].greenMask = Mask (5, 6);
-	    screen->fb[0].blueMask = Mask (0, 5);
+	    screen->fb.depth = 16;
+	    screen->fb.bitsPerPixel = 16;
+	    screen->fb.redMask = Mask (11, 5);
+	    screen->fb.greenMask = Mask (5, 6);
+	    screen->fb.blueMask = Mask (0, 5);
 	}
 	else
 	{
-	    screen->fb[0].depth = 24;
-	    screen->fb[0].bitsPerPixel = 32;
-	    screen->fb[0].redMask = Mask (16, 8);
-	    screen->fb[0].greenMask = Mask (8, 8);
-	    screen->fb[0].blueMask = Mask (0, 8);
+	    screen->fb.depth = 24;
+	    screen->fb.bitsPerPixel = 32;
+	    screen->fb.redMask = Mask (16, 8);
+	    screen->fb.greenMask = Mask (8, 8);
+	    screen->fb.blueMask = Mask (0, 8);
 	}
     }
 
@@ -167,23 +167,22 @@ fakeMapFramebuffer (KdScreenInfo *screen)
     
     KdSetPointerMatrix (&m);
     
-    priv->bytes_per_line = ((screen->width * screen->fb[0].bitsPerPixel + 31) >> 5) << 2;
+    priv->bytes_per_line = ((screen->width * screen->fb.bitsPerPixel + 31) >> 5) << 2;
     if (priv->base)
 	free (priv->base);
     priv->base = malloc (priv->bytes_per_line * screen->height);
     
     if (scrpriv->shadow)
     {
-	if (!KdShadowFbAlloc (screen, 0, 
-			      scrpriv->randr & (RR_Rotate_90|RR_Rotate_270)))
+	if (!KdShadowFbAlloc (screen, scrpriv->randr & (RR_Rotate_90|RR_Rotate_270)))
 	    return FALSE;
     }
     else
     {
-        screen->fb[0].byteStride = priv->bytes_per_line;
-        screen->fb[0].pixelStride = (priv->bytes_per_line * 8/
-				     screen->fb[0].bitsPerPixel);
-        screen->fb[0].frameBuffer = (CARD8 *) (priv->base);
+        screen->fb.byteStride = priv->bytes_per_line;
+        screen->fb.pixelStride = (priv->bytes_per_line * 8/
+				     screen->fb.bitsPerPixel);
+        screen->fb.frameBuffer = (CARD8 *) (priv->base);
     }
     
     return TRUE;
@@ -216,7 +215,7 @@ Bool
 fakeUnmapFramebuffer (KdScreenInfo *screen)
 {
     FakePriv		*priv = screen->card->driver;
-    KdShadowFbFree (screen, 0);
+    KdShadowFbFree (screen);
     if (priv->base)
     {
 	free (priv->base);
@@ -338,10 +337,10 @@ fakeRandRSetConfig (ScreenPtr		pScreen,
     (*pScreen->ModifyPixmapHeader) (fbGetScreenPixmap (pScreen),
 				    pScreen->width,
 				    pScreen->height,
-				    screen->fb[0].depth,
-				    screen->fb[0].bitsPerPixel,
-				    screen->fb[0].byteStride,
-				    screen->fb[0].frameBuffer);
+				    screen->fb.depth,
+				    screen->fb.bitsPerPixel,
+				    screen->fb.byteStride,
+				    screen->fb.frameBuffer);
     
     /* set the subpixel order */
     
@@ -460,7 +459,7 @@ fakeCardFini (KdCardInfo *card)
 }
 
 void
-fakeGetColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
+fakeGetColors (ScreenPtr pScreen, int n, xColorItem *pdefs)
 {
     while (n--)
     {
@@ -472,6 +471,6 @@ fakeGetColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
 }
 
 void
-fakePutColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
+fakePutColors (ScreenPtr pScreen, int n, xColorItem *pdefs)
 {
 }
diff --git a/hw/kdrive/fake/fake.h b/hw/kdrive/fake/fake.h
index 3c4a51b..d505860 100644
--- a/hw/kdrive/fake/fake.h
+++ b/hw/kdrive/fake/fake.h
@@ -85,10 +85,10 @@ void
 fakeCardFini (KdCardInfo *card);
 
 void
-fakeGetColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs);
+fakeGetColors (ScreenPtr pScreen, int n, xColorItem *pdefs);
 
 void
-fakePutColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs);
+fakePutColors (ScreenPtr pScreen, int n, xColorItem *pdefs);
 
 Bool
 fakeMapFramebuffer (KdScreenInfo *screen);
diff --git a/hw/kdrive/fbdev/fbdev.c b/hw/kdrive/fbdev/fbdev.c
index d4fc5db..37bda17 100644
--- a/hw/kdrive/fbdev/fbdev.c
+++ b/hw/kdrive/fbdev/fbdev.c
@@ -175,12 +175,12 @@ fbdevScreenInitialize (KdScreenInfo *screen, FbdevScrPriv *scrpriv)
 	}
 	screen->rate = 103; /* FIXME: should get proper value from fb driver */
     }
-    if (!screen->fb[0].depth)
+    if (!screen->fb.depth)
     {
 	if (k >= 0)
-	    screen->fb[0].depth = var.bits_per_pixel;
+	    screen->fb.depth = var.bits_per_pixel;
 	else
-	    screen->fb[0].depth = 16;
+	    screen->fb.depth = 16;
     }
 
     if ((screen->width != var.xres) || (screen->height != var.yres))
@@ -196,7 +196,7 @@ fbdevScreenInitialize (KdScreenInfo *screen, FbdevScrPriv *scrpriv)
     }
 
     var.activate = FB_ACTIVATE_NOW;
-    var.bits_per_pixel = screen->fb[0].depth;
+    var.bits_per_pixel = screen->fb.depth;
     var.nonstd = 0;
     var.grayscale = 0;
 
@@ -222,60 +222,60 @@ fbdevScreenInitialize (KdScreenInfo *screen, FbdevScrPriv *scrpriv)
     case FB_VISUAL_PSEUDOCOLOR:
 	if (gray)
 	{
-	    screen->fb[0].visuals = (1 << StaticGray);
+	    screen->fb.visuals = (1 << StaticGray);
 	    /* could also support GrayScale, but what's the point? */
 	}
 	else
 	{
-	    screen->fb[0].visuals = ((1 << StaticGray) |
+	    screen->fb.visuals = ((1 << StaticGray) |
 			       (1 << GrayScale) |
 			       (1 << StaticColor) |
 			       (1 << PseudoColor) |
 			       (1 << TrueColor) |
 			       (1 << DirectColor));
 	}
-	screen->fb[0].blueMask  = 0x00;
-	screen->fb[0].greenMask = 0x00;
-	screen->fb[0].redMask   = 0x00;
+	screen->fb.blueMask  = 0x00;
+	screen->fb.greenMask = 0x00;
+	screen->fb.redMask   = 0x00;
 	break;
     case FB_VISUAL_STATIC_PSEUDOCOLOR:
 	if (gray)
 	{
-	    screen->fb[0].visuals = (1 << StaticGray);
+	    screen->fb.visuals = (1 << StaticGray);
 	}
 	else
 	{
-	    screen->fb[0].visuals = (1 << StaticColor);
+	    screen->fb.visuals = (1 << StaticColor);
 	}
-	screen->fb[0].blueMask  = 0x00;
-	screen->fb[0].greenMask = 0x00;
-	screen->fb[0].redMask   = 0x00;
+	screen->fb.blueMask  = 0x00;
+	screen->fb.greenMask = 0x00;
+	screen->fb.redMask   = 0x00;
 	break;
     case FB_VISUAL_TRUECOLOR:
     case FB_VISUAL_DIRECTCOLOR:
-	screen->fb[0].visuals = (1 << TrueColor);
+	screen->fb.visuals = (1 << TrueColor);
 #define Mask(o,l)   (((1 << l) - 1) << o)
-	screen->fb[0].redMask = Mask (priv->var.red.offset, priv->var.red.length);
-	screen->fb[0].greenMask = Mask (priv->var.green.offset, priv->var.green.length);
-	screen->fb[0].blueMask = Mask (priv->var.blue.offset, priv->var.blue.length);
+	screen->fb.redMask = Mask (priv->var.red.offset, priv->var.red.length);
+	screen->fb.greenMask = Mask (priv->var.green.offset, priv->var.green.length);
+	screen->fb.blueMask = Mask (priv->var.blue.offset, priv->var.blue.length);
 
 	/*
 	 * This is a kludge so that Render will work -- fill in the gaps
 	 * in the pixel
 	 */
-	screen->fb[0].redMask = fbdevMakeContig (screen->fb[0].redMask,
-						 screen->fb[0].greenMask|
-						 screen->fb[0].blueMask);
+	screen->fb.redMask = fbdevMakeContig (screen->fb.redMask,
+						 screen->fb.greenMask|
+						 screen->fb.blueMask);
 
-	screen->fb[0].greenMask = fbdevMakeContig (screen->fb[0].greenMask,
-						   screen->fb[0].redMask|
-						   screen->fb[0].blueMask);
+	screen->fb.greenMask = fbdevMakeContig (screen->fb.greenMask,
+						   screen->fb.redMask|
+						   screen->fb.blueMask);
 
-	screen->fb[0].blueMask = fbdevMakeContig (screen->fb[0].blueMask,
-						  screen->fb[0].redMask|
-						  screen->fb[0].greenMask);
+	screen->fb.blueMask = fbdevMakeContig (screen->fb.blueMask,
+						  screen->fb.redMask|
+						  screen->fb.greenMask);
 
-	allbits = screen->fb[0].redMask | screen->fb[0].greenMask | screen->fb[0].blueMask;
+	allbits = screen->fb.redMask | screen->fb.greenMask | screen->fb.blueMask;
 	depth = 32;
 	while (depth && !(allbits & (1 << (depth - 1))))
 	    depth--;
@@ -284,8 +284,8 @@ fbdevScreenInitialize (KdScreenInfo *screen, FbdevScrPriv *scrpriv)
 	return FALSE;
 	break;
     }
-    screen->fb[0].depth = depth;
-    screen->fb[0].bitsPerPixel = priv->var.bits_per_pixel;
+    screen->fb.depth = depth;
+    screen->fb.bitsPerPixel = priv->var.bits_per_pixel;
 
     scrpriv->randr = screen->randr;
 
@@ -348,16 +348,16 @@ fbdevMapFramebuffer (KdScreenInfo *screen)
 
     if (scrpriv->shadow)
     {
-	if (!KdShadowFbAlloc (screen, 0,
+	if (!KdShadowFbAlloc (screen,
 			      scrpriv->randr & (RR_Rotate_90|RR_Rotate_270)))
 	    return FALSE;
     }
     else
     {
-        screen->fb[0].byteStride = priv->fix.line_length;
-        screen->fb[0].pixelStride = (priv->fix.line_length * 8 /
+        screen->fb.byteStride = priv->fix.line_length;
+        screen->fb.pixelStride = (priv->fix.line_length * 8 /
     				 priv->var.bits_per_pixel);
-        screen->fb[0].frameBuffer = (CARD8 *) (priv->fb);
+        screen->fb.frameBuffer = (CARD8 *) (priv->fb);
     }
 
     return TRUE;
@@ -390,7 +390,7 @@ fbdevSetScreenSizes (ScreenPtr pScreen)
 Bool
 fbdevUnmapFramebuffer (KdScreenInfo *screen)
 {
-    KdShadowFbFree (screen, 0);
+    KdShadowFbFree (screen);
     return TRUE;
 }
 
@@ -538,10 +538,10 @@ fbdevRandRSetConfig (ScreenPtr		pScreen,
     (*pScreen->ModifyPixmapHeader) (fbGetScreenPixmap (pScreen),
 				    pScreen->width,
 				    pScreen->height,
-				    screen->fb[0].depth,
-				    screen->fb[0].bitsPerPixel,
-				    screen->fb[0].byteStride,
-				    screen->fb[0].frameBuffer);
+				    screen->fb.depth,
+				    screen->fb.bitsPerPixel,
+				    screen->fb.byteStride,
+				    screen->fb.frameBuffer);
 
     /* set the subpixel order */
 
@@ -600,7 +600,7 @@ fbdevCreateColormap (ColormapPtr pmap)
 	    return FALSE;
 	for (i = 0; i < nent; i++)
 	    pdefs[i].pixel = i;
-	fbdevGetColors (pScreen, 0, nent, pdefs);
+	fbdevGetColors (pScreen, nent, pdefs);
 	for (i = 0; i < nent; i++)
 	{
 	    pmap->red[i].co.local.red = pdefs[i].red;
@@ -745,7 +745,7 @@ fbdevCardFini (KdCardInfo *card)
 }
 
 void
-fbdevGetColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
+fbdevGetColors (ScreenPtr pScreen, int n, xColorItem *pdefs)
 {
     KdScreenPriv(pScreen);
     FbdevPriv	    *priv = pScreenPriv->card->driver;
@@ -786,7 +786,7 @@ fbdevGetColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
 }
 
 void
-fbdevPutColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
+fbdevPutColors (ScreenPtr pScreen, int n, xColorItem *pdefs)
 {
     KdScreenPriv(pScreen);
     FbdevPriv	*priv = pScreenPriv->card->driver;
diff --git a/hw/kdrive/fbdev/fbdev.h b/hw/kdrive/fbdev/fbdev.h
index 3da8e47..4d4f7a9 100644
--- a/hw/kdrive/fbdev/fbdev.h
+++ b/hw/kdrive/fbdev/fbdev.h
@@ -94,10 +94,10 @@ void
 fbdevCardFini (KdCardInfo *card);
 
 void
-fbdevGetColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs);
+fbdevGetColors (ScreenPtr pScreen, int n, xColorItem *pdefs);
 
 void
-fbdevPutColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs);
+fbdevPutColors (ScreenPtr pScreen, int n, xColorItem *pdefs);
 
 Bool
 fbdevMapFramebuffer (KdScreenInfo *screen);
diff --git a/hw/kdrive/src/Makefile.am b/hw/kdrive/src/Makefile.am
index 7ac23c2..9aa8e5e 100644
--- a/hw/kdrive/src/Makefile.am
+++ b/hw/kdrive/src/Makefile.am
@@ -15,7 +15,6 @@ endif
 libkdrive_la_SOURCES =	\
 	fourcc.h	\
 	kcmap.c		\
-	kcurscol.c	\
 	kdrive.c	\
 	kdrive.h	\
 	kinfo.c		\
diff --git a/hw/kdrive/src/kcmap.c b/hw/kdrive/src/kcmap.c
index 053e719..40697e0 100644
--- a/hw/kdrive/src/kcmap.c
+++ b/hw/kdrive/src/kcmap.c
@@ -30,10 +30,10 @@
  */
 
 void
-KdSetColormap (ScreenPtr pScreen, int fb)
+KdSetColormap (ScreenPtr pScreen)
 {
     KdScreenPriv(pScreen);
-    ColormapPtr	pCmap = pScreenPriv->pInstalledmap[fb];
+    ColormapPtr	pCmap = pScreenPriv->pInstalledmap;
     Pixel	pixels[KD_MAX_PSEUDO_SIZE];
     xrgb	colors[KD_MAX_PSEUDO_SIZE];
     xColorItem	defs[KD_MAX_PSEUDO_SIZE];
@@ -41,7 +41,7 @@ KdSetColormap (ScreenPtr pScreen, int fb)
 
     if (!pScreenPriv->card->cfuncs->putColors)
 	return;
-    if (pScreenPriv->screen->fb[fb].depth > KD_MAX_PSEUDO_DEPTH)
+    if (pScreenPriv->screen->fb.depth > KD_MAX_PSEUDO_DEPTH)
 	return;
 
     if (!pScreenPriv->enabled)
@@ -55,12 +55,12 @@ KdSetColormap (ScreenPtr pScreen, int fb)
      * true/direct as well as pseudo/static visuals
      */
 
-    for (i = 0; i < (1 << pScreenPriv->screen->fb[fb].depth); i++)
+    for (i = 0; i < (1 << pScreenPriv->screen->fb.depth); i++)
 	pixels[i] = i;
 
-    QueryColors (pCmap, (1 << pScreenPriv->screen->fb[fb].depth), pixels, colors);
+    QueryColors (pCmap, (1 << pScreenPriv->screen->fb.depth), pixels, colors);
 
-    for (i = 0; i < (1 << pScreenPriv->screen->fb[fb].depth); i++)
+    for (i = 0; i < (1 << pScreenPriv->screen->fb.depth); i++)
     {
 	defs[i].pixel = i;
 	defs[i].red = colors[i].red;
@@ -69,8 +69,8 @@ KdSetColormap (ScreenPtr pScreen, int fb)
 	defs[i].flags = DoRed|DoGreen|DoBlue;
     }
 
-    (*pScreenPriv->card->cfuncs->putColors) (pCmap->pScreen, fb,
-					     (1 << pScreenPriv->screen->fb[fb].depth),
+    (*pScreenPriv->card->cfuncs->putColors) (pCmap->pScreen,
+					     (1 << pScreenPriv->screen->fb.depth),
 					     defs);
 
     /* recolor hardware cursor */
@@ -87,77 +87,35 @@ KdEnableColormap (ScreenPtr pScreen)
 {
     KdScreenPriv(pScreen);
     int	    i;
-    int	    fb;
-    Bool    done = FALSE;
 
     if (!pScreenPriv->card->cfuncs->putColors)
 	return;
-    for (fb = 0; fb < KD_MAX_FB && pScreenPriv->screen->fb[fb].depth; fb++)
+
+    if (pScreenPriv->screen->fb.depth <= KD_MAX_PSEUDO_DEPTH)
     {
-	if (pScreenPriv->screen->fb[fb].depth <= KD_MAX_PSEUDO_DEPTH && !done)
-	{
-	    for (i = 0; i < (1 << pScreenPriv->screen->fb[fb].depth); i++)
-		pScreenPriv->systemPalette[i].pixel = i;
-	    (*pScreenPriv->card->cfuncs->getColors) (pScreen, fb,
-						   (1 << pScreenPriv->screen->fb[fb].depth),
-						   pScreenPriv->systemPalette);
-	    done = TRUE;
-	}
-	KdSetColormap (pScreen, fb);
+	for (i = 0; i < (1 << pScreenPriv->screen->fb.depth); i++)
+	    pScreenPriv->systemPalette[i].pixel = i;
+	(*pScreenPriv->card->cfuncs->getColors) (pScreen,
+						 (1 << pScreenPriv->screen->fb.depth),
+						 pScreenPriv->systemPalette);
     }
+    KdSetColormap (pScreen);
 }
 
 void
 KdDisableColormap (ScreenPtr pScreen)
 {
     KdScreenPriv(pScreen);
-    int	    fb;
 
     if (!pScreenPriv->card->cfuncs->putColors)
 	return;
-    for (fb = 0; fb < KD_MAX_FB && pScreenPriv->screen->fb[fb].depth; fb++)
-    {
-	if (pScreenPriv->screen->fb[fb].depth <= KD_MAX_PSEUDO_DEPTH)
-	{
-	    (*pScreenPriv->card->cfuncs->putColors) (pScreen, fb,
-						     (1 << pScreenPriv->screen->fb[fb].depth),
-						     pScreenPriv->systemPalette);
-	    break;
-	}
-    }
-}
 
-static int
-KdColormapFb (ColormapPtr   pCmap)
-{
-    ScreenPtr	pScreen = pCmap->pScreen;
-    KdScreenPriv (pScreen);
-    KdScreenInfo    *screen = pScreenPriv->screen;
-    int		d;
-    DepthPtr	depth;
-    int		v;
-    VisualID	vid = pCmap->pVisual->vid;
-    int		fb;
-
-    if (screen->fb[1].depth)
+    if (pScreenPriv->screen->fb.depth <= KD_MAX_PSEUDO_DEPTH)
     {
-	for (d = 0; d < pScreen->numDepths; d++)
-	{
-	    depth = &pScreen->allowedDepths[d];
-	    for (v = 0; v < depth->numVids; v++)
-	    {
-		if (depth->vids[v] == vid)
-		{
-		    for (fb = 0; fb < KD_MAX_FB && screen->fb[fb].depth; fb++)
-		    {
-			if (depth->depth == screen->fb[fb].depth)
-			    return fb;
-		    }
-		}
-	    }
-	}
+	(*pScreenPriv->card->cfuncs->putColors) (pScreen,
+						 (1 << pScreenPriv->screen->fb.depth),
+						 pScreenPriv->systemPalette);
     }
-    return 0;
 }
 
 /*
@@ -173,20 +131,19 @@ void
 KdInstallColormap (ColormapPtr pCmap)
 {
     KdScreenPriv(pCmap->pScreen);
-    int		fb = KdColormapFb (pCmap);
 
-    if (pCmap == pScreenPriv->pInstalledmap[fb])
+    if (pCmap == pScreenPriv->pInstalledmap)
 	return;
 
     /* Tell X clients that the installed colormap is going away. */
-    if (pScreenPriv->pInstalledmap[fb])
-	WalkTree(pScreenPriv->pInstalledmap[fb]->pScreen, TellLostMap,
-		 (pointer) &(pScreenPriv->pInstalledmap[fb]->mid));
+    if (pScreenPriv->pInstalledmap)
+	WalkTree(pScreenPriv->pInstalledmap->pScreen, TellLostMap,
+		 (pointer) &(pScreenPriv->pInstalledmap->mid));
 
     /* Take note of the new installed colorscreen-> */
-    pScreenPriv->pInstalledmap[fb] = pCmap;
+    pScreenPriv->pInstalledmap = pCmap;
 
-    KdSetColormap (pCmap->pScreen, fb);
+    KdSetColormap (pCmap->pScreen);
 
     /* Tell X clients of the new colormap */
     WalkTree(pCmap->pScreen, TellGainedMap, (pointer) &(pCmap->mid));
@@ -203,12 +160,11 @@ void
 KdUninstallColormap (ColormapPtr pCmap)
 {
     KdScreenPriv(pCmap->pScreen);
-    int		fb = KdColormapFb (pCmap);
     Colormap	defMapID;
     ColormapPtr defMap;
 
     /* ignore if not installed */
-    if (pCmap != pScreenPriv->pInstalledmap[fb])
+    if (pCmap != pScreenPriv->pInstalledmap)
 	return;
 
     /* ignore attempts to uninstall default colormap */
@@ -216,17 +172,17 @@ KdUninstallColormap (ColormapPtr pCmap)
     if ((Colormap) pCmap->mid == defMapID)
 	return;
 
-    /* install default if on same fb */
+    /* install default */
     dixLookupResourceByType((pointer *)&defMap, defMapID, RT_COLORMAP,
 			    serverClient, DixInstallAccess);
-    if (defMap && KdColormapFb (defMap) == fb)
+    if (defMap)
 	(*pCmap->pScreen->InstallColormap)(defMap);
     else
     {
 	/* uninstall and clear colormap pointer */
 	WalkTree(pCmap->pScreen, TellLostMap,
 		 (pointer) &(pCmap->mid));
-	pScreenPriv->pInstalledmap[fb] = 0;
+	pScreenPriv->pInstalledmap = 0;
     }
 }
 
@@ -234,16 +190,12 @@ int
 KdListInstalledColormaps (ScreenPtr pScreen, Colormap *pCmaps)
 {
     KdScreenPriv(pScreen);
-    int		fb;
     int		n = 0;
 
-    for (fb = 0; fb < KD_MAX_FB && pScreenPriv->screen->fb[fb].depth; fb++)
+    if (pScreenPriv->pInstalledmap)
     {
-	if (pScreenPriv->pInstalledmap[fb])
-	{
-	    *pCmaps++ = pScreenPriv->pInstalledmap[fb]->mid;
-	    n++;
-	}
+	*pCmaps++ = pScreenPriv->pInstalledmap->mid;
+	n++;
     }
     return n;
 }
@@ -261,15 +213,14 @@ KdStoreColors (ColormapPtr pCmap, int ndef, xColorItem *pdefs)
     KdScreenPriv(pCmap->pScreen);
     VisualPtr           pVisual;
     xColorItem          expanddefs[KD_MAX_PSEUDO_SIZE];
-    int			fb = KdColormapFb (pCmap);
 
-    if (pCmap != pScreenPriv->pInstalledmap[fb])
+    if (pCmap != pScreenPriv->pInstalledmap)
 	return;
 
     if (!pScreenPriv->card->cfuncs->putColors)
 	return;
 
-    if (pScreenPriv->screen->fb[fb].depth > KD_MAX_PSEUDO_DEPTH)
+    if (pScreenPriv->screen->fb.depth > KD_MAX_PSEUDO_DEPTH)
 	return;
 
     if (!pScreenPriv->enabled)
@@ -287,7 +238,7 @@ KdStoreColors (ColormapPtr pCmap, int ndef, xColorItem *pdefs)
 	pdefs = expanddefs;
     }
 
-    (*pScreenPriv->card->cfuncs->putColors) (pCmap->pScreen, fb, ndef, pdefs);
+    (*pScreenPriv->card->cfuncs->putColors) (pCmap->pScreen, ndef, pdefs);
 
     /* recolor hardware cursor */
     if (pScreenPriv->card->cfuncs->recolorCursor)
diff --git a/hw/kdrive/src/kcurscol.c b/hw/kdrive/src/kcurscol.c
deleted file mode 100644
index 2eef6d9..0000000
--- a/hw/kdrive/src/kcurscol.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright © 1999 Keith Packard
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Keith Packard not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  Keith Packard makes no
- * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.
- *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <kdrive-config.h>
-#endif
-#include "kdrive.h"
-#include "cursorstr.h"
-
-static int
-KdComputeCmapShift (unsigned long mask)
-{
-    int	shift;
-    unsigned long   bit;
-
-    shift = 16;
-    bit = 0x80000000;
-    while (!(mask & bit))
-    {
-	shift--;
-	bit >>= 1;
-    }
-    return shift;
-}
-
-#define Shift(v,d)  ((d) < 0 ? ((v) >> (-d)) : ((v) << (d)))
-
-void
-KdAllocateCursorPixels (ScreenPtr	pScreen,
-			int		fb,
-			CursorPtr	pCursor,
-			Pixel		*source,
-			Pixel		*mask)
-{
-    xColorItem	    sourceColor, maskColor;
-    int		    r, g, b;
-    KdScreenPriv(pScreen);
-
-    if (pScreenPriv->screen->fb[fb].redMask)
-    {
-
-	r = KdComputeCmapShift (pScreenPriv->screen->fb[fb].redMask);
-	g = KdComputeCmapShift (pScreenPriv->screen->fb[fb].greenMask);
-	b = KdComputeCmapShift (pScreenPriv->screen->fb[fb].blueMask);
-	*source = ((Shift(pCursor->foreRed,r) & pScreenPriv->screen->fb[fb].redMask) |
-			    (Shift(pCursor->foreGreen,g) & pScreenPriv->screen->fb[fb].greenMask) |
-			    (Shift(pCursor->foreBlue,b) & pScreenPriv->screen->fb[fb].blueMask));
-	*mask = ((Shift(pCursor->backRed,r) & pScreenPriv->screen->fb[fb].redMask) |
-			  (Shift(pCursor->backGreen,g) & pScreenPriv->screen->fb[fb].greenMask) |
-			  (Shift(pCursor->backBlue,b) & pScreenPriv->screen->fb[fb].blueMask));
-    }
-    else
-    {
-	/*
-	 * Set these to an invalid pixel value so that
-	 * when the store colors comes through, the cursor
-	 * won't get recolored
-	 */
-	*source = ~0;
-	*mask = ~0;
-
-	sourceColor.red = pCursor->foreRed;
-	sourceColor.green = pCursor->foreGreen;
-	sourceColor.blue = pCursor->foreBlue;
-	FakeAllocColor(pScreenPriv->pInstalledmap[fb], &sourceColor);
-	maskColor.red = pCursor->backRed;
-	maskColor.green = pCursor->backGreen;
-	maskColor.blue = pCursor->backBlue;
-	FakeAllocColor(pScreenPriv->pInstalledmap[fb], &maskColor);
-	FakeFreeColor(pScreenPriv->pInstalledmap[fb], sourceColor.pixel);
-	FakeFreeColor(pScreenPriv->pInstalledmap[fb], maskColor.pixel);
-	*source = sourceColor.pixel;
-	*mask = maskColor.pixel;
-    }
-}
diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c
index 76c03fd..d481d50 100644
--- a/hw/kdrive/src/kdrive.c
+++ b/hw/kdrive/src/kdrive.c
@@ -389,7 +389,6 @@ KdParseScreen (KdScreenInfo *screen,
 {
     char    delim;
     char    save[1024];
-    int	    fb;
     int	    i;
     int	    pixels, mm;
 
@@ -403,8 +402,7 @@ KdParseScreen (KdScreenInfo *screen,
     screen->height_mm = 0;
     screen->subpixel_order = kdSubpixelOrder;
     screen->rate = 0;
-    for (fb = 0; fb < KD_MAX_FB; fb++)
-	screen->fb[fb].depth = 0;
+    screen->fb.depth = 0;
     if (!arg)
 	return;
     if (strlen (arg) >= sizeof (save))
@@ -477,25 +475,18 @@ KdParseScreen (KdScreenInfo *screen,
 	screen->randr |= RR_Reflect_Y;
     }
 
-    fb = 0;
-    while (fb < KD_MAX_FB)
+    arg = KdParseFindNext (arg, "x/,", save, &delim);
+    if (save[0])
     {
-	arg = KdParseFindNext (arg, "x/,", save, &delim);
-	if (!save[0])
-	    break;
-	screen->fb[fb].depth = atoi(save);
+	screen->fb.depth = atoi(save);
 	if (delim == '/')
 	{
 	    arg = KdParseFindNext (arg, "x,", save, &delim);
-	    if (!save[0])
-		break;
-	    screen->fb[fb].bitsPerPixel = atoi (save);
+	    if (save[0])
+		screen->fb.bitsPerPixel = atoi (save);
 	}
 	else
-	    screen->fb[fb].bitsPerPixel = 0;
-	if (delim != ',')
-	    break;
-	fb++;
+	    screen->fb.bitsPerPixel = 0;
     }
 
     if (delim == 'x')
@@ -919,7 +910,6 @@ KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
     KdScreenInfo	*screen = kdCurrentScreen;
     KdCardInfo		*card = screen->card;
     KdPrivScreenPtr	pScreenPriv;
-    int			fb;
     /*
      * note that screen->fb is set up for the nominal orientation
      * of the screen; that means if randr is rotated, the values
@@ -949,8 +939,7 @@ KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
     screen->pScreen = pScreen;
     pScreenPriv->screen = screen;
     pScreenPriv->card = card;
-    for (fb = 0; fb < KD_MAX_FB && screen->fb[fb].depth; fb++)
-	pScreenPriv->bytesPerPixel[fb] = screen->fb[fb].bitsPerPixel >> 3;
+    pScreenPriv->bytesPerPixel = screen->fb.bitsPerPixel >> 3;
     pScreenPriv->dpmsState = KD_DPMS_NORMAL;
 #ifdef PANORAMIX
     dixScreenOrigins[pScreen->myNum] = screen->origin;
@@ -964,11 +953,11 @@ KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
      * backing store
      */
     if (!fbSetupScreen (pScreen,
-			screen->fb[0].frameBuffer,
+			screen->fb.frameBuffer,
 			width, height,
 			monitorResolution, monitorResolution,
-			screen->fb[0].pixelStride,
-			screen->fb[0].bitsPerPixel))
+			screen->fb.pixelStride,
+			screen->fb.bitsPerPixel))
     {
 	return FALSE;
     }
@@ -984,36 +973,14 @@ KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
     pScreen->SaveScreen		= KdSaveScreen;
     pScreen->CreateWindow	= KdCreateWindow;
 
-#if KD_MAX_FB > 1
-    if (screen->fb[1].depth)
-    {
-	if (!fbOverlayFinishScreenInit (pScreen,
-					screen->fb[0].frameBuffer,
-					screen->fb[1].frameBuffer,
-					width, height,
-					monitorResolution, monitorResolution,
-					screen->fb[0].pixelStride,
-					screen->fb[1].pixelStride,
-					screen->fb[0].bitsPerPixel,
-					screen->fb[1].bitsPerPixel,
-					screen->fb[0].depth,
-					screen->fb[1].depth))
-	{
-	    return FALSE;
-	}
-    }
-    else
-#endif
+    if (!fbFinishScreenInit (pScreen,
+			     screen->fb.frameBuffer,
+			     width, height,
+			     monitorResolution, monitorResolution,
+			     screen->fb.pixelStride,
+			     screen->fb.bitsPerPixel))
     {
-	if (!fbFinishScreenInit (pScreen,
-				 screen->fb[0].frameBuffer,
-				 width, height,
-				 monitorResolution, monitorResolution,
-				 screen->fb[0].pixelStride,
-				 screen->fb[0].bitsPerPixel))
-	{
-	    return FALSE;
-	}
+	return FALSE;
     }
 
     /*
@@ -1143,7 +1110,6 @@ KdSetPixmapFormats (ScreenInfo	*pScreenInfo)
     KdScreenInfo    *screen;
     int		    i;
     int		    bpp;
-    int		    fb;
     PixmapFormatRec *format;
 
     for (i = 1; i <= 32; i++)
@@ -1159,16 +1125,13 @@ KdSetPixmapFormats (ScreenInfo	*pScreenInfo)
     {
 	for (screen = card->screenList; screen; screen = screen->next)
 	{
-	    for (fb = 0; fb < KD_MAX_FB && screen->fb[fb].depth; fb++)
-	    {
-		bpp = screen->fb[fb].bitsPerPixel;
-		if (bpp == 24)
-		    bpp = 32;
-		if (!depthToBpp[screen->fb[fb].depth])
-		    depthToBpp[screen->fb[fb].depth] = bpp;
-		else if (depthToBpp[screen->fb[fb].depth] != bpp)
-		    return FALSE;
-	    }
+	    bpp = screen->fb.bitsPerPixel;
+	    if (bpp == 24)
+		bpp = 32;
+	    if (!depthToBpp[screen->fb.depth])
+		depthToBpp[screen->fb.depth] = bpp;
+	    else if (depthToBpp[screen->fb.depth] != bpp)
+		return FALSE;
 	}
     }
 
@@ -1214,20 +1177,15 @@ KdAddScreen (ScreenInfo	    *pScreenInfo,
     {
 	unsigned long	visuals;
 	Pixel		rm, gm, bm;
-	int		fb;
 
 	visuals = 0;
 	rm = gm = bm = 0;
-	for (fb = 0; fb < KD_MAX_FB && screen->fb[fb].depth; fb++)
+	if (pScreenInfo->formats[i].depth == screen->fb.depth)
 	{
-	    if (pScreenInfo->formats[i].depth == screen->fb[fb].depth)
-	    {
-		visuals = screen->fb[fb].visuals;
-		rm = screen->fb[fb].redMask;
-		gm = screen->fb[fb].greenMask;
-		bm = screen->fb[fb].blueMask;
-		break;
-	    }
+	    visuals = screen->fb.visuals;
+	    rm = screen->fb.redMask;
+	    gm = screen->fb.greenMask;
+	    bm = screen->fb.blueMask;
 	}
 	fbSetVisualTypesAndMasks (pScreenInfo->formats[i].depth,
 				  visuals,
@@ -1246,10 +1204,9 @@ int
 KdDepthToFb (ScreenPtr	pScreen, int depth)
 {
     KdScreenPriv(pScreen);
-    int	    fb;
 
-    for (fb = 0; fb <= KD_MAX_FB && pScreenPriv->screen->fb[fb].frameBuffer; fb++)
-	if (pScreenPriv->screen->fb[fb].depth == depth)
+    for (fb = 0; fb <= KD_MAX_FB && pScreenPriv->screen->fb.frameBuffer; fb++)
+	if (pScreenPriv->screen->fb.depth == depth)
 	    return fb;
 }
 
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 836b251..78d6414 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -53,10 +53,6 @@
 #define KD_DPMS_POWERDOWN   3
 #define KD_DPMS_MAX	    KD_DPMS_POWERDOWN
 
-#ifndef KD_MAX_FB
-#define KD_MAX_FB   FB_OVERLAY_MAX
-#endif
-
 #define Status int
 
 typedef struct _KdCardInfo {
@@ -106,7 +102,7 @@ typedef struct _KdScreenInfo {
     Bool        softCursor;
     int		mynum;
     DDXPointRec	origin;
-    KdFrameBuffer   fb[KD_MAX_FB];
+    KdFrameBuffer   fb;
 } KdScreenInfo;
 
 typedef struct _KdCardFuncs {
@@ -134,8 +130,8 @@ typedef struct _KdCardFuncs {
     void        (*disableAccel) (ScreenPtr);
     void        (*finiAccel) (ScreenPtr);
 
-    void        (*getColors) (ScreenPtr, int, int, xColorItem *);
-    void        (*putColors) (ScreenPtr, int, int, xColorItem *);
+    void        (*getColors) (ScreenPtr, int, xColorItem *);
+    void        (*putColors) (ScreenPtr, int, xColorItem *);
 
 } KdCardFuncs;
 
@@ -148,11 +144,11 @@ typedef struct {
 
     Bool	    enabled;
     Bool	    closed;
-    int		    bytesPerPixel[KD_MAX_FB];
+    int		    bytesPerPixel;
 
     int		    dpmsState;
 
-    ColormapPtr     pInstalledmap[KD_MAX_FB];         /* current colormap */
+    ColormapPtr     pInstalledmap;                    /* current colormap */
     xColorItem      systemPalette[KD_MAX_PSEUDO_SIZE];/* saved windows colors */
 
     CreateScreenResourcesProcPtr    CreateScreenResources;
@@ -370,7 +366,7 @@ extern GCOps		kdNoopOps;
 
 /* kcmap.c */
 void
-KdSetColormap (ScreenPtr pScreen, int fb);
+KdSetColormap (ScreenPtr pScreen);
 
 void
 KdEnableColormap (ScreenPtr pScreen);
@@ -390,14 +386,6 @@ KdListInstalledColormaps (ScreenPtr pScreen, Colormap *pCmaps);
 void
 KdStoreColors (ColormapPtr pCmap, int ndef, xColorItem *pdefs);
 
-/* kcurscol.c */
-void
-KdAllocateCursorPixels (ScreenPtr	pScreen,
-			int		fb,
-			CursorPtr	pCursor,
-			Pixel		*source,
-			Pixel		*mask);
-
 /* kdrive.c */
 extern miPointerScreenFuncRec kdPointerScreenFuncs;
 
@@ -646,10 +634,10 @@ KdRandRGetTiming (ScreenPtr	    pScreen,
 
 /* kshadow.c */
 Bool
-KdShadowFbAlloc (KdScreenInfo *screen, int fb, Bool rotate);
+KdShadowFbAlloc (KdScreenInfo *screen, Bool rotate);
 
 void
-KdShadowFbFree (KdScreenInfo *screen, int fb);
+KdShadowFbFree (KdScreenInfo *screen);
 
 Bool
 KdShadowSet (ScreenPtr pScreen, int randr, ShadowUpdateProc update, ShadowWindowProc window);
diff --git a/hw/kdrive/src/kmode.c b/hw/kdrive/src/kmode.c
index 1c3c240..38b7bc8 100644
--- a/hw/kdrive/src/kmode.c
+++ b/hw/kdrive/src/kmode.c
@@ -321,12 +321,10 @@ KdTuneMode (KdScreenInfo    *screen,
 	/*
 	 * Fix requested depth and geometry until it works
 	 */
-	if (screen->fb[1].depth)
-	    screen->fb[1].depth = 0;
-	else if (screen->fb[0].depth > 16)
-	    screen->fb[0].depth = 16;
-	else if (screen->fb[0].depth > 8)
-	    screen->fb[0].depth = 8;
+	if (screen->fb.depth > 16)
+	    screen->fb.depth = 16;
+	else if (screen->fb.depth > 8)
+	    screen->fb.depth = 8;
 	else
 	{
 	    t = kdFindPrevSize (KdFindMode (screen, supported));
diff --git a/hw/kdrive/src/kshadow.c b/hw/kdrive/src/kshadow.c
index ea44812..cf3391d 100644
--- a/hw/kdrive/src/kshadow.c
+++ b/hw/kdrive/src/kshadow.c
@@ -26,36 +26,36 @@
 #include "kdrive.h"
 
 Bool
-KdShadowFbAlloc (KdScreenInfo *screen, int fb, Bool rotate)
+KdShadowFbAlloc (KdScreenInfo *screen, Bool rotate)
 {
     int	    paddedWidth;
     void    *buf;
     int	    width = rotate ? screen->height : screen->width;
     int	    height = rotate ? screen->width : screen->height;
-    int	    bpp = screen->fb[fb].bitsPerPixel;
+    int	    bpp = screen->fb.bitsPerPixel;
 
     /* use fb computation for width */
     paddedWidth = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof (FbBits);
     buf = xalloc (paddedWidth * height);
     if (!buf)
 	return FALSE;
-    if (screen->fb[fb].shadow)
-	xfree (screen->fb[fb].frameBuffer);
-    screen->fb[fb].shadow = TRUE;
-    screen->fb[fb].frameBuffer = buf;
-    screen->fb[fb].byteStride = paddedWidth;
-    screen->fb[fb].pixelStride = paddedWidth * 8 / bpp;
+    if (screen->fb.shadow)
+	xfree (screen->fb.frameBuffer);
+    screen->fb.shadow = TRUE;
+    screen->fb.frameBuffer = buf;
+    screen->fb.byteStride = paddedWidth;
+    screen->fb.pixelStride = paddedWidth * 8 / bpp;
     return TRUE;
 }
 
 void
-KdShadowFbFree (KdScreenInfo *screen, int fb)
+KdShadowFbFree (KdScreenInfo *screen)
 {
-    if (screen->fb[fb].shadow)
+    if (screen->fb.shadow)
     {
-	xfree (screen->fb[fb].frameBuffer);
-	screen->fb[fb].frameBuffer = 0;
-	screen->fb[fb].shadow = FALSE;
+	xfree (screen->fb.frameBuffer);
+	screen->fb.frameBuffer = 0;
+	screen->fb.shadow = FALSE;
     }
 }
 
@@ -64,14 +64,12 @@ KdShadowSet (ScreenPtr pScreen, int randr, ShadowUpdateProc update, ShadowWindow
 {
     KdScreenPriv(pScreen);
     KdScreenInfo *screen = pScreenPriv->screen;
-    int	 fb;
 
     shadowRemove (pScreen, pScreen->GetScreenPixmap(pScreen));
-    for (fb = 0; fb < KD_MAX_FB && screen->fb[fb].depth; fb++)
+    if(screen->fb.shadow)
     {
-	if (screen->fb[fb].shadow)
-            return shadowAdd (pScreen, pScreen->GetScreenPixmap(pScreen),
-                              update, window, randr, 0);
+	return shadowAdd (pScreen, pScreen->GetScreenPixmap(pScreen),
+			  update, window, randr, 0);
     }
     return TRUE;
 }
commit 730f7d1c4fae8ca582a4a9998a4dc4b325f98896
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Sat Jan 2 15:06:18 2010 +0600

    kdrive: Remove unused KD_MAX_CARD_ADDRESS macro
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 9865e6f..836b251 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -57,10 +57,6 @@
 #define KD_MAX_FB   FB_OVERLAY_MAX
 #endif
 
-#ifndef KD_MAX_CARD_ADDRESS
-#define KD_MAX_CARD_ADDRESS 8
-#endif
-
 #define Status int
 
 typedef struct _KdCardInfo {
commit 5337ddcfd9dc2a5b823da39df7adaad6692214f0
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Sat Jan 2 14:59:07 2010 +0600

    kdrive: Move Xephyr-specific fields out of KdScreenInfo
    
    memory_base, memory_size, off_screen_base fields in
    KdScreenInfo are used only by fake EXA in Xephyr. Move
    them into Xephyr, cleanup Xfake and Xfbdev.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index b6a2ada..93118a8 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -220,6 +220,22 @@ ephyrWindowLinear (ScreenPtr	pScreen,
   return priv->base + row * priv->bytes_per_line + offset;
 }
 
+/**
+ * Figure out display buffer size. If fakexa is enabled, allocate a larger
+ * buffer so that fakexa has space to put offscreen pixmaps.
+ */
+int
+ephyrBufferHeight(KdScreenInfo *screen)
+{
+    int buffer_height;
+    if (ephyrFuncs.initAccel == NULL)
+	buffer_height = screen->height;
+    else
+	buffer_height = 3 * screen->height;
+    return buffer_height;
+}
+
+
 Bool
 ephyrMapFramebuffer (KdScreenInfo *screen)
 {
@@ -235,22 +251,11 @@ ephyrMapFramebuffer (KdScreenInfo *screen)
   KdSetPointerMatrix (&m);
   
   priv->bytes_per_line = ((screen->width * screen->fb[0].bitsPerPixel + 31) >> 5) << 2;
-  
-  /* point the framebuffer to the data in an XImage */
-  /* If fakexa is enabled, allocate a larger buffer so that fakexa has space to
-   * put offscreen pixmaps.
-   */
-  if (ephyrFuncs.initAccel == NULL)
-    buffer_height = screen->height;
-  else
-    buffer_height = 3 * screen->height;
+
+  buffer_height = ephyrBufferHeight(screen);
 
   priv->base = hostx_screen_init (screen, screen->width, screen->height, buffer_height);
 
-  screen->memory_base  = (CARD8 *) (priv->base);
-  screen->memory_size  = priv->bytes_per_line * buffer_height;
-  screen->off_screen_base = priv->bytes_per_line * screen->height;
-  
   if ((scrpriv->randr & RR_Rotate_0) && !(scrpriv->randr & RR_Reflect_All))
     {
       scrpriv->shadow = FALSE;
diff --git a/hw/kdrive/ephyr/ephyr.h b/hw/kdrive/ephyr/ephyr.h
index f5ea144..cb5e4b5 100644
--- a/hw/kdrive/ephyr/ephyr.h
+++ b/hw/kdrive/ephyr/ephyr.h
@@ -180,6 +180,8 @@ extern Bool ephyrCursorInit(ScreenPtr pScreen);
 
 extern void ephyrCursorEnable(ScreenPtr pScreen);
 
+extern int ephyrBufferHeight(KdScreenInfo *screen);
+
 /* ephyr_draw.c */
 
 Bool
diff --git a/hw/kdrive/ephyr/ephyr_draw.c b/hw/kdrive/ephyr/ephyr_draw.c
index 7b579c2..f9fac80 100644
--- a/hw/kdrive/ephyr/ephyr_draw.c
+++ b/hw/kdrive/ephyr/ephyr_draw.c
@@ -428,6 +428,7 @@ ephyrDrawInit(ScreenPtr pScreen)
     KdScreenPriv(pScreen);
     KdScreenInfo *screen = pScreenPriv->screen;
     EphyrScrPriv *scrpriv = screen->driver;
+    EphyrPriv *priv = screen->card->driver;
     EphyrFakexaPriv *fakexa;
     Bool success;
 
@@ -441,9 +442,9 @@ ephyrDrawInit(ScreenPtr pScreen)
 	return FALSE;
     }
 
-    fakexa->exa->memoryBase = screen->memory_base;
-    fakexa->exa->memorySize = screen->memory_size;
-    fakexa->exa->offScreenBase = screen->off_screen_base;
+    fakexa->exa->memoryBase = (CARD8 *) (priv->base);
+    fakexa->exa->memorySize = priv->bytes_per_line * ephyrBufferHeight(screen);
+    fakexa->exa->offScreenBase = priv->bytes_per_line * screen->height;
 
     /* Since we statically link against EXA, we shouldn't have to be smart about
      * versioning.
diff --git a/hw/kdrive/fake/fake.c b/hw/kdrive/fake/fake.c
index ea88f0e..a4044b6 100644
--- a/hw/kdrive/fake/fake.c
+++ b/hw/kdrive/fake/fake.c
@@ -171,9 +171,6 @@ fakeMapFramebuffer (KdScreenInfo *screen)
     if (priv->base)
 	free (priv->base);
     priv->base = malloc (priv->bytes_per_line * screen->height);
-    screen->memory_base = (CARD8 *) (priv->base);
-    screen->memory_size = 0;
-    screen->off_screen_base = 0;
     
     if (scrpriv->shadow)
     {
diff --git a/hw/kdrive/fbdev/fbdev.c b/hw/kdrive/fbdev/fbdev.c
index cdb4b5c..d4fc5db 100644
--- a/hw/kdrive/fbdev/fbdev.c
+++ b/hw/kdrive/fbdev/fbdev.c
@@ -345,15 +345,12 @@ fbdevMapFramebuffer (KdScreenInfo *screen)
 
     screen->width = priv->var.xres;
     screen->height = priv->var.yres;
-    screen->memory_base = (CARD8 *) (priv->fb);
-    screen->memory_size = priv->fix.smem_len;
 
     if (scrpriv->shadow)
     {
 	if (!KdShadowFbAlloc (screen, 0,
 			      scrpriv->randr & (RR_Rotate_90|RR_Rotate_270)))
 	    return FALSE;
-	screen->off_screen_base = screen->memory_size;
     }
     else
     {
@@ -361,7 +358,6 @@ fbdevMapFramebuffer (KdScreenInfo *screen)
         screen->fb[0].pixelStride = (priv->fix.line_length * 8 /
     				 priv->var.bits_per_pixel);
         screen->fb[0].frameBuffer = (CARD8 *) (priv->fb);
-	screen->off_screen_base = screen->fb[0].byteStride * screen->height;
     }
 
     return TRUE;
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 185995d..9865e6f 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -111,9 +111,6 @@ typedef struct _KdScreenInfo {
     int		mynum;
     DDXPointRec	origin;
     KdFrameBuffer   fb[KD_MAX_FB];
-    CARD8	*memory_base;
-    unsigned long   memory_size;
-    unsigned long   off_screen_base;
 } KdScreenInfo;
 
 typedef struct _KdCardFuncs {
commit 62883b499b72f678ab055de4d0370227ae441370
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Sat Jan 2 13:17:21 2010 +0600

    kdrive: Remove unused KdCardAttr from KdCardInfo
    
    Card attrs are unused in all current kdrive servers, so
    remove it completely to avoid allocating and passing dummy
    values to KdCardInfoAdd.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c
index 6db6e75..c7bfb5b 100644
--- a/hw/kdrive/ephyr/ephyrinit.c
+++ b/hw/kdrive/ephyr/ephyrinit.c
@@ -50,12 +50,8 @@ void processScreenArg (char *screen_size, char *parent_id) ;
 void
 InitCard (char *name)
 {
-    KdCardAttr	attr;
-
     EPHYR_DBG("mark");
-
-
-    KdCardInfoAdd (&ephyrFuncs, &attr, 0);
+    KdCardInfoAdd (&ephyrFuncs, 0);
 }
 
 void
diff --git a/hw/kdrive/fake/fakeinit.c b/hw/kdrive/fake/fakeinit.c
index 0472a71..87c221d 100644
--- a/hw/kdrive/fake/fakeinit.c
+++ b/hw/kdrive/fake/fakeinit.c
@@ -28,9 +28,7 @@
 void
 InitCard (char *name)
 {
-    KdCardAttr	attr;
-
-    KdCardInfoAdd (&fakeFuncs, &attr, 0);
+    KdCardInfoAdd (&fakeFuncs, 0);
 }
 
 void
diff --git a/hw/kdrive/fbdev/fbinit.c b/hw/kdrive/fbdev/fbinit.c
index 77d66f4..93646f6 100644
--- a/hw/kdrive/fbdev/fbinit.c
+++ b/hw/kdrive/fbdev/fbinit.c
@@ -28,9 +28,7 @@
 void
 InitCard (char *name)
 {
-    KdCardAttr	attr;
-
-    KdCardInfoAdd (&fbdevFuncs, &attr, 0);
+    KdCardInfoAdd (&fbdevFuncs, 0);
 }
 
 void
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index b327aa1..185995d 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -63,28 +63,9 @@
 
 #define Status int
 
-/*
- * Configuration information per video card
- */
-
-typedef struct _KdCardAttr {
-    CARD32  io;
-    CARD32  address[KD_MAX_CARD_ADDRESS];
-    int	    naddr;
-
-    /* PCI bus info */
-    CARD16  vendorID;
-    CARD16  deviceID;
-    CARD8   domain;
-    CARD8   bus;
-    CARD8   slot;
-    CARD8   func;
-} KdCardAttr;
-
 typedef struct _KdCardInfo {
     struct _KdCardFuncs	    *cfuncs;
     void		    *closure;
-    KdCardAttr		    attr;
     void		    *driver;
     struct _KdScreenInfo    *screenList;
     int			    selected;
@@ -526,7 +507,6 @@ KdBacktrace (int signum);
 /* kinfo.c */
 KdCardInfo *
 KdCardInfoAdd (KdCardFuncs  *funcs,
-	       KdCardAttr   *attr,
 	       void	    *closure);
 
 KdCardInfo *
diff --git a/hw/kdrive/src/kinfo.c b/hw/kdrive/src/kinfo.c
index 95afc79..0825ee2 100644
--- a/hw/kdrive/src/kinfo.c
+++ b/hw/kdrive/src/kinfo.c
@@ -29,7 +29,6 @@ KdCardInfo  *kdCardInfo;
 
 KdCardInfo *
 KdCardInfoAdd (KdCardFuncs  *funcs,
-	       KdCardAttr   *attr,
 	       void	    *closure)
 {
     KdCardInfo	*ci, **prev;
@@ -40,7 +39,6 @@ KdCardInfoAdd (KdCardFuncs  *funcs,
     for (prev = &kdCardInfo; *prev; prev = &(*prev)->next);
     *prev = ci;
     ci->cfuncs = funcs;
-    ci->attr = *attr;
     ci->closure = closure;
     ci->screenList = 0;
     ci->selected = 0;
commit 6c2b3a4247d10a50699ffa6abb643c5e959eefa8
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Mon Jan 4 14:07:04 2010 +0600

    kdrive: Add option to compile out input drivers
    
    Add --without-kdrive-{kbd,mouse,evdev} configure options disabling
    Linux keyboard driver, Linux mouse drivers (ps2, bus,ms),
    and Linux evdev driver.
    
    Build all drivers by default as before.
    
    Acked-by: Dan Nicholson <dbn.lists at gmail.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/configure.ac b/configure.ac
index 7e2c6a5..e0ddd48 100644
--- a/configure.ac
+++ b/configure.ac
@@ -640,6 +640,10 @@ AC_ARG_ENABLE(kdrive,         AS_HELP_STRING([--enable-kdrive], [Build kdrive se
 AC_ARG_ENABLE(xephyr,         AS_HELP_STRING([--enable-xephyr], [Build the kdrive Xephyr server (default: auto)]), [XEPHYR=$enableval], [XEPHYR=auto])
 AC_ARG_ENABLE(xfake,          AS_HELP_STRING([--enable-xfake], [Build the kdrive 'fake' server (default: auto)]), [XFAKE=$enableval], [XFAKE=auto])
 AC_ARG_ENABLE(xfbdev,         AS_HELP_STRING([--enable-xfbdev], [Build the kdrive framebuffer device server (default: auto)]), [XFBDEV=$enableval], [XFBDEV=auto])
+dnl kdrive options
+AC_ARG_ENABLE(kdrive-kbd,     AS_HELP_STRING([--enable-kdrive-kbd], [Build kbd driver for kdrive (default: enabled)]), [KDRIVE_KBD=$enableval], [KDRIVE_KBD=yes])
+AC_ARG_ENABLE(kdrive-mouse,   AC_HELP_STRING([--enable-kdrive-mouse], [Build mouse driver for kdrive (default: enabled)]), [KDRIVE_MOUSE=$enableval], [KDRIVE_MOUSE=yes])
+AC_ARG_ENABLE(kdrive-evdev,   AC_HELP_STRING([--enable-kdrive-evdev], [Build evdev driver for kdrive (default: enabled)]), [KDRIVE_EVDEV=$enableval], [KDRIVE_EVDEV=yes])
 
 
 dnl chown/chmod to be setuid root as part of build
@@ -1991,6 +1995,10 @@ XEPHYR_LIBS=
 XEPHYR_INCS=
 
 AM_CONDITIONAL(KDRIVE, [test x$KDRIVE = xyes])
+AM_CONDITIONAL(KDRIVE_KBD, test "x$KDRIVE_KBD" = xyes)
+AM_CONDITIONAL(KDRIVE_EVDEV, test "x$KDRIVE_EVDEV" = xyes)
+AM_CONDITIONAL(KDRIVE_MOUSE, test "x$KDRIVE_MOUSE" = xyes)
+
 if test "$KDRIVE" = yes; then
     AC_DEFINE(KDRIVESERVER,1,[Build Kdrive X server])
     AC_DEFINE(KDRIVEDDXACTIONS,,[Build kdrive ddx])
@@ -2023,6 +2031,16 @@ if test "$KDRIVE" = yes; then
         fi
     fi
 
+    if test "x$KDRIVE_KBD" = xyes; then
+       AC_DEFINE(KDRIVE_KBD, 1, [Enable KDrive kbd driver])
+    fi
+    if test "x$KDRIVE_EVDEV" = xyes; then
+       AC_DEFINE(KDRIVE_EVDEV, 1, [Enable KDrive evdev driver])
+    fi
+    if test "x$KDRIVE_MOUSE" = xyes; then
+       AC_DEFINE(KDRIVE_MOUSE, 1, [Enable KDrive mouse driver])
+    fi
+
     XEPHYR_REQUIRED_LIBS="x11 $LIBXEXT xfont xau xdmcp"
     if test "x$XV" = xyes; then
         XEPHYR_REQUIRED_LIBS="$XEPHYR_REQUIRED_LIBS xv"
diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c
index 2b72b4e..6db6e75 100644
--- a/hw/kdrive/ephyr/ephyrinit.c
+++ b/hw/kdrive/ephyr/ephyrinit.c
@@ -40,6 +40,11 @@ extern Bool noGlxVisualInit;
 #endif
 extern Bool   ephyrNoXV;
 
+#ifdef KDRIVE_EVDEV
+extern KdPointerDriver	LinuxEvdevMouseDriver;
+extern KdKeyboardDriver LinuxEvdevKeyboardDriver;
+#endif
+
 void processScreenArg (char *screen_size, char *parent_id) ;
 
 void
@@ -66,11 +71,11 @@ InitInput (int argc, char **argv)
   KdPointerInfo *pi;
 
   KdAddKeyboardDriver(&EphyrKeyboardDriver);
-#ifdef linux
+#ifdef KDRIVE_EVDEV
   KdAddKeyboardDriver(&LinuxEvdevKeyboardDriver);
 #endif
   KdAddPointerDriver(&EphyrMouseDriver);
-#ifdef linux
+#ifdef KDRIVE_EVDEV
   KdAddPointerDriver(&LinuxEvdevMouseDriver);
 #endif
 
diff --git a/hw/kdrive/linux/Makefile.am b/hw/kdrive/linux/Makefile.am
index 13df142..2f89b8f 100644
--- a/hw/kdrive/linux/Makefile.am
+++ b/hw/kdrive/linux/Makefile.am
@@ -6,19 +6,22 @@ AM_CFLAGS = -DHAVE_DIX_CONFIG_H
 
 noinst_LTLIBRARIES = liblinux.la
 
-if TSLIB
-TSLIB_C = tslib.c
+liblinux_la_SOURCES =
+
+liblinux_la_SOURCES += linux.c klinux.h
+
+if KDRIVE_KBD
+liblinux_la_SOURCES += keyboard.c
+endif
+
+if KDRIVE_EVDEV
+liblinux_la_SOURCES += evdev.c
 endif
 
-KDRIVE_HW_SOURCES =	\
-	evdev.c		\
-	keyboard.c	\
-	linux.c
-
-liblinux_la_SOURCES = 	\
-	bus.c		\
-	mouse.c		\
-	ms.c		\
-	ps2.c		\
-	$(KDRIVE_HW_SOURCES) \
-	$(TSLIB_C)
+if KDRIVE_MOUSE
+liblinux_la_SOURCES += mouse.c bus.c ms.c ps2.c
+endif
+
+if TSLIB
+liblinux_la_SOURCES += tslib.c
+endif
diff --git a/hw/kdrive/linux/linux.c b/hw/kdrive/linux/linux.c
index e56ffb4..9863c14 100644
--- a/hw/kdrive/linux/linux.c
+++ b/hw/kdrive/linux/linux.c
@@ -33,6 +33,22 @@
 #include <X11/keysym.h>
 #include <linux/apm_bios.h>
 
+#ifdef KDRIVE_MOUSE
+extern KdPointerDriver	LinuxMouseDriver;
+extern KdPointerDriver	Ps2MouseDriver;
+extern KdPointerDriver	MsMouseDriver;
+#endif
+#ifdef TSLIB
+extern KdPointerDriver	TsDriver;
+#endif
+#ifdef KDRIVE_EVDEV
+extern KdPointerDriver	LinuxEvdevMouseDriver;
+extern KdKeyboardDriver LinuxEvdevKeyboardDriver;
+#endif
+#ifdef KDRIVE_KBD
+extern KdKeyboardDriver	LinuxKeyboardDriver;
+#endif
+
 static int  vtno;
 int  LinuxConsoleFd;
 int  LinuxApmFd = -1;
@@ -345,15 +361,21 @@ LinuxFini (void)
 void
 KdOsAddInputDrivers (void)
 {
+#ifdef KDRIVE_MOUSE
     KdAddPointerDriver(&LinuxMouseDriver);
     KdAddPointerDriver(&MsMouseDriver);
     KdAddPointerDriver(&Ps2MouseDriver);
+#endif
 #ifdef TSLIB
     KdAddPointerDriver(&TsDriver);
 #endif
+#ifdef KDRIVE_EVDEV
     KdAddPointerDriver(&LinuxEvdevMouseDriver);
-    KdAddKeyboardDriver(&LinuxKeyboardDriver);
     KdAddKeyboardDriver(&LinuxEvdevKeyboardDriver);
+#endif
+#ifdef KDRIVE_KBD
+    KdAddKeyboardDriver(&LinuxKeyboardDriver);
+#endif
 }
 
 static void
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 8bd8c25..b327aa1 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -623,16 +623,6 @@ KdRingBell (KdKeyboardInfo      *ki,
             int                 pitch,
             int                 duration);
 
-extern KdPointerDriver	LinuxMouseDriver;
-extern KdPointerDriver	LinuxEvdevMouseDriver;
-extern KdPointerDriver	Ps2MouseDriver;
-extern KdPointerDriver	BusMouseDriver;
-extern KdPointerDriver	MsMouseDriver;
-extern KdPointerDriver	TsDriver;
-extern KdKeyboardDriver	LinuxKeyboardDriver;
-extern KdKeyboardDriver LinuxEvdevKeyboardDriver;
-extern KdOsFuncs	LinuxFuncs;
-
 extern KdPointerDriver	VxWorksMouseDriver;
 extern KdKeyboardDriver	VxWorksKeyboardDriver;
 extern KdOsFuncs	VxWorksFuncs;
diff --git a/include/kdrive-config.h.in b/include/kdrive-config.h.in
index 14efb56..0e54aa1 100644
--- a/include/kdrive-config.h.in
+++ b/include/kdrive-config.h.in
@@ -19,6 +19,15 @@
 /* Support tslib touchscreen abstraction library */
 #undef TSLIB
 
+/* Support KDrive kbd driver */
+#undef KDRIVE_KBD
+
+/* Support KDrive mouse driver */
+#undef KDRIVE_MOUSE
+
+/* Support KDrive evdev driver */
+#undef KDRIVE_EVDEV
+
 /* Verbose debugging output hilarity */
 #undef DEBUG
 
commit 72ba717b1d639e94fa9ab56ca026131edc020a30
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Sat Jan 2 15:03:24 2010 +0600

    kdrive: Remove unused KdCardInfo::needSync field
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 2041d71..8bd8c25 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -90,7 +90,6 @@ typedef struct _KdCardInfo {
     int			    selected;
     struct _KdCardInfo	    *next;
 
-    Bool		    needSync;
     int			    lastMarker;
 } KdCardInfo;
 
commit d21b41cdb5e89eb428f36b19e965f0ab49e051d9
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Sat Jan 2 13:21:25 2010 +0600

    kdrive: Remove .gitignore left from SDL server
    
    SDL server is gone, no need to keep its .gitignore anymore.
    
    Reviewed-by: Gaetan Nadon <memsize at videotron.ca>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>

diff --git a/hw/kdrive/sdl/.gitignore b/hw/kdrive/sdl/.gitignore
deleted file mode 100644
index 072341b..0000000
--- a/hw/kdrive/sdl/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-#		Add & Override for this directory and it's subdirectories
-Xsdl
commit 6f265d55a61f9be323583b8acacae783be72bda9
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jan 5 13:15:25 2010 +1000

    dix: don't update the slave coordinates from the VCK.
    
    A keyboard event from a device with both valuators and keys will be posted
    through the VCK. In this case, do not update the slave device coordinates
    from the VCK - they're always 0/0. Leave them as-is, for the next pointer
    event will continue where it left.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/getevents.c b/dix/getevents.c
index 2df32e8..bfde2e9 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -630,9 +630,12 @@ updateFromMaster(EventListPtr events, DeviceIntPtr dev, int type, int *num_event
     if (master && master->last.slave != dev)
     {
         CreateClassesChangedEvent(events, master, dev, type);
-        updateSlaveDeviceCoords(master, dev);
+        if (IsPointerDevice(master))
+        {
+            updateSlaveDeviceCoords(master, dev);
+            master->last.numValuators = dev->last.numValuators;
+        }
         master->last.slave = dev;
-        master->last.numValuators = dev->last.numValuators;
         (*num_events)++;
         events++;
     }
commit 326429badfc76885e4652ddc72860810c0e8d102
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Nov 10 14:56:36 2009 -0500

    modes: Remove the ClockRanges type
    
    ba2d39dd5428cb5922b797a1d4ea45b859412b40 introduced warnings:
    
    xf86Mode.c: In function ‘xf86CheckModeForDriver’:
    xf86Mode.c:986: warning: passing argument 1 of ‘modeInClockRange’ from incompatible pointer type
    xf86Mode.c:253: note: expected ‘ClockRangePtr’ but argument is of type ‘ClockRangesPtr’
    xf86Mode.c:1002: warning: passing argument 1 of ‘modeInClockRange’ from incompatible pointer type
    xf86Mode.c:253: note: expected ‘ClockRangePtr’ but argument is of type ‘ClockRangesPtr’
    
    Because I foolishly didn't notice that we had types with nearly
    identical members named ClockRange and ClockRanges.  The latter
    contained an extra 'strategy' member at the end, which claimed to be
    needed by the vidmode extension.  Of course, this was a lie: the only time
    we'd use it was in mode validation, for drivers using LOOKUP_CLKDIV2 with
    non-programmable clocks.  The only driver using LOOKUP_CLKDIV2 is
    rendition, which has a programmable clock.  The only driver using the
    ClockRanges type was smi, which did not use it for its 'strategy' member,
    so has been fixed to use ClockRange instead.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Mode.c b/hw/xfree86/common/xf86Mode.c
index 4a948d7..949d4fc 100644
--- a/hw/xfree86/common/xf86Mode.c
+++ b/hw/xfree86/common/xf86Mode.c
@@ -941,14 +941,13 @@ xf86InitialCheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode,
 ModeStatus
 xf86CheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, int flags)
 {
-    ClockRangesPtr cp;
+    ClockRangePtr cp;
     int i, k, gap, minimumGap = CLOCK_TOLERANCE + 1;
     int extraFlags = 0;
     int clockIndex = -1;
     int MulFactor = 1;
     int DivFactor = 1;
     int ModePrivFlags = 0;
-    Bool allowDiv2;
     ModeStatus status = MODE_NOMODE;
 
     /* Some sanity checking */
@@ -1005,8 +1004,7 @@ xf86CheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, int flags)
 		 * find a matching clock.
 		 */
     
-		allowDiv2 = (cp->strategy & LOOKUP_CLKDIV2) != 0;
-		i = xf86GetNearestClock(scrp, mode->Clock, allowDiv2,
+		i = xf86GetNearestClock(scrp, mode->Clock, 0,
 			   cp->ClockDivFactor, cp->ClockMulFactor, &k);
 		/*
 		 * If the clock is too far from the requested clock, this
@@ -1194,7 +1192,7 @@ xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
     int saveType;
     PixmapFormatRec *BankFormat;
     ClockRangePtr cp;
-    ClockRangesPtr storeClockRanges;
+    ClockRangePtr storeClockRanges;
     int numTimings = 0;
     range hsync[MAX_HSYNC];
     range vrefresh[MAX_VREFRESH];
@@ -1300,8 +1298,7 @@ xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
     }
 
     /*
-     * Store the clockRanges for later use by the VidMode extension. Must
-     * also store the strategy, since ClockDiv2 flag is stored there.
+     * Store the clockRanges for later use by the VidMode extension.
      */
     storeClockRanges = scrp->clockRanges;
     while (storeClockRanges != NULL) {
@@ -1309,11 +1306,10 @@ xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
     }
     for (cp = clockRanges; cp != NULL; cp = cp->next,
 	   	storeClockRanges = storeClockRanges->next) {
-	storeClockRanges = xnfalloc(sizeof(ClockRanges));
+	storeClockRanges = xnfalloc(sizeof(ClockRange));
 	if (scrp->clockRanges == NULL)
 	    scrp->clockRanges = storeClockRanges;
 	memcpy(storeClockRanges, cp, sizeof(ClockRange));
-	storeClockRanges->strategy = strategy;
     }
 
     /* Determine which pixmap format to pass to miScanLineWidth() */
diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h
index 7b0b758..de1f1b6 100644
--- a/hw/xfree86/common/xf86str.h
+++ b/hw/xfree86/common/xf86str.h
@@ -241,20 +241,6 @@ typedef struct x_ClockRange {
     int			PrivFlags;
 } ClockRange, *ClockRangePtr;
 
-/* Need to store the strategy with clockRange for VidMode extension */
-typedef struct x_ClockRanges {
-    struct x_ClockRanges *next;
-    int			minClock;
-    int			maxClock;
-    int			clockIndex;	/* -1 for programmable clocks */
-    Bool		interlaceAllowed;
-    Bool		doubleScanAllowed;
-    int			ClockMulFactor;
-    int			ClockDivFactor;
-    int			PrivFlags;
-    int			strategy;
-} ClockRanges, *ClockRangesPtr;
-
 /*
  * The driverFunc. xorgDriverFuncOp specifies the action driver should
  * perform. If requested option is not supported function should return
@@ -786,7 +772,7 @@ typedef struct _ScrnInfoRec {
     Bool		silkenMouse;
 
     /* Storage for clockRanges and adjustFlags for use with the VidMode ext */
-    ClockRangesPtr	clockRanges;
+    ClockRangePtr	clockRanges;
     int			adjustFlags;
 
     /*
commit 13c8bd3fde3b0831921e59f84936022a16379d63
Author: Alan Coopersmith <alan.coopersmith at sun.com>
Date:   Mon Jan 4 18:21:54 2010 -0800

    CloseDevice: call XkbRemoveResourceClient before freeing key class struct
    
    XkbRemoveResourceClient() returns immediately if dev->key is NULL.
    CloseDevice calls XkbRemoveResourceClient until it removes all resources.
    
    If we free dev->key and NULL it before XkbRemoveResourceClient, then
    infinite loop ensues, and the server appears to hang on exit or crash.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at sun.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/devices.c b/dix/devices.c
index 6329d28..92b95ed 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -842,6 +842,9 @@ CloseDevice(DeviceIntPtr dev)
     if(dev->valuator && dev->valuator->accelScheme.AccelCleanupProc)
 	dev->valuator->accelScheme.AccelCleanupProc(dev);
 
+    while (dev->xkb_interest)
+	XkbRemoveResourceClient((DevicePtr)dev,dev->xkb_interest->resource);
+
     xfree(dev->name);
 
     classes = (ClassesPtr)&dev->key;
@@ -853,9 +856,6 @@ CloseDevice(DeviceIntPtr dev)
         FreeAllDeviceClasses(classes);
     }
 
-    while (dev->xkb_interest)
-	XkbRemoveResourceClient((DevicePtr)dev,dev->xkb_interest->resource);
-
     if (DevHasCursor(dev) && dev->spriteInfo->sprite) {
         xfree(dev->spriteInfo->sprite->spriteTrace);
         xfree(dev->spriteInfo->sprite);
commit e707612e9de4e5e1d91dc1a8152810912d7e18bb
Author: Michel Dänzer <daenzer at vmware.com>
Date:   Mon Jan 4 09:07:48 2010 +0100

    EXA: Restore migration call in exaDoPutImage().
    
    Turns out this is still necessary if the driver PrepareAccess hook succeeds.
    
    Signed-off-by: Michel Dänzer <daenzer at vmware.com>
    Tested-by: Maarten Maathuis <madman2003 at gmail.com>
    Tested-by: Andrew Chant <andrew.chant+debian at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index 4c55a4c..4680c37 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -172,6 +172,17 @@ exaDoPutImage (DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
     if (pExaScr->swappedOut)
 	return FALSE;
 
+    if (pExaScr->do_migration) {
+	ExaMigrationRec pixmaps[1];
+
+	pixmaps[0].as_dst = TRUE;
+	pixmaps[0].as_src = FALSE;
+	pixmaps[0].pPix = pPix;
+	pixmaps[0].pReg = DamagePendingRegion(pExaPixmap->pDamage);
+
+	exaDoMigration (pixmaps, 1, TRUE);
+    }
+
     pPix = exaGetOffscreenPixmap (pDrawable, &xoff, &yoff);
 
     if (!pPix)
commit e10072b7c74a6f5e24f6dfa37e73688d1f3425e3
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Sat Jan 2 05:43:28 2010 +0600

    Add Xephyr.man to .gitignore
    
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by:  Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/ephyr/.gitignore b/hw/kdrive/ephyr/.gitignore
index f35f006..bfe7e08 100644
--- a/hw/kdrive/ephyr/.gitignore
+++ b/hw/kdrive/ephyr/.gitignore
@@ -1,2 +1,3 @@
 #		Add & Override for this directory and it's subdirectories
 Xephyr
+Xephyr.man
commit fb26cb793c6eba189050662c566f7ea0559bd486
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Sat Jan 2 05:43:27 2010 +0600

    Remove unused pShadow field from drivers' private structures
    
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/ephyr/ephyr.h b/hw/kdrive/ephyr/ephyr.h
index 5d58a21..f5ea144 100644
--- a/hw/kdrive/ephyr/ephyr.h
+++ b/hw/kdrive/ephyr/ephyr.h
@@ -63,7 +63,6 @@ typedef struct _ephyrFakexaPriv {
 typedef struct _ephyrScrPriv {
     Rotation	randr;
     Bool	shadow;
-    PixmapPtr	pShadow;
     DamagePtr   pDamage;
     EphyrFakexaPriv *fakexa;
 } EphyrScrPriv;
diff --git a/hw/kdrive/fake/fake.h b/hw/kdrive/fake/fake.h
index 88d2096..3c4a51b 100644
--- a/hw/kdrive/fake/fake.h
+++ b/hw/kdrive/fake/fake.h
@@ -38,7 +38,6 @@ typedef struct _fakePriv {
 typedef struct _fakeScrPriv {
     Rotation	randr;
     Bool	shadow;
-    PixmapPtr	pShadow;
 } FakeScrPriv;
 
 extern KdCardFuncs  fakeFuncs;
diff --git a/hw/kdrive/fbdev/fbdev.h b/hw/kdrive/fbdev/fbdev.h
index 2125ec8..3da8e47 100644
--- a/hw/kdrive/fbdev/fbdev.h
+++ b/hw/kdrive/fbdev/fbdev.h
@@ -46,7 +46,6 @@ typedef struct _fbdevPriv {
 typedef struct _fbdevScrPriv {
     Rotation			randr;
     Bool			shadow;
-    PixmapPtr			pShadow;
 } FbdevScrPriv;
 
 extern KdCardFuncs  fbdevFuncs;
commit 2c85d72fc7bd013af327321ad5d626dc73c3caf0
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Sat Jan 2 05:43:26 2010 +0600

    Do not check xfree argument for NULL
    
    xfree itself checks for NULL, and even this is not necessary
    as passing NULL to free(3) is safe.
    
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 254fcbc..b6a2ada 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -1074,8 +1074,7 @@ MouseInit (KdPointerInfo *pi)
     ((EphyrPointerPrivate *)pi->driverPrivate)->enabled = FALSE;
     pi->nAxes = 3;
     pi->nButtons = 32;
-    if (pi->name)
-        xfree(pi->name);
+    xfree(pi->name);
     pi->name = strdup("Xephyr virtual mouse");
     ephyrMouse = pi;
     return Success;
@@ -1125,8 +1124,7 @@ EphyrKeyboardInit (KdKeyboardInfo *ki)
   }
   ki->minScanCode = ephyrKeySyms.minKeyCode;
   ki->maxScanCode = ephyrKeySyms.maxKeyCode;
-  if (ki->name)
-      xfree(ki->name);
+  xfree(ki->name);
   ki->name = strdup("Xephyr virtual keyboard");
   ephyrKbd = ki;
   return Success;
diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index f741d74..5f5fd3b 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -440,10 +440,9 @@ ephyrDRIClipNotify (WindowPtr a_win,
     is_ok = TRUE ;
 
 out:
-    if (rects) {
-        xfree (rects) ;
-        rects = NULL ;
-    }
+    xfree (rects) ;
+    rects = NULL ;
+
     EPHYR_LOG ("leave. is_ok:%d\n", is_ok) ;
     /*do cleanup here*/
 }
@@ -566,10 +565,9 @@ EphyrDuplicateVisual (unsigned int a_screen,
 
     is_ok = TRUE ;
 out:
-    if (new_visuals) {
-        xfree (new_visuals) ;
-        new_visuals = NULL ;
-    }
+    xfree (new_visuals) ;
+    new_visuals = NULL ;
+
     EPHYR_LOG ("leave\n") ; 
     return is_ok ;
 }
@@ -1254,10 +1252,9 @@ ProcXF86DRIGetDrawableInfo (register ClientPtr client)
                       sizeof(drm_clip_rect_t) * rep.numBackClipRects,
                       (char *)backClipRects);
     }
-    if (clipRects) {
-        xfree(clipRects);
-        clipRects = NULL ;
-    }
+    xfree(clipRects);
+    clipRects = NULL ;
+
     EPHYR_LOG ("leave\n") ;
 
     return (client->noClientException);
diff --git a/hw/kdrive/ephyr/ephyrglxext.c b/hw/kdrive/ephyr/ephyrglxext.c
index 63c4ced..a0278cc 100644
--- a/hw/kdrive/ephyr/ephyrglxext.c
+++ b/hw/kdrive/ephyr/ephyrglxext.c
@@ -243,10 +243,9 @@ ephyrGLXGetVisualConfigsReal (__GLXclientState *a_cl,
 
 out:
     EPHYR_LOG ("leave\n") ;
-    if (props_buf) {
-        xfree (props_buf) ;
-        props_buf = NULL ;
-    }
+    xfree (props_buf) ;
+    props_buf = NULL ;
+
     return res ;
 }
 
@@ -301,10 +300,9 @@ ephyrGLXGetFBConfigsSGIXReal (__GLXclientState *a_cl,
 
 out:
     EPHYR_LOG ("leave\n") ;
-    if (props_buf) {
-        xfree (props_buf) ;
-        props_buf = NULL ;
-    }
+    xfree (props_buf) ;
+    props_buf = NULL ;
+
     return res ;
 }
 
@@ -391,14 +389,12 @@ ephyrGLXQueryServerString(__GLXclientState *a_cl, GLbyte *a_pc)
 
 out:
     EPHYR_LOG ("leave\n") ;
-    if (server_string) {
-        xfree (server_string) ;
-        server_string = NULL;
-    }
-    if (buf) {
-        xfree (buf);
-        buf = NULL;
-    }
+    xfree (server_string) ;
+    server_string = NULL;
+
+    xfree (buf);
+    buf = NULL;
+
     return res ;
 }
 
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index 41c0b75..f4a1b9d 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -485,10 +485,8 @@ ephyrHostEncodingsDelete (EphyrHostEncoding *a_encodings,
     if (!a_encodings)
         return ;
     for (i=0; i < a_num_encodings; i++) {
-        if (a_encodings[i].name) {
-            xfree (a_encodings[i].name) ;
-            a_encodings[i].name = NULL ;
-        }
+        xfree (a_encodings[i].name) ;
+        a_encodings[i].name = NULL ;
     }
     xfree (a_encodings) ;
 }
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index 5058ebe..bb2ee10 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -371,10 +371,8 @@ ephyrXVPrivDelete (EphyrXVPriv *a_this)
         ephyrHostXVAdaptorArrayDelete (a_this->host_adaptors) ;
         a_this->host_adaptors = NULL ;
     }
-    if (a_this->adaptors) {
-        xfree (a_this->adaptors) ;
-        a_this->adaptors = NULL ;
-    }
+    xfree (a_this->adaptors) ;
+    a_this->adaptors = NULL ;
     xfree (a_this) ;
     EPHYR_LOG ("leave\n") ;
 }
@@ -675,14 +673,11 @@ ephyrXVPrivRegisterAdaptors (EphyrXVPriv *a_this,
     is_ok = TRUE ;
 
 out:
-    if (registered_adaptors) {
-        xfree (registered_adaptors) ;
-        registered_adaptors = NULL ;
-    }
-    if (adaptors) {
-        xfree (adaptors) ;
-        adaptors=NULL ;
-    }
+    xfree (registered_adaptors) ;
+    registered_adaptors = NULL ;
+    xfree (adaptors) ;
+    adaptors = NULL ;
+
     EPHYR_LOG ("leave\n") ;
     return is_ok ;
 }
diff --git a/hw/kdrive/fake/fake.c b/hw/kdrive/fake/fake.c
index ff59798..ea88f0e 100644
--- a/hw/kdrive/fake/fake.c
+++ b/hw/kdrive/fake/fake.c
@@ -457,9 +457,8 @@ void
 fakeCardFini (KdCardInfo *card)
 {
     FakePriv	*priv = card->driver;
-    
-    if (priv->base)
-	free (priv->base);
+
+    free (priv->base);
     xfree (priv);
 }
 
diff --git a/hw/kdrive/linux/bus.c b/hw/kdrive/linux/bus.c
index 93c3ea5..de9b90f 100644
--- a/hw/kdrive/linux/bus.c
+++ b/hw/kdrive/linux/bus.c
@@ -75,8 +75,7 @@ BusInit (KdPointerInfo *pi)
             if ((fd = open (BusNames[i], 0)) >= 0)
             {
                 close(fd);
-                if (pi->path)
-                    xfree(pi->path);
+                xfree(pi->path);
                 pi->path = strdup(BusNames[i]);
                 return Success;
             }
diff --git a/hw/kdrive/linux/keyboard.c b/hw/kdrive/linux/keyboard.c
index 53d3c3a..6eed7ae 100644
--- a/hw/kdrive/linux/keyboard.c
+++ b/hw/kdrive/linux/keyboard.c
@@ -737,11 +737,9 @@ LinuxKeyboardInit (KdKeyboardInfo *ki)
     if (!ki)
         return !Success;
 
-    if (ki->path)
-        xfree(ki->path);
+    xfree(ki->path);
     ki->path = strdup("console");
-    if (ki->name)
-        xfree(ki->name);
+    xfree(ki->name);
     ki->name = strdup("Linux console keyboard");
 
     readKernelMapping (ki);
diff --git a/hw/kdrive/linux/tslib.c b/hw/kdrive/linux/tslib.c
index a0b989d..322ccc7 100644
--- a/hw/kdrive/linux/tslib.c
+++ b/hw/kdrive/linux/tslib.c
@@ -175,10 +175,8 @@ TslibInit (KdPointerInfo *pi)
 static void
 TslibFini (KdPointerInfo *pi)
 {
-    if (pi->driverPrivate) {
-        xfree(pi->driverPrivate);
-        pi->driverPrivate = NULL;
-    }
+    xfree(pi->driverPrivate);
+    pi->driverPrivate = NULL;
 }
 
 
diff --git a/hw/kdrive/src/kinfo.c b/hw/kdrive/src/kinfo.c
index af64156..95afc79 100644
--- a/hw/kdrive/src/kinfo.c
+++ b/hw/kdrive/src/kinfo.c
@@ -138,40 +138,28 @@ KdFreePointer(KdPointerInfo *pi)
 {
     InputOption *option, *prev = NULL;
 
-    if (pi->name)
-        xfree(pi->name);
-    if (pi->path)
-        xfree(pi->path);
+    xfree(pi->name);
+    xfree(pi->path);
 
     for (option = pi->options; option; option = option->next) {
-        if (prev)
-            xfree(prev);
-        if (option->key)
-            xfree(option->key);
-        if (option->value)
-            xfree(option->value);
+        xfree(prev);
+        xfree(option->key);
+        xfree(option->value);
         prev = option;
     }
 
-    if (prev)
-        xfree(prev);
-
+    xfree(prev);
     xfree(pi);
 }
 
 void
 KdFreeKeyboard(KdKeyboardInfo *ki)
 {
-    if (ki->name)
-        xfree(ki->name);
-    if (ki->path)
-        xfree(ki->path);
-    if (ki->xkbRules)
-        xfree(ki->xkbRules);
-    if (ki->xkbModel)
-        xfree(ki->xkbModel);
-    if (ki->xkbLayout)
-        xfree(ki->xkbLayout);
+    xfree(ki->name);
+    xfree(ki->path);
+    xfree(ki->xkbRules);
+    xfree(ki->xkbModel);
+    xfree(ki->xkbLayout);
     ki->next = NULL;
     xfree(ki);
 }
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index 1ceb8c6..27ecc5d 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -247,20 +247,18 @@ KdXVFreeAdaptor(XvAdaptorPtr pAdaptor)
 {
    int i;
 
-   if(pAdaptor->name)
-      xfree(pAdaptor->name);
+   xfree(pAdaptor->name);
 
    if(pAdaptor->pEncodings) {
       XvEncodingPtr pEncode = pAdaptor->pEncodings;
 
       for(i = 0; i < pAdaptor->nEncodings; i++, pEncode++) {
-          if(pEncode->name) xfree(pEncode->name);
+          xfree(pEncode->name);
       }
       xfree(pAdaptor->pEncodings);
    }
 
-   if(pAdaptor->pFormats)
-      xfree(pAdaptor->pFormats);
+   xfree(pAdaptor->pFormats);
 
    if(pAdaptor->pPorts) {
       XvPortPtr pPort = pAdaptor->pPorts;
@@ -283,17 +281,15 @@ KdXVFreeAdaptor(XvAdaptorPtr pAdaptor)
       XvAttributePtr pAttribute = pAdaptor->pAttributes;
 
       for(i = 0; i < pAdaptor->nAttributes; i++, pAttribute++) {
-          if(pAttribute->name) xfree(pAttribute->name);
+          xfree(pAttribute->name);
       }
 
       xfree(pAdaptor->pAttributes);
    }
 
-   if(pAdaptor->nImages)
-      xfree(pAdaptor->pImages);
+   xfree(pAdaptor->pImages);
 
-   if(pAdaptor->devPriv.ptr)
-      xfree(pAdaptor->devPriv.ptr);
+   xfree(pAdaptor->devPriv.ptr);
 }
 
 static Bool
@@ -1157,12 +1153,9 @@ KdXVCloseScreen(int i, ScreenPtr pScreen)
        KdXVFreeAdaptor(pa);
   }
 
-  if(pxvs->pAdaptors)
-    xfree(pxvs->pAdaptors);
-
+  xfree(pxvs->pAdaptors);
   xfree(ScreenPriv);
 
-
   return TRUE;
 }
 
commit 15bc35c6e44c65812de5c3e85ec8bbf78b032ded
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Sat Jan 2 05:43:25 2010 +0600

    Remove trailing whitespace
    
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/fbdev/fbdev.c b/hw/kdrive/fbdev/fbdev.c
index 4eeca28..cdb4b5c 100644
--- a/hw/kdrive/fbdev/fbdev.c
+++ b/hw/kdrive/fbdev/fbdev.c
@@ -38,12 +38,12 @@ fbdevInitialize (KdCardInfo *card, FbdevPriv *priv)
     int		    k;
     unsigned long   off;
 
-    if (fbdevDevicePath == NULL) 
+    if (fbdevDevicePath == NULL)
       fbdevDevicePath = "/dev/fb0";
 
     if ((priv->fd = open(fbdevDevicePath, O_RDWR)) < 0)
       {
-	ErrorF("Error opening framebuffer %s: %s\n", 
+	ErrorF("Error opening framebuffer %s: %s\n",
 	       fbdevDevicePath, strerror(errno));
         return FALSE;
       }
@@ -68,8 +68,8 @@ fbdevInitialize (KdCardInfo *card, FbdevPriv *priv)
 				   PROT_READ|PROT_WRITE,
 				   MAP_SHARED,
 				   priv->fd, 0);
-    
-    if (priv->fb_base == (char *)-1) 
+
+    if (priv->fb_base == (char *)-1)
     {
         perror("ERROR: mmap framebuffer fails!");
 	close (priv->fd);
@@ -88,14 +88,14 @@ fbdevCardInit (KdCardInfo *card)
     priv = (FbdevPriv *) xalloc (sizeof (FbdevPriv));
     if (!priv)
 	return FALSE;
-    
+
     if (!fbdevInitialize (card, priv))
     {
 	xfree (priv);
 	return FALSE;
     }
     card->driver = priv;
-    
+
     return TRUE;
 }
 
@@ -124,7 +124,7 @@ static void
 fbdevConvertMonitorTiming (const KdMonitorTiming *t, struct fb_var_screeninfo *var)
 {
     memset (var, 0, sizeof (struct fb_var_screeninfo));
-    
+
     var->xres = t->horizontal;
     var->yres = t->vertical;
     var->xres_virtual = t->horizontal;
@@ -160,10 +160,10 @@ fbdevScreenInitialize (KdScreenInfo *screen, FbdevScrPriv *scrpriv)
     int k;
 
     k = ioctl (priv->fd, FBIOGET_VSCREENINFO, &var);
-    
+
     if (!screen->width || !screen->height)
     {
-	if (k >= 0) 
+	if (k >= 0)
 	{
 	    screen->width = var.xres;
 	    screen->height = var.yres;
@@ -177,7 +177,7 @@ fbdevScreenInitialize (KdScreenInfo *screen, FbdevScrPriv *scrpriv)
     }
     if (!screen->fb[0].depth)
     {
-	if (k >= 0) 
+	if (k >= 0)
 	    screen->fb[0].depth = var.bits_per_pixel;
 	else
 	    screen->fb[0].depth = 16;
@@ -217,7 +217,7 @@ fbdevScreenInitialize (KdScreenInfo *screen, FbdevScrPriv *scrpriv)
     ioctl (priv->fd, FBIOGET_VSCREENINFO, &priv->var);
     depth = priv->var.bits_per_pixel;
     gray = priv->var.grayscale;
-    
+
     switch (priv->fix.visual) {
     case FB_VISUAL_PSEUDOCOLOR:
 	if (gray)
@@ -309,7 +309,7 @@ fbdevScreenInit (KdScreenInfo *screen)
     }
     return TRUE;
 }
-    
+
 void *
 fbdevWindowLinear (ScreenPtr	pScreen,
 		   CARD32	row,
@@ -338,19 +338,19 @@ fbdevMapFramebuffer (KdScreenInfo *screen)
 	scrpriv->shadow = TRUE;
     else
 	scrpriv->shadow = FALSE;
-    
+
     KdComputePointerMatrix (&m, scrpriv->randr, screen->width, screen->height);
-    
+
     KdSetPointerMatrix (&m);
-    
+
     screen->width = priv->var.xres;
     screen->height = priv->var.yres;
     screen->memory_base = (CARD8 *) (priv->fb);
     screen->memory_size = priv->fix.smem_len;
-    
+
     if (scrpriv->shadow)
     {
-	if (!KdShadowFbAlloc (screen, 0, 
+	if (!KdShadowFbAlloc (screen, 0,
 			      scrpriv->randr & (RR_Rotate_90|RR_Rotate_270)))
 	    return FALSE;
 	screen->off_screen_base = screen->memory_size;
@@ -358,12 +358,12 @@ fbdevMapFramebuffer (KdScreenInfo *screen)
     else
     {
         screen->fb[0].byteStride = priv->fix.line_length;
-        screen->fb[0].pixelStride = (priv->fix.line_length * 8 / 
+        screen->fb[0].pixelStride = (priv->fix.line_length * 8 /
     				 priv->var.bits_per_pixel);
         screen->fb[0].frameBuffer = (CARD8 *) (priv->fb);
 	screen->off_screen_base = screen->fb[0].byteStride * screen->height;
     }
-    
+
     return TRUE;
 }
 
@@ -458,25 +458,25 @@ fbdevRandRGetInfo (ScreenPtr pScreen, Rotation *rotations)
     RRScreenSizePtr	    pSize;
     Rotation		    randr;
     int			    n;
-    
+
     *rotations = RR_Rotate_All|RR_Reflect_All;
-    
+
     for (n = 0; n < pScreen->numDepths; n++)
 	if (pScreen->allowedDepths[n].numVids)
 	    break;
     if (n == pScreen->numDepths)
 	return FALSE;
-    
+
     pSize = RRRegisterSize (pScreen,
 			    screen->width,
 			    screen->height,
 			    screen->width_mm,
 			    screen->height_mm);
-    
+
     randr = KdSubRotation (scrpriv->randr, screen->randr);
-    
+
     RRSetCurrentConfig (pScreen, randr, 0, pSize);
-    
+
     return TRUE;
 }
 
@@ -512,20 +512,20 @@ fbdevRandRSetConfig (ScreenPtr		pScreen,
 	KdDisableScreen (pScreen);
 
     oldscr = *scrpriv;
-    
+
     oldwidth = screen->width;
     oldheight = screen->height;
     oldmmwidth = pScreen->mmWidth;
     oldmmheight = pScreen->mmHeight;
-    
+
     /*
      * Set new configuration
      */
-    
+
     scrpriv->randr = KdAddRotation (screen->randr, randr);
 
     fbdevUnmapFramebuffer (screen);
-    
+
     if (!fbdevMapFramebuffer (screen))
 	goto bail4;
 
@@ -546,9 +546,9 @@ fbdevRandRSetConfig (ScreenPtr		pScreen,
 				    screen->fb[0].bitsPerPixel,
 				    screen->fb[0].byteStride,
 				    screen->fb[0].frameBuffer);
-    
+
     /* set the subpixel order */
-    
+
     KdSetSubpixelOrder (pScreen, scrpriv->randr);
     if (wasEnabled)
 	KdEnableScreen (pScreen);
@@ -563,7 +563,7 @@ bail4:
     pScreen->height = oldheight;
     pScreen->mmWidth = oldmmwidth;
     pScreen->mmHeight = oldmmheight;
-    
+
     if (wasEnabled)
 	KdEnableScreen (pScreen);
     return FALSE;
@@ -573,7 +573,7 @@ Bool
 fbdevRandRInit (ScreenPtr pScreen)
 {
     rrScrPrivPtr    pScrPriv;
-    
+
     if (!RRScreenInit (pScreen))
 	return FALSE;
 
@@ -594,7 +594,7 @@ fbdevCreateColormap (ColormapPtr pmap)
     int			i;
     int			nent;
     xColorItem		*pdefs;
-    
+
     switch (priv->fix.visual) {
     case FB_VISUAL_STATIC_PSEUDOCOLOR:
 	pVisual = pmap->pVisual;
@@ -639,7 +639,7 @@ fbdevFinishInitScreen (ScreenPtr pScreen)
     if (!fbdevRandRInit (pScreen))
 	return FALSE;
 #endif
-    
+
     return TRUE;
 }
 
@@ -663,7 +663,7 @@ fbdevEnable (ScreenPtr pScreen)
     int			k;
 
     priv->var.activate = FB_ACTIVATE_NOW|FB_CHANGE_CMAP_VBL;
-    
+
     /* display it on the LCD */
     k = ioctl (priv->fd, FBIOPUT_VSCREENINFO, &priv->var);
     if (k < 0)
@@ -671,13 +671,13 @@ fbdevEnable (ScreenPtr pScreen)
 	perror ("FBIOPUT_VSCREENINFO");
 	return FALSE;
     }
-    
+
     if (priv->fix.visual == FB_VISUAL_DIRECTCOLOR)
     {
 	struct fb_cmap	cmap;
 	int		i;
 
-	for (i = 0; 
+	for (i = 0;
 	     i < (1 << priv->var.red.length) ||
 	     i < (1 << priv->var.green.length) ||
 	     i < (1 << priv->var.blue.length); i++)
@@ -742,7 +742,7 @@ void
 fbdevCardFini (KdCardInfo *card)
 {
     FbdevPriv	*priv = card->driver;
-    
+
     munmap (priv->fb_base, priv->fix.smem_len);
     close (priv->fd);
     xfree (priv);
diff --git a/hw/kdrive/fbdev/fbdev.h b/hw/kdrive/fbdev/fbdev.h
index 9e322da..2125ec8 100644
--- a/hw/kdrive/fbdev/fbdev.h
+++ b/hw/kdrive/fbdev/fbdev.h
@@ -42,7 +42,7 @@ typedef struct _fbdevPriv {
     char			*fb;
     char			*fb_base;
 } FbdevPriv;
-    
+
 typedef struct _fbdevScrPriv {
     Rotation			randr;
     Bool			shadow;
@@ -63,7 +63,7 @@ fbdevScreenInit (KdScreenInfo *screen);
 
 Bool
 fbdevScreenInitialize (KdScreenInfo *screen, FbdevScrPriv *scrpriv);
-    
+
 Bool
 fbdevInitScreen (ScreenPtr pScreen);
 
@@ -122,7 +122,7 @@ fbdevSetShadow (ScreenPtr pScreen);
 
 Bool
 fbdevCreateColormap (ColormapPtr pmap);
-    
+
 #ifdef RANDR
 Bool
 fbdevRandRGetInfo (ScreenPtr pScreen, Rotation *rotations);
diff --git a/hw/kdrive/fbdev/fbinit.c b/hw/kdrive/fbdev/fbinit.c
index de80c79..77d66f4 100644
--- a/hw/kdrive/fbdev/fbinit.c
+++ b/hw/kdrive/fbdev/fbinit.c
@@ -60,11 +60,11 @@ ddxProcessArgument (int argc, char **argv, int i)
 {
   if (!strcmp (argv[i], "-fb"))
     {
-      if (i+1 < argc) 
+      if (i+1 < argc)
 	{
 	  fbdevDevicePath = argv[i+1];
 	  return 2;
-	} 
+	}
       UseMsg();
       exit(1);
     }
@@ -86,18 +86,18 @@ KdCardFuncs	fbdevFuncs = {
     fbdevRestore,	    /* restore */
     fbdevScreenFini,	    /* scrfini */
     fbdevCardFini,	    /* cardfini */
-    
+
     0,			    /* initCursor */
     0,			    /* enableCursor */
     0,			    /* disableCursor */
     0,			    /* finiCursor */
     0,			    /* recolorCursor */
-    
+
     0,			    /* initAccel */
     0,			    /* enableAccel */
     0,			    /* disableAccel */
     0,			    /* finiAccel */
-    
+
     fbdevGetColors,    	    /* getColors */
     fbdevPutColors,	    /* putColors */
 };
diff --git a/hw/kdrive/linux/evdev.c b/hw/kdrive/linux/evdev.c
index 096a2dd..485a2b5 100644
--- a/hw/kdrive/linux/evdev.c
+++ b/hw/kdrive/linux/evdev.c
@@ -48,7 +48,7 @@ typedef struct _kevdev {
     int                            abs[ABS_MAX + 1];
     int                            prevabs[ABS_MAX + 1];
     long                    key[NBITS(KEY_MAX + 1)];
-    
+
     /* supported device info */
     long                    relbits[NBITS(REL_MAX + 1)];
     long                    absbits[NBITS(ABS_MAX + 1)];
@@ -106,12 +106,12 @@ EvdevPtrMotion (KdPointerInfo    *pi, struct input_event *ev)
             int a;
             for (a = 0; a <= ke->max_rel; a++)
             {
-                if (ISBITSET (ke->relbits, a)) 
+                if (ISBITSET (ke->relbits, a))
 		{
                     if (a == 0)
                         KdEnqueuePointerEvent(pi, flags, ke->rel[a], 0, 0);
                     else if (a == 1)
-                        KdEnqueuePointerEvent(pi, flags, 0, ke->rel[a], 0); 
+                        KdEnqueuePointerEvent(pi, flags, 0, ke->rel[a], 0);
                 }
 		ke->rel[a] = 0;
             }
@@ -131,9 +131,9 @@ EvdevPtrMotion (KdPointerInfo    *pi, struct input_event *ev)
             ErrorF ("\n");
             break;
         }
-    
-    if (ev->code == REL_WHEEL) {           
-      for (i = 0; i < abs (ev->value); i++) 
+
+    if (ev->code == REL_WHEEL) {
+      for (i = 0; i < abs (ev->value); i++)
       {
         if (ev->value > 0)
           flags |= KD_BUTTON_4;
@@ -150,7 +150,7 @@ EvdevPtrMotion (KdPointerInfo    *pi, struct input_event *ev)
         KdEnqueuePointerEvent (pi, flags, 0, 0, 0);
       }
     }
-    
+
 }
 
 static void
@@ -164,7 +164,7 @@ EvdevPtrRead (int evdevPort, void *closure)
 
     n = read (evdevPort, &events, NUM_EVENTS * sizeof (struct input_event));
     if (n <= 0) {
-        if (errno == ENODEV) 
+        if (errno == ENODEV)
             DeleteInputDeviceRequest(pi->dixdev);
         return;
     }
@@ -231,7 +231,7 @@ EvdevPtrInit (KdPointerInfo *pi)
 
 static Status
 EvdevPtrEnable (KdPointerInfo *pi)
-{        
+{
     int fd;
     unsigned long   ev[NBITS(EV_MAX)];
     Kevdev            *ke;
@@ -352,7 +352,7 @@ EvdevPtrFini (KdPointerInfo *pi)
 
 
 /*
- * Evdev keyboard functions 
+ * Evdev keyboard functions
  */
 
 static void
@@ -374,7 +374,7 @@ EvdevKbdRead (int evdevPort, void *closure)
 
     n = read (evdevPort, &events, NUM_EVENTS * sizeof (struct input_event));
     if (n <= 0) {
-        if (errno == ENODEV) 
+        if (errno == ENODEV)
             DeleteInputDeviceRequest(ki->dixdev);
         return;
     }
@@ -395,7 +395,7 @@ static Status
 EvdevKbdInit (KdKeyboardInfo *ki)
 {
     int fd;
-    
+
     if (!ki->path) {
         ErrorF("Couldn't find evdev device path\n");
         return BadValue;
diff --git a/hw/kdrive/linux/keyboard.c b/hw/kdrive/linux/keyboard.c
index 79cf598..53d3c3a 100644
--- a/hw/kdrive/linux/keyboard.c
+++ b/hw/kdrive/linux/keyboard.c
@@ -231,7 +231,7 @@ readKernelMapping(KdKeyboardInfo *ki)
         return;
 
     fd = LinuxConsoleFd;
-    
+
     minKeyCode = NR_KEYS;
     maxKeyCode = 0;
     row = 0;
@@ -241,7 +241,7 @@ readKernelMapping(KdKeyboardInfo *ki)
         kbe.kb_index = LNX_KEY_INDEX(i);
 
         k = ki->keySyms.map + row * ki->keySyms.mapWidth;
-	
+
 	for (j = 0; j < ki->keySyms.mapWidth; ++j)
 	{
 	    unsigned short kval;
@@ -463,7 +463,7 @@ readKernelMapping(KdKeyboardInfo *ki)
 		k[j] = (kbe.kb_value & 0xFF) + 0x1008FF00;
 		break;
 #endif
-		
+
 	    default:
 		break;
 	    }
@@ -720,7 +720,7 @@ static void
 LinuxKeyboardDisable (KdKeyboardInfo *ki)
 {
     int fd;
-    
+
     if (!ki)
         return;
 
diff --git a/hw/kdrive/linux/linux.c b/hw/kdrive/linux/linux.c
index f76c2cb..e56ffb4 100644
--- a/hw/kdrive/linux/linux.c
+++ b/hw/kdrive/linux/linux.c
@@ -79,7 +79,7 @@ LinuxInit (void)
 	vtno = kdVirtualTerminal;
     else
     {
-	if ((fd = open("/dev/tty0",O_WRONLY,0)) < 0) 
+	if ((fd = open("/dev/tty0",O_WRONLY,0)) < 0)
 	{
 	    FatalError(
 		       "LinuxInit: Cannot open /dev/tty0 (%s)\n",
@@ -129,8 +129,8 @@ LinuxSetSwitchMode (int mode)
 {
     struct sigaction	act;
     struct vt_mode	VT;
-    
-    if (ioctl(LinuxConsoleFd, VT_GETMODE, &VT) < 0) 
+
+    if (ioctl(LinuxConsoleFd, VT_GETMODE, &VT) < 0)
     {
 	FatalError ("LinuxInit: VT_GETMODE failed\n");
     }
@@ -141,7 +141,7 @@ LinuxSetSwitchMode (int mode)
 	sigemptyset (&act.sa_mask);
 	act.sa_flags = 0;
 	sigaction (SIGUSR1, &act, 0);
-    
+
 	VT.mode = mode;
 	VT.relsig = SIGUSR1;
 	VT.acqsig = SIGUSR1;
@@ -152,12 +152,12 @@ LinuxSetSwitchMode (int mode)
 	sigemptyset (&act.sa_mask);
 	act.sa_flags = 0;
 	sigaction (SIGUSR1, &act, 0);
-    
+
 	VT.mode = mode;
 	VT.relsig = 0;
 	VT.acqsig = 0;
     }
-    if (ioctl(LinuxConsoleFd, VT_SETMODE, &VT) < 0) 
+    if (ioctl(LinuxConsoleFd, VT_SETMODE, &VT) < 0)
     {
 	FatalError("LinuxInit: VT_SETMODE failed\n");
     }
@@ -237,7 +237,7 @@ LinuxEnable (void)
      */
     LinuxApmFd = open ("/dev/apm_bios", 2);
     if (LinuxApmFd < 0 && errno == ENOENT)
-	LinuxApmFd = open ("/dev/misc/apm_bios", 2); 
+	LinuxApmFd = open ("/dev/misc/apm_bios", 2);
     if (LinuxApmFd >= 0)
     {
 	LinuxApmRunning = TRUE;
@@ -245,7 +245,7 @@ LinuxEnable (void)
 	RegisterBlockAndWakeupHandlers (LinuxApmBlock, LinuxApmWakeup, 0);
 	AddEnabledDevice (LinuxApmFd);
     }
-	
+
     /*
      * now get the VT
      */
@@ -308,8 +308,8 @@ LinuxFini (void)
 	 * Find a legal VT to switch to, either the one we started from
 	 * or the lowest active one that isn't ours
 	 */
-	if (activeVT < 0 || 
-	    activeVT == vts.v_active || 
+	if (activeVT < 0 ||
+	    activeVT == vts.v_active ||
 	    !(vts.v_state & (1 << activeVT)))
 	{
 	    for (activeVT = 1; activeVT < 16; activeVT++)
diff --git a/hw/kdrive/linux/mouse.c b/hw/kdrive/linux/mouse.c
index 6f399b5..007263e 100644
--- a/hw/kdrive/linux/mouse.c
+++ b/hw/kdrive/linux/mouse.c
@@ -112,7 +112,7 @@ MouseFlush (Kbufio *b, char *buf, int size)
     CARD32  done = now + 100;
     int	    c;
     int	    n = 0;
-    
+
     while ((c = MouseReadByte (b, done - now)) != -1)
     {
 	if (buf)
@@ -170,7 +170,7 @@ static Bool
 MouseWriteByte (int fd, unsigned char c, int timeout)
 {
     int	ret;
-    
+
 #ifdef DEBUG_BYTES
     ErrorF ("\tput %02x\n", c);
 #endif
@@ -234,7 +234,7 @@ typedef struct _kmouse {
     int			invalid;/* total invalid bytes for this protocol */
     unsigned long	state;	/* private per protocol, init to prot->state */
 } Kmouse;
-    
+
 static int mouseValid (KdPointerInfo *pi, unsigned char *ev, int ne)
 {
     Kmouse		*km = pi->driverPrivate;
@@ -271,16 +271,16 @@ static Bool MouseReasonable (KdPointerInfo *pi, unsigned long flags, int dx, int
 {
     Kmouse		*km = pi->driverPrivate;
 
-    if (km->stage == MouseWorking) 
+    if (km->stage == MouseWorking)
 	return TRUE;
-    if (dx < -50 || dx > 50) 
+    if (dx < -50 || dx > 50)
     {
 #ifdef DEBUG
 	ErrorF ("Large X %d\n", dx);
 #endif
 	return FALSE;
     }
-    if (dy < -50 || dy > 50) 
+    if (dy < -50 || dy > 50)
     {
 #ifdef DEBUG
 	ErrorF ("Large Y %d\n", dy);
@@ -299,7 +299,7 @@ static Bool ps2Parse (KdPointerInfo *pi, unsigned char *ev, int ne)
     int		    dx, dy, dz;
     unsigned long   flags;
     unsigned long   flagsrelease = 0;
-    
+
     flags = KD_MOUSE_DELTA;
     if (ev[0] & 4)
 	flags |= KD_BUTTON_2;
@@ -307,7 +307,7 @@ static Bool ps2Parse (KdPointerInfo *pi, unsigned char *ev, int ne)
 	flags |= KD_BUTTON_3;
     if (ev[0] & 1)
 	flags |= KD_BUTTON_1;
-    
+
     if (ne > 3)
     {
 	dz = (int) (signed char) ev[3];
@@ -322,7 +322,7 @@ static Bool ps2Parse (KdPointerInfo *pi, unsigned char *ev, int ne)
 	    flagsrelease = KD_BUTTON_5;
 	}
     }
-	
+
     dx = ev[1];
     if (ev[0] & 0x10)
 	dx -= 256;
@@ -407,14 +407,14 @@ static const KmouseProt exps2Prot = {
 #define PSM_4DMOUSE_ID          6
 #define PSM_4DPLUS_ID           8
 
-static unsigned char	ps2_init[] = { 
+static unsigned char	ps2_init[] = {
     PSMC_ENABLE_DEV,
     0,
 };
 
 #define NINIT_PS2   1
 
-static unsigned char    wheel_3button_init[] = { 
+static unsigned char    wheel_3button_init[] = {
     PSMC_SET_SAMPLING_RATE, 200,
     PSMC_SET_SAMPLING_RATE, 100,
     PSMC_SET_SAMPLING_RATE,  80,
@@ -431,7 +431,7 @@ static unsigned char    wheel_5button_init[] = {
     PSMC_SET_SAMPLING_RATE, 200,
     PSMC_SET_SAMPLING_RATE, 200,
     PSMC_SET_SAMPLING_RATE,  80,
-    PSMC_SEND_DEV_ID, 
+    PSMC_SEND_DEV_ID,
     0
 };
 
@@ -439,8 +439,8 @@ static unsigned char    wheel_5button_init[] = {
 
 static unsigned char	intelli_init[] = {
     PSMC_SET_SAMPLING_RATE, 200,
-    PSMC_SET_SAMPLING_RATE, 100, 
-    PSMC_SET_SAMPLING_RATE,  80, 
+    PSMC_SET_SAMPLING_RATE, 100,
+    PSMC_SET_SAMPLING_RATE,  80,
     0
 };
 
@@ -453,7 +453,7 @@ ps2SkipInit (KdPointerInfo *pi, int ninit, Bool ret_next)
     int	    c = -1;
     int	    skipping;
     Bool    waiting;
-    
+
     skipping = 0;
     waiting = FALSE;
     while (ninit || ret_next)
@@ -486,7 +486,7 @@ ps2Init (KdPointerInfo *pi)
     int		    id;
     unsigned char   *init;
     int		    ninit;
-    
+
     /* Send Intellimouse initialization sequence */
     MouseWriteBytes (km->iob.fd, intelli_init, strlen ((char *) intelli_init), 100);
     /*
@@ -530,7 +530,7 @@ static Bool busParse (KdPointerInfo *pi, unsigned char *ev, int ne)
     Kmouse	    *km = pi->driverPrivate;
     int		    dx, dy;
     unsigned long   flags;
-    
+
     flags = KD_MOUSE_DELTA;
     dx = (signed char) ev[1];
     dy = -(signed char) ev[2];
@@ -636,14 +636,14 @@ static Bool logiParse (KdPointerInfo *pi, unsigned char *ev, int ne)
     unsigned long   flags;
 
     flags = KD_MOUSE_DELTA;
-    
+
     if (ne == 3)
     {
 	if (ev[0] & 0x20)
 	    flags |= KD_BUTTON_1;
 	if (ev[0] & 0x10)
 	    flags |= KD_BUTTON_3;
-    
+
 	dx = (signed char)(((ev[0] & 0x03) << 6) | (ev[1] & 0x3F));
 	dy = (signed char)(((ev[0] & 0x0C) << 4) | (ev[2] & 0x3F));
 	flags |= km->state & KD_BUTTON_2;
@@ -686,7 +686,7 @@ static Bool mscParse (KdPointerInfo *pi, unsigned char *ev, int ne)
     unsigned long   flags;
 
     flags = KD_MOUSE_DELTA;
-    
+
     if (!(ev[0] & 0x4))
 	flags |= KD_BUTTON_1;
     if (!(ev[0] & 0x2))
@@ -871,7 +871,7 @@ MouseRead (int mousePort, void *closure)
 		    switch (km->stage)
 		    {
 		    case MouseBroken:
-#ifdef DEBUG			
+#ifdef DEBUG
 			ErrorF ("Mouse protocol %s seems OK\n",
 				km->prot->name);
 #endif
@@ -939,7 +939,7 @@ MouseInit (KdPointerInfo *pi)
 
     if (!pi)
         return BadImplementation;
-    
+
     if (!pi->path || strcmp(pi->path, "auto") == 0) {
         for (i = 0; i < NUM_DEFAULT_MOUSE; i++) {
             fd = open (kdefaultMouse[i], 2);
@@ -952,7 +952,7 @@ MouseInit (KdPointerInfo *pi)
     else {
         fd = open (pi->path, 2);
     }
-	    
+
     if (fd < 0)
         return BadMatch;
 
@@ -1008,7 +1008,7 @@ MouseDisable (KdPointerInfo *pi)
     Kmouse *km;
     if (!pi || !pi->driverPrivate)
         return;
-    
+
     km = pi->driverPrivate;
     KdUnregisterFd (pi, km->iob.fd, TRUE);
 }
diff --git a/hw/kdrive/linux/ms.c b/hw/kdrive/linux/ms.c
index 5786ed1..b6151cd 100644
--- a/hw/kdrive/linux/ms.c
+++ b/hw/kdrive/linux/ms.c
@@ -83,7 +83,7 @@ MsRead (int port, void *closure)
 		flags |= KD_BUTTON_1;
 	    if (b[0] & 0x10)
 		flags |= KD_BUTTON_3;
-	    
+
 	    dx = (char)(((b[0] & 0x03) << 6) | (b[1] & 0x3F));
 	    dy = (char)(((b[0] & 0x0C) << 4) | (b[2] & 0x3F));
             n -= 3;
@@ -103,8 +103,8 @@ MsInit (KdPointerInfo *pi)
         pi->path = strdup("/dev/mouse");
     if (!pi->name)
         pi->name = strdup("Microsoft protocol mouse");
-    
-    return Success; 
+
+    return Success;
 }
 
 static Status
diff --git a/hw/kdrive/linux/ps2.c b/hw/kdrive/linux/ps2.c
index 3967584..552a3c7 100644
--- a/hw/kdrive/linux/ps2.c
+++ b/hw/kdrive/linux/ps2.c
@@ -99,7 +99,7 @@ Ps2Read (int ps2Port, void *closure)
 		flags |= right_button;
 	    if (b[0] & 1)
 		flags |= left_button;
-		
+
 	    dx = b[1];
 	    if (b[0] & 0x10)
 		dx -= 256;
@@ -146,7 +146,7 @@ static Status
 Ps2Enable (KdPointerInfo *pi)
 {
     int fd;
-    
+
     if (!pi)
         return BadImplementation;
 
diff --git a/hw/kdrive/linux/tslib.c b/hw/kdrive/linux/tslib.c
index 7cc23e6..a0b989d 100644
--- a/hw/kdrive/linux/tslib.c
+++ b/hw/kdrive/linux/tslib.c
@@ -9,7 +9,7 @@
  * Copyright © 2002 MontaVista Software Inc.
  * Copyright © 2005 OpenedHand Ltd.
  * Copyright © 2006 Nokia Corporation
- * 
+ *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
  * the above copyright notice appear in all copies and that both that
@@ -76,7 +76,7 @@ TsRead (int fd, void *closure)
         if (event.pressure) {
             flags = KD_BUTTON_1;
 
-            /* 
+            /*
              * Here we test for the touch screen driver actually being on the
              * touch screen, if it is we send absolute coordinates. If not,
              * then we send delta's so that we can track the entire vga screen.
@@ -127,7 +127,7 @@ TslibEnable (KdPointerInfo *pi)
     }
 
     KdRegisterFd(private->fd, TsRead, pi);
-  
+
     return Success;
 }
 
@@ -155,7 +155,7 @@ TslibInit (KdPointerInfo *pi)
 
     if (!pi || !pi->dixdev)
         return !Success;
-    
+
     pi->driverPrivate = (struct TslibPrivate *)
                         xcalloc(sizeof(struct TslibPrivate), 1);
     if (!pi->driverPrivate)
diff --git a/hw/kdrive/src/kcmap.c b/hw/kdrive/src/kcmap.c
index 2c33e79..053e719 100644
--- a/hw/kdrive/src/kcmap.c
+++ b/hw/kdrive/src/kcmap.c
@@ -43,10 +43,10 @@ KdSetColormap (ScreenPtr pScreen, int fb)
 	return;
     if (pScreenPriv->screen->fb[fb].depth > KD_MAX_PSEUDO_DEPTH)
 	return;
-    
+
     if (!pScreenPriv->enabled)
 	return;
-    
+
     if (!pCmap)
 	return;
 
@@ -54,12 +54,12 @@ KdSetColormap (ScreenPtr pScreen, int fb)
      * Make DIX convert pixels into RGB values -- this handles
      * true/direct as well as pseudo/static visuals
      */
-    
+
     for (i = 0; i < (1 << pScreenPriv->screen->fb[fb].depth); i++)
 	pixels[i] = i;
 
     QueryColors (pCmap, (1 << pScreenPriv->screen->fb[fb].depth), pixels, colors);
-    
+
     for (i = 0; i < (1 << pScreenPriv->screen->fb[fb].depth); i++)
     {
 	defs[i].pixel = i;
@@ -187,7 +187,7 @@ KdInstallColormap (ColormapPtr pCmap)
     pScreenPriv->pInstalledmap[fb] = pCmap;
 
     KdSetColormap (pCmap->pScreen, fb);
-    
+
     /* Tell X clients of the new colormap */
     WalkTree(pCmap->pScreen, TellGainedMap, (pointer) &(pCmap->mid));
 }
@@ -195,7 +195,7 @@ KdInstallColormap (ColormapPtr pCmap)
 /*
  * KdUninstallColormap
  *
- * This function uninstalls a colormap by either installing 
+ * This function uninstalls a colormap by either installing
  * the default X colormap or erasing the installed colormap pointer.
  * The default X colormap itself cannot be uninstalled.
  */
@@ -236,7 +236,7 @@ KdListInstalledColormaps (ScreenPtr pScreen, Colormap *pCmaps)
     KdScreenPriv(pScreen);
     int		fb;
     int		n = 0;
-    
+
     for (fb = 0; fb < KD_MAX_FB && pScreenPriv->screen->fb[fb].depth; fb++)
     {
 	if (pScreenPriv->pInstalledmap[fb])
@@ -265,16 +265,16 @@ KdStoreColors (ColormapPtr pCmap, int ndef, xColorItem *pdefs)
 
     if (pCmap != pScreenPriv->pInstalledmap[fb])
 	return;
-    
+
     if (!pScreenPriv->card->cfuncs->putColors)
 	return;
-    
+
     if (pScreenPriv->screen->fb[fb].depth > KD_MAX_PSEUDO_DEPTH)
 	return;
-    
+
     if (!pScreenPriv->enabled)
 	return;
-    
+
     /* Check for DirectColor or TrueColor being simulated on a PseudoColor device. */
     pVisual = pCmap->pVisual;
     if ((pVisual->class | DynamicClass) == DirectColor)
@@ -288,7 +288,7 @@ KdStoreColors (ColormapPtr pCmap, int ndef, xColorItem *pdefs)
     }
 
     (*pScreenPriv->card->cfuncs->putColors) (pCmap->pScreen, fb, ndef, pdefs);
-    
+
     /* recolor hardware cursor */
     if (pScreenPriv->card->cfuncs->recolorCursor)
 	(*pScreenPriv->card->cfuncs->recolorCursor) (pCmap->pScreen, ndef, pdefs);
diff --git a/hw/kdrive/src/kcurscol.c b/hw/kdrive/src/kcurscol.c
index 6a17df3..2eef6d9 100644
--- a/hw/kdrive/src/kcurscol.c
+++ b/hw/kdrive/src/kcurscol.c
@@ -31,7 +31,7 @@ KdComputeCmapShift (unsigned long mask)
 {
     int	shift;
     unsigned long   bit;
-    
+
     shift = 16;
     bit = 0x80000000;
     while (!(mask & bit))
@@ -47,7 +47,7 @@ KdComputeCmapShift (unsigned long mask)
 void
 KdAllocateCursorPixels (ScreenPtr	pScreen,
 			int		fb,
-			CursorPtr	pCursor, 
+			CursorPtr	pCursor,
 			Pixel		*source,
 			Pixel		*mask)
 {
@@ -77,7 +77,7 @@ KdAllocateCursorPixels (ScreenPtr	pScreen,
 	 */
 	*source = ~0;
 	*mask = ~0;
-	
+
 	sourceColor.red = pCursor->foreRed;
 	sourceColor.green = pCursor->foreGreen;
 	sourceColor.blue = pCursor->foreBlue;
diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c
index 5cfe54f..76c03fd 100644
--- a/hw/kdrive/src/kdrive.c
+++ b/hw/kdrive/src/kdrive.c
@@ -148,9 +148,9 @@ KdSetRootClip (ScreenPtr pScreen, BOOL enable)
 	REGION_EMPTY(pScreen, &pWin->borderClip);
 	REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
     }
-    
+
     ResizeChildrenWinSize (pWin, 0, 0, 0, 0);
-    
+
     if (WasViewable)
     {
 	if (pWin->firstChild)
@@ -185,7 +185,7 @@ void
 KdDisableScreen (ScreenPtr pScreen)
 {
     KdScreenPriv(pScreen);
-    
+
     if (!pScreenPriv->enabled)
 	return;
     if (!pScreenPriv->closed)
@@ -209,7 +209,7 @@ KdDoSwitchCmd (char *reason)
     {
 	char    *command = xalloc (strlen (kdSwitchCmd) +
 				   1 +
-				   strlen (reason) + 
+				   strlen (reason) +
 				   1);
 	if (!command)
 	    return;
@@ -392,7 +392,7 @@ KdParseScreen (KdScreenInfo *screen,
     int	    fb;
     int	    i;
     int	    pixels, mm;
-    
+
     screen->dumb = kdDumbDriver;
     screen->softCursor = kdSoftCursor;
     screen->origin = kdOrigin;
@@ -409,16 +409,16 @@ KdParseScreen (KdScreenInfo *screen,
 	return;
     if (strlen (arg) >= sizeof (save))
 	return;
-    
+
     for (i = 0; i < 2; i++)
     {
 	arg = KdParseFindNext (arg, "x/@XY", save, &delim);
 	if (!save[0])
 	    return;
-	
+
 	pixels = atoi(save);
 	mm = 0;
-	
+
 	if (delim == '/')
 	{
 	    arg = KdParseFindNext (arg, "x at XY", save, &delim);
@@ -426,7 +426,7 @@ KdParseScreen (KdScreenInfo *screen,
 		return;
 	    mm = atoi(save);
 	}
-	
+
 	if (i == 0)
 	{
 	    screen->width = pixels;
@@ -476,7 +476,7 @@ KdParseScreen (KdScreenInfo *screen,
 	arg = KdParseFindNext (arg, "xY", save, &delim);
 	screen->randr |= RR_Reflect_Y;
     }
-    
+
     fb = 0;
     while (fb < KD_MAX_FB)
     {
@@ -691,7 +691,7 @@ KdOsInit (KdOsFuncs *pOsFuncs)
     kdOsFuncs = pOsFuncs;
     if (pOsFuncs)
     {
-	if (serverGeneration == 1) 
+	if (serverGeneration == 1)
 	{
 	    KdDoSwitchCmd ("start");
             if (pOsFuncs->Init)
@@ -704,7 +704,7 @@ Bool
 KdAllocatePrivates (ScreenPtr pScreen)
 {
     KdPrivScreenPtr	pScreenPriv;
-    
+
     if (kdGeneration != serverGeneration)
 	kdGeneration = serverGeneration;
 
@@ -741,20 +741,20 @@ KdCloseScreen (int index, ScreenPtr pScreen)
     KdScreenInfo    *screen = pScreenPriv->screen;
     KdCardInfo	    *card = pScreenPriv->card;
     Bool	    ret;
-    
+
     pScreenPriv->closed = TRUE;
     pScreen->CloseScreen = pScreenPriv->CloseScreen;
     if(pScreen->CloseScreen)
         ret = (*pScreen->CloseScreen) (index, pScreen);
     else
 	ret = TRUE;
-    
+
     if (pScreenPriv->dpmsState != KD_DPMS_NORMAL)
 	(*card->cfuncs->dpms) (pScreen, KD_DPMS_NORMAL);
-    
+
     if (screen->mynum == card->selected)
 	KdDisableScreen (pScreen);
-    
+
     /*
      * Restore video hardware when last screen is closed
      */
@@ -763,7 +763,7 @@ KdCloseScreen (int index, ScreenPtr pScreen)
 	if (kdEnabled && card->cfuncs->restore)
 	    (*card->cfuncs->restore) (card);
     }
-	
+
     if (!pScreenPriv->screen->dumb && card->cfuncs->finiAccel)
 	(*card->cfuncs->finiAccel) (pScreen);
 
@@ -794,9 +794,9 @@ KdCloseScreen (int index, ScreenPtr pScreen)
 	    }
 	}
     }
-    
+
     pScreenPriv->screen->pScreen = 0;
-    
+
     xfree ((pointer) pScreenPriv);
     return ret;
 }
@@ -806,10 +806,10 @@ KdSaveScreen (ScreenPtr pScreen, int on)
 {
     KdScreenPriv(pScreen);
     int	    dpmsState;
-    
+
     if (!pScreenPriv->card->cfuncs->dpms)
 	return FALSE;
-    
+
     dpmsState = pScreenPriv->dpmsState;
     switch (on) {
     case SCREEN_SAVER_OFF:
@@ -861,7 +861,7 @@ KdSetSubpixelOrder (ScreenPtr pScreen, Rotation randr)
     int			subpixel_order = screen->subpixel_order;
     Rotation		subpixel_dir;
     int			i;
-    
+
     static struct {
 	int	    subpixel_order;
 	Rotation    direction;
@@ -874,7 +874,7 @@ KdSetSubpixelOrder (ScreenPtr pScreen, Rotation randr)
 
     static struct {
 	int	bit;
-	int	normal; 
+	int	normal;
 	int	reflect;
     } reflects[] = {
 	{ RR_Reflect_X, SubPixelHorizontalRGB,	SubPixelHorizontalBGR },
@@ -882,7 +882,7 @@ KdSetSubpixelOrder (ScreenPtr pScreen, Rotation randr)
 	{ RR_Reflect_Y, SubPixelVerticalRGB,	SubPixelVerticalBGR },
 	{ RR_Reflect_Y, SubPixelVerticalRGB,	SubPixelVerticalRGB },
     };
-    
+
     /* map subpixel to direction */
     for (i = 0; i < 4; i++)
 	if (orders[i].subpixel_order == subpixel_order)
@@ -890,7 +890,7 @@ KdSetSubpixelOrder (ScreenPtr pScreen, Rotation randr)
     if (i < 4)
     {
 	subpixel_dir = KdAddRotation (randr & RR_Rotate_All, orders[i].direction);
-	
+
 	/* map back to subpixel order */
 	for (i = 0; i < 4; i++)
 	    if (orders[i].direction & subpixel_dir)
@@ -931,7 +931,7 @@ KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
     KdAllocatePrivates (pScreen);
 
     pScreenPriv = KdGetScreenPriv(pScreen);
-    
+
     if (!rotated)
     {
 	width = screen->width;
@@ -963,10 +963,10 @@ KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
      * our GC functions; fbFinishScreenInit initializes MI
      * backing store
      */
-    if (!fbSetupScreen (pScreen, 
-			screen->fb[0].frameBuffer, 
-			width, height, 
-			monitorResolution, monitorResolution, 
+    if (!fbSetupScreen (pScreen,
+			screen->fb[0].frameBuffer,
+			width, height,
+			monitorResolution, monitorResolution,
 			screen->fb[0].pixelStride,
 			screen->fb[0].bitsPerPixel))
     {
@@ -980,17 +980,17 @@ KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
     pScreen->UninstallColormap	= KdUninstallColormap;
     pScreen->ListInstalledColormaps = KdListInstalledColormaps;
     pScreen->StoreColors	= KdStoreColors;
-     
+
     pScreen->SaveScreen		= KdSaveScreen;
     pScreen->CreateWindow	= KdCreateWindow;
 
 #if KD_MAX_FB > 1
     if (screen->fb[1].depth)
     {
-	if (!fbOverlayFinishScreenInit (pScreen, 
-					screen->fb[0].frameBuffer, 
-					screen->fb[1].frameBuffer, 
-					width, height, 
+	if (!fbOverlayFinishScreenInit (pScreen,
+					screen->fb[0].frameBuffer,
+					screen->fb[1].frameBuffer,
+					width, height,
 					monitorResolution, monitorResolution,
 					screen->fb[0].pixelStride,
 					screen->fb[1].pixelStride,
@@ -1005,8 +1005,8 @@ KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
     else
 #endif
     {
-	if (!fbFinishScreenInit (pScreen, 
-				 screen->fb[0].frameBuffer, 
+	if (!fbFinishScreenInit (pScreen,
+				 screen->fb[0].frameBuffer,
 				 width, height,
 				 monitorResolution, monitorResolution,
 				 screen->fb[0].pixelStride,
@@ -1015,7 +1015,7 @@ KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
 	    return FALSE;
 	}
     }
-    
+
     /*
      * Fix screen sizes; for some reason mi takes dpi instead of mm.
      * Rounding errors are annoying
@@ -1028,14 +1028,14 @@ KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
 	pScreen->mmHeight = *height_mmp;
     else
 	*height_mmp = pScreen->mmHeight;
-    
+
     /*
      * Plug in our own block/wakeup handlers.
      * miScreenInit installs NoopDDA in both places
      */
     pScreen->BlockHandler	= KdBlockHandler;
     pScreen->WakeupHandler	= KdWakeupHandler;
-    
+
 #ifdef RENDER
     if (!fbPictureInit (pScreen, 0, 0))
 	return FALSE;
@@ -1043,26 +1043,26 @@ KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
     if (card->cfuncs->initScreen)
 	if (!(*card->cfuncs->initScreen) (pScreen))
 	    return FALSE;
-	    
+
     if (!screen->dumb && card->cfuncs->initAccel)
 	if (!(*card->cfuncs->initAccel) (pScreen))
 	    screen->dumb = TRUE;
-    
+
     if (card->cfuncs->finishInitScreen)
 	if (!(*card->cfuncs->finishInitScreen) (pScreen))
 	    return FALSE;
-	    
+
 #if 0
     fbInitValidateTree (pScreen);
 #endif
-    
+
 #if 0
     pScreen->backingStoreSupport = Always;
     miInitializeBackingStore (pScreen);
 #endif
 
 
-    /* 
+    /*
      * Wrap CloseScreen, the order now is:
      *	KdCloseScreen
      *	miBSCloseScreen
@@ -1073,9 +1073,9 @@ KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
 
     pScreenPriv->CreateScreenResources = pScreen->CreateScreenResources;
     pScreen->CreateScreenResources = KdCreateScreenResources;
-    
+
     if (screen->softCursor ||
-	!card->cfuncs->initCursor || 
+	!card->cfuncs->initCursor ||
 	!(*card->cfuncs->initCursor) (pScreen))
     {
 	/* Use MI for cursor display and event queueing. */
@@ -1083,7 +1083,7 @@ KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
 	miDCInitialize(pScreen, &kdPointerScreenFuncs);
     }
 
-    
+
     if (!fbCreateDefColormap (pScreen))
     {
 	return FALSE;
@@ -1100,7 +1100,7 @@ KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
 	if(kdOsFuncs->Enable)
 	    (*kdOsFuncs->Enable) ();
     }
-    
+
     if (screen->mynum == card->selected)
     {
 	if(card->cfuncs->preserve)
@@ -1115,7 +1115,7 @@ KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
 	if (!screen->dumb && card->cfuncs->enableAccel)
 	    (*card->cfuncs->enableAccel) (pScreen);
     }
-    
+
     return TRUE;
 }
 
@@ -1126,9 +1126,9 @@ KdInitScreen (ScreenInfo    *pScreenInfo,
 	      char	    **argv)
 {
     KdCardInfo	*card = screen->card;
-    
+
     (*card->cfuncs->scrinit) (screen);
-    
+
     if (!card->cfuncs->initAccel)
 	screen->dumb = TRUE;
     if (!card->cfuncs->initCursor)
@@ -1166,26 +1166,26 @@ KdSetPixmapFormats (ScreenInfo	*pScreenInfo)
 		    bpp = 32;
 		if (!depthToBpp[screen->fb[fb].depth])
 		    depthToBpp[screen->fb[fb].depth] = bpp;
-		else if (depthToBpp[screen->fb[fb].depth] != bpp) 
+		else if (depthToBpp[screen->fb[fb].depth] != bpp)
 		    return FALSE;
 	    }
 	}
     }
-    
+
     /*
      * Fill in additional formats
      */
     for (i = 0; i < NUM_KD_DEPTHS; i++)
 	if (!depthToBpp[kdDepths[i].depth])
 	    depthToBpp[kdDepths[i].depth] = kdDepths[i].bpp;
-	
+
     pScreenInfo->imageByteOrder     = IMAGE_BYTE_ORDER;
     pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
     pScreenInfo->bitmapScanlinePad  = BITMAP_SCANLINE_PAD;
     pScreenInfo->bitmapBitOrder     = BITMAP_BIT_ORDER;
-    
+
     pScreenInfo->numPixmapFormats = 0;
-    
+
     for (i = 1; i <= 32; i++)
     {
 	if (depthToBpp[i])
@@ -1196,7 +1196,7 @@ KdSetPixmapFormats (ScreenInfo	*pScreenInfo)
 	    format->scanlinePad = BITMAP_SCANLINE_PAD;
 	}
     }
-    
+
     return TRUE;
 }
 
@@ -1215,7 +1215,7 @@ KdAddScreen (ScreenInfo	    *pScreenInfo,
 	unsigned long	visuals;
 	Pixel		rm, gm, bm;
 	int		fb;
-	
+
 	visuals = 0;
 	rm = gm = bm = 0;
 	for (fb = 0; fb < KD_MAX_FB && screen->fb[fb].depth; fb++)
@@ -1236,7 +1236,7 @@ KdAddScreen (ScreenInfo	    *pScreenInfo,
     }
 
     kdCurrentScreen = screen;
-    
+
     AddScreen (KdScreenInit, argc, argv);
 }
 
@@ -1292,14 +1292,14 @@ KdInitOutput (ScreenInfo    *pScreenInfo,
 		KdInitScreen (pScreenInfo, screen, argc, argv);
 	}
     }
-    
+
     /*
      * Merge the various pixmap formats together, this can fail
      * when two screens share depth but not bitsPerPixel
      */
     if (!KdSetPixmapFormats (pScreenInfo))
 	return;
-    
+
     /*
      * Add all of the screens
      */
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 9620391..2041d71 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -242,7 +242,7 @@ struct _KdPointerInfo {
         int z;
         int flags;
         int absrel;
-    } heldEvent;         
+    } heldEvent;
     unsigned char         buttonState;
     Bool                  transformCoordinates;
     int                   pressureThreshold;
@@ -421,7 +421,7 @@ KdStoreColors (ColormapPtr pCmap, int ndef, xColorItem *pdefs);
 void
 KdAllocateCursorPixels (ScreenPtr	pScreen,
 			int		fb,
-			CursorPtr	pCursor, 
+			CursorPtr	pCursor,
 			Pixel		*source,
 			Pixel		*mask);
 
@@ -517,13 +517,13 @@ void
 KdInitOutput (ScreenInfo    *pScreenInfo,
 	      int	    argc,
 	      char	    **argv);
- 
+
 void
 KdSetSubpixelOrder (ScreenPtr pScreen, Rotation randr);
 
 void
 KdBacktrace (int signum);
-    
+
 /* kinfo.c */
 KdCardInfo *
 KdCardInfoAdd (KdCardFuncs  *funcs,
@@ -584,7 +584,7 @@ _KdEnqueuePointerEvent(KdPointerInfo *pi, int type, int x, int y, int z,
 
 void
 KdReleaseAllKeys (void);
-    
+
 void
 KdSetLed (KdKeyboardInfo *ki, int led, Bool on);
 
@@ -604,7 +604,7 @@ KdBlockHandler (int		screen,
 		pointer		readmask);
 
 void
-KdWakeupHandler (int		screen, 
+KdWakeupHandler (int		screen,
 		 pointer    	data,
 		 unsigned long	result,
 		 pointer	readmask);
@@ -669,14 +669,14 @@ KdTuneMode (KdScreenInfo    *screen,
 
 #ifdef RANDR
 Bool
-KdRandRGetInfo (ScreenPtr pScreen, 
+KdRandRGetInfo (ScreenPtr pScreen,
 		int randr,
-		Bool (*supported) (ScreenPtr pScreen, 
+		Bool (*supported) (ScreenPtr pScreen,
 				   const KdMonitorTiming *));
 
 const KdMonitorTiming *
 KdRandRGetTiming (ScreenPtr	    pScreen,
-		  Bool		    (*supported) (ScreenPtr pScreen, 
+		  Bool		    (*supported) (ScreenPtr pScreen,
 						  const KdMonitorTiming *),
 		  int		    rate,
 		  RRScreenSizePtr   pSize);
@@ -691,7 +691,7 @@ KdShadowFbFree (KdScreenInfo *screen, int fb);
 
 Bool
 KdShadowSet (ScreenPtr pScreen, int randr, ShadowUpdateProc update, ShadowWindowProc window);
-    
+
 void
 KdShadowUnset (ScreenPtr pScreen);
 
diff --git a/hw/kdrive/src/kinfo.c b/hw/kdrive/src/kinfo.c
index 4551fd7..af64156 100644
--- a/hw/kdrive/src/kinfo.c
+++ b/hw/kdrive/src/kinfo.c
@@ -155,10 +155,10 @@ KdFreePointer(KdPointerInfo *pi)
 
     if (prev)
         xfree(prev);
-    
+
     xfree(pi);
 }
- 
+
 void
 KdFreeKeyboard(KdKeyboardInfo *ki)
 {
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 09b5d3b..a88f2dc 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -76,7 +76,7 @@ static KdPointerMatrix	kdPointerMatrix = {
 };
 
 void KdResetInputMachine (void);
-    
+
 #define KD_MAX_INPUT_FDS    8
 
 typedef struct _kdInputFd {
@@ -105,7 +105,7 @@ static void
 KdBlockSigio (void)
 {
     sigset_t	set;
-    
+
     sigemptyset (&set);
     sigaddset (&set, SIGIO);
     sigprocmask (SIG_BLOCK, &set, 0);
@@ -115,7 +115,7 @@ static void
 KdUnblockSigio (void)
 {
     sigset_t	set;
-    
+
     sigemptyset (&set);
     sigaddset (&set, SIGIO);
     sigprocmask (SIG_UNBLOCK, &set, 0);
@@ -175,7 +175,7 @@ KdAddFd (int fd)
 {
     struct sigaction	act;
     sigset_t		set;
-    
+
     kdnFds++;
     fcntl (fd, F_SETOWN, getpid());
     KdNonBlockFd (fd);
@@ -196,7 +196,7 @@ KdRemoveFd (int fd)
 {
     struct sigaction	act;
     int			flags;
-    
+
     kdnFds--;
     RemoveEnabledDevice (fd);
     flags = fcntl (fd, F_GETFL);
@@ -324,7 +324,7 @@ KdEnableInput (void)
     InternalEvent ev;
     KdKeyboardInfo *ki;
     KdPointerInfo *pi;
-    
+
     kdInputEnabled = TRUE;
 
     for (ki = kdKeyboards; ki; ki = ki->next) {
@@ -352,7 +352,7 @@ KdFindKeyboardDriver (char *name)
     /* ask a stupid question ... */
     if (!name)
         return NULL;
-    
+
     for (ret = kdKeyboardDrivers; ret; ret = ret->next) {
         if (strcmp(ret->name, name) == 0)
             return ret;
@@ -487,11 +487,11 @@ KdPointerProc(DeviceIntPtr pDevice, int onoff)
                           pi->name ? pi->name : "Generic KDrive Pointer");
 
 	return Success;
-	
+
     case DEVICE_ON:
         if (pDev->on == TRUE)
             return Success;
-        
+
         if (!pi->driver->Enable) {
             ErrorF("no enable function\n");
             return BadImplementation;
@@ -538,7 +538,7 @@ KdPointerProc(DeviceIntPtr pDevice, int onoff)
         (*pi->driver->Fini) (pi);
 
         KdRemovePointer(pi);
-        
+
         return Success;
     }
 
@@ -557,7 +557,7 @@ KdBell (int volume, DeviceIntPtr pDev, pointer arg, int something)
 {
     KeybdCtrl *ctrl = arg;
     KdKeyboardInfo *ki = NULL;
-    
+
     for (ki = kdKeyboards; ki; ki = ki->next) {
         if (ki->dixdev && ki->dixdev->id == pDev->id)
             break;
@@ -565,7 +565,7 @@ KdBell (int volume, DeviceIntPtr pDev, pointer arg, int something)
 
     if (!ki || !ki->dixdev || ki->dixdev->id != pDev->id || !ki->driver)
         return;
-    
+
     KdRingBell(ki, volume, ctrl->bell_pitch, ctrl->bell_duration);
 }
 
@@ -590,7 +590,7 @@ KdRingBell(KdKeyboardInfo *ki, int volume, int pitch, int duration)
 {
     if (!ki || !ki->driver || !ki->driver->Bell)
         return;
-        
+
     if (kdInputEnabled)
         (*ki->driver->Bell) (ki, volume, pitch, duration);
 }
@@ -691,7 +691,7 @@ KdKbdCtrl (DeviceIntPtr pDevice, KeybdCtrl *ctrl)
 
     KdSetLeds(ki, ctrl->leds);
     ki->bellPitch = ctrl->bell_pitch;
-    ki->bellDuration = ctrl->bell_duration; 
+    ki->bellDuration = ctrl->bell_duration;
 }
 
 extern KeybdCtrl defaultKeyboardControl;
@@ -794,7 +794,7 @@ KdKeyboardProc(DeviceIntPtr pDevice, int onoff)
         pDev->on = FALSE;
 
         return Success;
-        
+
         break;
 
     case DEVICE_CLOSE:
@@ -935,7 +935,7 @@ KdAddKeyboard (KdKeyboardInfo *ki)
 
     if (!ki)
         return !Success;
-    
+
     ki->dixdev = AddInputDevice(serverClient, KdKeyboardProc, TRUE);
     if (!ki->dixdev) {
         ErrorF("Couldn't register keyboard device %s\n",
@@ -1042,12 +1042,12 @@ KdRemovePointer (KdPointerInfo *pi)
     KdFreePointer(pi);
 }
 
-/* 
+/*
  * You can call your kdriver server with something like:
  * $ ./hw/kdrive/yourserver/X :1 -mouse evdev,,device=/dev/input/event4 -keybd
- * evdev,,device=/dev/input/event1,xkbmodel=abnt2,xkblayout=br 
+ * evdev,,device=/dev/input/event1,xkbmodel=abnt2,xkblayout=br
  */
-static Bool 
+static Bool
 KdGetOptions (InputOption **options, char *string)
 {
     InputOption     *newopt = NULL, **tmpo = NULL;
@@ -1058,7 +1058,7 @@ KdGetOptions (InputOption **options, char *string)
         return FALSE;
 
     for (tmpo = options; *tmpo; tmpo = &(*tmpo)->next)
-        ; /* Hello, I'm here */ 
+        ; /* Hello, I'm here */
     *tmpo = newopt;
 
     if (strchr(string, '='))
@@ -1099,7 +1099,7 @@ KdParseKbdOptions (KdKeyboardInfo *ki)
         else if (!strcasecmp (option->key, "device"))
             ki->path = strdup(option->value);
         else
-           ErrorF("Kbd option key (%s) of value (%s) not assigned!\n", 
+           ErrorF("Kbd option key (%s) of value (%s) not assigned!\n",
                     option->key, option->value);
     }
 }
@@ -1160,11 +1160,11 @@ KdParseKeyboard (char *arg)
     {
         arg = KdParseFindNext (arg, ",", save, &delim);
 
-	if (!KdGetOptions(&options, save)) 
+	if (!KdGetOptions(&options, save))
 	{
 	    KdFreeKeyboard(ki);
 	    return NULL;
-        }    
+        }
     }
 
     if (options)
@@ -1196,7 +1196,7 @@ KdParsePointerOptions (KdPointerInfo *pi)
         else if (!strcasecmp (option->key, "protocol"))
             pi->protocol = strdup(option->value);
         else
-            ErrorF("Pointer option key (%s) of value (%s) not assigned!\n", 
+            ErrorF("Pointer option key (%s) of value (%s) not assigned!\n",
                     option->key, option->value);
     }
 }
@@ -1448,7 +1448,7 @@ KdInitInput (void)
  *	<>  -> (deliver) synthetic_2_down_1
  *	k   -> (deliver) synthetic_2_down_1
  */
- 
+
 typedef enum _inputClass {
     down_1, up_1,
     down_2, up_2,
@@ -1628,7 +1628,7 @@ KdInsideEmulationWindow (KdPointerInfo *pi, int x, int y, int z)
     return (abs (pi->emulationDx) < EMULATION_WINDOW &&
 	    abs (pi->emulationDy) < EMULATION_WINDOW);
 }
-				     
+
 static KdInputClass
 KdClassifyInput (KdPointerInfo *pi, int type, int x, int y, int z, int b)
 {
@@ -1906,7 +1906,7 @@ KdEnqueuePointerEvent(KdPointerInfo *pi, unsigned long flags, int rx, int ry,
 
     if (!pi)
 	return;
-    
+
     ms = GetTimeInMillis();
 
     /* we don't need to transform z, so we don't. */
@@ -2001,7 +2001,7 @@ KdBlockHandler (int		screen,
 	if (pi->timeoutPending)
 	{
 	    int	ms;
-    
+
 	    ms = pi->emulationTimeout - GetTimeInMillis ();
 	    if (ms < 1)
 		ms = 1;
@@ -2020,7 +2020,7 @@ KdBlockHandler (int		screen,
 }
 
 void
-KdWakeupHandler (int		screen, 
+KdWakeupHandler (int		screen,
 		 pointer    	data,
 		 unsigned long	lresult,
 		 pointer	readmask)
@@ -2029,7 +2029,7 @@ KdWakeupHandler (int		screen,
     fd_set	*pReadmask = (fd_set *) readmask;
     int		i;
     KdPointerInfo	*pi;
-    
+
     if (kdInputEnabled && result > 0)
     {
 	for (i = 0; i < kdNumInputFds; i++)
@@ -2069,13 +2069,13 @@ KdCursorOffScreen(ScreenPtr *ppScreen, int *x, int *y)
     int		best_x, best_y;
     int		n_best_x, n_best_y;
     CARD32	ms;
-    
+
     if (kdDisableZaphod || screenInfo.numScreens <= 1)
 	return FALSE;
 
     if (0 <= *x && *x < pScreen->width && 0 <= *y && *y < pScreen->height)
 	return FALSE;
-	
+
     ms = GetTimeInMillis ();
     if (kdOffScreen && (int) (ms - kdOffScreenTime) < 1000)
 	return FALSE;
@@ -2088,7 +2088,7 @@ KdCursorOffScreen(ScreenPtr *ppScreen, int *x, int *y)
     for (n = 0; n < screenInfo.numScreens; n++)
     {
 	pNewScreen = screenInfo.screens[n];
-	if (pNewScreen == pScreen) 
+	if (pNewScreen == pScreen)
 	    continue;
 	dx = KdScreenOrigin(pNewScreen)->x - KdScreenOrigin(pScreen)->x;
 	dy = KdScreenOrigin(pNewScreen)->y - KdScreenOrigin(pScreen)->y;
@@ -2130,17 +2130,17 @@ KdCursorOffScreen(ScreenPtr *ppScreen, int *x, int *y)
     if (n_best_x == -1)
 	return FALSE;
     pNewScreen = screenInfo.screens[n_best_x];
-    
+
     if (*x < 0)
 	*x += pNewScreen->width;
     if (*y < 0)
 	*y += pNewScreen->height;
-    
+
     if (*x >= pScreen->width)
 	*x -= pScreen->width;
     if (*y >= pScreen->height)
 	*y -= pScreen->height;
-    
+
     *ppScreen = pNewScreen;
     return TRUE;
 }
@@ -2167,7 +2167,7 @@ KdWarpCursor (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
     KdUnblockSigio ();
 }
 
-miPointerScreenFuncRec kdPointerScreenFuncs = 
+miPointerScreenFuncRec kdPointerScreenFuncs =
 {
     KdCursorOffScreen,
     KdCrossScreen,
diff --git a/hw/kdrive/src/kmap.c b/hw/kdrive/src/kmap.c
index 60e8ae1..2bf0840 100644
--- a/hw/kdrive/src/kmap.c
+++ b/hw/kdrive/src/kmap.c
@@ -45,7 +45,7 @@ KdMapDevice (CARD32 addr, CARD32 size)
     DRAW_DEBUG ((DEBUG_S3INIT, "Virtual address of 0x%x is 0x%x", addr, d));
     a = VirtualCopyAddr (addr);
     DRAW_DEBUG ((DEBUG_S3INIT, "Translated address is 0x%x", a));
-    if (!VirtualCopy (d, a, size, 
+    if (!VirtualCopy (d, a, size,
 		      PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL))
     {
 	DRAW_DEBUG ((DEBUG_FAILURE, "VirtualCopy failed %d",
@@ -67,7 +67,7 @@ KdMapDevice (CARD32 addr, CARD32 size)
     if (fd < 0)
 	FatalError ("KdMapDevice: failed to open /dev/mem (%s)\n",
 		    strerror (errno));
-    
+
     a = mmap ((caddr_t) 0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, addr);
     close (fd);
     if ((long) a == -1)
@@ -124,7 +124,7 @@ KdSetMappedMode (CARD32 addr, CARD32 size, int mode)
 	sentry.base = base;
 	sentry.size = nsize;
 	sentry.type = type;
-	
+
 	if (ioctl (mtrr, MTRRIOC_ADD_ENTRY, &sentry) < 0)
 	    ErrorF ("MTRRIOC_ADD_ENTRY failed 0x%x 0x%x %d (%s)\n",
 		    base, bound - base, type, strerror(errno));
@@ -163,7 +163,7 @@ KdResetMappedMode (CARD32 addr, CARD32 size, int mode)
 	sentry.base = base;
 	sentry.size = nsize;
 	sentry.type = type;
-	
+
 	if (ioctl (mtrr, MTRRIOC_DEL_ENTRY, &sentry) < 0)
 	    ErrorF ("MTRRIOC_DEL_ENTRY failed 0x%x 0x%x %d (%s)\n",
 		    base, bound - base, type, strerror(errno));
diff --git a/hw/kdrive/src/kmode.c b/hw/kdrive/src/kmode.c
index d02cb55..1c3c240 100644
--- a/hw/kdrive/src/kmode.c
+++ b/hw/kdrive/src/kmode.c
@@ -15,7 +15,7 @@
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *
  * Author:  Keith Packard, SuSE, Inc.
@@ -38,7 +38,7 @@ const KdMonitorTiming  kdMonitorTimings[] = {
 	            17,	    12,	    32,     KdSyncNegative,
 	            1,      11,     14,     KdSyncNegative,
     },
-    
+
     /* Other VESA modes */
     {	640,	350,	85,	31500,			    /* VESA */
 		    32,	    96,	    192,    KdSyncPositive, /* 26.413 */
@@ -60,7 +60,7 @@ const KdMonitorTiming  kdMonitorTimings[] = {
         16,     80,  160, KdSyncPositive, /* 32.954 */
         1,      45,   49, KdSyncPositive, /* 52.727 */
     },
-    
+
     /* 640x480 modes */
     {	640,	480,	85,	36000,			    /* VESA */
 		    56,	    80,	    192,    KdSyncNegative, /* 43.269 */
@@ -78,7 +78,7 @@ const KdMonitorTiming  kdMonitorTimings[] = {
 		   16,	    48,	    160,    KdSyncNegative, /* 31.469 */
 		   10,	    33,	    45,	    KdSyncNegative, /* 59.940 */
     },
-    
+
     /* 800x600 modes */
     {	800,	600,	85,	56250,			    /* VESA */
 		    32,	    152,    248,    KdSyncPositive, /* 53.674 */
@@ -102,7 +102,7 @@ const KdMonitorTiming  kdMonitorTimings[] = {
 		    24,	    128,    224,    KdSyncPositive, /* 35.156 */
 		    1,	    22,	    25,	    KdSyncPositive, /* 56.250 */
     },
-    
+
     /* 1024x768 modes */
     {	1024,	768,	85,	94500,			    /* VESA */
 		    48,	    208,    352,    KdSyncPositive, /* 68.677 */
@@ -120,13 +120,13 @@ const KdMonitorTiming  kdMonitorTimings[] = {
 		    24,	    160,    320,    KdSyncNegative, /* 48.363 */
 		    3,	    29,	    38,	    KdSyncNegative, /* 60.004 */
     },
-    
+
     /* 1152x864 mode */
     {	1152,	864,	75,	108000,			    /* VESA */
 		    64,	    256,    448,    KdSyncPositive, /* 67.500 */
 		    1,	    32,	    36,	    KdSyncPositive, /* 75.000 */
     },
-    
+
     /* 1152x900 modes */
     {	1152,	900,	85,	122500,			    /* ADDED */
 		    48,	    208,    384,    KdSyncPositive, /* 79.753 */
@@ -315,7 +315,7 @@ KdTuneMode (KdScreenInfo    *screen,
 					  const KdMonitorTiming *))
 {
     const KdMonitorTiming   *t;
-    
+
     while (!(*usable) (screen))
     {
 	/*
@@ -327,7 +327,7 @@ KdTuneMode (KdScreenInfo    *screen,
 	    screen->fb[0].depth = 16;
 	else if (screen->fb[0].depth > 8)
 	    screen->fb[0].depth = 8;
-	else 
+	else
 	{
 	    t = kdFindPrevSize (KdFindMode (screen, supported));
 	    if (!t)
@@ -344,14 +344,14 @@ KdTuneMode (KdScreenInfo    *screen,
 Bool
 KdRandRGetInfo (ScreenPtr pScreen,
 		int randr,
-		Bool (*supported) (ScreenPtr pScreen, 
+		Bool (*supported) (ScreenPtr pScreen,
 				   const KdMonitorTiming *))
 {
     KdScreenPriv(pScreen);
     KdScreenInfo	    *screen = pScreenPriv->screen;
     int			    i;
     const KdMonitorTiming   *t;
-    
+
     for (i = 0, t = kdMonitorTimings; i < NUM_MONITOR_TIMINGS; i++, t++)
     {
 	if ((*supported) (pScreen, t))
@@ -373,20 +373,20 @@ KdRandRGetInfo (ScreenPtr pScreen,
 		RRSetCurrentConfig (pScreen, randr, t->rate, pSize);
 	}
     }
-    
+
     return TRUE;
 }
 
 const KdMonitorTiming *
 KdRandRGetTiming (ScreenPtr	    pScreen,
-		  Bool		    (*supported) (ScreenPtr pScreen, 
+		  Bool		    (*supported) (ScreenPtr pScreen,
 						  const KdMonitorTiming *),
 		  int		    rate,
 		  RRScreenSizePtr   pSize)
 {
     int			    i;
     const KdMonitorTiming   *t;
-    
+
     for (i = 0, t = kdMonitorTimings; i < NUM_MONITOR_TIMINGS; i++, t++)
     {
 	if (t->horizontal == pSize->width &&
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index 9a74654..1ceb8c6 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -1,6 +1,6 @@
-/* 
+/*
 
-   XFree86 Xv DDX written by Mark Vojkovich (markv at valinux.com) 
+   XFree86 Xv DDX written by Mark Vojkovich (markv at valinux.com)
    Adapted for KDrive by Pontus Lidman <pontus.lidman at nokia.com>
 
    Copyright (C) 2000, 2001 - Nokia Home Communications
@@ -67,29 +67,29 @@ static int KdXVQueryAdaptors(ScreenPtr, XvAdaptorPtr *, int *);
 static int KdXVAllocatePort(unsigned long, XvPortPtr, XvPortPtr*);
 static int KdXVFreePort(XvPortPtr);
 static int KdXVPutVideo(ClientPtr, DrawablePtr,XvPortPtr, GCPtr,
-   				INT16, INT16, CARD16, CARD16, 
+   				INT16, INT16, CARD16, CARD16,
 				INT16, INT16, CARD16, CARD16);
 static int KdXVPutStill(ClientPtr, DrawablePtr,XvPortPtr, GCPtr,
-   				INT16, INT16, CARD16, CARD16, 
+   				INT16, INT16, CARD16, CARD16,
 				INT16, INT16, CARD16, CARD16);
 static int KdXVGetVideo(ClientPtr, DrawablePtr,XvPortPtr, GCPtr,
-   				INT16, INT16, CARD16, CARD16, 
+   				INT16, INT16, CARD16, CARD16,
 				INT16, INT16, CARD16, CARD16);
 static int KdXVGetStill(ClientPtr, DrawablePtr,XvPortPtr, GCPtr,
-   				INT16, INT16, CARD16, CARD16, 
+   				INT16, INT16, CARD16, CARD16,
 				INT16, INT16, CARD16, CARD16);
 static int KdXVStopVideo(ClientPtr, XvPortPtr, DrawablePtr);
 static int KdXVSetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32);
 static int KdXVGetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32 *);
 static int KdXVQueryBestSize(ClientPtr, XvPortPtr, CARD8,
-   				CARD16, CARD16,CARD16, CARD16, 
+   				CARD16, CARD16,CARD16, CARD16,
 				unsigned int*, unsigned int*);
 static int KdXVPutImage(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
-   				INT16, INT16, CARD16, CARD16, 
+   				INT16, INT16, CARD16, CARD16,
 				INT16, INT16, CARD16, CARD16,
 				XvImagePtr, unsigned char*, Bool,
 				CARD16, CARD16);
-static int KdXVQueryImageAttributes(ClientPtr, XvPortPtr, XvImagePtr, 
+static int KdXVQueryImageAttributes(ClientPtr, XvPortPtr, XvImagePtr,
 				CARD16*, CARD16*, int*, int*);
 
 
@@ -134,12 +134,12 @@ KdXVRegisterGenericAdaptorDriver(
 
 /*   fprintf(stderr,"KdXVRegisterGenericAdaptorDriver\n"); */
 
-  newdrivers = xrealloc(GenDrivers, sizeof(KdXVInitGenericAdaptorPtr) * 
+  newdrivers = xrealloc(GenDrivers, sizeof(KdXVInitGenericAdaptorPtr) *
 			(1 + NumGenDrivers));
   if (!newdrivers)
     return 0;
   GenDrivers = newdrivers;
-  
+
   GenDrivers[NumGenDrivers++] = InitFunc;
 
   return 1;
@@ -184,7 +184,7 @@ KdXVFreeVideoAdaptorRec(KdVideoAdaptorPtr ptr)
 
 Bool
 KdXVScreenInit(
-   ScreenPtr pScreen, 
+   ScreenPtr pScreen,
    KdVideoAdaptorPtr *adaptors,
    int num
 ){
@@ -197,7 +197,7 @@ KdXVScreenInit(
       KdXVGeneration = serverGeneration;
 
   if(!XvGetScreenKeyProc || !XvGetRTPortProc || !XvScreenInitProc)
-	return FALSE;  
+	return FALSE;
 
   if(Success != (*XvScreenInitProc)(pScreen)) return FALSE;
 
@@ -259,7 +259,7 @@ KdXVFreeAdaptor(XvAdaptorPtr pAdaptor)
       xfree(pAdaptor->pEncodings);
    }
 
-   if(pAdaptor->pFormats) 
+   if(pAdaptor->pFormats)
       xfree(pAdaptor->pFormats);
 
    if(pAdaptor->pPorts) {
@@ -269,9 +269,9 @@ KdXVFreeAdaptor(XvAdaptorPtr pAdaptor)
       for(i = 0; i < pAdaptor->nPorts; i++, pPort++) {
           pPriv = (XvPortRecPrivatePtr)pPort->devPriv.ptr;
 	  if(pPriv) {
-	     if(pPriv->clientClip) 
+	     if(pPriv->clientClip)
 		REGION_DESTROY(pAdaptor->pScreen, pPriv->clientClip);
-             if(pPriv->pCompositeClip && pPriv->FreeCompositeClip) 
+             if(pPriv->pCompositeClip && pPriv->FreeCompositeClip)
 		REGION_DESTROY(pAdaptor->pScreen, pPriv->pCompositeClip);
 	     xfree(pPriv);
 	  }
@@ -291,14 +291,14 @@ KdXVFreeAdaptor(XvAdaptorPtr pAdaptor)
 
    if(pAdaptor->nImages)
       xfree(pAdaptor->pImages);
-	
+
    if(pAdaptor->devPriv.ptr)
       xfree(pAdaptor->devPriv.ptr);
 }
 
 static Bool
 KdXVInitAdaptors(
-   ScreenPtr pScreen, 
+   ScreenPtr pScreen,
    KdVideoAdaptorPtr *infoPtr,
    int number
 ) {
@@ -329,7 +329,7 @@ KdXVInitAdaptors(
   pxvs->nAdaptors = 0;
   pxvs->pAdaptors = NULL;
 
-  if(!(pAdaptor = xcalloc(number, sizeof(XvAdaptorRec)))) 
+  if(!(pAdaptor = xcalloc(number, sizeof(XvAdaptorRec))))
       return FALSE;
 
   for(pa = pAdaptor, na = 0, numAdaptor = 0; na < number; na++, adaptorPtr++) {
@@ -343,7 +343,7 @@ KdXVInitAdaptors(
       if(!adaptorPtr->nEncodings || !adaptorPtr->pEncodings)
 	   continue;
 
-      pa->type = adaptorPtr->type; 
+      pa->type = adaptorPtr->type;
 
       if(!adaptorPtr->PutVideo && !adaptorPtr->GetVideo)
 	 pa->type &= ~XvVideoMask;
@@ -354,19 +354,19 @@ KdXVInitAdaptors(
       if(!adaptorPtr->PutImage || !adaptorPtr->QueryImageAttributes)
 	 pa->type &= ~XvImageMask;
 
-      if(!adaptorPtr->PutVideo && !adaptorPtr->PutImage && 
+      if(!adaptorPtr->PutVideo && !adaptorPtr->PutImage &&
 							  !adaptorPtr->PutStill)
 	 pa->type &= ~XvInputMask;
 
       if(!adaptorPtr->GetVideo && !adaptorPtr->GetStill)
 	 pa->type &= ~XvOutputMask;
-	 
-      if(!(adaptorPtr->type & (XvPixmapMask | XvWindowMask))) 
+
+      if(!(adaptorPtr->type & (XvPixmapMask | XvWindowMask)))
 	  continue;
-      if(!(adaptorPtr->type & (XvImageMask | XvVideoMask | XvStillMask))) 
+      if(!(adaptorPtr->type & (XvImageMask | XvVideoMask | XvStillMask)))
 	  continue;
 
-      pa->pScreen = pScreen; 
+      pa->pScreen = pScreen;
       pa->ddAllocatePort = KdXVAllocatePort;
       pa->ddFreePort = KdXVFreePort;
       pa->ddPutVideo = KdXVPutVideo;
@@ -385,8 +385,8 @@ KdXVInitAdaptors(
       if(adaptorPtr->nEncodings &&
 	(pEncode = xcalloc(adaptorPtr->nEncodings, sizeof(XvEncodingRec)))) {
 
-	for(pe = pEncode, encodingPtr = adaptorPtr->pEncodings, i = 0; 
-	    i < adaptorPtr->nEncodings; pe++, i++, encodingPtr++) 
+	for(pe = pEncode, encodingPtr = adaptorPtr->pEncodings, i = 0;
+	    i < adaptorPtr->nEncodings; pe++, i++, encodingPtr++)
         {
 	    pe->id = encodingPtr->id;
 	    pe->pScreen = pScreen;
@@ -398,14 +398,14 @@ KdXVInitAdaptors(
 	    pe->rate.denominator = encodingPtr->rate.denominator;
 	}
 	pa->nEncodings = adaptorPtr->nEncodings;
-	pa->pEncodings = pEncode;  
-      } 
+	pa->pEncodings = pEncode;
+      }
 
       if(adaptorPtr->nImages &&
          (pImage = xcalloc(adaptorPtr->nImages, sizeof(XvImageRec)))) {
 
           for(i = 0, pi = pImage, imagePtr = adaptorPtr->pImages;
-	      i < adaptorPtr->nImages; i++, pi++, imagePtr++) 
+	      i < adaptorPtr->nImages; i++, pi++, imagePtr++)
   	  {
 	     pi->id = imagePtr->id;
 	     pi->type = imagePtr->type;
@@ -437,8 +437,8 @@ KdXVInitAdaptors(
       if(adaptorPtr->nAttributes &&
 	(pAttribute = xcalloc(adaptorPtr->nAttributes, sizeof(XvAttributeRec))))
       {
-	for(pat = pAttribute, attributePtr = adaptorPtr->pAttributes, i = 0; 
-	    i < adaptorPtr->nAttributes; pat++, i++, attributePtr++) 
+	for(pat = pAttribute, attributePtr = adaptorPtr->pAttributes, i = 0;
+	    i < adaptorPtr->nAttributes; pat++, i++, attributePtr++)
         {
 	    pat->flags = attributePtr->flags;
 	    pat->min_value = attributePtr->min_value;
@@ -447,8 +447,8 @@ KdXVInitAdaptors(
                 strcpy(pat->name, attributePtr->name);
 	}
 	pa->nAttributes = adaptorPtr->nAttributes;
-	pa->pAttributes = pAttribute;  
-      } 
+	pa->pAttributes = pAttribute;
+      }
 
 
       totFormat = adaptorPtr->nFormats;
@@ -457,8 +457,8 @@ KdXVInitAdaptors(
           KdXVFreeAdaptor(pa);
           continue;
       }
-      for(pf = pFormat, i = 0, numFormat = 0, formatPtr = adaptorPtr->pFormats; 
-	  i < adaptorPtr->nFormats; i++, formatPtr++) 
+      for(pf = pFormat, i = 0, numFormat = 0, formatPtr = adaptorPtr->pFormats;
+	  i < adaptorPtr->nFormats; i++, formatPtr++)
       {
 	  numVisuals = pScreen->numVisuals;
           pVisual = pScreen->visuals;
@@ -468,26 +468,26 @@ KdXVInitAdaptors(
                  (pVisual->nplanes == formatPtr->depth)) {
 
 		   if(numFormat >= totFormat) {
-			void *moreSpace; 
+			void *moreSpace;
 			totFormat *= 2;
-			moreSpace = xrealloc(pFormat, 
+			moreSpace = xrealloc(pFormat,
 					     totFormat * sizeof(XvFormatRec));
 			if(!moreSpace) break;
 			pFormat = moreSpace;
 			pf = pFormat + numFormat;
 		   }
 
-                   pf->visual = pVisual->vid; 
+                   pf->visual = pVisual->vid;
 		   pf->depth = formatPtr->depth;
 
 		   pf++;
 		   numFormat++;
               }
               pVisual++;
-          }	
+          }
       }
       pa->nFormats = numFormat;
-      pa->pFormats = pFormat;  
+      pa->pFormats = pFormat;
       if(!numFormat) {
           KdXVFreeAdaptor(pa);
           continue;
@@ -517,15 +517,15 @@ KdXVInitAdaptors(
           KdXVFreeAdaptor(pa);
           continue;
       }
-      for(pp = pPort, i = 0, numPort = 0; 
+      for(pp = pPort, i = 0, numPort = 0;
 	  i < adaptorPtr->nPorts; i++) {
 
-          if(!(pp->id = FakeClientID(0))) 
+          if(!(pp->id = FakeClientID(0)))
 		continue;
 
-	  if(!(portPriv = xcalloc(1, sizeof(XvPortRecPrivate)))) 
+	  if(!(portPriv = xcalloc(1, sizeof(XvPortRecPrivate))))
 		continue;
-	  
+
 	  if(!AddResource(pp->id, PortResource, pp)) {
 		xfree(portPriv);
 		continue;
@@ -542,7 +542,7 @@ KdXVInitAdaptors(
 	  portPriv->screen = screen;
 	  portPriv->AdaptorRec = adaptorPriv;
           portPriv->DevPriv.ptr = adaptorPtr->pPortPrivates[i].ptr;
-	
+
           pp++;
           numPort++;
       }
@@ -554,7 +554,7 @@ KdXVInitAdaptors(
       }
 
       pa->base_id = pPort->id;
-      
+
       pa++;
       numAdaptor++;
   }
@@ -580,13 +580,13 @@ KdXVInitAdaptors(
    the GC and used it's clip list when they needed to reclip the window,
    even if the client clip was different from the one the video was
    initialized with.  If the original GC was destroyed, they had to stop
-   the video.  I like the new method better (MArk). 
+   the video.  I like the new method better (MArk).
 
    This function only works for windows.  Will need to rewrite when
    (if) we support pixmap rendering.
 */
 
-static void  
+static void
 KdXVUpdateCompositeClip(XvPortRecPrivatePtr portPriv)
 {
    RegionPtr	pregWin, pCompositeClip;
@@ -623,7 +623,7 @@ KdXVUpdateCompositeClip(XvPortRecPrivatePtr portPriv)
 
    if(freeCompClip) {
    	REGION_DESTROY(pWin->pScreen, pregWin);
-   }    
+   }
 }
 
 /* Save the current clientClip and update the CompositeClip whenever
@@ -631,7 +631,7 @@ KdXVUpdateCompositeClip(XvPortRecPrivatePtr portPriv)
 
 static void
 KdXVCopyClip(
-   XvPortRecPrivatePtr portPriv, 
+   XvPortRecPrivatePtr portPriv,
    GCPtr pGC
 ){
     /* copy the new clip if it exists */
@@ -672,12 +672,12 @@ KdXVRegetVideo(XvPortRecPrivatePtr portPriv)
   WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y;
   WinBox.x2 = WinBox.x1 + portPriv->drw_w;
   WinBox.y2 = WinBox.y1 + portPriv->drw_h;
-  
+
   /* clip to the window composite clip */
   REGION_INIT(portPriv->pDraw->pScreen, &WinRegion, &WinBox, 1);
   REGION_INIT(portPriv->pDraw->pScreen, &ClipRegion, NullBox, 1);
-  REGION_INTERSECT(portPriv->pDraw->pScreen, &ClipRegion, &WinRegion, portPriv->pCompositeClip); 
-  
+  REGION_INTERSECT(portPriv->pDraw->pScreen, &ClipRegion, &WinRegion, portPriv->pCompositeClip);
+
   /* that's all if it's totally obscured */
   if(!REGION_NOTEMPTY(portPriv->pDraw->pScreen, &ClipRegion)) {
 	clippedAway = TRUE;
@@ -689,10 +689,10 @@ KdXVRegetVideo(XvPortRecPrivatePtr portPriv)
   }
 
   ret = (*portPriv->AdaptorRec->GetVideo)(portPriv->screen, portPriv->pDraw,
-			portPriv->vid_x, portPriv->vid_y, 
-			WinBox.x1, WinBox.y1, 
-			portPriv->vid_w, portPriv->vid_h, 
-			portPriv->drw_w, portPriv->drw_h, 
+			portPriv->vid_x, portPriv->vid_y,
+			WinBox.x1, WinBox.y1,
+			portPriv->vid_w, portPriv->vid_h,
+			portPriv->drw_w, portPriv->drw_h,
 			&ClipRegion, portPriv->DevPriv.ptr);
 
   if(ret == Success)
@@ -736,11 +736,11 @@ KdXVReputVideo(XvPortRecPrivatePtr portPriv)
   WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y;
   WinBox.x2 = WinBox.x1 + portPriv->drw_w;
   WinBox.y2 = WinBox.y1 + portPriv->drw_h;
-  
+
   /* clip to the window composite clip */
   REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
   REGION_INIT(pScreen, &ClipRegion, NullBox, 1);
-  REGION_INTERSECT(Screen, &ClipRegion, &WinRegion, portPriv->pCompositeClip); 
+  REGION_INTERSECT(Screen, &ClipRegion, &WinRegion, portPriv->pCompositeClip);
 
   /* clip and translate to the viewport */
   if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
@@ -753,10 +753,10 @@ KdXVReputVideo(XvPortRecPrivatePtr portPriv)
      VPBox.y2 = screen->height;
 
      REGION_INIT(pScreen, &VPReg, &VPBox, 1);
-     REGION_INTERSECT(Screen, &ClipRegion, &ClipRegion, &VPReg); 
+     REGION_INTERSECT(Screen, &ClipRegion, &ClipRegion, &VPReg);
      REGION_UNINIT(pScreen, &VPReg);
   }
-  
+
   /* that's all if it's totally obscured */
   if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
 	clippedAway = TRUE;
@@ -767,8 +767,8 @@ KdXVReputVideo(XvPortRecPrivatePtr portPriv)
   if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
      BoxPtr clipBox = REGION_RECTS(&ClipRegion);
      if(  (REGION_NUM_RECTS(&ClipRegion) != 1) ||
-	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) || 
-	  (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) 
+	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
+	  (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
      {
 	    clippedAway = TRUE;
 	    goto CLIP_VIDEO_BAILOUT;
@@ -780,10 +780,10 @@ KdXVReputVideo(XvPortRecPrivatePtr portPriv)
   }
 
   ret = (*portPriv->AdaptorRec->PutVideo)(portPriv->screen, portPriv->pDraw,
-			portPriv->vid_x, portPriv->vid_y, 
+			portPriv->vid_x, portPriv->vid_y,
 			WinBox.x1, WinBox.y1,
-			portPriv->vid_w, portPriv->vid_h, 
-			portPriv->drw_w, portPriv->drw_h, 
+			portPriv->vid_w, portPriv->vid_h,
+			portPriv->drw_w, portPriv->drw_h,
 			&ClipRegion, portPriv->DevPriv.ptr);
 
   if(ret == Success) portPriv->isOn = XV_ON;
@@ -825,11 +825,11 @@ KdXVReputImage(XvPortRecPrivatePtr portPriv)
   WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y;
   WinBox.x2 = WinBox.x1 + portPriv->drw_w;
   WinBox.y2 = WinBox.y1 + portPriv->drw_h;
-  
+
   /* clip to the window composite clip */
   REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
   REGION_INIT(pScreen, &ClipRegion, NullBox, 1);
-  REGION_INTERSECT(Screen, &ClipRegion, &WinRegion, portPriv->pCompositeClip); 
+  REGION_INTERSECT(Screen, &ClipRegion, &WinRegion, portPriv->pCompositeClip);
 
   /* clip and translate to the viewport */
   if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
@@ -842,10 +842,10 @@ KdXVReputImage(XvPortRecPrivatePtr portPriv)
      VPBox.y2 = screen->height;
 
      REGION_INIT(pScreen, &VPReg, &VPBox, 1);
-     REGION_INTERSECT(Screen, &ClipRegion, &ClipRegion, &VPReg); 
+     REGION_INTERSECT(Screen, &ClipRegion, &ClipRegion, &VPReg);
      REGION_UNINIT(pScreen, &VPReg);
   }
-  
+
   /* that's all if it's totally obscured */
   if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
 	clippedAway = TRUE;
@@ -856,8 +856,8 @@ KdXVReputImage(XvPortRecPrivatePtr portPriv)
   if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
      BoxPtr clipBox = REGION_RECTS(&ClipRegion);
      if(  (REGION_NUM_RECTS(&ClipRegion) != 1) ||
-	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) || 
-	  (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) 
+	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
+	  (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
      {
 	    clippedAway = TRUE;
 	    goto CLIP_VIDEO_BAILOUT;
@@ -897,10 +897,10 @@ static int
 KdXVReputAllVideo(WindowPtr pWin, pointer data)
 {
     KdXVWindowPtr WinPriv;
-    
+
     if (pWin->drawable.type != DRAWABLE_WINDOW)
 	return WT_DONTWALKCHILDREN;
-    
+
     WinPriv = GET_KDXV_WINDOW(pWin);
 
     while(WinPriv) {
@@ -917,7 +917,7 @@ KdXVReputAllVideo(WindowPtr pWin, pointer data)
 static int
 KdXVEnlistPortInWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv)
 {
-   KdXVWindowPtr winPriv, PrivRoot;    
+   KdXVWindowPtr winPriv, PrivRoot;
 
    winPriv = PrivRoot = GET_KDXV_WINDOW(pWin);
 
@@ -934,7 +934,7 @@ KdXVEnlistPortInWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv)
 	winPriv->PortRec = portPriv;
 	winPriv->next = PrivRoot;
 	dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, winPriv);
-   }   
+   }
    return Success;
 }
 
@@ -948,14 +948,14 @@ KdXVRemovePortFromWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv)
 
      while(winPriv) {
 	if(winPriv->PortRec == portPriv) {
-	    if(prevPriv) 
+	    if(prevPriv)
 		prevPriv->next = winPriv->next;
-	    else 
+	    else
 		dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, winPriv->next);
 	    xfree(winPriv);
 	    break;
 	}
-	prevPriv = winPriv; 
+	prevPriv = winPriv;
 	winPriv = winPriv->next;
      }
      portPriv->pDraw = NULL;
@@ -1033,7 +1033,7 @@ KdXVWindowExposures(WindowPtr pWin, RegionPtr reg1, RegionPtr reg2)
 
   /* filter out XClearWindow/Area */
   if (!pWin->valdata) return;
-   
+
   pPrev = NULL;
 
   while(WinPriv) {
@@ -1044,10 +1044,10 @@ KdXVWindowExposures(WindowPtr pWin, RegionPtr reg1, RegionPtr reg2)
      switch(pPriv->type) {
      case XvInputMask:
 	KdXVReputVideo(pPriv);
-	break;	     
+	break;
      case XvOutputMask:
-	KdXVRegetVideo(pPriv);	
-	break;     
+	KdXVRegetVideo(pPriv);
+	break;
      default:  /* overlaid still/image*/
 	if (pPriv->AdaptorRec->ReputImage)
 	   KdXVReputImage(pPriv);
@@ -1061,7 +1061,7 @@ KdXVWindowExposures(WindowPtr pWin, RegionPtr reg1, RegionPtr reg2)
 	    }
 	    pPriv->pDraw = NULL;
 
-	    if(!pPrev) 
+	    if(!pPrev)
 		dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, WinPriv->next);
 	    else
 	       pPrev->next = WinPriv->next;
@@ -1078,7 +1078,7 @@ KdXVWindowExposures(WindowPtr pWin, RegionPtr reg1, RegionPtr reg2)
 }
 
 
-static void 
+static void
 KdXVClipNotify(WindowPtr pWin, int dx, int dy)
 {
   ScreenPtr pScreen = pWin->drawable.pScreen;
@@ -1097,7 +1097,7 @@ KdXVClipNotify(WindowPtr pWin, int dx, int dy)
 
      pPriv->pCompositeClip = NULL;
 
-     /* Stop everything except images, but stop them too if the 
+     /* Stop everything except images, but stop them too if the
 	window isn't visible.  But we only remove the images. */
 
      if(pPriv->type || !visible) {
@@ -1110,7 +1110,7 @@ KdXVClipNotify(WindowPtr pWin, int dx, int dy)
 	if(!pPriv->type) {  /* overlaid still/image */
 	    pPriv->pDraw = NULL;
 
-	    if(!pPrev) 
+	    if(!pPrev)
 		dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, WinPriv->next);
 	    else
 	       pPrev->next = WinPriv->next;
@@ -1153,7 +1153,7 @@ KdXVCloseScreen(int i, ScreenPtr pScreen)
 
 /*   fprintf(stderr,"XV: Unwrapping screen funcs\n"); */
 
-  for(c = 0, pa = pxvs->pAdaptors; c < pxvs->nAdaptors; c++, pa++) { 
+  for(c = 0, pa = pxvs->pAdaptors; c < pxvs->nAdaptors; c++, pa++) {
        KdXVFreeAdaptor(pa);
   }
 
@@ -1193,9 +1193,9 @@ KdXVEnable(ScreenPtr pScreen)
 {
     if (!KdXVRunning (pScreen))
 	return TRUE;
-    
-    WalkTree(pScreen, KdXVReputAllVideo, 0); 
- 
+
+    WalkTree(pScreen, KdXVReputAllVideo, 0);
+
     return TRUE;
 }
 
@@ -1214,7 +1214,7 @@ KdXVDisable(ScreenPtr pScreen)
 
     pxvs = GET_XV_SCREEN(pScreen);
     ScreenPriv = GET_KDXV_SCREEN(pScreen);
-    
+
     for(i = 0; i < pxvs->nAdaptors; i++) {
 	pAdaptor = &pxvs->pAdaptors[i];
 	for(j = 0; j < pAdaptor->nPorts; j++) {
@@ -1263,8 +1263,8 @@ KdXVPutVideo(
    DrawablePtr pDraw,
    XvPortPtr pPort,
    GCPtr pGC,
-   INT16 vid_x, INT16 vid_y, 
-   CARD16 vid_w, CARD16 vid_h, 
+   INT16 vid_x, INT16 vid_y,
+   CARD16 vid_w, CARD16 vid_h,
    INT16 drw_x, INT16 drw_y,
    CARD16 drw_w, CARD16 drw_h
 ){
@@ -1277,7 +1277,7 @@ KdXVPutVideo(
       pPort->pDraw = (DrawablePtr)NULL;
       return BadAlloc;
   }
-  
+
   /* If we are changing windows, unregister our port in the old window */
   if(portPriv->pDraw && (portPriv->pDraw != pDraw))
      KdXVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv);
@@ -1302,7 +1302,7 @@ KdXVPutVideo(
   pPort->pDraw = pDraw;
 
   if (!pScreenPriv->enabled) return Success;
-  
+
   return(KdXVReputVideo(portPriv));
 }
 
@@ -1312,13 +1312,13 @@ KdXVPutStill(
    DrawablePtr pDraw,
    XvPortPtr pPort,
    GCPtr pGC,
-   INT16 vid_x, INT16 vid_y, 
-   CARD16 vid_w, CARD16 vid_h, 
+   INT16 vid_x, INT16 vid_y,
+   CARD16 vid_w, CARD16 vid_h,
    INT16 drw_x, INT16 drw_y,
    CARD16 drw_w, CARD16 drw_h
 ){
   XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
-  ScreenPtr pScreen = pDraw->pScreen;  
+  ScreenPtr pScreen = pDraw->pScreen;
   KdScreenPriv(pScreen);
   KdScreenInfo *screen=pScreenPriv->screen;
   RegionRec WinRegion;
@@ -1336,10 +1336,10 @@ KdXVPutStill(
   WinBox.y1 = pDraw->y + drw_y;
   WinBox.x2 = WinBox.x1 + drw_w;
   WinBox.y2 = WinBox.y1 + drw_h;
-  
+
   REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
   REGION_INIT(pScreen, &ClipRegion, NullBox, 1);
-  REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, pGC->pCompositeClip);   
+  REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, pGC->pCompositeClip);
 
   if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
      RegionRec VPReg;
@@ -1351,7 +1351,7 @@ KdXVPutStill(
      VPBox.y2 = screen->height;
 
      REGION_INIT(pScreen, &VPReg, &VPBox, 1);
-     REGION_INTERSECT(Screen, &ClipRegion, &ClipRegion, &VPReg); 
+     REGION_INTERSECT(Screen, &ClipRegion, &ClipRegion, &VPReg);
      REGION_UNINIT(pScreen, &VPReg);
   }
 
@@ -1367,7 +1367,7 @@ KdXVPutStill(
   if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
      BoxPtr clipBox = REGION_RECTS(&ClipRegion);
      if(  (REGION_NUM_RECTS(&ClipRegion) != 1) ||
-	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) || 
+	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
 	  (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
      {
 	  clippedAway = TRUE;
@@ -1417,8 +1417,8 @@ KdXVGetVideo(
    DrawablePtr pDraw,
    XvPortPtr pPort,
    GCPtr pGC,
-   INT16 vid_x, INT16 vid_y, 
-   CARD16 vid_w, CARD16 vid_h, 
+   INT16 vid_x, INT16 vid_y,
+   CARD16 vid_w, CARD16 vid_h,
    INT16 drw_x, INT16 drw_y,
    CARD16 drw_w, CARD16 drw_h
 ){
@@ -1431,7 +1431,7 @@ KdXVGetVideo(
       pPort->pDraw = (DrawablePtr)NULL;
       return BadAlloc;
   }
-  
+
   /* If we are changing windows, unregister our port in the old window */
   if(portPriv->pDraw && (portPriv->pDraw != pDraw))
      KdXVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv);
@@ -1454,7 +1454,7 @@ KdXVGetVideo(
 
   /* To indicate to the DI layer that we were successful */
   pPort->pDraw = pDraw;
-  
+
   if(!pScreenPriv->enabled) return Success;
 
   return(KdXVRegetVideo(portPriv));
@@ -1466,8 +1466,8 @@ KdXVGetStill(
    DrawablePtr pDraw,
    XvPortPtr pPort,
    GCPtr pGC,
-   INT16 vid_x, INT16 vid_y, 
-   CARD16 vid_w, CARD16 vid_h, 
+   INT16 vid_x, INT16 vid_y,
+   CARD16 vid_w, CARD16 vid_h,
    INT16 drw_x, INT16 drw_y,
    CARD16 drw_w, CARD16 drw_h
 ){
@@ -1489,10 +1489,10 @@ KdXVGetStill(
   WinBox.y1 = pDraw->y + drw_y;
   WinBox.x2 = WinBox.x1 + drw_w;
   WinBox.y2 = WinBox.y1 + drw_h;
-  
+
   REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
   REGION_INIT(pScreen, &ClipRegion, NullBox, 1);
-  REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, pGC->pCompositeClip);   
+  REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, pGC->pCompositeClip);
 
   if(portPriv->pDraw) {
      KdXVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv);
@@ -1526,7 +1526,7 @@ GET_STILL_BAILOUT:
   return ret;
 }
 
- 
+
 
 static int
 KdXVStopVideo(
@@ -1539,7 +1539,7 @@ KdXVStopVideo(
 
   if(pDraw->type != DRAWABLE_WINDOW)
       return BadAlloc;
-  
+
   KdXVRemovePortFromWindow((WindowPtr)pDraw, portPriv);
 
   if(!pScreenPriv->enabled) return Success;
@@ -1563,8 +1563,8 @@ KdXVSetPortAttribute(
    INT32 value
 ){
   XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
-     
-  return((*portPriv->AdaptorRec->SetPortAttribute)(portPriv->screen, 
+
+  return((*portPriv->AdaptorRec->SetPortAttribute)(portPriv->screen,
 		attribute, value, portPriv->DevPriv.ptr));
 }
 
@@ -1577,8 +1577,8 @@ KdXVGetPortAttribute(
    INT32 *p_value
 ){
   XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
-     
-  return((*portPriv->AdaptorRec->GetPortAttribute)(portPriv->screen, 
+
+  return((*portPriv->AdaptorRec->GetPortAttribute)(portPriv->screen,
 		attribute, (int *) p_value, portPriv->DevPriv.ptr));
 }
 
@@ -1594,8 +1594,8 @@ KdXVQueryBestSize(
    unsigned int *p_w, unsigned int *p_h
 ){
   XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
-     
-  (*portPriv->AdaptorRec->QueryBestSize)(portPriv->screen, 
+
+  (*portPriv->AdaptorRec->QueryBestSize)(portPriv->screen,
 		(Bool)motion, vid_w, vid_h, drw_w, drw_h,
 		p_w, p_h, portPriv->DevPriv.ptr);
 
@@ -1603,14 +1603,14 @@ KdXVQueryBestSize(
 }
 
 
-static int 
+static int
 KdXVPutImage(
-   ClientPtr client, 
-   DrawablePtr pDraw, 
-   XvPortPtr pPort, 
+   ClientPtr client,
+   DrawablePtr pDraw,
+   XvPortPtr pPort,
    GCPtr pGC,
-   INT16 src_x, INT16 src_y, 
-   CARD16 src_w, CARD16 src_h, 
+   INT16 src_x, INT16 src_y,
+   CARD16 src_w, CARD16 src_h,
    INT16 drw_x, INT16 drw_y,
    CARD16 drw_w, CARD16 drw_h,
    XvImagePtr format,
@@ -1636,10 +1636,10 @@ KdXVPutImage(
   WinBox.y1 = pDraw->y + drw_y;
   WinBox.x2 = WinBox.x1 + drw_w;
   WinBox.y2 = WinBox.y1 + drw_h;
-  
+
   REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
   REGION_INIT(pScreen, &ClipRegion, NullBox, 1);
-  REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, pGC->pCompositeClip);   
+  REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, pGC->pCompositeClip);
 
   if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
      RegionRec VPReg;
@@ -1651,7 +1651,7 @@ KdXVPutImage(
      VPBox.y2 = pScreen->height;
 
      REGION_INIT(pScreen, &VPReg, &VPBox, 1);
-     REGION_INTERSECT(Screen, &ClipRegion, &ClipRegion, &VPReg); 
+     REGION_INTERSECT(Screen, &ClipRegion, &ClipRegion, &VPReg);
      REGION_UNINIT(pScreen, &VPReg);
   }
 
@@ -1667,7 +1667,7 @@ KdXVPutImage(
   if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
      BoxPtr clipBox = REGION_RECTS(&ClipRegion);
      if(  (REGION_NUM_RECTS(&ClipRegion) != 1) ||
-	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) || 
+	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
 	  (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
      {
 	  clippedAway = TRUE;
@@ -1712,19 +1712,19 @@ PUT_IMAGE_BAILOUT:
 }
 
 
-static  int 
+static  int
 KdXVQueryImageAttributes(
-   ClientPtr client, 
+   ClientPtr client,
    XvPortPtr pPort,
-   XvImagePtr format, 
-   CARD16 *width, 
-   CARD16 *height, 
+   XvImagePtr format,
+   CARD16 *width,
+   CARD16 *height,
    int *pitches,
    int *offsets
 ){
   XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
 
-  return (*portPriv->AdaptorRec->QueryImageAttributes)(portPriv->screen, 
+  return (*portPriv->AdaptorRec->QueryImageAttributes)(portPriv->screen,
 			format->id, width, height, pitches, offsets);
 }
 
@@ -1878,7 +1878,7 @@ KXVPaintRegion (DrawablePtr pDraw, RegionPtr pRgn, Pixel fg)
     xRectangle	*rects, *r;
     BoxPtr	pBox = REGION_RECTS (pRgn);
     int		nBox = REGION_NUM_RECTS (pRgn);
-    
+
     rects = xalloc (nBox * sizeof (xRectangle));
     if (!rects)
 	goto bail0;
@@ -1892,18 +1892,18 @@ KXVPaintRegion (DrawablePtr pDraw, RegionPtr pRgn, Pixel fg)
 	r++;
 	pBox++;
     }
-    
+
     pGC = GetScratchGC (pDraw->depth, pDraw->pScreen);
     if (!pGC)
 	goto bail1;
-    
+
     val[0] = fg;
     val[1] = IncludeInferiors;
     ChangeGC (pGC, GCForeground|GCSubwindowMode, val);
-    
+
     ValidateGC (pDraw, pGC);
-    
-    (*pGC->ops->PolyFillRect) (pDraw, pGC, 
+
+    (*pGC->ops->PolyFillRect) (pDraw, pGC,
 			       REGION_NUM_RECTS (pRgn), rects);
 
     FreeScratchGC (pGC);
diff --git a/hw/kdrive/src/kxv.h b/hw/kdrive/src/kxv.h
index 900baef..21a295b 100644
--- a/hw/kdrive/src/kxv.h
+++ b/hw/kdrive/src/kxv.h
@@ -1,6 +1,6 @@
-/* 
+/*
 
-   XFree86 Xv DDX written by Mark Vojkovich (markv at valinux.com) 
+   XFree86 Xv DDX written by Mark Vojkovich (markv at valinux.com)
    Adapted for KDrive by Pontus Lidman <pontus.lidman at nokia.com>
 
    Copyright (C) 2000, 2001 - Nokia Home Communications
@@ -60,21 +60,21 @@ typedef struct {
   int id;
   int type;
   int byte_order;
-  unsigned char guid[16];               
+  unsigned char guid[16];
   int bits_per_pixel;
   int format;
   int num_planes;
 
   /* for RGB formats only */
   int depth;
-  unsigned int red_mask;       
-  unsigned int green_mask;   
-  unsigned int blue_mask;   
+  unsigned int red_mask;
+  unsigned int green_mask;
+  unsigned int blue_mask;
 
   /* for YUV formats only */
   unsigned int y_sample_bits;
   unsigned int u_sample_bits;
-  unsigned int v_sample_bits;   
+  unsigned int v_sample_bits;
   unsigned int horz_y_period;
   unsigned int horz_u_period;
   unsigned int horz_v_period;
@@ -83,7 +83,7 @@ typedef struct {
   unsigned int vert_v_period;
   char component_order[32];
   int scanline_order;
-} KdImageRec, *KdImagePtr; 
+} KdImageRec, *KdImagePtr;
 
 
 typedef struct {
@@ -92,7 +92,7 @@ typedef struct {
   unsigned short width, height;
   int *pitches; /* bytes */
   int *offsets; /* in bytes from start of framebuffer */
-  DevUnion devPrivate;  
+  DevUnion devPrivate;
 } KdSurfaceRec, *KdSurfacePtr;
 
 
@@ -118,7 +118,7 @@ typedef int (* SetPortAttributeFuncPtr)(KdScreenInfo * screen, Atom attribute,
 typedef int (* GetPortAttributeFuncPtr)(KdScreenInfo * screen, Atom attribute,
 	int *value, pointer data);
 typedef void (* QueryBestSizeFuncPtr)(KdScreenInfo * screen, Bool motion,
-	short vid_w, short vid_h, short drw_w, short drw_h, 
+	short vid_w, short vid_h, short drw_w, short drw_h,
 	unsigned int *p_w, unsigned int *p_h, pointer data);
 typedef int (* PutImageFuncPtr)( KdScreenInfo * screen,  DrawablePtr pDraw,
 	short src_x, short src_y, short drw_x, short drw_y,
@@ -128,8 +128,8 @@ typedef int (* PutImageFuncPtr)( KdScreenInfo * screen,  DrawablePtr pDraw,
 typedef int (* ReputImageFuncPtr)( KdScreenInfo * screen, DrawablePtr pDraw,
 				  short drw_x, short drw_y,
 				  RegionPtr clipBoxes, pointer data );
-typedef int (*QueryImageAttributesFuncPtr)(KdScreenInfo * screen, 
-	int image, unsigned short *width, unsigned short *height, 
+typedef int (*QueryImageAttributesFuncPtr)(KdScreenInfo * screen,
+	int image, unsigned short *width, unsigned short *height,
 	int *pitches, int *offsets);
 
 typedef enum {
@@ -148,7 +148,7 @@ typedef struct {
 } KdVideoEncodingRec, *KdVideoEncodingPtr;
 
 typedef struct {
-  char 	depth;  
+  char 	depth;
   short class;
 } KdVideoFormatRec, *KdVideoFormatPtr;
 
@@ -160,13 +160,13 @@ typedef struct {
 } KdAttributeRec, *KdAttributePtr;
 
 typedef struct {
-  unsigned int type; 
+  unsigned int type;
   int flags;
   char *name;
   int nEncodings;
-  KdVideoEncodingPtr pEncodings;  
+  KdVideoEncodingPtr pEncodings;
   int nFormats;
-  KdVideoFormatPtr pFormats;  
+  KdVideoFormatPtr pFormats;
   int nPorts;
   DevUnion *pPortPrivates;
   int nAttributes;
@@ -188,7 +188,7 @@ typedef struct {
 
 Bool
 KdXVScreenInit(
-   ScreenPtr pScreen, 
+   ScreenPtr pScreen,
    KdVideoAdaptorPtr 	*Adaptors,
    int num
 );
@@ -239,7 +239,7 @@ typedef struct {
 } KdXVScreenRec, *KdXVScreenPtr;
 
 typedef struct {
-  int flags;  
+  int flags;
   PutVideoFuncPtr PutVideo;
   PutStillFuncPtr PutStill;
   GetVideoFuncPtr GetVideo;
@@ -276,4 +276,4 @@ typedef struct _KdXVWindowRec{
 } KdXVWindowRec, *KdXVWindowPtr;
 
 #endif  /* _XVDIX_H_ */
- 
+
commit 1763550d0181ac1c775b9ddf490114eff2fbe67e
Author: Simon Thum <simon.thum at gmx.de>
Date:   Fri Jan 1 19:58:05 2010 +0100

    dix: add smooth limited pointer acceleration profile
    
    This profile is inspired by the accel code removed from the wacom driver.
    It ascends from zero to acceleration, maxing out at threshold. This means you
    can control the slope using threshold, which wasn't possible in wacom.
    For sanity's sake, threshold should grow with acceleration.
    
    Works best with adaptive deceleration, since otherwise it only generates
    acceleration above 1, causing seldom pixel skips.
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index 6fb9e21..c2f4378 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -868,6 +868,31 @@ SmoothLinearProfile(
 }
 
 
+/**
+ * From 0 to threshold, the response graduates smoothly from min_accel to
+ * acceleration. Beyond threshold it is exactly the specified acceleration.
+ */
+static float
+SmoothLimitedProfile(
+    DeviceIntPtr dev,
+    DeviceVelocityPtr vel,
+    float velocity,
+    float threshold,
+    float acc)
+{
+    float res;
+
+    if(velocity >= threshold || threshold == 0.0f)
+	return acc;
+
+    velocity /= threshold; /* should be [0..1[ now */
+
+    res = CalcPenumbralGradient(velocity) * (acc - vel->min_acceleration);
+
+    return vel->min_acceleration + res;
+}
+
+
 static float
 LinearProfile(
     DeviceIntPtr dev,
@@ -879,7 +904,6 @@ LinearProfile(
     return acc * velocity;
 }
 
-
 static float
 NoProfile(
     DeviceIntPtr dev,
@@ -911,6 +935,8 @@ GetAccelerationProfile(
             return PowerProfile;
         case AccelProfileLinear:
             return LinearProfile;
+        case AccelProfileSmoothLimited:
+            return SmoothLimitedProfile;
         case AccelProfileNone:
             return NoProfile;
         default:
diff --git a/include/ptrveloc.h b/include/ptrveloc.h
index 2a4b40b..676c464 100644
--- a/include/ptrveloc.h
+++ b/include/ptrveloc.h
@@ -37,7 +37,8 @@
 #define AccelProfileSimple 4
 #define AccelProfilePower 5
 #define AccelProfileLinear 6
-#define AccelProfileLAST AccelProfileLinear
+#define AccelProfileSmoothLimited 7
+#define AccelProfileLAST AccelProfileSmoothLimited
 
 /* fwd */
 struct _DeviceVelocityRec;
commit 435f27667f84269768efecde34de4af2b2d43376
Author: Julien Cristau <jcristau at debian.org>
Date:   Sun Sep 27 14:45:47 2009 +0200

    config: add libudev input-hotplug backend
    
    Add a backend using libudev for input hotplug, and disable the hal and
    dbus backends if this one is enabled.
    
    XKB configuration happens using xkb{rules,model,layout,variant,options}
    properties (case-insensitive) on the device.  We fill in InputAttributes
    to allow configuration through InputClass in Xorg.
    
    Requires udev 148 for the input_id helper and ID_INPUT* properties.
    
    Signed-off-by: Julien Cristau <jcristau at debian.org>
    Acked-by: Dan Nicholson <dbn.lists at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/config/Makefile.am b/config/Makefile.am
index 7fa2df8..27f251b 100644
--- a/config/Makefile.am
+++ b/config/Makefile.am
@@ -1,12 +1,20 @@
-AM_CFLAGS = @DIX_CFLAGS@
+AM_CFLAGS = $(DIX_CFLAGS)
 
 noinst_LTLIBRARIES = libconfig.la
 libconfig_la_SOURCES = config.c config-backends.h
 
+if CONFIG_UDEV
+
+AM_CFLAGS += $(UDEV_CFLAGS)
+libconfig_la_SOURCES += udev.c
+libconfig_la_LIBADD = $(UDEV_LIBS)
+
+else
+
 if CONFIG_NEED_DBUS
-AM_CFLAGS += @DBUS_CFLAGS@
+AM_CFLAGS += $(DBUS_CFLAGS)
 libconfig_la_SOURCES += dbus-core.c
-endif
+libconfig_la_LIBADD = $(DBUS_LIBS)
 
 if CONFIG_DBUS_API
 dbusconfigdir = $(sysconfdir)/dbus-1/system.d
@@ -16,7 +24,13 @@ libconfig_la_SOURCES += dbus.c
 endif
 
 if CONFIG_HAL
+AM_CFLAGS += $(HAL_CFLAGS)
 libconfig_la_SOURCES += hal.c
+libconfig_la_LIBADD += $(HAL_LIBS)
 endif
 
+endif # CONFIG_NEED_DBUS
+
+endif # !CONFIG_UDEV
+
 EXTRA_DIST = xorg-server.conf x11-input.fdi
diff --git a/config/config-backends.h b/config/config-backends.h
index 907e86b..0a2a22a 100644
--- a/config/config-backends.h
+++ b/config/config-backends.h
@@ -26,8 +26,18 @@
 #ifdef HAVE_DIX_CONFIG_H
 #include <dix-config.h>
 #endif
+#include "input.h"
 
-#ifdef CONFIG_NEED_DBUS
+void remove_devices(const char *backend, const char *config_info);
+BOOL device_is_duplicate(const char *config_info);
+void add_option(InputOption **options, const char *key, const char *value);
+
+#ifdef CONFIG_UDEV
+int config_udev_init(void);
+void config_udev_fini(void);
+#else
+
+# ifdef CONFIG_NEED_DBUS
 #include <dbus/dbus.h>
 
 typedef void (*config_dbus_core_connect_hook)(DBusConnection *connection,
@@ -46,14 +56,15 @@ int config_dbus_core_init(void);
 void config_dbus_core_fini(void);
 int config_dbus_core_add_hook(struct config_dbus_core_hook *hook);
 void config_dbus_core_remove_hook(struct config_dbus_core_hook *hook);
-#endif
+# endif
 
-#ifdef CONFIG_DBUS_API
+# ifdef CONFIG_DBUS_API
 int config_dbus_init(void);
 void config_dbus_fini(void);
-#endif
+# endif
 
-#ifdef CONFIG_HAL
+# ifdef CONFIG_HAL
 int config_hal_init(void);
 void config_hal_fini(void);
+# endif
 #endif
diff --git a/config/config.c b/config/config.c
index b013293..7bf5e41 100644
--- a/config/config.c
+++ b/config/config.c
@@ -28,13 +28,17 @@
 #endif
 
 #include "os.h"
+#include "inputstr.h"
 #include "hotplug.h"
 #include "config-backends.h"
 
 void
 config_init(void)
 {
-#if defined(CONFIG_DBUS_API) || defined(CONFIG_HAL)
+#ifdef CONFIG_UDEV
+    if (!config_udev_init())
+        ErrorF("[config] failed to initialise udev\n");
+#elif defined(CONFIG_NEED_DBUS)
     if (config_dbus_core_init()) {
 # ifdef CONFIG_DBUS_API
        if (!config_dbus_init())
@@ -54,7 +58,9 @@ config_init(void)
 void
 config_fini(void)
 {
-#if defined(CONFIG_DBUS_API) || defined(CONFIG_HAL)
+#if defined(CONFIG_UDEV)
+    config_udev_fini();
+#elif defined(CONFIG_NEED_DBUS)
 # ifdef CONFIG_HAL
     config_hal_fini();
 # endif
@@ -64,3 +70,70 @@ config_fini(void)
     config_dbus_core_fini();
 #endif
 }
+
+static void
+remove_device(const char *backend, DeviceIntPtr dev)
+{
+    /* this only gets called for devices that have already been added */
+    LogMessage(X_INFO, "config/%s: removing device %s\n", backend, dev->name);
+
+    /* Call PIE here so we don't try to dereference a device that's
+     * already been removed. */
+    OsBlockSignals();
+    ProcessInputEvents();
+    DeleteInputDeviceRequest(dev);
+    OsReleaseSignals();
+}
+
+void
+remove_devices(const char *backend, const char *config_info)
+{
+    DeviceIntPtr dev, next;
+
+    for (dev = inputInfo.devices; dev; dev = next) {
+        next = dev->next;
+        if (dev->config_info && strcmp(dev->config_info, config_info) == 0)
+            remove_device(backend, dev);
+    }
+    for (dev = inputInfo.off_devices; dev; dev = next) {
+        next = dev->next;
+        if (dev->config_info && strcmp(dev->config_info, config_info) == 0)
+            remove_device(backend, dev);
+    }
+}
+
+BOOL
+device_is_duplicate(const char *config_info)
+{
+    DeviceIntPtr dev;
+
+    for (dev = inputInfo.devices; dev; dev = dev->next)
+    {
+        if (dev->config_info && (strcmp(dev->config_info, config_info) == 0))
+            return TRUE;
+    }
+
+    for (dev = inputInfo.off_devices; dev; dev = dev->next)
+    {
+        if (dev->config_info && (strcmp(dev->config_info, config_info) == 0))
+            return TRUE;
+    }
+
+    return FALSE;
+}
+
+void
+add_option(InputOption **options, const char *key, const char *value)
+{
+    if (!value || *value == '\0')
+        return;
+
+    for (; *options; options = &(*options)->next)
+        ;
+    *options = xcalloc(sizeof(**options), 1);
+    if (!*options) /* Yeesh. */
+        return;
+    (*options)->key = xstrdup(key);
+    (*options)->value = xstrdup(value);
+    (*options)->next = NULL;
+}
diff --git a/config/hal.c b/config/hal.c
index 6bebbdf..1b01ecc 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -58,25 +58,9 @@ struct xkb_options {
     char* options;
 };
 
-
-static void
-remove_device(DeviceIntPtr dev)
-{
-    /* this only gets called for devices that have already been added */
-    LogMessage(X_INFO, "config/hal: removing device %s\n", dev->name);
-
-    /* Call PIE here so we don't try to dereference a device that's
-     * already been removed. */
-    OsBlockSignals();
-    ProcessInputEvents();
-    DeleteInputDeviceRequest(dev);
-    OsReleaseSignals();
-}
-
 static void
 device_removed(LibHalContext *ctx, const char *udi)
 {
-    DeviceIntPtr dev, next;
     char *value;
 
     value = xalloc(strlen(udi) + 5); /* "hal:" + NULL */
@@ -84,36 +68,11 @@ device_removed(LibHalContext *ctx, const char *udi)
         return;
     sprintf(value, "hal:%s", udi);
 
-    for (dev = inputInfo.devices; dev; dev = next) {
-	next = dev->next;
-        if (dev->config_info && strcmp(dev->config_info, value) == 0)
-            remove_device(dev);
-    }
-    for (dev = inputInfo.off_devices; dev; dev = next) {
-	next = dev->next;
-        if (dev->config_info && strcmp(dev->config_info, value) == 0)
-            remove_device(dev);
-    }
+    remove_devices("hal", value);
 
     xfree(value);
 }
 
-static void
-add_option(InputOption **options, const char *key, const char *value)
-{
-    if (!value || *value == '\0')
-        return;
-
-    for (; *options; options = &(*options)->next)
-        ;
-    *options = xcalloc(sizeof(**options), 1);
-    if (!*options) /* Yeesh. */
-        return;
-    (*options)->key = xstrdup(key);
-    (*options)->value = xstrdup(value);
-    (*options)->next = NULL;
-}
-
 static char *
 get_prop_string(LibHalContext *hal_ctx, const char *udi, const char *name)
 {
@@ -166,26 +125,6 @@ get_prop_string_array(LibHalContext *hal_ctx, const char *udi, const char *prop)
     return ret;
 }
 
-static BOOL
-device_is_duplicate(char *config_info)
-{
-    DeviceIntPtr dev;
-
-    for (dev = inputInfo.devices; dev; dev = dev->next)
-    {
-        if (dev->config_info && (strcmp(dev->config_info, config_info) == 0))
-            return TRUE;
-    }
-
-    for (dev = inputInfo.off_devices; dev; dev = dev->next)
-    {
-        if (dev->config_info && (strcmp(dev->config_info, config_info) == 0))
-            return TRUE;
-    }
-
-    return FALSE;
-}
-
 static void
 device_added(LibHalContext *hal_ctx, const char *udi)
 {
diff --git a/config/udev.c b/config/udev.c
new file mode 100644
index 0000000..3ef0d7f
--- /dev/null
+++ b/config/udev.c
@@ -0,0 +1,260 @@
+/*
+ * Copyright © 2009 Julien Cristau
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Author: Julien Cristau <jcristau at debian.org>
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <libudev.h>
+
+#include "input.h"
+#include "inputstr.h"
+#include "hotplug.h"
+#include "config-backends.h"
+#include "os.h"
+
+#define UDEV_XKB_PROP_KEY "xkb"
+
+static struct udev_monitor *udev_monitor;
+
+static void
+device_added(struct udev_device *udev_device)
+{
+    const char *path, *name = NULL;
+    char *config_info = NULL;
+    const char *syspath;
+    const char *key, *value, *tmp;
+    InputOption *options = NULL, *tmpo;
+    InputAttributes attrs = {};
+    DeviceIntPtr dev = NULL;
+    struct udev_list_entry *set, *entry;
+    struct udev_device *parent;
+    int rc;
+
+    path = udev_device_get_devnode(udev_device);
+
+    syspath = udev_device_get_syspath(udev_device);
+
+    if (!path || !syspath)
+        return;
+
+    if (!udev_device_get_property_value(udev_device, "ID_INPUT"))
+        return;
+
+    options = xcalloc(sizeof(*options), 1);
+    if (!options)
+        return;
+
+    options->key = xstrdup("_source");
+    options->value = xstrdup("server/udev");
+    if (!options->key || !options->value)
+        goto unwind;
+
+    parent = udev_device_get_parent(udev_device);
+    if (parent)
+        name = udev_device_get_property_value(parent, "NAME");
+    if (!name)
+        name = "(unnamed)";
+    else
+        attrs.product = name;
+    add_option(&options, "name", name);
+
+    add_option(&options, "path", path);
+    add_option(&options, "device", path);
+    attrs.device = path;
+
+    config_info = Xprintf("udev:%s", syspath);
+    if (!config_info)
+        goto unwind;
+
+    if (device_is_duplicate(config_info)) {
+        LogMessage(X_WARNING, "config/udev: device %s already added. "
+                              "Ignoring.\n", name);
+        goto unwind;
+    }
+
+    set = udev_device_get_properties_list_entry(udev_device);
+    udev_list_entry_foreach(entry, set) {
+        key = udev_list_entry_get_name(entry);
+        if (!key)
+            continue;
+        value = udev_list_entry_get_value(entry);
+        if (!strncasecmp(key, UDEV_XKB_PROP_KEY,
+                                sizeof(UDEV_XKB_PROP_KEY) - 1)) {
+            tmp = key + sizeof(UDEV_XKB_PROP_KEY) - 1;
+            if (!strcasecmp(tmp, "rules"))
+                add_option(&options, "xkb_rules", value);
+            else if (!strcasecmp(tmp, "layout"))
+                add_option(&options, "xkb_layout", value);
+            else if (!strcasecmp(tmp, "variant"))
+                add_option(&options, "xkb_variant", value);
+            else if (!strcasecmp(tmp, "model"))
+                add_option(&options, "xkb_model", value);
+            else if (!strcasecmp(tmp, "options"))
+                add_option(&options, "xkb_options", value);
+        } else if (!strcmp(key, "ID_VENDOR")) {
+            attrs.vendor = value;
+        } else if (!strcmp(key, "ID_INPUT_KEY")) {
+            attrs.flags |= ATTR_KEYBOARD;
+        } else if (!strcmp(key, "ID_INPUT_MOUSE")) {
+            attrs.flags |= ATTR_POINTER;
+        } else if (!strcmp(key, "ID_INPUT_JOYSTICK")) {
+            attrs.flags |= ATTR_JOYSTICK;
+        } else if (!strcmp(key, "ID_INPUT_TABLET")) {
+            attrs.flags |= ATTR_TABLET;
+        } else if (!strcmp(key, "ID_INPUT_TOUCHPAD")) {
+            attrs.flags |= ATTR_TOUCHPAD;
+        } else if (!strcmp(key, "ID_INPUT_TOUCHSCREEN")) {
+            attrs.flags |= ATTR_TOUCHSCREEN;
+        }
+    }
+    LogMessage(X_INFO, "config/udev: Adding input device %s (%s)\n",
+               name, path);
+    rc = NewInputDeviceRequest(options, &attrs, &dev);
+    if (rc != Success)
+        goto unwind;
+
+    for (; dev; dev = dev->next) {
+        xfree(dev->config_info);
+        dev->config_info = xstrdup(config_info);
+    }
+
+ unwind:
+    xfree(config_info);
+    while (!dev && (tmpo = options)) {
+        options = tmpo->next;
+        xfree(tmpo->key);
+        xfree(tmpo->value);
+        xfree(tmpo);
+    }
+
+    return;
+}
+
+static void
+device_removed(struct udev_device *device)
+{
+    char *value;
+    const char *syspath = udev_device_get_syspath(device);
+
+    value = Xprintf("udev:%s", syspath);
+    if (!value)
+        return;
+
+    remove_devices("udev", value);
+
+    xfree(value);
+}
+
+static void
+wakeup_handler(pointer data, int err, pointer read_mask)
+{
+    int udev_fd = udev_monitor_get_fd(udev_monitor);
+    struct udev_device *udev_device;
+    const char *action;
+
+    if (err < 0)
+        return;
+
+    if (FD_ISSET(udev_fd, (fd_set *)read_mask)) {
+        udev_device = udev_monitor_receive_device(udev_monitor);
+        if (!udev_device)
+            return;
+        action = udev_device_get_action(udev_device);
+        if (action) {
+            if (!strcmp(action, "add"))
+                device_added(udev_device);
+            else if (!strcmp(action, "remove"))
+                device_removed(udev_device);
+        }
+        udev_device_unref(udev_device);
+    }
+}
+
+static void
+block_handler(pointer data, struct timeval **tv, pointer read_mask)
+{
+}
+
+int
+config_udev_init(void)
+{
+    struct udev *udev;
+    struct udev_enumerate *enumerate;
+    struct udev_list_entry *devices, *device;
+    int rc;
+
+    udev = udev_new();
+    if (!udev)
+        return 0;
+    udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
+    if (!udev_monitor)
+        return 0;
+    rc = udev_monitor_filter_add_match_subsystem_devtype(udev_monitor,
+                                                         "input", NULL);
+    if (rc < 0)
+        return 0;
+
+    if (udev_monitor_enable_receiving(udev_monitor)) {
+        ErrorF("config/udev: failed to bind the udev monitor\n");
+        return 0;
+    }
+
+    enumerate = udev_enumerate_new(udev);
+    if (!enumerate)
+        return 0;
+    udev_enumerate_add_match_subsystem(enumerate, "input");
+    udev_enumerate_scan_devices(enumerate);
+    devices = udev_enumerate_get_list_entry(enumerate);
+    udev_list_entry_foreach(device, devices) {
+        const char *syspath = udev_list_entry_get_name(device);
+        struct udev_device *udev_device = udev_device_new_from_syspath(udev, syspath);
+        device_added(udev_device);
+        udev_device_unref(udev_device);
+    }
+    udev_enumerate_unref(enumerate);
+
+    RegisterBlockAndWakeupHandlers(block_handler, wakeup_handler, NULL);
+    AddGeneralSocket(udev_monitor_get_fd(udev_monitor));
+
+    return 1;
+}
+
+void
+config_udev_fini(void)
+{
+    struct udev *udev;
+
+    if (!udev_monitor)
+        return;
+
+    udev = udev_monitor_get_udev(udev_monitor);
+
+    RemoveGeneralSocket(udev_monitor_get_fd(udev_monitor));
+    RemoveBlockAndWakeupHandlers(block_handler, wakeup_handler, udev_monitor);
+    udev_monitor_unref(udev_monitor);
+    udev_monitor = NULL;
+    udev_unref(udev);
+}
diff --git a/configure.ac b/configure.ac
index e5eb380..7e2c6a5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -618,6 +618,7 @@ AC_ARG_ENABLE(multibuffer,    AS_HELP_STRING([--enable-multibuffer], [Build Mult
 AC_ARG_ENABLE(dbe,            AS_HELP_STRING([--disable-dbe], [Build DBE extension (default: enabled)]), [DBE=$enableval], [DBE=yes])
 AC_ARG_ENABLE(xf86bigfont,    AS_HELP_STRING([--disable-xf86bigfont], [Build XF86 Big Font extension (default: disabled)]), [XF86BIGFONT=$enableval], [XF86BIGFONT=no])
 AC_ARG_ENABLE(dpms,           AS_HELP_STRING([--disable-dpms], [Build DPMS extension (default: enabled)]), [DPMSExtension=$enableval], [DPMSExtension=yes])
+AC_ARG_ENABLE(config-udev,    AS_HELP_STRING([--enable-config-udev], [Build udev support (default: no)]), [CONFIG_UDEV=$enableval], [CONFIG_UDEV=no])
 AC_ARG_ENABLE(config-dbus,    AS_HELP_STRING([--enable-config-dbus], [Build D-BUS API support (default: no)]), [CONFIG_DBUS_API=$enableval], [CONFIG_DBUS_API=no])
 AC_ARG_ENABLE(config-hal,     AS_HELP_STRING([--disable-config-hal], [Build HAL support (default: auto)]), [CONFIG_HAL=$enableval], [CONFIG_HAL=auto])
 AC_ARG_ENABLE(xfree86-utils,     AS_HELP_STRING([--enable-xfree86-utils], [Build xfree86 DDX utilities (default: enabled)]), [XF86UTILS=$enableval], [XF86UTILS=yes])
@@ -775,6 +776,26 @@ LIBXI="xi >= 1.2.99.1"
 LIBXTST="xtst >= 1.0.99.2"
 LIBPCIACCESS="pciaccess >= 0.8.0"
 LIBGLIB="glib-2.0 >= 2.16"
+LIBUDEV="libudev >= 143"
+
+if test "x$CONFIG_UDEV" = xyes &&
+ { test "x$CONFIG_DBUS_API" = xyes || test "x$CONFIG_HAL" = xyes; }; then
+	AC_MSG_ERROR([Hotplugging through both libudev and dbus/hal not allowed])
+fi
+
+PKG_CHECK_MODULES(UDEV, $LIBUDEV, [HAVE_LIBUDEV=yes], [HAVE_LIBUDEV=no])
+if test "x$CONFIG_UDEV" = xauto; then
+	CONFIG_UDEV="$HAVE_LIBUDEV"
+fi
+AM_CONDITIONAL(CONFIG_UDEV, [test "x$CONFIG_UDEV" = xyes])
+if test "x$CONFIG_UDEV" = xyes; then
+	CONFIG_DBUS_API=no
+	CONFIG_HAL=no
+	if ! test "x$HAVE_LIBUDEV" = xyes; then
+		AC_MSG_ERROR([udev configuration API requested, but libudev is not installed])
+	fi
+	AC_DEFINE(CONFIG_UDEV, 1, [Use libudev for input hotplug])
+fi
 
 dnl HAVE_DBUS is true if we actually have the D-Bus library, whereas
 dnl CONFIG_DBUS_API is true if we want to enable the D-Bus config
@@ -808,13 +829,11 @@ if test "x$CONFIG_HAL" = xyes; then
 	fi
 
 	AC_DEFINE(CONFIG_HAL, 1, [Use the HAL hotplug API])
-        REQUIRED_LIBS="$REQUIRED_LIBS hal"
 	CONFIG_NEED_DBUS="yes"
 fi
 AM_CONDITIONAL(CONFIG_HAL, [test "x$CONFIG_HAL" = xyes])
 
 if test "x$CONFIG_NEED_DBUS" = xyes; then
-	REQUIRED_LIBS="$REQUIRED_LIBS dbus-1"
         AC_DEFINE(CONFIG_NEED_DBUS, 1, [Use D-Bus for input hotplug])
 fi
 AM_CONDITIONAL(CONFIG_NEED_DBUS, [test "x$CONFIG_NEED_DBUS" = xyes])
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index c084591..09b5d3b 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -2281,6 +2281,14 @@ NewInputDeviceRequest(InputOption *options, InputAttributes *attrs,
             return BadValue;
         }
 #endif
+#ifdef CONFIG_UDEV
+        else if (strcmp(option->key, "_source") == 0 &&
+                 strcmp(option->value, "server/udev") == 0)
+        {
+            ErrorF("Ignoring device from udev.\n");
+            return BadValue;
+        }
+#endif
     }
 
     if (!ki && !pi) {
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 56ab2ee..1abc182 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -1461,12 +1461,19 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
     }
 
     if (xf86Info.allowEmptyInput && !(foundPointer && foundKeyboard)) {
-#ifdef CONFIG_HAL
-	xf86Msg(X_INFO, "The server relies on HAL to provide the list of "
+#if defined(CONFIG_HAL) || defined(CONFIG_UDEV)
+	const char *config_backend;
+#if defined(CONFIG_HAL)
+	config_backend = "HAL";
+#else
+	config_backend = "udev";
+#endif
+	xf86Msg(X_INFO, "The server relies on %s to provide the list of "
 	                "input devices.\n\tIf no devices become available, "
-	                "reconfigure HAL or disable AutoAddDevices.\n");
+	                "reconfigure %s or disable AutoAddDevices.\n",
+			config_backend, config_backend);
 #else
-	xf86Msg(X_INFO, "HAL is disabled and no input devices were configured.\n"
+	xf86Msg(X_INFO, "Hotplugging is disabled and no input devices were configured.\n"
 			"\tTry disabling AllowEmptyInput.\n");
 #endif
     }
diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c
index 317b78a..8b483f3 100644
--- a/hw/xfree86/common/xf86Globals.c
+++ b/hw/xfree86/common/xf86Globals.c
@@ -132,7 +132,7 @@ xf86InfoRec xf86Info = {
     .kbdCustomKeycodes          = FALSE,
     .disableRandR               = FALSE,
     .randRFrom                  = X_DEFAULT,
-#ifdef CONFIG_HAL
+#if defined(CONFIG_HAL) || defined(CONFIG_UDEV)
     .allowEmptyInput            = TRUE,
     .autoAddDevices             = TRUE,
     .autoEnableDevices          = TRUE
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 87b5100..57db056 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -692,9 +692,9 @@ NewInputDeviceRequest (InputOption *options, InputAttributes *attrs,
             }
         }
 
-        /* Right now, the only automatic config we know of is HAL. */
         if (strcmp(option->key, "_source") == 0 &&
-            strcmp(option->value, "server/hal") == 0) {
+            (strcmp(option->value, "server/hal") == 0 ||
+             strcmp(option->value, "server/udev") == 0)) {
             is_auto = 1;
             if (!xf86Info.autoAddDevices) {
                 rval = BadMatch;
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index ab04414..84c78db 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -399,6 +399,9 @@
 /* Support D-Bus */
 #undef HAVE_DBUS
 
+/* Use libudev for input hotplug */
+#undef CONFIG_UDEV
+
 /* Use D-Bus for input hotplug */
 #undef CONFIG_NEED_DBUS
 
commit b8b12e41c453c3bf94b11e7a18934d3b6e1869bf
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Dec 23 16:05:16 2009 +1000

    xfree86: move sanity checks below option and input classes merges.
    
    While the identifier is likely set before the input classes are merged, the
    driver may not be. Hence don't check for a driver before we've completed
    configuration for this device.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>
    Signed-off-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index e0c7830..87b5100 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -702,16 +702,6 @@ NewInputDeviceRequest (InputOption *options, InputAttributes *attrs,
             }
         }
     }
-    if (!idev->driver || !idev->identifier) {
-        xf86Msg(X_ERROR, "No input driver/identifier specified (ignoring)\n");
-        rval = BadRequest;
-        goto unwind;
-    }
-
-    if (!idev->identifier) {
-        xf86Msg(X_ERROR, "No device identifier specified (ignoring)\n");
-        return BadMatch;
-    }
 
     for (option = options; option; option = option->next) {
         /* Steal option key/value strings from the provided list.
@@ -729,6 +719,17 @@ NewInputDeviceRequest (InputOption *options, InputAttributes *attrs,
             goto unwind;
     }
 
+    if (!idev->driver || !idev->identifier) {
+        xf86Msg(X_ERROR, "No input driver/identifier specified (ignoring)\n");
+        rval = BadRequest;
+        goto unwind;
+    }
+
+    if (!idev->identifier) {
+        xf86Msg(X_ERROR, "No device identifier specified (ignoring)\n");
+        return BadMatch;
+    }
+
     rval = xf86NewInputDevice(idev, pdev,
                 (!is_auto || (is_auto && xf86Info.autoEnableDevices)));
     if (rval == Success)
commit 9fad8f06fb89ac2ae05bea0fa24cab3df7677297
Merge: 871bbe1... 42e8c92...
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Dec 30 09:28:19 2009 -0800

    Merge remote branch 'dbn/inputclass'

commit 871bbe1d87fa3c7ebd075e1d1eec33e45b08493d
Merge: db2c6f7... e116563...
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Dec 30 09:16:45 2009 -0800

    Merge remote branch 'dbn/xorg.conf.d'

commit db2c6f7c91289b5d49978974093a1002b3b53a56
Author: Michel Dänzer <daenzer at vmware.com>
Date:   Tue Dec 29 15:48:44 2009 +0100

    EXA: Don't use UTS/DFS directly for Put/GetImage when there's a system copy.
    
    We want to save the result in the system memory copy, in case we'll need it
    again for subsequent software fallbacks.
    
    Signed-off-by: Michel Dänzer <daenzer at vmware.com>
    Acked-By: Maarten Maathuis <madman2003 at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index f34b7a7..4c55a4c 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -157,6 +157,10 @@ exaDoPutImage (DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
     if (pExaScr->fallback_counter || pExaPixmap->accel_blocked || !pExaScr->info->UploadToScreen)
 	return FALSE;
 
+    /* If there's a system copy, we want to save the result there */
+    if (pExaPixmap->pDamage)
+	return FALSE;
+
     /* Don't bother with under 8bpp, XYPixmaps. */
     if (format != ZPixmap || bpp < 8)
 	return FALSE;
@@ -168,17 +172,6 @@ exaDoPutImage (DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
     if (pExaScr->swappedOut)
 	return FALSE;
 
-    if (pExaScr->do_migration) {
-	ExaMigrationRec pixmaps[1];
-
-	pixmaps[0].as_dst = TRUE;
-	pixmaps[0].as_src = FALSE;
-	pixmaps[0].pPix = pPix;
-	pixmaps[0].pReg = DamagePendingRegion(pExaPixmap->pDamage);
-
-	exaDoMigration (pixmaps, 1, TRUE);
-    }
-
     pPix = exaGetOffscreenPixmap (pDrawable, &xoff, &yoff);
 
     if (!pPix)
@@ -1261,35 +1254,16 @@ exaGetImage (DrawablePtr pDrawable, int x, int y, int w, int h,
 {
     ExaScreenPriv (pDrawable->pScreen);
     PixmapPtr pPix = exaGetDrawablePixmap (pDrawable);
+    ExaPixmapPriv(pPix);
     int xoff, yoff;
     Bool ok;
 
     if (pExaScr->fallback_counter || pExaScr->swappedOut)
 	goto fallback;
 
-    exaGetDrawableDeltas (pDrawable, pPix, &xoff, &yoff);
-
-    if (pExaScr->do_migration) {
-	BoxRec Box;
-	RegionRec Reg;
-	ExaMigrationRec pixmaps[1];
-
-	Box.x1 = pDrawable->x + x + xoff;
-	Box.y1 = pDrawable->y + y + yoff;
-	Box.x2 = Box.x1 + w;
-	Box.y2 = Box.y1 + h;
-
-	REGION_INIT(pScreen, &Reg, &Box, 1);
-
-	pixmaps[0].as_dst = FALSE;
-	pixmaps[0].as_src = TRUE;
-	pixmaps[0].pPix = pPix;
-	pixmaps[0].pReg = &Reg;
-
-	exaDoMigration(pixmaps, 1, FALSE);
-
-	REGION_UNINIT(pScreen, &Reg);
-    }
+    /* If there's a system copy, we want to save the result there */
+    if (pExaPixmap->pDamage)
+	goto fallback;
 
     pPix = exaGetOffscreenPixmap (pDrawable, &xoff, &yoff);
 
commit f28ca728e90ccbb901e8e7215a842525d8e786d3
Author: Thomas Hellstrom <thellstrom at vmware.com>
Date:   Tue Dec 29 12:51:30 2009 +0100

    EXA: Restrict the regions that need to be migrated for composite fallback for src / mask pictures.
    
    [ Michel: Minor fixups to address compiler warnings ]
    
    Signed-off-by: Thomas Hellstrom <thellstrom at vmware.com>
    Signed-off-by: Michel Dänzer <daenzer at vmware.com>
    Acked-by: Maarten Maathuis <madman2003 at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index c559b9a..21d9646 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -165,6 +165,7 @@ typedef struct {
     BitmapToRegionProcPtr        SavedBitmapToRegion;
     CreateScreenResourcesProcPtr SavedCreateScreenResources;
     ModifyPixmapHeaderProcPtr    SavedModifyPixmapHeader;
+    SourceValidateProcPtr        SavedSourceValidate;
 #ifdef RENDER
     CompositeProcPtr             SavedComposite;
     TrianglesProcPtr		 SavedTriangles;
@@ -201,6 +202,15 @@ typedef struct {
     unsigned int fallback_counter;
 
     ExaGlyphCacheRec             glyphCaches[EXA_NUM_GLYPH_CACHES];
+
+    /**
+     * Regions affected by fallback composite source / mask operations.
+     */
+
+    RegionRec srcReg;
+    RegionRec maskReg;
+    PixmapPtr srcPix;
+
 } ExaScreenPrivRec, *ExaScreenPrivPtr;
 
 /*
diff --git a/exa/exa_unaccel.c b/exa/exa_unaccel.c
index a97a309..b4ead7f 100644
--- a/exa/exa_unaccel.c
+++ b/exa/exa_unaccel.c
@@ -435,6 +435,173 @@ ExaCheckGetSpans (DrawablePtr pDrawable,
     EXA_POST_FALLBACK(pScreen);
 }
 
+static void
+ExaSrcValidate(DrawablePtr pDrawable,
+	       int x,
+	       int y,
+	       int width,
+	       int height)
+{
+    ScreenPtr pScreen = pDrawable->pScreen;
+    ExaScreenPriv(pScreen);
+    PixmapPtr pPix = exaGetDrawablePixmap (pDrawable);
+    BoxRec box;
+    RegionRec reg;
+    RegionPtr dst;
+    int xoff, yoff;
+
+    exaGetDrawableDeltas(pDrawable, pPix, &xoff, &yoff);
+
+    box.x1 = x + xoff;
+    box.y1 = y + yoff;
+    box.x2 = box.x1 + width;
+    box.y2 = box.y1 + height;
+
+    dst = (pExaScr->srcPix == pPix) ? &pExaScr->srcReg :
+	&pExaScr->maskReg;
+
+    REGION_INIT(pScreen, &reg, &box, 1);
+    REGION_UNION(pScreen, dst, dst, &reg);
+    REGION_UNINIT(pScreen, &reg);
+
+    swap(pExaScr, pScreen, SourceValidate);
+    pScreen->SourceValidate(pDrawable, x, y, width, height);
+    swap(pExaScr, pScreen, SourceValidate);
+}
+
+static Bool
+ExaPrepareCompositeReg(ScreenPtr  pScreen,
+		       CARD8      op,
+		       PicturePtr pSrc,
+		       PicturePtr pMask,
+		       PicturePtr pDst,
+		       INT16      xSrc,
+		       INT16      ySrc,
+		       INT16      xMask,
+		       INT16      yMask,
+		       INT16      xDst,
+		       INT16      yDst,
+		       CARD16     width,
+		       CARD16     height)
+{
+    RegionRec region;
+    RegionPtr dstReg = NULL;
+    RegionPtr srcReg = NULL;
+    RegionPtr maskReg = NULL;
+    PixmapPtr pSrcPix = NULL;
+    PixmapPtr pMaskPix = NULL;
+    PixmapPtr pDstPix;
+    ExaScreenPriv(pScreen);
+    Bool ret;
+
+
+    REGION_NULL(pScreen, &region);
+
+    if (pSrc->pDrawable) {
+	pSrcPix = exaGetDrawablePixmap(pSrc->pDrawable);
+	REGION_NULL(pScreen, &pExaScr->srcReg);
+	srcReg = &pExaScr->srcReg;
+	pExaScr->srcPix = pSrcPix;
+	if (pSrc != pDst)
+	    REGION_TRANSLATE(pScreen, pSrc->pCompositeClip,
+			     -pSrc->pDrawable->x,
+			     -pSrc->pDrawable->y);
+    }
+
+    if (pMask && pMask->pDrawable) {
+	pMaskPix = exaGetDrawablePixmap(pMask->pDrawable);
+	REGION_NULL(pScreen, &pExaScr->maskReg);
+	maskReg = &pExaScr->maskReg;
+	if (pMask != pDst && pMask != pSrc)
+	    REGION_TRANSLATE(pScreen, pMask->pCompositeClip,
+			     -pMask->pDrawable->x,
+			     -pMask->pDrawable->y);
+    }
+
+    REGION_TRANSLATE(pScreen, pDst->pCompositeClip,
+		     -pDst->pDrawable->x,
+		     -pDst->pDrawable->y);
+
+    pExaScr->SavedSourceValidate = ExaSrcValidate;
+    swap(pExaScr, pScreen, SourceValidate);
+    ret = miComputeCompositeRegion (&region, pSrc, pMask, pDst,
+				    xSrc, ySrc, xMask, yMask,
+				    xDst,
+				    yDst,
+				    width, height);
+    swap(pExaScr, pScreen, SourceValidate);
+
+    REGION_TRANSLATE(pScreen, pDst->pCompositeClip,
+		     pDst->pDrawable->x,
+		     pDst->pDrawable->y);
+    if (pSrc->pDrawable && pSrc != pDst)
+	REGION_TRANSLATE(pScreen, pSrc->pCompositeClip,
+			 pSrc->pDrawable->x,
+			 pSrc->pDrawable->y);
+    if (pMask && pMask->pDrawable && pMask != pDst && pMask != pSrc)
+	REGION_TRANSLATE(pScreen, pMask->pCompositeClip,
+			 pMask->pDrawable->x,
+			 pMask->pDrawable->y);
+
+    if (!ret) {
+	if (srcReg)
+	    REGION_UNINIT(pScreen, srcReg);
+	if (maskReg)
+	    REGION_UNINIT(pScreen, maskReg);
+
+	return FALSE;
+    }
+
+    /**
+     * Don't limit alphamaps readbacks for now until we've figured out how that
+     * should be done.
+     */
+
+    if (pSrc->alphaMap && pSrc->alphaMap->pDrawable)
+	pExaScr->prepare_access_reg(exaGetDrawablePixmap(pSrc->alphaMap->pDrawable),
+				    EXA_PREPARE_AUX_SRC,
+				    NULL);
+    if (pMask && pMask->alphaMap && pMask->alphaMap->pDrawable)
+	pExaScr->prepare_access_reg(exaGetDrawablePixmap(pMask->alphaMap->pDrawable),
+				    EXA_PREPARE_AUX_MASK,
+				    NULL);
+
+    if (pSrcPix)
+	pExaScr->prepare_access_reg(pSrcPix,
+				    EXA_PREPARE_SRC,
+				    srcReg);
+
+    if (pMaskPix)
+	pExaScr->prepare_access_reg(pMaskPix,
+				    EXA_PREPARE_MASK,
+				    maskReg);
+
+    if (srcReg)
+	REGION_UNINIT(pScreen, srcReg);
+    if (maskReg)
+	REGION_UNINIT(pScreen, maskReg);
+
+    pDstPix = exaGetDrawablePixmap(pDst->pDrawable);
+    if (!exaOpReadsDestination(op)) {
+	int xoff;
+	int yoff;
+
+	exaGetDrawableDeltas (pDst->pDrawable, pDstPix, &xoff, &yoff);
+	REGION_TRANSLATE(pScreen, &region, pDst->pDrawable->x + xoff,
+			 pDst->pDrawable->y + yoff);
+	dstReg = &region;
+    }
+
+    if (pDst->alphaMap && pDst->alphaMap->pDrawable)
+	pExaScr->prepare_access_reg(exaGetDrawablePixmap(pDst->alphaMap->pDrawable),
+				    EXA_PREPARE_AUX_DEST,
+				    dstReg);
+    pExaScr->prepare_access_reg(pDstPix, EXA_PREPARE_DEST, dstReg);
+
+    REGION_UNINIT(pScreen, &region);
+    return TRUE;
+}
+
 void
 ExaCheckComposite (CARD8      op,
                    PicturePtr pSrc,
@@ -453,54 +620,38 @@ ExaCheckComposite (CARD8      op,
 #ifdef RENDER
     PictureScreenPtr	ps = GetPictureScreen(pScreen);
 #endif /* RENDER */
-    RegionRec region;
-    int xoff, yoff;
     EXA_PRE_FALLBACK(pScreen);
 
-    REGION_NULL(pScreen, &region);
-
-    /* We need to prepare access to any separate alpha maps first, in case the
-     * driver doesn't support EXA_PREPARE_AUX*, in which case EXA_PREPARE_SRC
-     * may be used for moving them out.
-     */
-    if (pSrc->alphaMap && pSrc->alphaMap->pDrawable)
-	exaPrepareAccess(pSrc->alphaMap->pDrawable, EXA_PREPARE_AUX_SRC);
-    if (pMask && pMask->alphaMap && pMask->alphaMap->pDrawable)
-	exaPrepareAccess(pMask->alphaMap->pDrawable, EXA_PREPARE_AUX_MASK);
-
-    if (!exaOpReadsDestination(op) && pExaScr->prepare_access_reg) {
-	PixmapPtr pDstPix;
-
-	if (!miComputeCompositeRegion (&region, pSrc, pMask, pDst,
-				       xSrc, ySrc, xMask, yMask,
-				       xDst + pDst->pDrawable->x,
-				       yDst + pDst->pDrawable->y,
-				       width, height))
-	    goto skip;
-
-	pDstPix = exaGetDrawablePixmap(pDst->pDrawable);
-	exaGetDrawableDeltas (pDst->pDrawable, pDstPix, &xoff, &yoff);
-	REGION_TRANSLATE(pScreen, &region, xoff, yoff);
+    if (pExaScr->prepare_access_reg) {
+	if (!ExaPrepareCompositeReg(pScreen, op, pSrc, pMask, pDst, xSrc,
+				   ySrc, xMask, yMask, xDst, yDst, width,
+				   height))
+	    goto out_no_clip;
+    } else {
 
-	if (pDst->alphaMap && pDst->alphaMap->pDrawable)
-	    pExaScr->prepare_access_reg(exaGetDrawablePixmap(pDst->alphaMap->pDrawable),
-					EXA_PREPARE_AUX_DEST, &region);
+	/* We need to prepare access to any separate alpha maps first,
+	 * in case the driver doesn't support EXA_PREPARE_AUX*,
+	 * in which case EXA_PREPARE_SRC may be used for moving them out.
+	 */
 
-	pExaScr->prepare_access_reg(pDstPix, EXA_PREPARE_DEST, &region);
-    } else {
+	if (pSrc->alphaMap && pSrc->alphaMap->pDrawable)
+	    exaPrepareAccess(pSrc->alphaMap->pDrawable, EXA_PREPARE_AUX_SRC);
+	if (pMask && pMask->alphaMap && pMask->alphaMap->pDrawable)
+	    exaPrepareAccess(pMask->alphaMap->pDrawable, EXA_PREPARE_AUX_MASK);
 	if (pDst->alphaMap && pDst->alphaMap->pDrawable)
 	    exaPrepareAccess(pDst->alphaMap->pDrawable, EXA_PREPARE_AUX_DEST);
 
 	exaPrepareAccess (pDst->pDrawable, EXA_PREPARE_DEST);
-    }
 
-    EXA_FALLBACK(("from picts %p/%p to pict %p\n",
-		 pSrc, pMask, pDst));
+	EXA_FALLBACK(("from picts %p/%p to pict %p\n",
+		      pSrc, pMask, pDst));
+
+	if (pSrc->pDrawable != NULL)
+	    exaPrepareAccess (pSrc->pDrawable, EXA_PREPARE_SRC);
+	if (pMask && pMask->pDrawable != NULL)
+	    exaPrepareAccess (pMask->pDrawable, EXA_PREPARE_MASK);
+    }
 
-    if (pSrc->pDrawable != NULL)
-	exaPrepareAccess (pSrc->pDrawable, EXA_PREPARE_SRC);
-    if (pMask && pMask->pDrawable != NULL)
-	exaPrepareAccess (pMask->pDrawable, EXA_PREPARE_MASK);
 #ifdef RENDER
     swap(pExaScr, ps, Composite);
     ps->Composite (op,
@@ -524,14 +675,12 @@ ExaCheckComposite (CARD8      op,
     exaFinishAccess (pDst->pDrawable, EXA_PREPARE_DEST);
     if (pDst->alphaMap && pDst->alphaMap->pDrawable)
 	exaFinishAccess(pDst->alphaMap->pDrawable, EXA_PREPARE_AUX_DEST);
-
-skip:
     if (pSrc->alphaMap && pSrc->alphaMap->pDrawable)
 	exaFinishAccess(pSrc->alphaMap->pDrawable, EXA_PREPARE_AUX_SRC);
     if (pMask && pMask->alphaMap && pMask->alphaMap->pDrawable)
 	exaFinishAccess(pMask->alphaMap->pDrawable, EXA_PREPARE_AUX_MASK);
 
-    REGION_UNINIT(pScreen, &region);
+out_no_clip:
     EXA_POST_FALLBACK(pScreen);
 }
 
commit 0c1f43c0f3e888172f11f62a2f208af70e0183cc
Author: Michel Dänzer <daenzer at vmware.com>
Date:   Tue Dec 29 12:51:29 2009 +0100

    EXA/mixed: Handle results of software fallbacks in DamageReport hook.
    
    This is more elegant and probably also slightly more correct than doing it
    at FinishAccess time.
    
    Signed-off-by: Michel Dänzer <daenzer at vmware.com>
    Acked-by: Maarten Maathuis <madman2003 at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/exa/exa.c b/exa/exa.c
index b3c5bff..c5ac7de 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -425,9 +425,6 @@ exaFinishAccess(DrawablePtr pDrawable, int index)
     /* We always hide the devPrivate.ptr. */
     pPixmap->devPrivate.ptr = NULL;
 
-    if (pExaScr->finish_access)
-	pExaScr->finish_access(pPixmap, index);
-
     if (!pExaScr->info->FinishAccess || !exaPixmapHasGpuCopy(pPixmap))
 	return;
 
@@ -981,7 +978,6 @@ exaDriverInit (ScreenPtr		pScreen,
 		pExaScr->do_move_in_pixmap = exaMoveInPixmap_mixed;
 		pExaScr->do_move_out_pixmap = NULL;
 		pExaScr->prepare_access_reg = exaPrepareAccessReg_mixed;
-		pExaScr->finish_access = exaFinishAccess_mixed;
 	    } else {
 		wrap(pExaScr, pScreen, CreatePixmap, exaCreatePixmap_driver);
 		wrap(pExaScr, pScreen, DestroyPixmap, exaDestroyPixmap_driver);
@@ -991,7 +987,6 @@ exaDriverInit (ScreenPtr		pScreen,
 		pExaScr->do_move_in_pixmap = NULL;
 		pExaScr->do_move_out_pixmap = NULL;
 		pExaScr->prepare_access_reg = NULL;
-		pExaScr->finish_access = NULL;
 	    }
 	} else {
 	    wrap(pExaScr, pScreen, CreatePixmap, exaCreatePixmap_classic);
@@ -1002,7 +997,6 @@ exaDriverInit (ScreenPtr		pScreen,
 	    pExaScr->do_move_in_pixmap = exaMoveInPixmap_classic;
 	    pExaScr->do_move_out_pixmap = exaMoveOutPixmap_classic;
 	    pExaScr->prepare_access_reg = exaPrepareAccessReg_classic;
-	    pExaScr->finish_access = NULL;
 	}
 	if (!(pExaScr->info->flags & EXA_HANDLES_PIXMAPS)) {
 	    LogMessage(X_INFO, "EXA(%d): Offscreen pixmap area of %lu bytes\n",
diff --git a/exa/exa_migration_mixed.c b/exa/exa_migration_mixed.c
index 14cb5a7..6816e6c 100644
--- a/exa/exa_migration_mixed.c
+++ b/exa/exa_migration_mixed.c
@@ -134,10 +134,32 @@ exaMoveInPixmap_mixed(PixmapPtr pPixmap)
     exaDoMigration(pixmaps, 1, TRUE);
 }
 
+void
+exaDamageReport_mixed(DamagePtr pDamage, RegionPtr pRegion, void *closure)
+{
+    PixmapPtr pPixmap = closure;
+    ExaPixmapPriv(pPixmap);
+
+    /* Move back results of software rendering on system memory copy of mixed driver
+     * pixmap (see exaPrepareAccessReg_mixed).
+     *
+     * Defer moving the destination back into the driver pixmap, to try and save
+     * overhead on multiple subsequent software fallbacks.
+     */
+    if (!pExaPixmap->use_gpu_copy && exaPixmapHasGpuCopy(pPixmap)) {
+	ExaScreenPriv(pPixmap->drawable.pScreen);
+
+	if (pExaScr->deferred_mixed_pixmap &&
+	    pExaScr->deferred_mixed_pixmap != pPixmap)
+	    exaMoveInPixmap_mixed(pExaScr->deferred_mixed_pixmap);
+	pExaScr->deferred_mixed_pixmap = pPixmap;
+    }
+}
+
 /* With mixed pixmaps, if we fail to get direct access to the driver pixmap, we
  * use the DownloadFromScreen hook to retrieve contents to a copy in system
  * memory, perform software rendering on that and move back the results with the
- * UploadToScreen hook (see exaFinishAccess_mixed).
+ * UploadToScreen hook (see exaDamageReport_mixed).
  */
 void
 exaPrepareAccessReg_mixed(PixmapPtr pPixmap, int index, RegionPtr pReg)
@@ -172,8 +194,9 @@ exaPrepareAccessReg_mixed(PixmapPtr pPixmap, int index, RegionPtr pReg)
 	    Bool as_dst = pixmaps[0].as_dst;
 
 	    /* Set up damage tracking */
-	    pExaPixmap->pDamage = DamageCreate(NULL, NULL, DamageReportNone,
-					       TRUE, pPixmap->drawable.pScreen,
+	    pExaPixmap->pDamage = DamageCreate(exaDamageReport_mixed, NULL,
+					       DamageReportNonEmpty, TRUE,
+					       pPixmap->drawable.pScreen,
 					       pPixmap);
 
 	    DamageRegister(&pPixmap->drawable, pExaPixmap->pDamage);
@@ -224,29 +247,3 @@ exaPrepareAccessReg_mixed(PixmapPtr pPixmap, int index, RegionPtr pReg)
     }
 }
 
-/* Move back results of software rendering on system memory copy of mixed driver
- * pixmap (see exaPrepareAccessReg_mixed).
- *
- * Defer moving the destination back into the driver pixmap, to try and save
- * overhead on multiple consequent software fallbacks.
- */
-void exaFinishAccess_mixed(PixmapPtr pPixmap, int index)
-{
-    ExaPixmapPriv(pPixmap);
-
-    if (pExaPixmap->pDamage && !pExaPixmap->use_gpu_copy &&
-	    exaPixmapHasGpuCopy(pPixmap)) {
-	DamageRegionProcessPending(&pPixmap->drawable);
-
-	if (index == EXA_PREPARE_DEST || index == EXA_PREPARE_AUX_DEST) {
-	    ExaScreenPriv(pPixmap->drawable.pScreen);
-
-	    if (pExaScr->deferred_mixed_pixmap &&
-		pExaScr->deferred_mixed_pixmap != pPixmap)
-		exaMoveInPixmap_mixed(pExaScr->deferred_mixed_pixmap);
-	    pExaScr->deferred_mixed_pixmap = pPixmap;
-	    pPixmap->devKind = pExaPixmap->fb_pitch;
-	} else
-	    exaMoveInPixmap_mixed(pPixmap);
-    }
-}
diff --git a/exa/exa_mixed.c b/exa/exa_mixed.c
index b262fc7..21cc3bd 100644
--- a/exa/exa_mixed.c
+++ b/exa/exa_mixed.c
@@ -101,7 +101,7 @@ exaCreatePixmap_mixed(ScreenPtr pScreen, int w, int h, int depth,
 	    pExaPixmap->sys_ptr = malloc((pPixmap->drawable.bitsPerPixel + 7) / 8);
 
 	    /* Set up damage tracking */
-	    pExaPixmap->pDamage = DamageCreate(NULL, NULL,
+	    pExaPixmap->pDamage = DamageCreate(exaDamageReport_mixed, NULL,
 					       DamageReportNonEmpty, TRUE,
 					       pPixmap->drawable.pScreen,
 					       pPixmap);
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index 0852355..c559b9a 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -177,7 +177,6 @@ typedef struct {
     void (*do_move_in_pixmap) (PixmapPtr pPixmap);
     void (*do_move_out_pixmap) (PixmapPtr pPixmap);
     void (*prepare_access_reg)(PixmapPtr pPixmap, int index, RegionPtr pReg);
-    void (*finish_access)(PixmapPtr pPixmap, int index);
 
     Bool			 swappedOut;
     enum ExaMigrationHeuristic	 migration;
@@ -620,10 +619,10 @@ void
 exaMoveInPixmap_mixed(PixmapPtr pPixmap);
 
 void
-exaPrepareAccessReg_mixed(PixmapPtr pPixmap, int index, RegionPtr pReg);
+exaDamageReport_mixed(DamagePtr pDamage, RegionPtr pRegion, void *closure);
 
 void
-exaFinishAccess_mixed(PixmapPtr pPixmap, int index);
+exaPrepareAccessReg_mixed(PixmapPtr pPixmap, int index, RegionPtr pReg);
 
 /* exa_render.c */
 Bool
commit 08bf26c28fc8147b64f2fe8345b9581e0101571c
Author: Michel Dänzer <daenzer at vmware.com>
Date:   Tue Dec 29 12:51:28 2009 +0100

    EXA: Fix migration avoidance for 1x1 pixmaps.
    
    Signed-off-by: Michel Dänzer <daenzer at vmware.com>
    Acked-by: Maarten Maathuis <madman2003 at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index c56c6bc..f34b7a7 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -1043,6 +1043,7 @@ exaFillRegionSolid (DrawablePtr	pDrawable, RegionPtr pRegion, Pixel pixel,
 	    pDrawable->width == 1 && pDrawable->height == 1 &&
 	    pDrawable->bitsPerPixel != 24) {
 	    ExaPixmapPriv(pPixmap);
+	    RegionPtr pending_damage = DamagePendingRegion(pExaPixmap->pDamage);
 
 	    switch (pDrawable->bitsPerPixel) {
 	    case 32:
@@ -1057,6 +1058,9 @@ exaFillRegionSolid (DrawablePtr	pDrawable, RegionPtr pRegion, Pixel pixel,
 
 	    REGION_UNION(pScreen, &pExaPixmap->validSys, &pExaPixmap->validSys,
 			 pRegion);
+	    REGION_UNION(pScreen, &pExaPixmap->validFB, &pExaPixmap->validFB,
+			 pRegion);
+	    REGION_SUBTRACT(pScreen, pending_damage, pending_damage, pRegion);
 	}
 
 	ret = TRUE;
diff --git a/exa/exa_mixed.c b/exa/exa_mixed.c
index 155ed47..b262fc7 100644
--- a/exa/exa_mixed.c
+++ b/exa/exa_mixed.c
@@ -94,9 +94,25 @@ exaCreatePixmap_mixed(ScreenPtr pScreen, int w, int h, int depth,
     if (!w || !h) {
 	exaCreateDriverPixmap_mixed(pPixmap);
 	pExaPixmap->use_gpu_copy = exaPixmapHasGpuCopy(pPixmap);
-    } else
+    } else {
 	pExaPixmap->use_gpu_copy = FALSE;
 
+	if (w == 1 && h == 1) {
+	    pExaPixmap->sys_ptr = malloc((pPixmap->drawable.bitsPerPixel + 7) / 8);
+
+	    /* Set up damage tracking */
+	    pExaPixmap->pDamage = DamageCreate(NULL, NULL,
+					       DamageReportNonEmpty, TRUE,
+					       pPixmap->drawable.pScreen,
+					       pPixmap);
+
+	    DamageRegister(&pPixmap->drawable, pExaPixmap->pDamage);
+	    /* This ensures that pending damage reflects the current operation. */
+	    /* This is used by exa to optimize migration. */
+	    DamageSetReportAfterOp(pExaPixmap->pDamage, TRUE);
+	}
+    }
+
     /* During a fallback we must prepare access. */
     if (pExaScr->fallback_counter)
 	exaPrepareAccess(&pPixmap->drawable, EXA_PREPARE_AUX_DEST);
commit 0bd8f0cd7f3823ee17ae8c88fd3e004bfff9982d
Author: Michel Dänzer <daenzer at vmware.com>
Date:   Tue Dec 29 12:51:27 2009 +0100

    EXA/classic: Fix crash with migration heuristic "smart".
    
    Signed-off-by: Michel Dänzer <daenzer at vmware.com>
    Acked-by: Maarten Maathuis <madman2003 at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/exa/exa_migration_classic.c b/exa/exa_migration_classic.c
index 95189be..871679f 100644
--- a/exa/exa_migration_classic.c
+++ b/exa/exa_migration_classic.c
@@ -75,6 +75,9 @@ exaPixmapIsDirty (PixmapPtr pPix)
     if (pExaPixmap == NULL)
 	EXA_FatalErrorDebugWithRet(("EXA bug: exaPixmapIsDirty was called on a non-exa pixmap.\n"), TRUE);
 
+    if (!pExaPixmap->pDamage)
+	return FALSE;
+
     return REGION_NOTEMPTY (pScreen, DamageRegion(pExaPixmap->pDamage)) ||
 	!REGION_EQUAL(pScreen, &pExaPixmap->validSys, &pExaPixmap->validFB);
 }
commit 40453bf7718f1c3d672b87e9d84991032cbef859
Author: Thomas Hellstrom <thellstrom at vmware.com>
Date:   Tue Dec 29 09:34:44 2009 +0100

    EXA: Limit src prepareAccess regions for a number of unaccelerated operations.
    
    When we can trivially calculate the affected source regions,
    do that before calling region bounded prepareAccess.
    
    [ Michel: Minor fixups to address compiler warnings ]
    
    Signed-off-by: Thomas Hellstrom <thellstrom at vmware.com>
    Signed-off-by: Michel Dänzer <daenzer at vmware.com>
    Acked-by: Maarten Maathuis <madman2003 at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/exa/exa_unaccel.c b/exa/exa_unaccel.c
index f077fc8..a97a309 100644
--- a/exa/exa_unaccel.c
+++ b/exa/exa_unaccel.c
@@ -123,11 +123,36 @@ ExaCheckCopyNtoN (DrawablePtr pSrc, DrawablePtr pDst,  GCPtr pGC,
 	     BoxPtr	pbox, int nbox, int dx, int dy, Bool	reverse, 
 	     Bool upsidedown, Pixel bitplane, void *closure)
 {
+    RegionRec reg;
+    int xoff, yoff;
     EXA_PRE_FALLBACK_GC(pGC);
     EXA_FALLBACK(("from %p to %p (%c,%c)\n", pSrc, pDst,
 		  exaDrawableLocation(pSrc), exaDrawableLocation(pDst)));
-    exaPrepareAccess (pDst, EXA_PREPARE_DEST);
-    exaPrepareAccess (pSrc, EXA_PREPARE_SRC);
+
+    if (pExaScr->prepare_access_reg) {
+	PixmapPtr pPixmap = exaGetDrawablePixmap(pSrc);
+
+	exaGetDrawableDeltas(pSrc, pPixmap, &xoff, &yoff);
+	REGION_INIT(pScreen, &reg, pbox, nbox);
+	REGION_TRANSLATE(pScreen, &reg, xoff + dx, yoff + dy);
+	pExaScr->prepare_access_reg(pPixmap, EXA_PREPARE_SRC, &reg);
+	REGION_UNINIT(pScreen, &reg);
+    } else
+	exaPrepareAccess (pSrc, EXA_PREPARE_SRC);
+
+    if (pExaScr->prepare_access_reg &&
+	!exaGCReadsDestination(pDst, pGC->planemask, pGC->fillStyle,
+			       pGC->alu, pGC->clientClipType)) {
+	PixmapPtr pPixmap = exaGetDrawablePixmap(pDst);
+
+	exaGetDrawableDeltas(pSrc, pPixmap, &xoff, &yoff);
+	REGION_INIT(pScreen, &reg, pbox, nbox);
+	REGION_TRANSLATE(pScreen, &reg, xoff, yoff);
+	pExaScr->prepare_access_reg(pPixmap, EXA_PREPARE_DEST, &reg);
+	REGION_UNINIT(pScreen, &reg);
+    } else
+	exaPrepareAccess (pDst, EXA_PREPARE_DEST);
+
     /* This will eventually call fbCopyNtoN, with some calculation overhead. */
     while (nbox--) {
 	pGC->ops->CopyArea (pSrc, pDst, pGC, pbox->x1 - pSrc->x + dx, pbox->y1 - pSrc->y + dy, 
@@ -139,6 +164,40 @@ ExaCheckCopyNtoN (DrawablePtr pSrc, DrawablePtr pDst,  GCPtr pGC,
     EXA_POST_FALLBACK_GC(pGC);
 }
 
+static void
+ExaFallbackPrepareReg(DrawablePtr pDrawable,
+		      GCPtr pGC,
+		      int x, int y, int width, int height,
+		      int index, Bool checkReads)
+{
+    ScreenPtr pScreen = pDrawable->pScreen;
+    ExaScreenPriv(pScreen);
+
+    if (pExaScr->prepare_access_reg &&
+	!(checkReads && exaGCReadsDestination(pDrawable,
+					      pGC->planemask,
+					      pGC->fillStyle,
+					      pGC->alu,
+					      pGC->clientClipType))) {
+	BoxRec box;
+	RegionRec reg;
+	int xoff, yoff;
+	PixmapPtr pPixmap = exaGetDrawablePixmap(pDrawable);
+
+	exaGetDrawableDeltas(pDrawable, pPixmap, &xoff, &yoff);
+	box.x1 = pDrawable->x + x + xoff;
+	box.y1 = pDrawable->y + y + yoff;
+	box.x2 = box.x1 + width;
+	box.y2 = box.y1 + height;
+
+	REGION_INIT(pScreen, &reg, &box, 1);
+	pExaScr->prepare_access_reg(pPixmap, index, &reg);
+	REGION_UNINIT(pScreen, &reg);
+    } else
+	exaPrepareAccess(pDrawable, index);
+}
+
+
 RegionPtr
 ExaCheckCopyArea (DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
 		 int srcx, int srcy, int w, int h, int dstx, int dsty)
@@ -148,8 +207,10 @@ ExaCheckCopyArea (DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
     EXA_PRE_FALLBACK_GC(pGC);
     EXA_FALLBACK(("from %p to %p (%c,%c)\n", pSrc, pDst,
 		  exaDrawableLocation(pSrc), exaDrawableLocation(pDst)));
-    exaPrepareAccess (pDst, EXA_PREPARE_DEST);
-    exaPrepareAccess (pSrc, EXA_PREPARE_SRC);
+    ExaFallbackPrepareReg(pSrc, pGC, srcx, srcy, w, h,
+			  EXA_PREPARE_SRC, FALSE);
+    ExaFallbackPrepareReg(pDst, pGC, dstx, dsty, w, h,
+			  EXA_PREPARE_DEST, TRUE);
     ret = pGC->ops->CopyArea (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty);
     exaFinishAccess (pSrc, EXA_PREPARE_SRC);
     exaFinishAccess (pDst, EXA_PREPARE_DEST);
@@ -168,8 +229,10 @@ ExaCheckCopyPlane (DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
     EXA_PRE_FALLBACK_GC(pGC);
     EXA_FALLBACK(("from %p to %p (%c,%c)\n", pSrc, pDst,
 		  exaDrawableLocation(pSrc), exaDrawableLocation(pDst)));
-    exaPrepareAccess (pDst, EXA_PREPARE_DEST);
-    exaPrepareAccess (pSrc, EXA_PREPARE_SRC);
+    ExaFallbackPrepareReg(pSrc, pGC, srcx, srcy, w, h,
+			  EXA_PREPARE_SRC, FALSE);
+    ExaFallbackPrepareReg(pDst, pGC, dstx, dsty, w, h,
+			  EXA_PREPARE_DEST, TRUE);
     ret = pGC->ops->CopyPlane (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty,
 		       bitPlane);
     exaFinishAccess (pSrc, EXA_PREPARE_SRC);
@@ -295,8 +358,10 @@ ExaCheckPushPixels (GCPtr pGC, PixmapPtr pBitmap,
     EXA_FALLBACK(("from %p to %p (%c,%c)\n", pBitmap, pDrawable,
 		  exaDrawableLocation(&pBitmap->drawable),
 		  exaDrawableLocation(pDrawable)));
-    exaPrepareAccess (pDrawable, EXA_PREPARE_DEST);
-    exaPrepareAccess (&pBitmap->drawable, EXA_PREPARE_SRC);
+    ExaFallbackPrepareReg(pDrawable, pGC, x, y, w, h,
+			  EXA_PREPARE_DEST, TRUE);
+    ExaFallbackPrepareReg(&pBitmap->drawable, pGC, 0, 0, w, h,
+			  EXA_PREPARE_SRC, FALSE);
     exaPrepareAccessGC (pGC);
     pGC->ops->PushPixels (pGC, pBitmap, pDrawable, w, h, x, y);
     exaFinishAccessGC (pGC);
@@ -337,29 +402,12 @@ ExaCheckGetImage(DrawablePtr pDrawable, int x, int y, int w, int h,
 		unsigned int format, unsigned long planeMask, char *d)
 {
     ScreenPtr pScreen = pDrawable->pScreen;
-    PixmapPtr pPix = exaGetDrawablePixmap (pDrawable);
     EXA_PRE_FALLBACK(pScreen);
     EXA_FALLBACK(("from %p (%c)\n", pDrawable,
 		  exaDrawableLocation(pDrawable)));
 
-    if (pExaScr->prepare_access_reg) {
-	int xoff, yoff;
-	BoxRec Box;
-	RegionRec Reg;
-
-	exaGetDrawableDeltas(pDrawable, pPix, &xoff, &yoff);
-
-	Box.x1 = pDrawable->x + x + xoff;
-	Box.y1 = pDrawable->y + y + yoff;
-	Box.x2 = Box.x1 + w;
-	Box.y2 = Box.y1 + h;
-
-	REGION_INIT(pScreen, &Reg, &Box, 1);
-
-	pExaScr->prepare_access_reg(pPix, EXA_PREPARE_SRC, &Reg);
-    } else
-	exaPrepareAccess(pDrawable, EXA_PREPARE_SRC);
-
+    ExaFallbackPrepareReg(pDrawable, NULL, x, y, w, h,
+			  EXA_PREPARE_SRC, FALSE);
     swap(pExaScr, pScreen, GetImage);
     pScreen->GetImage (pDrawable, x, y, w, h, format, planeMask, d);
     swap(pExaScr, pScreen, GetImage);
commit aa9ce8ab343d51a67924757c5a43c9572248bb24
Author: Michel Dänzer <daenzer at vmware.com>
Date:   Tue Dec 29 09:34:43 2009 +0100

    EXA: Use relevant source region to minimize migration on CopyWindow fallbacks.
    
    Signed-off-by: Michel Dänzer <daenzer at vmware.com>
    Acked-by: Maarten Maathuis <madman2003 at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/exa/exa_unaccel.c b/exa/exa_unaccel.c
index 0dbcd53..f077fc8 100644
--- a/exa/exa_unaccel.c
+++ b/exa/exa_unaccel.c
@@ -313,8 +313,18 @@ ExaCheckCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
     EXA_PRE_FALLBACK(pScreen);
     EXA_FALLBACK(("from %p\n", pWin));
 
-    /* being both src and dest, src is safest. */
-    exaPrepareAccess(pDrawable, EXA_PREPARE_SRC);
+    /* Only need the source bits, the destination region will be overwritten */
+    if (pExaScr->prepare_access_reg) {
+	PixmapPtr pPixmap = pScreen->GetWindowPixmap(pWin);
+	int xoff, yoff;
+
+	exaGetDrawableDeltas(&pWin->drawable, pPixmap, &xoff, &yoff);
+	REGION_TRANSLATE(pScreen, prgnSrc, xoff, yoff);
+	pExaScr->prepare_access_reg(pPixmap, EXA_PREPARE_SRC, prgnSrc);
+	REGION_TRANSLATE(pScreen, prgnSrc, -xoff, -yoff);
+    } else
+	exaPrepareAccess(pDrawable, EXA_PREPARE_SRC);
+
     swap(pExaScr, pScreen, CopyWindow);
     pScreen->CopyWindow (pWin, ptOldOrg, prgnSrc);
     swap(pExaScr, pScreen, CopyWindow);
commit 39cc110caa1f6481a7213ae39f82669333ec1645
Author: Thomas Hellstrom <thellstrom at vmware.com>
Date:   Tue Dec 29 09:34:42 2009 +0100

    EXA: Fix bugs in exaGetImage / ExaCheckGetImage migration.
    
    Signed-off-by: Thomas Hellstrom <thellstrom at vmware.com>
    Acked-by: Michel Dänzer <michel at daenzer.net>
    Acked-by: Maarten Maathuis <madman2003 at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index 0f6e5f7..c56c6bc 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -1270,7 +1270,7 @@ exaGetImage (DrawablePtr pDrawable, int x, int y, int w, int h,
 	RegionRec Reg;
 	ExaMigrationRec pixmaps[1];
 
-	Box.x1 = pDrawable->y + x + xoff;
+	Box.x1 = pDrawable->x + x + xoff;
 	Box.y1 = pDrawable->y + y + yoff;
 	Box.x2 = Box.x1 + w;
 	Box.y2 = Box.y1 + h;
diff --git a/exa/exa_unaccel.c b/exa/exa_unaccel.c
index eee14da..0dbcd53 100644
--- a/exa/exa_unaccel.c
+++ b/exa/exa_unaccel.c
@@ -339,7 +339,7 @@ ExaCheckGetImage(DrawablePtr pDrawable, int x, int y, int w, int h,
 
 	exaGetDrawableDeltas(pDrawable, pPix, &xoff, &yoff);
 
-	Box.x1 = pDrawable->y + x + xoff;
+	Box.x1 = pDrawable->x + x + xoff;
 	Box.y1 = pDrawable->y + y + yoff;
 	Box.x2 = Box.x1 + w;
 	Box.y2 = Box.y1 + h;
commit d42f3960514f1c410863ac6c09c5638b5ddeae20
Author: Michel Dänzer <daenzer at vmware.com>
Date:   Mon Dec 28 16:48:18 2009 +0100

    EXA: Allow optimized migration to be enabled with mixed pixmaps.
    
    This was always the intention, I only recently realized it wasn't the case
    yet...
    
    Signed-off-by: Michel Dänzer <daenzer at vmware.com>
    Acked-by: Maarten Maathuis <madman2003 at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/exa/examodule.c b/hw/xfree86/exa/examodule.c
index 601288c..bcb6a40 100644
--- a/hw/xfree86/exa/examodule.c
+++ b/hw/xfree86/exa/examodule.c
@@ -122,24 +122,25 @@ exaDDXDriverInit(ScreenPtr pScreen)
     memcpy(pScreenPriv->options, EXAOptions, sizeof(EXAOptions));
     xf86ProcessOptions (pScrn->scrnIndex, pScrn->options, pScreenPriv->options);
 
-    if ((pExaScr->info->flags & EXA_OFFSCREEN_PIXMAPS) &&
-  	pExaScr->info->offScreenBase < pExaScr->info->memorySize)
-    {
-	char *heuristicName;
-
-	heuristicName = xf86GetOptValString (pScreenPriv->options,
-					     EXAOPT_MIGRATION_HEURISTIC);
-	if (heuristicName != NULL) {
-	    if (strcmp(heuristicName, "greedy") == 0)
-		pExaScr->migration = ExaMigrationGreedy;
-	    else if (strcmp(heuristicName, "always") == 0)
-		pExaScr->migration = ExaMigrationAlways;
-	    else if (strcmp(heuristicName, "smart") == 0)
-		pExaScr->migration = ExaMigrationSmart;
-	    else {
-		xf86DrvMsg (pScreen->myNum, X_WARNING, 
-			    "EXA: unknown migration heuristic %s\n",
-			    heuristicName);
+    if (pExaScr->info->flags & EXA_OFFSCREEN_PIXMAPS) {
+	if (!(pExaScr->info->flags & EXA_HANDLES_PIXMAPS) &&
+	    pExaScr->info->offScreenBase < pExaScr->info->memorySize) {
+	    char *heuristicName;
+
+	    heuristicName = xf86GetOptValString (pScreenPriv->options,
+						 EXAOPT_MIGRATION_HEURISTIC);
+	    if (heuristicName != NULL) {
+		if (strcmp(heuristicName, "greedy") == 0)
+		    pExaScr->migration = ExaMigrationGreedy;
+		else if (strcmp(heuristicName, "always") == 0)
+		    pExaScr->migration = ExaMigrationAlways;
+		else if (strcmp(heuristicName, "smart") == 0)
+		    pExaScr->migration = ExaMigrationSmart;
+		else {
+		    xf86DrvMsg (pScreen->myNum, X_WARNING, 
+				"EXA: unknown migration heuristic %s\n",
+				heuristicName);
+		}
 	    }
 	}
 
commit 661630f9099f254e54c8da513aaed12f6532cc35
Author: Michel Dänzer <daenzer at vmware.com>
Date:   Mon Dec 28 16:48:17 2009 +0100

    EXA/mixed: Don't clear deferred status of pixmaps if migration is limited.
    
    * With optimized migration, only the pending damage region is synchronized for
      destination pixmaps.
    * Migration of source pixmaps can be limited to a bounding region.
    
    Signed-off-by: Michel Dänzer <daenzer at vmware.com>
    Acked-by: Maarten Maathuis <madman2003 at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/exa/exa_migration_mixed.c b/exa/exa_migration_mixed.c
index b755b83..14cb5a7 100644
--- a/exa/exa_migration_mixed.c
+++ b/exa/exa_migration_mixed.c
@@ -112,7 +112,8 @@ exaDoMigration_mixed(ExaMigrationPtr pixmaps, int npixmaps, Bool can_accel)
 	    pPixmap->devKind = pExaPixmap->fb_pitch;
 	    exaCopyDirtyToFb(pixmaps + i);
 
-	    if (pExaScr->deferred_mixed_pixmap == pPixmap)
+	    if (pExaScr->deferred_mixed_pixmap == pPixmap &&
+		!pixmaps[i].as_dst && !pixmaps[i].pReg)
 		pExaScr->deferred_mixed_pixmap = NULL;
 	}
 
commit 42e8c9224e6c54655c45f87999d37d0d67b3f7f5
Author: Dan Nicholson <dbn.lists at gmail.com>
Date:   Fri Oct 2 06:29:28 2009 -0700

    xfree86: Introduce InputClass configuration
    
    Currently Xorg uses hal's fdi files to decide what configuration options
    are applied to automatically added input devices. This is sub-optimal
    since it requires users to use a new and different configuration store
    than xorg.conf.
    
    The InputClass section attempts to provide a system similar to hal where
    configuration can be applied to all devices with certain attributes. For
    now, devices can be matched to:
    
    * A substring of the product name via a MatchProduct entry
    * A substring of the vendir name via a MatchVendor entry
    * A pathname pattern of the device file via a MatchDevicePath entry
    * A device type via boolean entries for MatchIsKeyboard, MatchIsPointer,
      MatchIsJoystick, MatchIsTablet, MatchIsTouchpad and MatchIsTouchscreen
    
    See the INPUTCLASS section in xorg.conf(5) for more details.
    
    Signed-off-by: Dan Nicholson <dbn.lists at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/configure.ac b/configure.ac
index 723c1fd..d5cf96d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -122,7 +122,7 @@ AM_CONDITIONAL(SPECIAL_DTRACE_OBJECTS, [test "x$SPECIAL_DTRACE_OBJECTS" = "xyes"
 
 AC_HEADER_DIRENT
 AC_HEADER_STDC
-AC_CHECK_HEADERS([fcntl.h stdlib.h string.h unistd.h dlfcn.h stropts.h])
+AC_CHECK_HEADERS([fcntl.h stdlib.h string.h unistd.h dlfcn.h stropts.h fnmatch.h])
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 11b7315..e0c7830 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -57,9 +57,11 @@
 #include <X11/Xatom.h>
 #include "xf86.h"
 #include "xf86Priv.h"
+#include "xf86Config.h"
 #include "xf86Xinput.h"
 #include "XIstubs.h"
 #include "xf86Optrec.h"
+#include "xf86Parser.h"
 #include "mipointer.h"
 #include "xf86InPriv.h"
 #include "compiler.h"
@@ -74,6 +76,11 @@
 #include "exglobals.h"
 #include "eventstr.h"
 
+#include <string.h>     /* InputClassMatches */
+#ifdef HAVE_FNMATCH_H
+#include <fnmatch.h>
+#endif
+
 #include "extnsionst.h"
 
 #include "windowstr.h"	/* screenIsSaved */
@@ -466,6 +473,85 @@ AddOtherInputDevices(void)
 {
 }
 
+/*
+ * Classes without any Match statements match all devices. Otherwise, all
+ * statements must match.
+ */
+static Bool
+InputClassMatches(XF86ConfInputClassPtr iclass, InputAttributes *attrs)
+{
+    if (iclass->match_product &&
+        (!attrs->product || !strstr(attrs->product, iclass->match_product)))
+        return False;
+    if (iclass->match_vendor &&
+        (!attrs->vendor || !strstr(attrs->vendor, iclass->match_vendor)))
+        return False;
+    if (iclass->match_device &&
+#ifdef HAVE_FNMATCH_H
+        (!attrs->device ||
+         fnmatch(iclass->match_device, attrs->device, 0) != 0))
+#else
+        (!attrs->device || !strstr(attrs->device, iclass->match_device)))
+#endif
+        return False;
+    if (iclass->is_keyboard.set &&
+        iclass->is_keyboard.val != !!(attrs->flags & ATTR_KEYBOARD))
+        return False;
+    if (iclass->is_pointer.set &&
+        iclass->is_pointer.val != !!(attrs->flags & ATTR_POINTER))
+        return False;
+    if (iclass->is_joystick.set &&
+        iclass->is_joystick.val != !!(attrs->flags & ATTR_JOYSTICK))
+        return False;
+    if (iclass->is_tablet.set &&
+        iclass->is_tablet.val != !!(attrs->flags & ATTR_TABLET))
+        return False;
+    if (iclass->is_touchpad.set &&
+        iclass->is_touchpad.val != !!(attrs->flags & ATTR_TOUCHPAD))
+        return False;
+    if (iclass->is_touchscreen.set &&
+        iclass->is_touchscreen.val != !!(attrs->flags & ATTR_TOUCHSCREEN))
+        return False;
+    return True;
+}
+
+/*
+ * Merge in any InputClass configurations. Each InputClass section can
+ * add to the original device configuration as well as any previous
+ * InputClass sections.
+ */
+static int
+MergeInputClasses(IDevPtr idev, InputAttributes *attrs)
+{
+    XF86ConfInputClassPtr cl;
+    XF86OptionPtr classopts;
+
+    for (cl = xf86configptr->conf_inputclass_lst; cl; cl = cl->list.next) {
+        if (!InputClassMatches(cl, attrs))
+            continue;
+
+        xf86Msg(X_CONFIG, "%s: Applying InputClass \"%s\"\n",
+                idev->identifier, cl->identifier);
+        if (cl->driver && !idev->driver) {
+            idev->driver = xstrdup(cl->driver);
+            if (!idev->driver) {
+                xf86Msg(X_ERROR, "Could not allocate memory while merging "
+                        "InputClass configuration");
+                return BadAlloc;
+            }
+        }
+
+        classopts = xf86optionListDup(cl->option_lst);
+        if (idev->commonOptions)
+            idev->commonOptions = xf86optionListMerge(classopts,
+                                                      idev->commonOptions);
+        else
+            idev->commonOptions = classopts;
+    }
+
+    return Success;
+}
+
 /**
  * Create a new input device, activate and enable it.
  *
@@ -636,6 +722,13 @@ NewInputDeviceRequest (InputOption *options, InputAttributes *attrs,
         option->value = NULL;
     }
 
+    /* Apply InputClass settings */
+    if (attrs) {
+        rval = MergeInputClasses(idev, attrs);
+        if (rval != Success)
+            goto unwind;
+    }
+
     rval = xf86NewInputDevice(idev, pdev,
                 (!is_auto || (is_auto && xf86Info.autoEnableDevices)));
     if (rval == Success)
diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre
index 84be12c..f276e9d 100644
--- a/hw/xfree86/doc/man/xorg.conf.man.pre
+++ b/hw/xfree86/doc/man/xorg.conf.man.pre
@@ -117,6 +117,7 @@ The section names are:
 .BR "Module         " "Dynamic module loading"
 .BR "Extensions     " "Extension enabling"
 .BR "InputDevice    " "Input device description"
+.BR "InputClass     " "Input class description"
 .BR "Device         " "Graphics device description"
 .BR "VideoAdaptor   " "Xv video adaptor description"
 .BR "Monitor        " "Monitor description"
@@ -882,6 +883,101 @@ may be reattached or set floating at runtime.
 .TP 7
 .BI "Option \*qSendDragEvents\*q  \*q" boolean \*q
 ???
+.SH "INPUTCLASS SECTION"
+The config file may have multiple
+.B InputClass
+sections.
+These sections are optional and are used to provide configuration for a
+class of input devices as they are automatically added. An input device can
+match more than one
+.B InputClass
+section. Each class can only supplement settings from a previous class, so
+it is best to arrange the sections with the most generic matches last.
+.PP
+.B InputClass
+sections have the following format:
+.PP
+.RS 4
+.nf
+.B  "Section \*qInputClass\*q"
+.BI "    Identifier  \*q" name \*q
+.I  "    entries"
+.I  "    ..."
+.I  "    options"
+.I  "    ..."
+.B  "EndSection"
+.fi
+.RE
+.PP
+The
+.B Identifier
+entry is required in all
+.B InputClass
+sections.
+All other entries are optional.
+.PP
+The
+.B Identifier
+entry specifies the unique name for this input class.
+The
+.B Driver
+entry specifies the name of the driver to use for this input device.
+After all classes have been examined, the
+.RI \*q inputdriver \*q
+module from the final
+.B Driver
+entry will be enabled when using the loadable server.
+.PP
+When an input device is automatically added, its characteristics are
+checked against all
+.B InputClass
+sections. Each section can contain optional entries to narrow the match
+of the class. If none of the optional entries appear, the
+.B InputClass
+section is generic and will match any input device. If more than one of
+these entries appear, they all must match for the configuration to apply.
+The allowed matching entries are shown below.
+.PP
+.TP 7
+.BI "MatchProduct  \*q" matchproduct \*q
+This entry can be used to check if the substring
+.RI \*q matchproduct \*q
+occurs in the device's product name.
+.TP 7
+.BI "MatchVendor  \*q" matchvendor \*q
+This entry can be used to check if the substring
+.RI \*q matchvendor \*q
+occurs in the device's vendor name.
+.TP 7
+.BI "MatchDevicePath \*q" matchdevice \*q
+This entry can be used to check if the device file matches the
+.RI \*q matchdevice \*q
+pathname pattern.
+.TP 7
+.BI "MatchIsKeyboard     \*q" bool \*q
+.TP 7
+.BI "MatchIsPointer      \*q" bool \*q
+.TP 7
+.BI "MatchIsJoystick     \*q" bool \*q
+.TP 7
+.BI "MatchIsTablet       \*q" bool \*q
+.TP 7
+.BI "MatchIsTouchpad     \*q" bool \*q
+.TP 7
+.BI "MatchIsTouchscreen  \*q" bool \*q
+Match device types. These entries take a boolean argument similar to
+.B Option
+entries.
+.PP
+When an input device has been matched to the
+.B InputClass
+section, any
+.B Option
+entries are applied to the device. See the
+.B InputDevice
+section above for a description of the various
+.B Option
+entries.
 .SH "DEVICE SECTION"
 The config file may have multiple
 .B Device
diff --git a/hw/xfree86/parser/InputClass.c b/hw/xfree86/parser/InputClass.c
new file mode 100644
index 0000000..1c98160
--- /dev/null
+++ b/hw/xfree86/parser/InputClass.c
@@ -0,0 +1,232 @@
+/*
+ * Copyright (c) 2009 Dan Nicholson
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/* View/edit this file with tab stops set to 4 */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+
+extern LexRec val;
+
+static
+xf86ConfigSymTabRec InputClassTab[] =
+{
+    {ENDSECTION, "endsection"},
+    {IDENTIFIER, "identifier"},
+    {OPTION, "option"},
+    {DRIVER, "driver"},
+    {MATCH_PRODUCT, "matchproduct"},
+    {MATCH_VENDOR, "matchvendor"},
+    {MATCH_DEVICE_PATH, "matchdevicepath"},
+    {MATCH_IS_KEYBOARD, "matchiskeyboard"},
+    {MATCH_IS_POINTER, "matchispointer"},
+    {MATCH_IS_JOYSTICK, "matchisjoystick"},
+    {MATCH_IS_TABLET, "matchistablet"},
+    {MATCH_IS_TOUCHPAD, "matchistouchpad"},
+    {MATCH_IS_TOUCHSCREEN, "matchistouchscreen"},
+    {-1, ""},
+};
+
+#define CLEANUP xf86freeInputClassList
+
+XF86ConfInputClassPtr
+xf86parseInputClassSection(void)
+{
+    int has_ident = FALSE;
+    int token;
+
+    parsePrologue(XF86ConfInputClassPtr, XF86ConfInputClassRec)
+
+    while ((token = xf86getToken(InputClassTab)) != ENDSECTION) {
+        switch (token) {
+        case COMMENT:
+            ptr->comment = xf86addComment(ptr->comment, val.str);
+            break;
+        case IDENTIFIER:
+            if (xf86getSubToken(&(ptr->comment)) != STRING)
+                Error(QUOTE_MSG, "Identifier");
+            if (has_ident == TRUE)
+                Error(MULTIPLE_MSG, "Identifier");
+            ptr->identifier = val.str;
+            has_ident = TRUE;
+            break;
+        case DRIVER:
+            if (xf86getSubToken(&(ptr->comment)) != STRING)
+                Error(QUOTE_MSG, "Driver");
+            if (strcmp(val.str, "keyboard") == 0)
+                ptr->driver = "kbd";
+            else
+                ptr->driver = val.str;
+            break;
+        case OPTION:
+            ptr->option_lst = xf86parseOption(ptr->option_lst);
+            break;
+        case MATCH_PRODUCT:
+            if (xf86getSubToken(&(ptr->comment)) != STRING)
+                Error(QUOTE_MSG, "MatchProduct");
+            ptr->match_product = val.str;
+            break;
+        case MATCH_VENDOR:
+            if (xf86getSubToken(&(ptr->comment)) != STRING)
+                Error(QUOTE_MSG, "MatchVendor");
+            ptr->match_vendor = val.str;
+            break;
+        case MATCH_DEVICE_PATH:
+            if (xf86getSubToken(&(ptr->comment)) != STRING)
+                Error(QUOTE_MSG, "MatchDevicePath");
+            ptr->match_device = val.str;
+            break;
+        case MATCH_IS_KEYBOARD:
+            if (xf86getSubToken(&(ptr->comment)) != STRING)
+                Error(QUOTE_MSG, "MatchIsKeyboard");
+            ptr->is_keyboard.set = xf86getBoolValue(&ptr->is_keyboard.val,
+                                                    val.str);
+            if (!ptr->is_keyboard.set)
+                Error(BOOL_MSG, "MatchIsKeyboard");
+            break;
+        case MATCH_IS_POINTER:
+            if (xf86getSubToken(&(ptr->comment)) != STRING)
+                Error(QUOTE_MSG, "MatchIsPointer");
+            ptr->is_pointer.set = xf86getBoolValue(&ptr->is_pointer.val,
+                                                   val.str);
+            if (!ptr->is_pointer.set)
+                Error(BOOL_MSG, "MatchIsPointer");
+            break;
+        case MATCH_IS_JOYSTICK:
+            if (xf86getSubToken(&(ptr->comment)) != STRING)
+                Error(QUOTE_MSG, "MatchIsJoystick");
+            ptr->is_joystick.set = xf86getBoolValue(&ptr->is_joystick.val,
+                                                    val.str);
+            if (!ptr->is_joystick.set)
+                Error(BOOL_MSG, "MatchIsJoystick");
+            break;
+        case MATCH_IS_TABLET:
+            if (xf86getSubToken(&(ptr->comment)) != STRING)
+                Error(QUOTE_MSG, "MatchIsTablet");
+            ptr->is_tablet.set = xf86getBoolValue(&ptr->is_tablet.val,
+                                                  val.str);
+            if (!ptr->is_tablet.set)
+                Error(BOOL_MSG, "MatchIsTablet");
+            break;
+        case MATCH_IS_TOUCHPAD:
+            if (xf86getSubToken(&(ptr->comment)) != STRING)
+                Error(QUOTE_MSG, "MatchIsTouchpad");
+            ptr->is_touchpad.set = xf86getBoolValue(&ptr->is_touchpad.val,
+                                                    val.str);
+            if (!ptr->is_touchpad.set)
+                Error(BOOL_MSG, "MatchIsTouchpad");
+            break;
+        case MATCH_IS_TOUCHSCREEN:
+            if (xf86getSubToken(&(ptr->comment)) != STRING)
+                Error(QUOTE_MSG, "MatchIsTouchscreen");
+            ptr->is_touchscreen.set = xf86getBoolValue(&ptr->is_touchscreen.val,
+                                                       val.str);
+            if (!ptr->is_touchscreen.set)
+                Error(BOOL_MSG, "MatchIsTouchscreen");
+            break;
+        case EOF_TOKEN:
+            Error(UNEXPECTED_EOF_MSG, NULL);
+            break;
+        default:
+            Error(INVALID_KEYWORD_MSG, xf86tokenString ());
+            break;
+        }
+    }
+
+    if (!has_ident)
+        Error(NO_IDENT_MSG, NULL);
+
+#ifdef DEBUG
+    printf("InputClass section parsed\n");
+#endif
+
+    return ptr;
+}
+
+void
+xf86printInputClassSection (FILE * cf, XF86ConfInputClassPtr ptr)
+{
+    while (ptr) {
+        fprintf(cf, "Section \"InputClass\"\n");
+        if (ptr->comment)
+            fprintf(cf, "%s", ptr->comment);
+        if (ptr->identifier)
+            fprintf(cf, "\tIdentifier      \"%s\"\n", ptr->identifier);
+        if (ptr->driver)
+            fprintf(cf, "\tDriver          \"%s\"\n", ptr->driver);
+        if (ptr->match_product)
+            fprintf(cf, "\tMatchProduct    \"%s\"\n", ptr->match_product);
+        if (ptr->match_vendor)
+            fprintf(cf, "\tMatchVendor     \"%s\"\n", ptr->match_vendor);
+        if (ptr->match_device)
+            fprintf(cf, "\tMatchDevicePath \"%s\"\n", ptr->match_device);
+        if (ptr->is_keyboard.set)
+            fprintf(cf, "\tIsKeyboard      \"%s\"\n",
+                    ptr->is_keyboard.val ? "yes" : "no");
+        if (ptr->is_pointer.set)
+            fprintf(cf, "\tIsPointer       \"%s\"\n",
+                    ptr->is_pointer.val ? "yes" : "no");
+        if (ptr->is_joystick.set)
+            fprintf(cf, "\tIsJoystick      \"%s\"\n",
+                    ptr->is_joystick.val ? "yes" : "no");
+        if (ptr->is_tablet.set)
+            fprintf(cf, "\tIsTablet        \"%s\"\n",
+                    ptr->is_tablet.val ? "yes" : "no");
+        if (ptr->is_touchpad.set)
+            fprintf(cf, "\tIsTouchpad      \"%s\"\n",
+                    ptr->is_touchpad.val ? "yes" : "no");
+        if (ptr->is_touchscreen.set)
+            fprintf(cf, "\tIsTouchscreen   \"%s\"\n",
+                    ptr->is_touchscreen.val ? "yes" : "no");
+        xf86printOptionList(cf, ptr->option_lst, 1);
+        fprintf(cf, "EndSection\n\n");
+        ptr = ptr->list.next;
+    }
+}
+
+void
+xf86freeInputClassList (XF86ConfInputClassPtr ptr)
+{
+    XF86ConfInputClassPtr prev;
+
+    while (ptr) {
+        TestFree(ptr->identifier);
+        TestFree(ptr->driver);
+        TestFree(ptr->match_product);
+        TestFree(ptr->match_vendor);
+        TestFree(ptr->match_device);
+        TestFree(ptr->comment);
+        xf86optionListFree(ptr->option_lst);
+
+        prev = ptr;
+        ptr = ptr->list.next;
+        free(prev);
+    }
+}
diff --git a/hw/xfree86/parser/Makefile.am b/hw/xfree86/parser/Makefile.am
index b8fab28..49c191f 100644
--- a/hw/xfree86/parser/Makefile.am
+++ b/hw/xfree86/parser/Makefile.am
@@ -13,6 +13,7 @@ INTERNAL_SOURCES= \
 	Files.c \
 	Flags.c \
 	Input.c \
+	InputClass.c \
 	Layout.c \
 	Module.c \
 	Video.c \
diff --git a/hw/xfree86/parser/configProcs.h b/hw/xfree86/parser/configProcs.h
index 26ba40e..7d8a8e5 100644
--- a/hw/xfree86/parser/configProcs.h
+++ b/hw/xfree86/parser/configProcs.h
@@ -48,6 +48,10 @@ XF86ConfInputPtr xf86parseInputSection(void);
 void xf86printInputSection(FILE *f, XF86ConfInputPtr ptr);
 void xf86freeInputList(XF86ConfInputPtr ptr);
 int xf86validateInput (XF86ConfigPtr p);
+/* InputClass.c */
+XF86ConfInputClassPtr xf86parseInputClassSection(void);
+void xf86printInputClassSection(FILE *f, XF86ConfInputClassPtr ptr);
+void xf86freeInputClassList(XF86ConfInputClassPtr ptr);
 /* Layout.c */
 XF86ConfLayoutPtr xf86parseLayoutSection(void);
 void xf86printLayoutSection(FILE *cf, XF86ConfLayoutPtr ptr);
diff --git a/hw/xfree86/parser/read.c b/hw/xfree86/parser/read.c
index e965d20..1091be5 100644
--- a/hw/xfree86/parser/read.c
+++ b/hw/xfree86/parser/read.c
@@ -177,6 +177,14 @@ xf86readConfigFile (void)
 				HANDLE_LIST (conf_input_lst, xf86parseInputSection,
 							 XF86ConfInputPtr);
 			}
+			else if (xf86nameCompare(val.str, "inputclass") == 0)
+			{
+				free(val.str);
+				val.str = NULL;
+				HANDLE_LIST (conf_inputclass_lst,
+						xf86parseInputClassSection,
+						XF86ConfInputClassPtr);
+			}
 			else if (xf86nameCompare (val.str, "module") == 0)
 			{
 				free(val.str);
diff --git a/hw/xfree86/parser/write.c b/hw/xfree86/parser/write.c
index 3b77b93..083203c 100644
--- a/hw/xfree86/parser/write.c
+++ b/hw/xfree86/parser/write.c
@@ -117,6 +117,8 @@ doWriteConfigFile (const char *filename, XF86ConfigPtr cptr)
 
 	xf86printInputSection (cf, cptr->conf_input_lst);
 
+	xf86printInputClassSection (cf, cptr->conf_inputclass_lst);
+
 	xf86printVideoAdaptorSection (cf, cptr->conf_videoadaptor_lst);
 
 	xf86printModesSection (cf, cptr->conf_modes_lst);
diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h
index 72beb5f..4e30993 100644
--- a/hw/xfree86/parser/xf86Parser.h
+++ b/hw/xfree86/parser/xf86Parser.h
@@ -338,6 +338,25 @@ typedef struct
 }
 xf86TriState;
 
+typedef struct
+{
+	GenericListRec list;
+	char *identifier;
+	char *driver;
+	char *match_product;
+	char *match_vendor;
+	char *match_device;
+	xf86TriState is_keyboard;
+	xf86TriState is_pointer;
+	xf86TriState is_joystick;
+	xf86TriState is_tablet;
+	xf86TriState is_touchpad;
+	xf86TriState is_touchscreen;
+	XF86OptionPtr option_lst;
+	char *comment;
+}
+XF86ConfInputClassRec, *XF86ConfInputClassPtr;
+
 /* Values for adj_where */
 #define CONF_ADJ_OBSOLETE	-1
 #define CONF_ADJ_ABSOLUTE	0
@@ -446,6 +465,7 @@ typedef struct
 	XF86ConfDevicePtr conf_device_lst;
 	XF86ConfScreenPtr conf_screen_lst;
 	XF86ConfInputPtr conf_input_lst;
+	XF86ConfInputClassPtr conf_inputclass_lst;
 	XF86ConfLayoutPtr conf_layout_lst;
 	XF86ConfVendorPtr conf_vendor_lst;
 	XF86ConfDRIPtr conf_dri;
diff --git a/hw/xfree86/parser/xf86tokens.h b/hw/xfree86/parser/xf86tokens.h
index 4c1d38c..e3a9d71 100644
--- a/hw/xfree86/parser/xf86tokens.h
+++ b/hw/xfree86/parser/xf86tokens.h
@@ -273,7 +273,18 @@ typedef enum {
 
     /* DRI Tokens */
     GROUP,
-    BUFFERS
+    BUFFERS,
+
+    /* InputClass Tokens */
+    MATCH_PRODUCT,
+    MATCH_VENDOR,
+    MATCH_DEVICE_PATH,
+    MATCH_IS_KEYBOARD,
+    MATCH_IS_POINTER,
+    MATCH_IS_JOYSTICK,
+    MATCH_IS_TABLET,
+    MATCH_IS_TOUCHPAD,
+    MATCH_IS_TOUCHSCREEN
 } ParserTokens;
 
 #endif /* _xf86_tokens_h */
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 1096371..ab04414 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -231,6 +231,9 @@
 /* Define to 1 if you have the <unistd.h> header file. */
 #undef HAVE_UNISTD_H
 
+/* Define to 1 if you have the <fnmatch.h> header file. */
+#undef HAVE_FNMATCH_H
+
 /* Have /dev/urandom */
 #undef HAVE_URANDOM
 
commit 0711598dd3e8366217676f462f1af7d0899656d9
Author: Dan Nicholson <dbn.lists at gmail.com>
Date:   Wed Sep 2 06:47:13 2009 -0700

    config: Introduce InputAttributes in NewInputDeviceRequest
    
    In order to give NewInputDeviceRequest more information, a new
    InputAttributes type is introduced. Currently, this collects the product
    and vendor name, device path, and sets booleans for attributes such as
    having keys and/or a pointer. Only the HAL backend fills in the
    attributes, though.
    
    Signed-off-by: Dan Nicholson <dbn.lists at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/stubs.c b/Xi/stubs.c
index 400e937..04ba976 100644
--- a/Xi/stubs.c
+++ b/Xi/stubs.c
@@ -227,7 +227,8 @@ ChangeDeviceControl(ClientPtr client, DeviceIntPtr dev,
  *
  */
 int
-NewInputDeviceRequest(InputOption *options, DeviceIntPtr *pdev)
+NewInputDeviceRequest(InputOption *options, InputAttributes *attrs,
+                      DeviceIntPtr *pdev)
 {
     return BadValue;
 }
diff --git a/config/dbus.c b/config/dbus.c
index 37462ac..86d9d28 100644
--- a/config/dbus.c
+++ b/config/dbus.c
@@ -147,7 +147,7 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
         dbus_message_iter_next(&iter);
     }
 
-    ret = NewInputDeviceRequest(options, &dev);
+    ret = NewInputDeviceRequest(options, NULL, &dev);
     if (ret != Success) {
         DebugF("[config/dbus] NewInputDeviceRequest failed\n");
         goto unwind;
diff --git a/config/hal.c b/config/hal.c
index 28f55a0..6bebbdf 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -191,6 +191,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
 {
     char *path = NULL, *driver = NULL, *name = NULL, *config_info = NULL;
     InputOption *options = NULL, *tmpo = NULL;
+    InputAttributes attrs = {0};
     DeviceIntPtr dev = NULL;
     DBusError error;
     struct xkb_options xkb_opts = {0};
@@ -215,10 +216,28 @@ device_added(LibHalContext *hal_ctx, const char *udi)
         LogMessage(X_WARNING,"config/hal: no driver or path specified for %s\n", udi);
         goto unwind;
     }
+    attrs.device = xstrdup(path);
 
     name = get_prop_string(hal_ctx, udi, "info.product");
     if (!name)
         name = xstrdup("(unnamed)");
+    else
+        attrs.product = xstrdup(name);
+
+    attrs.vendor = get_prop_string(hal_ctx, udi, "info.vendor");
+
+    if (libhal_device_query_capability(hal_ctx, udi, "input.keys", NULL))
+        attrs.flags |= ATTR_KEYBOARD;
+    if (libhal_device_query_capability(hal_ctx, udi, "input.mouse", NULL))
+        attrs.flags |= ATTR_POINTER;
+    if (libhal_device_query_capability(hal_ctx, udi, "input.joystick", NULL))
+        attrs.flags |= ATTR_JOYSTICK;
+    if (libhal_device_query_capability(hal_ctx, udi, "input.tablet", NULL))
+        attrs.flags |= ATTR_TABLET;
+    if (libhal_device_query_capability(hal_ctx, udi, "input.touchpad", NULL))
+        attrs.flags |= ATTR_TOUCHPAD;
+    if (libhal_device_query_capability(hal_ctx, udi, "input.touchscreen", NULL))
+        attrs.flags |= ATTR_TOUCHSCREEN;
 
     options = xcalloc(sizeof(*options), 1);
     if (!options){
@@ -400,7 +419,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
 
     /* this isn't an error, but how else do you output something that the user can see? */
     LogMessage(X_INFO, "config/hal: Adding input device %s\n", name);
-    if ((rc = NewInputDeviceRequest(options, &dev)) != Success) {
+    if ((rc = NewInputDeviceRequest(options, &attrs, &dev)) != Success) {
         LogMessage(X_ERROR, "config/hal: NewInputDeviceRequest failed (%d)\n", rc);
         dev = NULL;
         goto unwind;
@@ -430,6 +449,10 @@ unwind:
         xfree(tmpo);
     }
 
+    xfree(attrs.product);
+    xfree(attrs.vendor);
+    xfree(attrs.device);
+
     if (xkb_opts.layout)
         xfree(xkb_opts.layout);
     if (xkb_opts.rules)
diff --git a/hw/dmx/dmxinput.c b/hw/dmx/dmxinput.c
index d9118b6..c099349 100644
--- a/hw/dmx/dmxinput.c
+++ b/hw/dmx/dmxinput.c
@@ -103,7 +103,8 @@ void dmxUpdateWindowInfo(DMXUpdateType type, WindowPtr pWindow)
 }
 
 int
-NewInputDeviceRequest (InputOption *options, DeviceIntPtr *pdev)
+NewInputDeviceRequest (InputOption *options, InputAttributes *attrs,
+                       DeviceIntPtr *pdev)
 {
     return BadRequest;
 }
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 65fc75a..c084591 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -2249,7 +2249,8 @@ ChangeDeviceControl(register ClientPtr client, DeviceIntPtr pDev,
 }
 
 int
-NewInputDeviceRequest(InputOption *options, DeviceIntPtr *pdev)
+NewInputDeviceRequest(InputOption *options, InputAttributes *attrs,
+                      DeviceIntPtr *pdev)
 {
     InputOption *option = NULL;
     KdPointerInfo *pi = NULL;
diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index 8e5d5cf..bbf5786 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -83,7 +83,7 @@ typedef enum {
  */
 #define ABI_ANSIC_VERSION	SET_ABI_VERSION(0, 4)
 #define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(7, 0)
-#define ABI_XINPUT_VERSION	SET_ABI_VERSION(8, 0)
+#define ABI_XINPUT_VERSION	SET_ABI_VERSION(9, 0)
 #define ABI_EXTENSION_VERSION	SET_ABI_VERSION(3, 0)
 #define ABI_FONT_VERSION	SET_ABI_VERSION(0, 6)
 
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index f637cfe..11b7315 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -568,7 +568,8 @@ unwind:
 }
 
 int
-NewInputDeviceRequest (InputOption *options, DeviceIntPtr *pdev)
+NewInputDeviceRequest (InputOption *options, InputAttributes *attrs,
+                       DeviceIntPtr *pdev)
 {
     IDevRec *idev = NULL;
     InputOption *option = NULL;
diff --git a/hw/xquartz/darwinXinput.c b/hw/xquartz/darwinXinput.c
index 8af9fc7..43aea61 100644
--- a/hw/xquartz/darwinXinput.c
+++ b/hw/xquartz/darwinXinput.c
@@ -230,7 +230,8 @@ ChangeDeviceControl(ClientPtr client, DeviceIntPtr dev,
  *
  */
 int
-NewInputDeviceRequest(InputOption *options, DeviceIntPtr *pdev)
+NewInputDeviceRequest(InputOption *options, InputAttributes *attrs,
+                      DeviceIntPtr *pdev)
 {
   DEBUG_LOG("NewInputDeviceRequest(%p, %p)\n", options, pdev);
   return BadValue;
diff --git a/include/input.h b/include/input.h
index afcc006..7a6242d 100644
--- a/include/input.h
+++ b/include/input.h
@@ -52,6 +52,7 @@ SOFTWARE.
 #include "screenint.h"
 #include <X11/Xmd.h>
 #include <X11/Xproto.h>
+#include <stdint.h>
 #include "window.h"     /* for WindowPtr */
 #include "xkbrules.h"
 #include "events.h"
@@ -210,6 +211,20 @@ typedef struct _InputOption {
     struct _InputOption *next;
 } InputOption;
 
+typedef struct _InputAttributes {
+    char                *product;
+    char                *vendor;
+    char                *device;
+    uint32_t            flags;
+} InputAttributes;
+
+#define ATTR_KEYBOARD (1<<0)
+#define ATTR_POINTER (1<<1)
+#define ATTR_JOYSTICK (1<<2)
+#define ATTR_TABLET (1<<3)
+#define ATTR_TOUCHPAD (1<<4)
+#define ATTR_TOUCHSCREEN (1<<5)
+
 /* Key has been run through all input processing and events sent to clients. */
 #define KEY_PROCESSED 1
 /* Key has not been fully processed, no events have been sent. */
@@ -514,6 +529,7 @@ void FixUpEventFromWindow(DeviceIntPtr pDev,
 /* Implemented by the DDX. */
 extern _X_EXPORT int NewInputDeviceRequest(
     InputOption *options,
+    InputAttributes *attrs,
     DeviceIntPtr *dev);
 extern  _X_EXPORT void DeleteInputDeviceRequest(
     DeviceIntPtr dev);
commit c6e8637e29e0ca11dfb35c02da7ca6002ac8c597
Author: Dan Nicholson <dbn.lists at gmail.com>
Date:   Fri Oct 2 06:28:03 2009 -0700

    xfree86: Support non-Option boolean entries in configuration
    
    Refactored code into the parser to allow the freeform boolean types used
    in Option entries to be used in other configuration entries. This isn't
    as powerful as allowing "No" to precede the option names, but it atleast
    gives a common handling of "yes", "no", etc.
    
    A type xf86TriState has been added to support an optional boolean. This
    allows the boolean sense of the value to be kept while providing a means
    to signal that it is unset.
    
    Signed-off-by: Dan Nicholson <dbn.lists at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/xf86Option.c b/hw/xfree86/common/xf86Option.c
index ad8d1c4..a2868bf 100644
--- a/hw/xfree86/common/xf86Option.c
+++ b/hw/xfree86/common/xf86Option.c
@@ -42,6 +42,7 @@
 #include "xf86.h"
 #include "xf86Xinput.h"
 #include "xf86Optrec.h"
+#include "xf86Parser.h"
 
 static Bool ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p,
 			     Bool markUsed);
@@ -456,29 +457,7 @@ xf86ShowUnusedOptions(int scrnIndex, pointer options)
 static Bool
 GetBoolValue(OptionInfoPtr p, const char *s)
 {
-    if (*s == '\0') {
-	p->value.bool = TRUE;
-    } else {
-	if (xf86NameCmp(s, "1") == 0)
-	    p->value.bool = TRUE;
-	else if (xf86NameCmp(s, "on") == 0)
-	    p->value.bool = TRUE;
-	else if (xf86NameCmp(s, "true") == 0)
-	    p->value.bool = TRUE;
-	else if (xf86NameCmp(s, "yes") == 0)
-	    p->value.bool = TRUE;
-	else if (xf86NameCmp(s, "0") == 0)
-	    p->value.bool = FALSE;
-	else if (xf86NameCmp(s, "off") == 0)
-	    p->value.bool = FALSE;
-	else if (xf86NameCmp(s, "false") == 0)
-	    p->value.bool = FALSE;
-	else if (xf86NameCmp(s, "no") == 0)
-	    p->value.bool = FALSE;
-	else
-	    return FALSE;
-    }
-    return TRUE;
+    return xf86getBoolValue(&p->value.bool, s);
 }
 
 static Bool
diff --git a/hw/xfree86/parser/Configint.h b/hw/xfree86/parser/Configint.h
index cdc7be8..03509b3 100644
--- a/hw/xfree86/parser/Configint.h
+++ b/hw/xfree86/parser/Configint.h
@@ -148,6 +148,8 @@ else\
 "The %s keyword requires a number to follow it."
 #define POSITIVE_INT_MSG \
 "The %s keyword requires a positive integer to follow it."
+#define BOOL_MSG \
+"The %s keyword requires a boolean to follow it."
 #define ZAXISMAPPING_MSG \
 "The ZAxisMapping keyword requires 2 positive numbers or X or Y to follow it."
 #define AUTOREPEAT_MSG \
diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c
index d2e8b6d..270dbd5 100644
--- a/hw/xfree86/parser/scan.c
+++ b/hw/xfree86/parser/scan.c
@@ -1028,3 +1028,33 @@ xf86addComment(char *cur, char *add)
 
 	return (cur);
 }
+
+Bool
+xf86getBoolValue(Bool *val, const char *str)
+{
+	if (!val || !str)
+		return FALSE;
+	if (*str == '\0') {
+		*val = TRUE;
+	} else {
+		if (strcmp(str, "1") == 0)
+			*val = TRUE;
+		else if (strcmp(str, "on") == 0)
+			*val = TRUE;
+		else if (strcmp(str, "true") == 0)
+			*val = TRUE;
+		else if (strcmp(str, "yes") == 0)
+			*val = TRUE;
+		else if (strcmp(str, "0") == 0)
+			*val = FALSE;
+		else if (strcmp(str, "off") == 0)
+			*val = FALSE;
+		else if (strcmp(str, "false") == 0)
+			*val = FALSE;
+		else if (strcmp(str, "no") == 0)
+			*val = FALSE;
+		else
+			return FALSE;
+	}
+	return TRUE;
+}
diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h
index 6030800..72beb5f 100644
--- a/hw/xfree86/parser/xf86Parser.h
+++ b/hw/xfree86/parser/xf86Parser.h
@@ -64,6 +64,7 @@
 #ifndef _xf86Parser_h_
 #define _xf86Parser_h_
 
+#include <X11/Xdefs.h>
 #include "xf86Optrec.h"
 
 #define HAVE_PARSER_DECLS
@@ -330,6 +331,13 @@ typedef struct
 }
 XF86ConfInputrefRec, *XF86ConfInputrefPtr;
 
+typedef struct
+{
+	Bool set;
+	Bool val;
+}
+xf86TriState;
+
 /* Values for adj_where */
 #define CONF_ADJ_OBSOLETE	-1
 #define CONF_ADJ_ABSOLUTE	0
@@ -480,5 +488,6 @@ extern _X_EXPORT int xf86itemNotSublist(GenericListPtr list_1, GenericListPtr li
 extern _X_EXPORT int xf86pathIsAbsolute(const char *path);
 extern _X_EXPORT int xf86pathIsSafe(const char *path);
 extern _X_EXPORT char *xf86addComment(char *cur, char *add);
+extern _X_EXPORT Bool xf86getBoolValue(Bool *val, const char *str);
 
 #endif /* _xf86Parser_h_ */
commit e1165632bdfbd720889ed1adf5f7ab338032c0ee
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Dec 21 15:56:35 2009 +1000

    xfree86: Add Option AutoServerLayout for input devices.
    
    Any input device with this option will be automatically added to whichever
    server layout is selected at startup. This removes the need to reference a
    device from the ServerLayout section. The two following configuration are
    identical:
    
    CONFIG 1:
        Section "ServerLayout"
                InputDevice "foo"
        EndSection
    
        Section "InputDevice"
                Identifier "foo"
                ...
        EndSection
    
    CONFIG 2:
        Section "InputDevice"
                Identifier "foo"
                Option "AutoServerLayout" "on"
                ...
        EndSection
    
    The selection of the server layout affects both explicitly specified
    layouts and the implicit layout.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index e4f0d23..56ab2ee 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -1488,6 +1488,45 @@ static OptionInfoRec LayoutOptions[] = {
        {0}, FALSE },
 };
 
+static Bool
+configInputDevices(XF86ConfLayoutPtr layout, serverLayoutPtr servlayoutp)
+{
+    XF86ConfInputrefPtr irp;
+    IDevPtr *indp;
+    int count = 0;
+
+    /*
+     * Count the number of input devices.
+     */
+    irp = layout->lay_input_lst;
+    while (irp) {
+	count++;
+	irp = (XF86ConfInputrefPtr)irp->list.next;
+    }
+    DebugF("Found %d input devices in the layout section %s\n",
+	    count, layout.lay_identifier);
+    indp = xnfcalloc((count + 1), sizeof(IDevPtr));
+    indp[count] = NULL;
+    irp = layout->lay_input_lst;
+    count = 0;
+    while (irp) {
+	indp[count] = xnfalloc(sizeof(IDevRec));
+	if (!configInput(indp[count], irp->iref_inputdev, X_CONFIG)) {
+	    while(count--)
+		xfree(indp[count]);
+	    xfree(indp);
+	    return FALSE;
+	}
+	indp[count]->extraOptions = irp->iref_option_lst;
+	count++;
+	irp = (XF86ConfInputrefPtr)irp->list.next;
+    }
+    servlayoutp->inputs = indp;
+
+    return TRUE;
+}
+
+
 /*
  * figure out which layout is active, which screens are used in that layout,
  * which drivers and monitors are used in these screens
@@ -1498,14 +1537,12 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout,
 {
     XF86ConfAdjacencyPtr adjp;
     XF86ConfInactivePtr idp;
-    XF86ConfInputrefPtr irp;
     int count = 0;
     int scrnum;
     XF86ConfLayoutPtr l;
     MessageType from;
     screenLayoutPtr slp;
     GDevPtr gdp;
-    IDevPtr* indp;
     int i = 0, j;
 
     if (!servlayoutp)
@@ -1679,37 +1716,13 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout,
         count++;
         idp = (XF86ConfInactivePtr)idp->list.next;
     }
-    /*
-     * Count the number of input devices.
-     */
-    count = 0;
-    irp = conf_layout->lay_input_lst;
-    while (irp) {
-        count++;
-        irp = (XF86ConfInputrefPtr)irp->list.next;
-    }
-    DebugF("Found %d input devices in the layout section %s\n",
-           count, conf_layout->lay_identifier);
-    indp = xnfcalloc((count + 1), sizeof(IDevPtr));
-    indp[count] = NULL;
-    irp = conf_layout->lay_input_lst;
-    count = 0;
-    while (irp) {
-        indp[count] = xnfalloc(sizeof(IDevRec));
-	if (!configInput(indp[count], irp->iref_inputdev, X_CONFIG)) {
-            while(count--) 
-                xfree(indp[count]);
-            xfree(indp);
-            return FALSE;
-	}
-	indp[count]->extraOptions = irp->iref_option_lst;
-        count++;
-        irp = (XF86ConfInputrefPtr)irp->list.next;
-    }
+
+    if (!configInputDevices(conf_layout, servlayoutp))
+	return FALSE;
+
     servlayoutp->id = conf_layout->lay_identifier;
     servlayoutp->screens = slp;
     servlayoutp->inactives = gdp;
-    servlayoutp->inputs = indp;
     servlayoutp->options = conf_layout->lay_option_lst;
     from = X_DEFAULT;
 
@@ -1721,12 +1734,14 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout,
  * the only active screen.
  */
 static Bool
-configImpliedLayout(serverLayoutPtr servlayoutp, XF86ConfScreenPtr conf_screen)
+configImpliedLayout(serverLayoutPtr servlayoutp, XF86ConfScreenPtr conf_screen,
+                    XF86ConfigPtr xf86configptr)
 {
     MessageType from;
     XF86ConfScreenPtr s;
     screenLayoutPtr slp;
     IDevPtr *indp;
+    XF86ConfLayoutRec layout;
 
     if (!servlayoutp)
 	return FALSE;
@@ -1762,10 +1777,19 @@ configImpliedLayout(serverLayoutPtr servlayoutp, XF86ConfScreenPtr conf_screen)
     servlayoutp->screens = slp;
     servlayoutp->inactives = xnfcalloc(1, sizeof(GDevRec));
     servlayoutp->options = NULL;
-    /* Set up an empty input device list, then look for some core devices. */
-    indp = xnfalloc(sizeof(IDevPtr));
-    *indp = NULL;
-    servlayoutp->inputs = indp;
+
+    memset(&layout, 0, sizeof(layout));
+    layout.lay_identifier = servlayoutp->id;
+    if (xf86layoutAddInputDevices(xf86configptr, &layout) > 0) {
+	if (!configInputDevices(&layout, servlayoutp))
+	    return FALSE;
+	from = X_DEFAULT;
+    } else {
+	/* Set up an empty input device list, then look for some core devices. */
+	indp = xnfalloc(sizeof(IDevPtr));
+	*indp = NULL;
+	servlayoutp->inputs = indp;
+    }
 
     return TRUE;
 }
@@ -2478,7 +2502,8 @@ xf86HandleConfigFile(Bool autoconfig)
 		    "No Layout section.  Using the first Screen section.\n");
 	}
 	if (!configImpliedLayout(&xf86ConfigLayout,
-				 xf86configptr->conf_screen_lst)) {
+				 xf86configptr->conf_screen_lst,
+				 xf86configptr)) {
             xf86Msg(X_ERROR, "Unable to determine the screen layout\n");
 	    return CONFIG_PARSE_ERROR;
 	}
diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre
index 749eab0..7941a47 100644
--- a/hw/xfree86/doc/man/xorg.conf.man.pre
+++ b/hw/xfree86/doc/man/xorg.conf.man.pre
@@ -880,6 +880,11 @@ which are described here.
 See the individual input driver manual pages for a description of the
 device\-specific options.
 .TP 7
+.BI "Option \*qAutoServerLayout\*q  \*q" boolean \*q
+Always add the device to the ServerLayout section used by this instance of
+the server. This affects implied layouts as well as explicit layouts
+specified in the configuration and/or on the command line.
+.TP 7
 .BI "Option \*qCorePointer\*q"
 Deprecated, use
 .B SendCoreEvents
diff --git a/hw/xfree86/parser/Layout.c b/hw/xfree86/parser/Layout.c
index beb008b..00c1e7d 100644
--- a/hw/xfree86/parser/Layout.c
+++ b/hw/xfree86/parser/Layout.c
@@ -64,6 +64,10 @@
 #include "Configint.h"
 #include <string.h>
 
+
+/* Needed for auto server layout */
+extern int xf86CheckBoolOption(void* optlist, const char *name, int deflt);
+
 extern LexRec val;
 
 static xf86ConfigSymTabRec LayoutTab[] =
@@ -436,15 +440,67 @@ xf86freeLayoutList (XF86ConfLayoutPtr ptr)
 }
 
 int
+xf86layoutAddInputDevices(XF86ConfigPtr config, XF86ConfLayoutPtr layout)
+{
+    int count = 0;
+    XF86ConfInputPtr input = config->conf_input_lst;
+    XF86ConfInputrefPtr inptr;
+
+    /* add all AutoServerLayout devices to the server layout */
+    while (input)
+    {
+	if (xf86CheckBoolOption(input->inp_option_lst, "AutoServerLayout", FALSE))
+	{
+	    XF86ConfInputrefPtr iref = layout->lay_input_lst;
+
+	    /* avoid duplicates if referenced but lists AutoServerLayout too */
+	    while (iref)
+	    {
+		if (strcmp(iref->iref_inputdev_str, input->inp_identifier) == 0)
+		    break;
+		iref = iref->list.next;
+	    }
+
+	    if (!iref)
+	    {
+		XF86ConfInputrefPtr iptr;
+		iptr = calloc(1, sizeof(XF86ConfInputrefRec));
+		iptr->iref_inputdev_str = input->inp_identifier;
+		layout->lay_input_lst = (XF86ConfInputrefPtr)
+		    xf86addListItem((glp)layout->lay_input_lst, (glp)iptr);
+		count++;
+	    }
+	}
+	input = input->list.next;
+    }
+
+    inptr = layout->lay_input_lst;
+    while (inptr)
+    {
+	input = xf86findInput (inptr->iref_inputdev_str,
+		config->conf_input_lst);
+	if (!input)
+	{
+	    xf86validationError (UNDEFINED_INPUT_MSG,
+		    inptr->iref_inputdev_str, layout->lay_identifier);
+	    return -1;
+	}
+	else
+	    inptr->iref_inputdev = input;
+	inptr = inptr->list.next;
+    }
+
+    return count;
+}
+
+int
 xf86validateLayout (XF86ConfigPtr p)
 {
 	XF86ConfLayoutPtr layout = p->conf_layout_lst;
 	XF86ConfAdjacencyPtr adj;
 	XF86ConfInactivePtr iptr;
-	XF86ConfInputrefPtr inptr;
 	XF86ConfScreenPtr screen;
 	XF86ConfDevicePtr device;
-	XF86ConfInputPtr input;
 
 	while (layout)
 	{
@@ -479,21 +535,10 @@ xf86validateLayout (XF86ConfigPtr p)
 				iptr->inactive_device = device;
 			iptr = iptr->list.next;
 		}
-		inptr = layout->lay_input_lst;
-		while (inptr)
-		{
-			input = xf86findInput (inptr->iref_inputdev_str,
-									p->conf_input_lst);
-			if (!input)
-			{
-				xf86validationError (UNDEFINED_INPUT_MSG,
-						inptr->iref_inputdev_str, layout->lay_identifier);
-				return (FALSE);
-			}
-			else
-				inptr->iref_inputdev = input;
-			inptr = inptr->list.next;
-		}
+
+		if (xf86layoutAddInputDevices(p, layout) == -1)
+		    return FALSE;
+
 		layout = layout->list.next;
 	}
 	return (TRUE);
diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h
index 12bcd6e..4675d02 100644
--- a/hw/xfree86/parser/xf86Parser.h
+++ b/hw/xfree86/parser/xf86Parser.h
@@ -476,6 +476,7 @@ extern _X_EXPORT XF86ConfInputPtr xf86findInput(const char *ident, XF86ConfInput
 extern _X_EXPORT XF86ConfInputPtr xf86findInputByDriver(const char *driver, XF86ConfInputPtr p);
 extern _X_EXPORT XF86ConfVideoAdaptorPtr xf86findVideoAdaptor(const char *ident,
 						XF86ConfVideoAdaptorPtr p);
+extern int xf86layoutAddInputDevices(XF86ConfigPtr config, XF86ConfLayoutPtr layout);
 
 extern _X_EXPORT GenericListPtr xf86addListItem(GenericListPtr head, GenericListPtr c_new);
 extern _X_EXPORT int xf86itemNotSublist(GenericListPtr list_1, GenericListPtr list_2);
commit 592b20c517461d32daf44a940386ffcc11c434f8
Author: Dan Nicholson <dbn.lists at gmail.com>
Date:   Mon Dec 21 01:13:44 2009 -0800

    xfree86: Allow config directory to be specified on command line
    
    Add a new command line parameter, -configdir, to specify the config
    directory to be used. Rules are the same as -config for root vs. user
    privileges.
    
    Signed-off-by: Dan Nicholson <dbn.lists at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index ffb9643..e4f0d23 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -95,12 +95,22 @@ extern DeviceAssocRec mouse_assoc;
 			"%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
 			"%P/lib/X11/%X"
 #endif
-#ifndef CONFIGDIRPATH
-#define CONFIGDIRPATH	"/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \
-			"%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \
-			"%P/etc/X11/%X," \
-			"%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
-			"%P/lib/X11/%X"
+#ifndef ROOT_CONFIGDIRPATH
+#define ROOT_CONFIGDIRPATH	"%A," "%R," \
+				"/etc/X11/%R," "%P/etc/X11/%R," \
+				"/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \
+				"%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \
+				"%P/etc/X11/%X," \
+				"%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
+				"%P/lib/X11/%X"
+#endif
+#ifndef USER_CONFIGDIRPATH
+#define USER_CONFIGDIRPATH	"/etc/X11/%S," "%P/etc/X11/%S," \
+				"/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \
+				"%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \
+				"%P/etc/X11/%X," \
+				"%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
+				"%P/lib/X11/%X"
 #endif
 #ifndef PROJECTROOT
 #define PROJECTROOT	"/usr/X11R6"
@@ -2397,35 +2407,48 @@ ConfigStatus
 xf86HandleConfigFile(Bool autoconfig)
 {
     const char *filename, *dirname;
-    char *searchpath;
-    MessageType from = X_DEFAULT;
+    char *filesearch, *dirsearch;
+    MessageType filefrom = X_DEFAULT;
+    MessageType dirfrom = X_DEFAULT;
     char *scanptr;
     Bool singlecard = 0;
     Bool implicit_layout = FALSE;
 
     if (!autoconfig) {
-	if (getuid() == 0)
-	    searchpath = ROOT_CONFIGPATH;
-	else
-	    searchpath = USER_CONFIGPATH;
+	if (getuid() == 0) {
+	    filesearch = ROOT_CONFIGPATH;
+	    dirsearch = ROOT_CONFIGDIRPATH;
+	} else {
+	    filesearch = USER_CONFIGPATH;
+	    dirsearch = USER_CONFIGDIRPATH;
+	}
 
 	if (xf86ConfigFile)
-	    from = X_CMDLINE;
+	    filefrom = X_CMDLINE;
+	if (xf86ConfigDir)
+	    dirfrom = X_CMDLINE;
 
 	xf86initConfigFiles();
-	filename = xf86openConfigFile(searchpath, xf86ConfigFile, PROJECTROOT);
-	dirname = xf86openConfigDirFiles(CONFIGDIRPATH, NULL, PROJECTROOT);
+	filename = xf86openConfigFile(filesearch, xf86ConfigFile, PROJECTROOT);
+	dirname = xf86openConfigDirFiles(dirsearch, xf86ConfigDir, PROJECTROOT);
 	if (filename) {
-	    xf86MsgVerb(from, 0, "Using config file: \"%s\"\n", filename);
+	    xf86MsgVerb(filefrom, 0, "Using config file: \"%s\"\n", filename);
 	    xf86ConfigFile = xnfstrdup(filename);
 	} else {
 	    if (xf86ConfigFile)
 		xf86Msg(X_ERROR, "Unable to locate/open config file: \"%s\"\n",
 			xf86ConfigFile);
 	}
-	if (dirname)
-	    xf86MsgVerb(X_DEFAULT, 0, "Using config directory: \"%s\"\n",
+	if (dirname) {
+	    xf86MsgVerb(dirfrom, 0, "Using config directory: \"%s\"\n",
 			dirname);
+	    xf86ConfigDir = xnfstrdup(dirname);
+	} else {
+	    if (xf86ConfigDir)
+		xf86Msg(X_ERROR,
+			"Unable to locate/open config directory: \"%s\"\n",
+			xf86ConfigDir);
+	}
 	if (!filename && !dirname)
 	    return CONFIG_NOFILE;
     }
diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c
index 98f8284..317b78a 100644
--- a/hw/xfree86/common/xf86Globals.c
+++ b/hw/xfree86/common/xf86Globals.c
@@ -143,6 +143,7 @@ xf86InfoRec xf86Info = {
 #endif
 };
 const char *xf86ConfigFile = NULL;
+const char *xf86ConfigDir = NULL;
 const char *xf86ModulePath = DEFAULT_MODULE_PATH;
 MessageType xf86ModPathFrom = X_DEFAULT;
 const char *xf86LogFile = DEFAULT_LOGPREFIX;
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 3b25c89..6707448 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -1387,6 +1387,19 @@ ddxProcessArgument(int argc, char **argv, int i)
     xf86ConfigFile = argv[i + 1];
     return 2;
   }
+  if (!strcmp(argv[i], "-configdir"))
+  {
+    CHECK_FOR_REQUIRED_ARGUMENT();
+    if (getuid() != 0 && !xf86PathIsSafe(argv[i + 1])) {
+      FatalError("\nInvalid argument for %s\n"
+	  "\tFor non-root users, the file specified with %s must be\n"
+	  "\ta relative path and must not contain any \"..\" elements.\n"
+	  "\tUsing default "__XCONFIGDIR__" search path.\n\n",
+	  argv[i], argv[i]);
+    }
+    xf86ConfigDir = argv[i + 1];
+    return 2;
+  }
   if (!strcmp(argv[i],"-flipPixels"))
   {
     xf86FlipPixels = TRUE;
@@ -1670,6 +1683,8 @@ ddxUseMsg(void)
   }
   ErrorF("-config file           specify a configuration file, relative to the\n");
   ErrorF("                       "__XCONFIGFILE__" search path, only root can use absolute\n");
+  ErrorF("-configdir dir         specify a configuration directory, relative to the\n");
+  ErrorF("                       "__XCONFIGDIR__" search path, only root can use absolute\n");
   ErrorF("-verbose [n]           verbose startup messages\n");
   ErrorF("-logverbose [n]        verbose log messages\n");
   ErrorF("-quiet                 minimal startup messages\n");
diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h
index 3bb1571..0612c9c 100644
--- a/hw/xfree86/common/xf86Priv.h
+++ b/hw/xfree86/common/xf86Priv.h
@@ -46,6 +46,7 @@
  * The global state of these things is held in xf86InfoRec (when appropriate).
  */
 extern _X_EXPORT const char *xf86ConfigFile;
+extern _X_EXPORT const char *xf86ConfigDir;
 extern _X_EXPORT  Bool xf86AllowMouseOpenFail;
 #ifdef XF86VIDMODE
 extern _X_EXPORT  Bool xf86VidModeDisabled;
diff --git a/hw/xfree86/doc/man/Xorg.man.pre b/hw/xfree86/doc/man/Xorg.man.pre
index bb5a14f..46d0e44 100644
--- a/hw/xfree86/doc/man/Xorg.man.pre
+++ b/hw/xfree86/doc/man/Xorg.man.pre
@@ -109,7 +109,7 @@ script.
 .B __xservername__
 supports several mechanisms for supplying/obtaining configuration and
 run-time parameters: command line options, environment variables, the
-__xconfigfile__(__filemansuffix__) configuration file, auto-detection, and
+__xconfigfile__(__filemansuffix__) configuration files, auto-detection, and
 fallback defaults.  When the same information is supplied in more than
 one way, the highest precedence mechanism is used.  The list of mechanisms
 is ordered from highest precedence to lowest.  Note that not all parameters
@@ -176,6 +176,13 @@ This option will work for any file when the server is run as root (i.e,
 with real-uid 0), or for files relative to a directory in the config
 search path for all other users.
 .TP 8
+.BI \-configdir " directory"
+Read the server configuration files from
+.IR directory .
+This option will work for any directory when the server is run as root
+(i.e, with real-uid 0), or for directories relative to a directory in the
+config directory search path for all other users.
+.TP 8
 .B \-configure
 When this option is specified, the
 .B __xservername__
@@ -456,6 +463,10 @@ __xconfigfile__(__filemansuffix__) file option.
 .B __xservername__
 typically uses a configuration file called
 .B __xconfigfile__
+and configuration files with the suffix
+.I .conf
+in a directory called
+.B __xconfigdir__
 for its initial setup.
 Refer to the __xconfigfile__(__filemansuffix__) manual page for information
 about the format of this file.
@@ -464,7 +475,9 @@ about the format of this file.
 has a mechanism for automatically generating a built-in configuration
 at run-time when no
 .B __xconfigfile__
-file is present.  The current version of this automatic configuration
+file or
+.B __xconfigdir__
+files are present.  The current version of this automatic configuration
 mechanism works in two ways.
 .PP
 The first is via enhancements that have made many components of the
@@ -486,7 +499,7 @@ supported by __xservername__.  Enhancements are planned for future releases.
 .SH FILES
 The
 .B __xservername__
-server config file can be found in a range of locations.  These are
+server config files can be found in a range of locations.  These are
 documented fully in the __xconfigfile__(__filemansuffix__) manual page.  The
 most commonly used locations are shown here.
 .TP 30
@@ -505,6 +518,21 @@ Server configuration file.
 .B __projectroot__/lib/X11/__xconfigfile__
 Server configuration file.
 .TP 30
+.B /etc/X11/__xconfigdir__
+Server configuration directory.
+.TP 30
+.B /etc/X11/__xconfigdir__-4
+Server configuration directory.
+.TP 30
+.B /etc/__xconfigdir__
+Server configuration directory.
+.TP 30
+.B __projectroot__/etc/__xconfigdir__
+Server configuration directory.
+.TP 30
+.B __projectroot__/lib/X11/__xconfigdir__
+Server configuration directory.
+.TP 30
 .BI __logdir__/__xservername__. n .log
 Server log file for display
 .IR n .
diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c
index 24260e2..9f18350 100644
--- a/hw/xfree86/parser/scan.c
+++ b/hw/xfree86/parser/scan.c
@@ -874,11 +874,13 @@ AddConfigDirFiles(const char *dirpath, struct dirent **list, int num)
  * directory. The directory does not need to contain config files.
  */
 static char *
-OpenConfigDir(const char *path, const char *projroot, const char *confname)
+OpenConfigDir(const char *path, const char *cmdline, const char *projroot,
+	      const char *confname)
 {
 	char *dirpath, *pathcopy;
 	const char *template;
 	Bool found = FALSE;
+	int cmdlineUsed = 0;
 
 	pathcopy = strdup(path);
 	for (template = strtok(pathcopy, ","); template && !found;
@@ -886,9 +888,16 @@ OpenConfigDir(const char *path, const char *projroot, const char *confname)
 		struct dirent **list = NULL;
 		int num;
 
-		if (!(dirpath = DoSubstitution(template, NULL, projroot,
-					       NULL, NULL, confname)))
+		dirpath = DoSubstitution(template, cmdline, projroot,
+					 &cmdlineUsed, NULL, confname);
+		if (!dirpath)
 			continue;
+		if (cmdline && !cmdlineUsed) {
+			free(dirpath);
+			dirpath = NULL;
+			continue;
+		}
+
 		/* match files named *.conf */
 		num = scandir(dirpath, &list, ConfigFilter, alphasort);
 		found = AddConfigDirFiles(dirpath, list, num);
@@ -992,7 +1001,7 @@ xf86openConfigDirFiles(const char *path, const char *cmdline,
 		projroot = PROJECTROOT;
 
 	/* Search for the multiconf directory */
-	configDirPath = OpenConfigDir(path, projroot, XCONFIGDIR);
+	configDirPath = OpenConfigDir(path, cmdline, projroot, XCONFIGDIR);
 	return configDirPath;
 }
 
diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c
index 8fd82d0..91f5ec0 100644
--- a/hw/xwin/InitOutput.c
+++ b/hw/xwin/InitOutput.c
@@ -853,6 +853,9 @@ winUseMsg (void)
   ErrorF ("-config\n"
           "\tSpecify a configuration file.\n");
 
+  ErrorF ("-configdir\n"
+          "\tSpecify a configuration directory.\n");
+
   ErrorF ("-keyboard\n"
 	  "\tSpecify a keyboard device from the configuration file.\n");
 #endif
diff --git a/hw/xwin/winconfig.c b/hw/xwin/winconfig.c
index 6efd7ca..f1e805c 100644
--- a/hw/xwin/winconfig.c
+++ b/hw/xwin/winconfig.c
@@ -64,6 +64,7 @@ XF86ConfigPtr g_xf86configptr = NULL;
 WinCmdlineRec g_cmdline = {
 #ifdef XWIN_XF86CONFIG
   NULL,				/* configFile */
+  NULL,				/* configDir */
 #endif
   NULL,				/* fontPath */
 #ifdef XWIN_XF86CONFIG
@@ -117,19 +118,26 @@ winReadConfigfile ()
 {
   Bool		retval = TRUE;
   const char	*filename, *dirname;
-  MessageType	from = X_DEFAULT;
+  MessageType	filefrom = X_DEFAULT;
+  MessageType	dirfrom = X_DEFAULT;
   char		*xf86ConfigFile = NULL;
+  char		*xf86ConfigDir = NULL;
 
   if (g_cmdline.configFile)
     {
-      from = X_CMDLINE;
+      filefrom = X_CMDLINE;
       xf86ConfigFile = g_cmdline.configFile;
     }
+  if (g_cmdline.configDir)
+    {
+      dirfrom = X_CMDLINE;
+      xf86ConfigDir = g_cmdline.configDir;
+    }
 
   /* Parse config file into data structure */
   xf86initConfigFiles();
   filename = xf86openConfigFile (CONFIGPATH, xf86ConfigFile, PROJECTROOT);
-  dirname = xf86openConfigDirFiles (CONFIGDIRPATH, NULL, PROJECTROOT);
+  dirname = xf86openConfigDirFiles (CONFIGDIRPATH, xf86ConfigDir, PROJECTROOT);
 
   /* Hack for backward compatibility */
   if (!filename && from == X_DEFAULT)
@@ -150,6 +158,13 @@ winReadConfigfile ()
     {
       winMsg (from, "Using config directory: \"%s\"\n", dirname);
     }
+  else
+    {
+      winMsg (X_ERROR, "Unable to locate/open config directory");
+      if (xf86ConfigDir)
+	ErrorF (": \"%s\"", xf86ConfigDir);
+      ErrorF ("\n");
+    }
   if (!filename && !dirname)
     {
       return FALSE;
diff --git a/hw/xwin/winconfig.h b/hw/xwin/winconfig.h
index 63d6211..058884a 100644
--- a/hw/xwin/winconfig.h
+++ b/hw/xwin/winconfig.h
@@ -188,6 +188,7 @@ typedef struct
   /* Files */
 #ifdef XWIN_XF86CONFIG
   char *configFile;
+  char *configDir;
 #endif
   char *fontPath;
   /* input devices - keyboard */
diff --git a/hw/xwin/winprocarg.c b/hw/xwin/winprocarg.c
index 31e505e..fd7719c 100755
--- a/hw/xwin/winprocarg.c
+++ b/hw/xwin/winprocarg.c
@@ -1341,6 +1341,24 @@ ddxProcessArgument (int argc, char *argv[], int i)
     }
 
   /*
+   * Look for the '-configdir' argument
+   */
+  if (IS_OPTION ("-configdir"))
+    {
+      CHECK_ARGS (1);
+#ifdef XWIN_XF86CONFIG
+      g_cmdline.configDir = argv[++i];
+#else
+      winMessageBoxF ("The %s option is not supported in this "
+		      "release.\n"
+		      "Ignoring this option and continuing.\n",
+		      MB_ICONINFORMATION,
+		      argv[i]);
+#endif
+      return 2;
+    }
+
+  /*
    * Look for the '-keyboard' argument
    */
   if (IS_OPTION ("-keyboard"))
commit efa5269f23c2237eb5368bf5245ffbbf35714153
Author: Dan Nicholson <dbn.lists at gmail.com>
Date:   Mon Dec 21 00:04:16 2009 -0800

    xfree86: Use xorg.conf.d directory for multiple config files
    
    Currently there is a single file, xorg.conf, for configuring the server.
    This works fine most of the time, but it becomes a problem when packages
    or system services need to adjust the configuration. Instead, allow
    multiple configuration files to live in a directory. Typically this will
    be /etc/X11/xorg.conf.d.
    
    Files with a suffix of .conf will be read and added to the server
    configuration after xorg.conf. The server won't fall back to using the
    auto configuration unless there is no config file and there are no files
    in the config directory.
    
    Right now this uses a simpler search template than the config file
    search path by not using the command line or environment variable
    parameters. The matching code was refactored a bit to make this more
    coherent. Any DDX wanting to read the config files will need to call
    xf86initConfigFiles before opening/reading them. This is to allow
    xf86openConfigFile without xf86openConfigDirFiles and vice-versa.
    
    Signed-off-by: Dan Nicholson <dbn.lists at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/configure.ac b/configure.ac
index 723c1fd..b55eaaa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1737,6 +1737,7 @@ if test "x$XORG" = xyes; then
 
 	dnl these only go in xorg-config.h
 	XF86CONFIGFILE="xorg.conf"
+	XF86CONFIGDIR="xorg.conf.d"
 	CONFIGFILE="$sysconfdir/$XF86CONFIGFILE"
 	LOGPREFIX="$logdir/Xorg."
 	AC_DEFINE(XORG_SERVER, 1, [Building Xorg server])
@@ -1749,6 +1750,7 @@ if test "x$XORG" = xyes; then
 	AC_DEFINE(__XSERVERNAME__, "Xorg", [Name of X server])
 	AC_DEFINE_DIR(__XCONFIGFILE__, XF86CONFIGFILE, [Name of configuration file])
 	AC_DEFINE_DIR(XF86CONFIGFILE, XF86CONFIGFILE, [Name of configuration file])
+	AC_DEFINE_DIR(__XCONFIGDIR__, XF86CONFIGDIR, [Name of configuration directory])
 	AC_DEFINE_DIR(DEFAULT_MODULE_PATH, moduledir, [Default module search path])
 	AC_DEFINE_DIR(DEFAULT_LIBRARY_PATH, libdir, [Default library install path])
 	AC_DEFINE_DIR(DEFAULT_LOGPREFIX, LOGPREFIX, [Default log location])
diff --git a/cpprules.in b/cpprules.in
index 7fcb9bd..7219e36 100644
--- a/cpprules.in
+++ b/cpprules.in
@@ -36,7 +36,8 @@ MANDEFS = \
 	-D__adminmansuffix__=$(ADMIN_MAN_SUFFIX) \
 	-D__mandir__=$(mandir) \
 	-D__projectroot__=$(prefix) \
-	-D__xconfigfile__=$(__XCONFIGFILE__) -D__xconfigdir__=$(XCONFIGDIR) \
+	-D__xconfigfile__=$(__XCONFIGFILE__) \
+	-D__xconfigdir__=$(__XCONFIGDIR__) \
 	-D__xkbdir__=$(XKB_BASE_DIRECTORY) \
 	-D__modulepath__="$(DEFAULT_MODULE_PATH)" \
 	-D__xlogfile__=$(XLOGFILE) -D__xservername__=$(XSERVERNAME) 
diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c
index a6199b0..1c4595e 100644
--- a/hw/xfree86/common/xf86AutoConfig.c
+++ b/hw/xfree86/common/xf86AutoConfig.c
@@ -272,7 +272,8 @@ xf86AutoConfig(void)
     for (cp = builtinConfig; *cp; cp++)
 	xf86ErrorFVerb(3, "\t%s", *cp);
     xf86MsgVerb(X_DEFAULT, 3, "--- End of built-in configuration ---\n");
-    
+
+    xf86initConfigFiles();
     xf86setBuiltinConfig(builtinConfig);
     ret = xf86HandleConfigFile(TRUE);
     FreeConfig();
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 5ad5e70..ffb9643 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -95,6 +95,13 @@ extern DeviceAssocRec mouse_assoc;
 			"%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
 			"%P/lib/X11/%X"
 #endif
+#ifndef CONFIGDIRPATH
+#define CONFIGDIRPATH	"/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \
+			"%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \
+			"%P/etc/X11/%X," \
+			"%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
+			"%P/lib/X11/%X"
+#endif
 #ifndef PROJECTROOT
 #define PROJECTROOT	"/usr/X11R6"
 #endif
@@ -2389,7 +2396,7 @@ checkInput(serverLayoutPtr layout, Bool implicit_layout) {
 ConfigStatus
 xf86HandleConfigFile(Bool autoconfig)
 {
-    const char *filename;
+    const char *filename, *dirname;
     char *searchpath;
     MessageType from = X_DEFAULT;
     char *scanptr;
@@ -2405,7 +2412,9 @@ xf86HandleConfigFile(Bool autoconfig)
 	if (xf86ConfigFile)
 	    from = X_CMDLINE;
 
+	xf86initConfigFiles();
 	filename = xf86openConfigFile(searchpath, xf86ConfigFile, PROJECTROOT);
+	dirname = xf86openConfigDirFiles(CONFIGDIRPATH, NULL, PROJECTROOT);
 	if (filename) {
 	    xf86MsgVerb(from, 0, "Using config file: \"%s\"\n", filename);
 	    xf86ConfigFile = xnfstrdup(filename);
@@ -2413,10 +2422,14 @@ xf86HandleConfigFile(Bool autoconfig)
 	    if (xf86ConfigFile)
 		xf86Msg(X_ERROR, "Unable to locate/open config file: \"%s\"\n",
 			xf86ConfigFile);
-	    return CONFIG_NOFILE;
 	}
+	if (dirname)
+	    xf86MsgVerb(X_DEFAULT, 0, "Using config directory: \"%s\"\n",
+			dirname);
+	if (!filename && !dirname)
+	    return CONFIG_NOFILE;
     }
-     
+
     if ((xf86configptr = xf86readConfigFile ()) == NULL) {
 	xf86Msg(X_ERROR, "Problem parsing the config file\n");
 	return CONFIG_PARSE_ERROR;
diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre
index 84be12c..749eab0 100644
--- a/hw/xfree86/doc/man/xorg.conf.man.pre
+++ b/hw/xfree86/doc/man/xorg.conf.man.pre
@@ -2,27 +2,35 @@
 .ds q \N'34'
 .TH __xconfigfile__ __filemansuffix__ __vendorversion__
 .SH NAME
-__xconfigfile__ \- configuration File for __xservername__ X server
+__xconfigfile__ and __xconfigdir__ \- configuration files for
+__xservername__ X server
 .SH INTRODUCTION
 .B __xservername__
 supports several mechanisms for supplying/obtaining configuration and
 run-time parameters: command line options, environment variables, the
-__xconfigfile__ configuration file, auto-detection, and fallback defaults.
-When the same information is supplied in more than one way, the highest
-precedence mechanism is used.  The list of mechanisms is ordered from
-highest precedence to lowest.  Note that not all parameters can be
-supplied via all methods.  The available command line options and
-environment variables (and some defaults) are described in the Xserver(__appmansuffix__)
-and __xservername__(__appmansuffix__) manual pages.  Most configuration file parameters, with
-their defaults, are described below.  Driver and module specific
-configuration parameters are described in the relevant driver or module
-manual page.
+__xconfigfile__ and __xconfigdir__ configuration files, auto-detection,
+and fallback defaults. When the same information is supplied in more
+than one way, the highest precedence mechanism is used. The list of
+mechanisms is ordered from highest precedence to lowest. Note that not
+all parameters can be supplied via all methods. The available command
+line options and environment variables (and some defaults) are
+described in the Xserver(__appmansuffix__) and
+__xservername__(__appmansuffix__) manual pages. Most configuration file
+parameters, with their defaults, are described below. Driver and module
+specific configuration parameters are described in the relevant driver
+or module manual page.
 .SH DESCRIPTION
 .B __xservername__
 uses a configuration file called
 .I __xconfigfile__
+and files ending in the suffix
+.I .conf
+from the directory
+.I __xconfigdir__
 for its initial setup.
-This configuration file is searched for in the following places when the
+The
+.I __xconfigfile__
+configuration file is searched for in the following places when the
 server is started as a normal user:
 .PP
 .RS 4
@@ -93,9 +101,28 @@ directory), and
 is the machine's hostname as reported by
 .BR gethostname (__libmansuffix__).
 .PP
+Additional configuration files are searched for in the following
+directories:
+.PP
+.RS 4
+.nf
+.I /etc/X11/__xconfigdir__\-4
+.I /etc/X11/__xconfigdir__
+.I /etc/__xconfigdir__
+.IR __projectroot__/etc/X11/__xconfigdir__. <hostname>
+.I __projectroot__/etc/X11/__xconfigdir__\-4
+.I __projectroot__/etc/X11/__xconfigdir__
+.IR __projectroot__/lib/X11/__xconfigdir__. <hostname>
+.I __projectroot__/lib/X11/__xconfigdir__\-4
+.I __projectroot__/lib/X11/__xconfigdir__
+.fi
+.RE
+.PP
 The
 .I __xconfigfile__
-file is composed of a number of sections which may be present in any order,
+and
+.I __xconfigdir__
+files are composed of a number of sections which may be present in any order,
 or omitted to use default configuration values.
 Each section has the form:
 .PP
diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c
index d2e8b6d..24260e2 100644
--- a/hw/xfree86/parser/scan.c
+++ b/hw/xfree86/parser/scan.c
@@ -62,8 +62,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/types.h>
+#include <dirent.h>
 #include <unistd.h>
 #include <stdarg.h>
+#include <X11/Xdefs.h>
 #include <X11/Xfuncproto.h>
 
 #if defined(_POSIX_SOURCE)
@@ -90,17 +93,24 @@
 #include "xf86tokens.h"
 
 #define CONFIG_BUF_LEN     1024
+#define CONFIG_MAX_FILES   64
 
 static int StringToToken (char *, xf86ConfigSymTabRec *);
 
-static FILE *configFile = NULL;
+static struct {
+	FILE *file;
+	char *path;
+} configFiles[CONFIG_MAX_FILES];
 static const char **builtinConfig = NULL;
 static int builtinIndex = 0;
 static int configPos = 0;		/* current readers position */
 static int configLineNo = 0;	/* linenumber */
 static char *configBuf, *configRBuf;	/* buffer for lines */
 static char *configPath;		/* path to config file */
+static char *configDirPath;		/* path to config dir */
 static char *configSection = NULL;	/* name of current section being parsed */
+static int numFiles = 0;		/* number of config files */
+static int curFileIndex = 0;		/* index of current config file */
 static int pushToken = LOCK_TOKEN;
 static int eol_seen = 0;		/* private state to handle comments */
 LexRec val;
@@ -155,7 +165,7 @@ xf86strToUL (char *str)
 /*
  * xf86getNextLine --
  *
- *  read from the configFile FILE stream until we encounter a new
+ *  read from the configFiles FILE stream until we encounter a new
  *  line; this is effectively just a big wrapper for fgets(3).
  *
  *  xf86getToken() assumes that we will read up to the next
@@ -213,9 +223,18 @@ xf86getNextLine(void)
 	/* read in another block of chars */
 
 	do {
-		ret = fgets(configBuf + pos, configBufLen - pos - 1, configFile);
+		ret = fgets(configBuf + pos, configBufLen - pos - 1,
+			    configFiles[curFileIndex].file);
 
-		if (!ret) break;
+		if (!ret) {
+			/* stop if there are no more files */
+			if (++curFileIndex >= numFiles) {
+				curFileIndex = 0;
+				break;
+			}
+			configLineNo = 0;
+			continue;
+		}
 
 		/* search for EOL in the new block of chars */
 
@@ -306,7 +325,7 @@ again:
 		if (!c)
 		{
 			char *ret;
-			if (configFile)
+			if (numFiles > 0)
 				ret = xf86getNextLine();
 			else {
 				if (builtinConfig[builtinIndex] == NULL)
@@ -575,6 +594,12 @@ xf86pathIsSafe(const char *path)
 #ifndef XCONFIGFILE
 #define XCONFIGFILE	"xorg.conf"
 #endif
+#ifndef XCONFIGDIR
+#define XCONFIGDIR	"xorg.conf.d"
+#endif
+#ifndef XCONFIGSUFFIX
+#define XCONFIGSUFFIX	".conf"
+#endif
 #ifndef PROJECTROOT
 #define PROJECTROOT	"/usr/X11R6"
 #endif
@@ -616,7 +641,8 @@ xf86pathIsSafe(const char *path)
 
 static char *
 DoSubstitution(const char *template, const char *cmdline, const char *projroot,
-				int *cmdlineUsed, int *envUsed, char *XConfigFile)
+				int *cmdlineUsed, int *envUsed,
+				const char *XConfigFile)
 {
 	char *result;
 	int i, l;
@@ -745,7 +771,155 @@ DoSubstitution(const char *template, const char *cmdline, const char *projroot,
 	return result;
 }
 
-/* 
+/*
+ * Given some searching parameters, locate and open the xorg config file.
+ */
+static char *
+OpenConfigFile(const char *path, const char *cmdline, const char *projroot,
+	       const char *confname)
+{
+	char *filepath = NULL;
+	char *pathcopy;
+	const char *template;
+	int cmdlineUsed = 0;
+	FILE *file = NULL;
+
+	pathcopy = strdup(path);
+	for (template = strtok(pathcopy, ","); template && !file;
+	     template = strtok(NULL, ",")) {
+		filepath = DoSubstitution(template, cmdline, projroot,
+					  &cmdlineUsed, NULL, confname);
+		if (!filepath)
+			continue;
+		if (cmdline && !cmdlineUsed) {
+			free(filepath);
+			filepath = NULL;
+			continue;
+		}
+		file = fopen(filepath, "r");
+		if (!file) {
+			free(filepath);
+			filepath = NULL;
+		}
+	}
+
+	if (file) {
+		configFiles[numFiles].file = file;
+		configFiles[numFiles].path = strdup(filepath);
+		numFiles++;
+	}
+	return filepath;
+}
+
+/*
+ * Match non-hidden files in the xorg config directory with a .conf
+ * suffix. This filter is passed to scandir(3).
+ */
+static int
+ConfigFilter(const struct dirent *de)
+{
+	const char *name = de->d_name;
+	size_t len = strlen(name);
+	size_t suflen = strlen(XCONFIGSUFFIX);
+
+	if (!name || name[0] == '.' || len <= suflen)
+		return 0;
+	if (strcmp(&name[len-suflen], XCONFIGSUFFIX) != 0)
+		return 0;
+	return 1;
+}
+
+static Bool
+AddConfigDirFiles(const char *dirpath, struct dirent **list, int num)
+{
+	int i;
+	Bool openedFile = FALSE;
+	Bool warnOnce = FALSE;
+
+	for (i = 0; i < num; i++) {
+		char *path;
+		FILE *file;
+
+		if (numFiles >= CONFIG_MAX_FILES) {
+			if (!warnOnce) {
+				ErrorF("Maximum number of configuration "
+				       "files opened\n");
+				warnOnce = TRUE;
+			}
+			free(list[i]);
+			continue;
+		}
+
+		path = malloc(PATH_MAX + 1);
+		snprintf(path, PATH_MAX + 1, "%s/%s", dirpath,
+			 list[i]->d_name);
+		free(list[i]);
+		file = fopen(path, "r");
+		if (!file) {
+			free(path);
+			continue;
+		}
+		openedFile = TRUE;
+
+		configFiles[numFiles].file = file;
+		configFiles[numFiles].path = path;
+		numFiles++;
+	}
+
+	return openedFile;
+}
+
+/*
+ * Given some searching parameters, locate and open the xorg config
+ * directory. The directory does not need to contain config files.
+ */
+static char *
+OpenConfigDir(const char *path, const char *projroot, const char *confname)
+{
+	char *dirpath, *pathcopy;
+	const char *template;
+	Bool found = FALSE;
+
+	pathcopy = strdup(path);
+	for (template = strtok(pathcopy, ","); template && !found;
+	     template = strtok(NULL, ",")) {
+		struct dirent **list = NULL;
+		int num;
+
+		if (!(dirpath = DoSubstitution(template, NULL, projroot,
+					       NULL, NULL, confname)))
+			continue;
+		/* match files named *.conf */
+		num = scandir(dirpath, &list, ConfigFilter, alphasort);
+		found = AddConfigDirFiles(dirpath, list, num);
+		if (!found) {
+			free(dirpath);
+			dirpath = NULL;
+			if (list)
+				free(list);
+		}
+	}
+
+	return dirpath;
+}
+
+/*
+ * xf86initConfigFiles -- Setup global variables and buffers.
+ */
+void
+xf86initConfigFiles(void)
+{
+	curFileIndex = 0;
+	configPos = 0;
+	configLineNo = 0;
+	pushToken = LOCK_TOKEN;
+
+	configBuf = malloc(CONFIG_BUF_LEN);
+	configRBuf = malloc(CONFIG_BUF_LEN);
+	configBuf[0] = '\0';	/* sanity ... */
+}
+
+/*
  * xf86openConfigFile --
  *
  * This function take a config file search path (optional), a command-line
@@ -758,7 +932,7 @@ DoSubstitution(const char *template, const char *cmdline, const char *projroot,
  * opened.  When no file is found, the return value is NULL.
  *
  * The escape sequences allowed in the search path are defined above.
- *  
+ *
  */
 
 #ifndef DEFAULT_CONF_PATH
@@ -780,117 +954,90 @@ DoSubstitution(const char *template, const char *cmdline, const char *projroot,
 const char *
 xf86openConfigFile(const char *path, const char *cmdline, const char *projroot)
 {
-	char *pathcopy;
-	const char *template;
-	int cmdlineUsed = 0;
-
-	configFile = NULL;
-	configPos = 0;		/* current readers position */
-	configLineNo = 0;	/* linenumber */
-	pushToken = LOCK_TOKEN;
-
 	if (!path || !path[0])
 		path = DEFAULT_CONF_PATH;
-	pathcopy = malloc(strlen(path) + 1);
-	strcpy(pathcopy, path);
 	if (!projroot || !projroot[0])
 		projroot = PROJECTROOT;
 
-	template = strtok(pathcopy, ",");
-
-	/* First, search for a config file. */
-	while (template && !configFile) {
-		if ((configPath = DoSubstitution(template, cmdline, projroot,
-						 &cmdlineUsed, NULL,
-						 XCONFIGFILE))) {
-			if ((configFile = fopen(configPath, "r")) != 0) {
-				if (cmdline && !cmdlineUsed) {
-					fclose(configFile);
-					configFile = NULL;
-				}
-			}
-		}
-		if (configPath && !configFile) {
-			free(configPath);
-			configPath = NULL;
-		}
-		template = strtok(NULL, ",");
-	}
-	
-	/* Then search for fallback */
-	if (!configFile) {
-	    strcpy(pathcopy, path);
-	    template = strtok(pathcopy, ",");
-
-	    while (template && !configFile) {
-		if ((configPath = DoSubstitution(template, cmdline, projroot,
-						 &cmdlineUsed, NULL,
-						 XFREE86CFGFILE))) {
-		    if ((configFile = fopen(configPath, "r")) != 0) {
-			if (cmdline && !cmdlineUsed) {
-			    fclose(configFile);
-			    configFile = NULL;
-			}
-		    }
-		}
-		if (configPath && !configFile) {
-		    free(configPath);
-		    configPath = NULL;
-		}
-		template = strtok(NULL, ",");
-	    }
-	}
-	
-	free(pathcopy);
-	if (!configFile) {
-
-		return NULL;
-	}
+	/* Search for a config file or a fallback */
+	configPath = OpenConfigFile(path, cmdline, projroot, XCONFIGFILE);
+	if (!configPath)
+		configPath = OpenConfigFile(path, cmdline, projroot,
+					    XFREE86CFGFILE);
+	return configPath;
+}
 
-	configBuf = malloc (CONFIG_BUF_LEN);
-	configRBuf = malloc (CONFIG_BUF_LEN);
-	configBuf[0] = '\0';		/* sanity ... */
+/*
+ * xf86openConfigDirFiles --
+ *
+ * This function take a config directory search path (optional), a
+ * command-line specified directory name (optional) and the ProjectRoot path
+ * (optional) and locates and opens a config directory based on that
+ * information.  If a command-line name is specified, then this function
+ * fails if it is not found.
+ *
+ * The return value is a pointer to the actual name of the direcoty that was
+ * opened.  When no directory is found, the return value is NULL.
+ *
+ * The escape sequences allowed in the search path are defined above.
+ *
+ */
+const char *
+xf86openConfigDirFiles(const char *path, const char *cmdline,
+		       const char *projroot)
+{
+	if (!path || !path[0])
+		path = DEFAULT_CONF_PATH;
+	if (!projroot || !projroot[0])
+		projroot = PROJECTROOT;
 
-	return configPath;
+	/* Search for the multiconf directory */
+	configDirPath = OpenConfigDir(path, projroot, XCONFIGDIR);
+	return configDirPath;
 }
 
 void
 xf86closeConfigFile (void)
 {
+	int i;
+
 	free (configPath);
 	configPath = NULL;
+	free (configDirPath);
+	configDirPath = NULL;
 	free (configRBuf);
 	configRBuf = NULL;
 	free (configBuf);
 	configBuf = NULL;
 
-	if (configFile) {
-		fclose (configFile);
-		configFile = NULL;
-	} else {
+	if (numFiles == 0) {
 		builtinConfig = NULL;
 		builtinIndex = 0;
 	}
+	for (i = 0; i < numFiles; i++) {
+		fclose(configFiles[i].file);
+		configFiles[i].file = NULL;
+		free(configFiles[i].path);
+		configFiles[i].path = NULL;
+	}
+	numFiles = 0;
 }
 
 void
 xf86setBuiltinConfig(const char *config[])
 {
 	builtinConfig = config;
-	configPath = strdup("<builtin configuration>");
-	configBuf = malloc (CONFIG_BUF_LEN);
-	configRBuf = malloc (CONFIG_BUF_LEN);
-	configBuf[0] = '\0';		/* sanity ... */
-
 }
 
 void
 xf86parseError (char *format,...)
 {
 	va_list ap;
+	char *filename = numFiles ? configFiles[curFileIndex].path :
+			 "<builtin configuration>";
 
 	ErrorF ("Parse error on line %d of section %s in file %s\n\t",
-		 configLineNo, configSection, configPath);
+		 configLineNo, configSection, filename);
 	va_start (ap, format);
 	VErrorF (format, ap);
 	va_end (ap);
@@ -902,8 +1049,10 @@ void
 xf86validationError (char *format,...)
 {
 	va_list ap;
+	char *filename = numFiles ? configFiles[curFileIndex].path :
+			 "<builtin configuration>";
 
-	ErrorF ("Data incomplete in file %s\n\t", configPath);
+	ErrorF ("Data incomplete in file %s\n\t", filename);
 	va_start (ap, format);
 	VErrorF (format, ap);
 	va_end (ap);
diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h
index efa1b85..12bcd6e 100644
--- a/hw/xfree86/parser/xf86Parser.h
+++ b/hw/xfree86/parser/xf86Parser.h
@@ -456,8 +456,11 @@ xf86ConfigSymTabRec, *xf86ConfigSymTabPtr;
 /*
  * prototypes for public functions
  */
-extern const char *xf86openConfigFile(const char *, const char *,
-				      const char *);
+extern void xf86initConfigFiles(void);
+extern const char *xf86openConfigFile(const char *path, const char *cmdline,
+				      const char *projroot);
+extern const char *xf86openConfigDirFiles(const char *path, const char *cmdline,
+					  const char *projroot);
 extern void xf86setBuiltinConfig(const char *config[]);
 extern XF86ConfigPtr xf86readConfigFile(void);
 extern void xf86closeConfigFile(void);
diff --git a/hw/xwin/winconfig.c b/hw/xwin/winconfig.c
index 3e1908c..6efd7ca 100644
--- a/hw/xwin/winconfig.c
+++ b/hw/xwin/winconfig.c
@@ -50,6 +50,13 @@
                     "%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
                     "%P/lib/X11/%X"
 #endif
+#ifndef CONFIGDIRPATH
+#define CONFIGDIRPATH  "/etc/X11/%X-%M," "/etc/X11/%X," "/etc/%X," \
+                       "%P/etc/X11/%X.%H," "%P/etc/X11/%X-%M," \
+                       "%P/etc/X11/%X," \
+                       "%P/lib/X11/%X.%H," "%P/lib/X11/%X-%M," \
+                       "%P/lib/X11/%X"
+#endif
 
 XF86ConfigPtr g_xf86configptr = NULL;
 #endif
@@ -109,7 +116,7 @@ Bool
 winReadConfigfile ()
 {
   Bool		retval = TRUE;
-  const char	*filename;
+  const char	*filename, *dirname;
   MessageType	from = X_DEFAULT;
   char		*xf86ConfigFile = NULL;
 
@@ -120,9 +127,10 @@ winReadConfigfile ()
     }
 
   /* Parse config file into data structure */
-
+  xf86initConfigFiles();
   filename = xf86openConfigFile (CONFIGPATH, xf86ConfigFile, PROJECTROOT);
-    
+  dirname = xf86openConfigDirFiles (CONFIGDIRPATH, NULL, PROJECTROOT);
+
   /* Hack for backward compatibility */
   if (!filename && from == X_DEFAULT)
     filename = xf86openConfigFile (CONFIGPATH, "XF86Config", PROJECTROOT);
@@ -137,6 +145,13 @@ winReadConfigfile ()
       if (xf86ConfigFile)
 	ErrorF (": \"%s\"", xf86ConfigFile);
       ErrorF ("\n");
+    }
+  if (dirname)
+    {
+      winMsg (from, "Using config directory: \"%s\"\n", dirname);
+    }
+  if (!filename && !dirname)
+    {
       return FALSE;
     }
   if ((g_xf86configptr = xf86readConfigFile ()) == NULL)
diff --git a/include/xorg-config.h.in b/include/xorg-config.h.in
index 9fe7cde..8946a65 100644
--- a/include/xorg-config.h.in
+++ b/include/xorg-config.h.in
@@ -36,6 +36,9 @@
 /* Path to configuration file. */
 #undef __XCONFIGFILE__
 
+/* Name of configuration directory. */
+#undef __XCONFIGDIR__
+
 /* Path to loadable modules. */
 #undef DEFAULT_MODULE_PATH
 
commit f1e869aca176e9113f9d234b0ea59b4cac295cc4
Author: Dan Nicholson <dbn.lists at gmail.com>
Date:   Mon Dec 21 00:03:11 2009 -0800

    xfree86: Unexport configuration file symbols
    
    These functions should not be used outside of DDXs, so no need to put
    them in the ABI.
    
    Signed-off-by: Dan Nicholson <dbn.lists at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h
index 6030800..efa1b85 100644
--- a/hw/xfree86/parser/xf86Parser.h
+++ b/hw/xfree86/parser/xf86Parser.h
@@ -456,13 +456,13 @@ xf86ConfigSymTabRec, *xf86ConfigSymTabPtr;
 /*
  * prototypes for public functions
  */
-extern _X_EXPORT const char *xf86openConfigFile (const char *, const char *,
-					const char *);
-extern _X_EXPORT void xf86setBuiltinConfig(const char *config[]);
-extern _X_EXPORT XF86ConfigPtr xf86readConfigFile (void);
-extern _X_EXPORT void xf86closeConfigFile (void);
-extern _X_EXPORT void xf86freeConfig (XF86ConfigPtr p);
-extern _X_EXPORT int xf86writeConfigFile (const char *, XF86ConfigPtr);
+extern const char *xf86openConfigFile(const char *, const char *,
+				      const char *);
+extern void xf86setBuiltinConfig(const char *config[]);
+extern XF86ConfigPtr xf86readConfigFile(void);
+extern void xf86closeConfigFile(void);
+extern void xf86freeConfig(XF86ConfigPtr p);
+extern int xf86writeConfigFile(const char *, XF86ConfigPtr);
 extern _X_EXPORT XF86ConfDevicePtr xf86findDevice(const char *ident, XF86ConfDevicePtr p);
 extern _X_EXPORT XF86ConfLayoutPtr xf86findLayout(const char *name, XF86ConfLayoutPtr list);
 extern _X_EXPORT XF86ConfMonitorPtr xf86findMonitor(const char *ident, XF86ConfMonitorPtr p);


More information about the Xquartz-changes mailing list