xserver: Branch 'master' - 18 commits

Peter Hutterer whot at kemper.freedesktop.org
Tue Jun 16 22:54:58 PDT 2009


 Xi/Makefile.am                        |   34 +-
 Xi/chdevcur.c                         |  113 -------
 Xi/chdevcur.h                         |   36 --
 Xi/chdevhier.c                        |  540 ----------------------------------
 Xi/chdevhier.h                        |   44 --
 Xi/exevents.c                         |   37 +-
 Xi/extinit.c                          |   18 -
 Xi/getcptr.c                          |  106 ------
 Xi/getcptr.h                          |   38 --
 Xi/querydev.c                         |  451 ----------------------------
 Xi/querydev.h                         |   45 --
 Xi/querydp.c                          |  210 -------------
 Xi/querydp.h                          |   39 --
 Xi/queryst.c                          |    2 
 Xi/queryversion.c                     |  128 --------
 Xi/queryversion.h                     |   40 --
 Xi/setcptr.c                          |  113 -------
 Xi/setcptr.h                          |   36 --
 Xi/warpdevp.c                         |  179 -----------
 Xi/warpdevp.h                         |   36 --
 Xi/xiallowev.c                        |    6 
 Xi/xichangecursor.c                   |  107 ++++++
 Xi/xichangecursor.h                   |   36 ++
 Xi/xichangehierarchy.c                |  505 +++++++++++++++++++++++++++++++
 Xi/xichangehierarchy.h                |   44 ++
 Xi/xigetclientpointer.c               |  106 ++++++
 Xi/xigetclientpointer.h               |   38 ++
 Xi/xigrabdev.c                        |    9 
 Xi/xipassivegrab.c                    |    9 
 Xi/xiproperty.c                       |   26 -
 Xi/xiquerydevice.c                    |  468 +++++++++++++++++++++++++++++
 Xi/xiquerydevice.h                    |   45 ++
 Xi/xiquerypointer.c                   |  204 ++++++++++++
 Xi/xiquerypointer.h                   |   39 ++
 Xi/xiqueryversion.c                   |  128 ++++++++
 Xi/xiqueryversion.h                   |   40 ++
 Xi/xiselectev.c                       |    6 
 Xi/xisetclientpointer.c               |  108 ++++++
 Xi/xisetclientpointer.h               |   36 ++
 Xi/xisetdevfocus.c                    |   12 
 Xi/xiwarppointer.c                    |  173 ++++++++++
 Xi/xiwarppointer.h                    |   36 ++
 configure.ac                          |    2 
 dix/devices.c                         |  139 +++++++-
 dix/eventconvert.c                    |    2 
 dix/getevents.c                       |    4 
 hw/kdrive/src/kinput.c                |   45 ++
 hw/vfb/InitInput.c                    |   24 +
 hw/xfree86/common/xf86Module.h        |    2 
 hw/xfree86/common/xf86Xinput.c        |    4 
 hw/xfree86/common/xf86Xinput.h        |    2 
 hw/xfree86/dixmods/extmod/xf86vmode.c |    4 
 hw/xfree86/int10/helper_exec.c        |   28 -
 hw/xnest/Pointer.c                    |   20 +
 hw/xquartz/darwin.c                   |   67 +++-
 hw/xwin/winmouse.c                    |   20 +
 include/events.h                      |    2 
 include/exevents.h                    |    1 
 include/input.h                       |    6 
 include/inputstr.h                    |   12 
 xkb/xkbInit.c                         |    1 
 61 files changed, 2483 insertions(+), 2328 deletions(-)

New commits:
commit e92dcb6ce07aa3cfb53e8bad5701481c106c4094
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Jun 18 14:40:20 2009 +1000

    input: unify button numbers on master devices.
    
    Master devices provide the union of all attached slave devices' buttons,
    i.e. the number of buttons on the master device is always the number of
    buttons of the slave device with the highest number of buttons. When slaves
    are attached or detached, the master device adjusts the button number to
    reflect the new buttons.
    
    On a slave switch, this slave's button labels are copied into the master (up
    to slave->num_buttons). The remaining button labels (if any) stay as they
    are. Thus, if any of the higher buttons is still pressed, it reflects the
    label of the last pressed device that provided this button.
    
    If two devices press the same button and it is differently labelled the last
    pressed one will be reflected in the master device.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 8b69a3a..e54af09 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -588,6 +588,8 @@ DeepCopyPointerClasses(DeviceIntPtr from, DeviceIntPtr to)
         } else
             xfree(to->button->xkb_acts);
 
+         memcpy(to->button->labels, from->button->labels,
+                from->button->numButtons * sizeof(Atom));
         to->button->sourceid = from->id;
     } else if (to->button && !from->button)
     {
@@ -670,10 +672,7 @@ DeepCopyDeviceClasses(DeviceIntPtr from, DeviceIntPtr to, DeviceChangedEvent *dc
 
 
 /**
- * Change MD to look like SD by copying all classes over. An event is sent to
- * all interested clients.
- * @param device The slave device
- * @param dcce Pointer to the event struct.
+ * Send an XI2 DeviceChangedEvent to all interested clients.
  */
 void
 XISendDeviceChangedEvent(DeviceIntPtr device, DeviceIntPtr master, DeviceChangedEvent *dce)
@@ -700,7 +699,7 @@ XISendDeviceChangedEvent(DeviceIntPtr device, DeviceIntPtr master, DeviceChanged
         len += sizeof(CARD32) * nkeys; /* keycodes */
     }
 
-    dcce = xalloc(len);
+    dcce = xcalloc(1, len);
     if (!dcce)
     {
         ErrorF("[Xi] BadAlloc in SendDeviceChangedEvent.\n");
@@ -713,7 +712,7 @@ XISendDeviceChangedEvent(DeviceIntPtr device, DeviceIntPtr master, DeviceChanged
     dcce->time         = GetTimeInMillis();
     dcce->deviceid     = master->id;
     dcce->sourceid     = device->id;
-    dcce->reason       = XISlaveSwitch;
+    dcce->reason       = (dce->flags & DEVCHANGE_DEVICE_CHANGE) ? XIDeviceChange : XISlaveSwitch;
     dcce->num_classes  = 0;
     dcce->length = (len - sizeof(xEvent))/4;
 
diff --git a/dix/devices.c b/dix/devices.c
index 3d19065..b237e03 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -109,6 +109,7 @@ DevPrivateKey XTstDevicePrivateKey = &XTstDevicePrivateKeyIndex;
  */
 DeviceIntPtr vxtstpointer, vxtstkeyboard;
 
+static void RecalculateMasterButtons(DeviceIntPtr slave);
 
 /**
  * DIX property handler.
@@ -369,6 +370,8 @@ EnableDevice(DeviceIntPtr dev, BOOL sendevent)
         XISendDeviceHierarchyEvent(flags);
     }
 
+    RecalculateMasterButtons(dev);
+
     return TRUE;
 }
 
@@ -460,6 +463,9 @@ DisableDevice(DeviceIntPtr dev, BOOL sendevent)
         flags[dev->id] = XIDeviceDisabled;
         XISendDeviceHierarchyEvent(flags);
     }
+
+    RecalculateMasterButtons(dev);
+
     return TRUE;
 }
 
@@ -2260,6 +2266,77 @@ ProcQueryKeymap(ClientPtr client)
    return Success;
 }
 
+
+/**
+ * Recalculate the number of buttons for the master device. The number of
+ * buttons on the master device is equal to the number of buttons on the
+ * slave device with the highest number of buttons.
+ */
+static void
+RecalculateMasterButtons(DeviceIntPtr slave)
+{
+    DeviceIntPtr dev, master;
+    int maxbuttons = 0;
+
+    if (!slave->button || IsMaster(slave))
+        return;
+
+    master = GetMaster(slave, MASTER_POINTER);
+    if (!master)
+        return;
+
+    for (dev = inputInfo.devices; dev; dev = dev->next)
+    {
+        if (IsMaster(dev) ||
+            dev->u.master != master ||
+            !dev->button)
+            continue;
+
+        maxbuttons = max(maxbuttons, dev->button->numButtons);
+    }
+
+    if (master->button->numButtons != maxbuttons)
+    {
+        int i;
+        DeviceChangedEvent event;
+
+        memset(&event, 0, sizeof(event));
+
+        master->button->numButtons = maxbuttons;
+
+        event.header = ET_Internal;
+        event.type = ET_DeviceChanged;
+        event.time = CurrentTime;
+        event.deviceid = master->id;
+        event.flags = DEVCHANGE_POINTER_EVENT | DEVCHANGE_DEVICE_CHANGE;
+        event.buttons.num_buttons = maxbuttons;
+        memcpy(&event.buttons.names, master->button->labels, maxbuttons *
+                sizeof(Atom));
+
+        if (master->valuator)
+        {
+            event.num_valuators = master->valuator->numAxes;
+            for (i = 0; i < event.num_valuators; i++)
+            {
+                event.valuators[i].min = master->valuator->axes[i].min_value;
+                event.valuators[i].max = master->valuator->axes[i].max_value;
+                event.valuators[i].resolution = master->valuator->axes[i].resolution;
+                /* This should, eventually, be a per-axis mode */
+                event.valuators[i].mode = master->valuator->mode;
+                event.valuators[i].name = master->valuator->axes[i].label;
+            }
+        }
+
+        if (master->key)
+        {
+            event.keys.min_keycode = master->key->xkbInfo->desc->min_key_code;
+            event.keys.max_keycode = master->key->xkbInfo->desc->max_key_code;
+        }
+
+        XISendDeviceChangedEvent(master, master, &event);
+    }
+}
+
 /**
  * Attach device 'dev' to device 'master'.
  * Client is set to the client that issued the request, or NULL if it comes
@@ -2323,6 +2400,8 @@ AttachDevice(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr master)
         dev->spriteInfo->paired = master;
         dev->spriteInfo->spriteOwner = FALSE;
 
+        RecalculateMasterButtons(master);
+
         if (!oldmaster)
         {
             /* Attaching a floating SD makes it disappear to XI 1 clients */
diff --git a/include/events.h b/include/events.h
index d44188b..f6405c5 100644
--- a/include/events.h
+++ b/include/events.h
@@ -119,6 +119,8 @@ typedef struct
  * pointer event or a keyboard event */
 #define DEVCHANGE_POINTER_EVENT 0x4
 #define DEVCHANGE_KEYBOARD_EVENT 0x8
+/* device capabilities changed */
+#define DEVCHANGE_DEVICE_CHANGE 0x10
 
 /**
  * Sent whenever a device's capabilities have changed.
commit 280b7f92d729ec910ffa3d18dce7bbc215be7a3c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Jun 17 22:38:24 2009 +1000

    dix: reduce MDs and xtest pointers to 7 buttons by default.
    
    MD's will soon be the union of all devices anyway. XTest pointers are only
    for the core protocol XTest stuff, so 7 buttons (lmr + 4 wheel buttons)
    should do.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/devices.c b/dix/devices.c
index 5fa196e..3d19065 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -554,7 +554,7 @@ CoreKeyboardProc(DeviceIntPtr pDev, int what)
 static int
 CorePointerProc(DeviceIntPtr pDev, int what)
 {
-#define NBUTTONS 32
+#define NBUTTONS 7
 #define NAXES 2
     BYTE map[NBUTTONS + 1];
     int i = 0;
commit 6c7d992735eebbd7a20247926e7725896348b865
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Jun 17 09:11:52 2009 +1000

    Require inputproto 1.9.99.12
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/configure.ac b/configure.ac
index 1265117..2ffb7d0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -700,7 +700,7 @@ XEXT_LIB='$(top_builddir)/Xext/libXext.la'
 XEXTXORG_LIB='$(top_builddir)/Xext/libXextbuiltin.la'
 
 dnl Core modules for most extensions, et al.
-REQUIRED_MODULES="[randrproto >= 1.2.99.3] [renderproto >= 0.9.3] [fixesproto >= 4.0] [damageproto >= 1.1] xcmiscproto [xextproto >= 7.0.3] [xproto >= 7.0.13] [xtrans >= 1.2.2] bigreqsproto resourceproto fontsproto [inputproto >= 1.9.99.11] [kbproto >= 1.0.3]"
+REQUIRED_MODULES="[randrproto >= 1.2.99.3] [renderproto >= 0.9.3] [fixesproto >= 4.0] [damageproto >= 1.1] xcmiscproto [xextproto >= 7.0.3] [xproto >= 7.0.13] [xtrans >= 1.2.2] bigreqsproto resourceproto fontsproto [inputproto >= 1.9.99.12] [kbproto >= 1.0.3]"
 REQUIRED_LIBS="xfont xau fontenc [pixman-1 >= 0.13.2]"
 
 dnl HAVE_DBUS is true if we actually have the D-Bus library, whereas
commit 09cef7573938e5c08007e578e1b638bc5e1796a8
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Jun 17 09:04:08 2009 +1000

    Xi: valuator/button labels are called labels now, not 'names'
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/extinit.c b/Xi/extinit.c
index 20d49e1..1376f4f 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -712,7 +712,7 @@ SDeviceChangedEvent(xXIDeviceChangedEvent* from, xXIDeviceChangedEvent* to)
             case ValuatorClass:
                 {
                     xXIValuatorInfo* ai = (xXIValuatorInfo*)any;
-                    swapl(&ai->name, n);
+                    swapl(&ai->label, n);
                     swapl(&ai->min.integral, n);
                     swapl(&ai->min.frac, n);
                     swapl(&ai->max.integral, n);
diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
index bc30888..b316c86 100644
--- a/Xi/xiquerydevice.c
+++ b/Xi/xiquerydevice.c
@@ -314,7 +314,7 @@ ListValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info, int axisnumber)
 
     info->type = ValuatorClass;
     info->length = sizeof(xXIValuatorInfo)/4;
-    info->name = v->axes[axisnumber].label;
+    info->label = v->axes[axisnumber].label;
     info->min.integral = v->axes[axisnumber].min_value;
     info->min.frac = 0;
     info->max.integral = v->axes[axisnumber].max_value;
@@ -335,7 +335,7 @@ SwapValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info)
     char n;
     swaps(&info->type, n);
     swaps(&info->length, n);
-    swapl(&info->name, n);
+    swapl(&info->label, n);
     swapl(&info->min.integral, n);
     swapl(&info->min.frac, n);
     swapl(&info->max.integral, n);
commit bc2ff5365030ad8bc11efde430b1064080dd7098
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jun 16 19:36:57 2009 +1000

    Xi: copy the valuator mode from SD to MD.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 98973b7..8b69a3a 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -550,6 +550,7 @@ DeepCopyPointerClasses(DeviceIntPtr from, DeviceIntPtr to)
 
         v->axisVal = (double*)(v->axes + from->valuator->numAxes);
         v->sourceid = from->id;
+        v->mode = from->valuator->mode;
     } else if (to->valuator && !from->valuator)
     {
         ClassesPtr classes;
commit 87d1f44bad608507e3995e17eb84fa0a0119796c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jun 16 14:18:45 2009 +1000

    Xi: copy the button and axes labels into the XIQueryDevice reply.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
index cc57815..bc30888 100644
--- a/Xi/xiquerydevice.c
+++ b/Xi/xiquerydevice.c
@@ -34,6 +34,7 @@
 
 #include "inputstr.h"
 #include <X11/X.h>
+#include <X11/Xatom.h>
 #include <X11/extensions/XI2proto.h>
 #include "xkbstr.h"
 #include "xkbsrv.h"
@@ -240,8 +241,8 @@ ListButtonInfo(DeviceIntPtr dev, xXIButtonInfo* info)
     for (i = 0; dev && dev->button && i < dev->button->numButtons; i++)
         if (BitIsOn(dev->button->down, i))
             SetBit(bits, i);
-
-    /** XXX: button labels */
+    bits += mask_len * 4;
+    memcpy(bits, dev->button->labels, dev->button->numButtons * sizeof(Atom));
 
     return info->length * 4;
 }
@@ -313,7 +314,7 @@ ListValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info, int axisnumber)
 
     info->type = ValuatorClass;
     info->length = sizeof(xXIValuatorInfo)/4;
-    info->name = XIGetKnownProperty(AXIS_LABEL_PROP_REL_MISC); /* XXX */
+    info->name = v->axes[axisnumber].label;
     info->min.integral = v->axes[axisnumber].min_value;
     info->min.frac = 0;
     info->max.integral = v->axes[axisnumber].max_value;
commit a30fef9956b296f59ea18a9ee38d0abafeb15a4e
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jun 16 16:38:11 2009 +1000

    input: Add labels to buttons and valuators - ABI_XINPUT_VERSION 7
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index dc9eba7..98973b7 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1153,7 +1153,7 @@ InitProximityClassDeviceStruct(DeviceIntPtr dev)
  * @see InitValuatorClassDeviceStruct
  */
 void
-InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, int minval, int maxval,
+InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval, int maxval,
 		       int resolution, int min_res, int max_res)
 {
     AxisInfoPtr ax;
@@ -1170,6 +1170,7 @@ InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, int minval, int maxval,
     ax->resolution = resolution;
     ax->min_resolution = min_res;
     ax->max_resolution = max_res;
+    ax->label = label;
 }
 
 static void
diff --git a/dix/devices.c b/dix/devices.c
index 517829a..5fa196e 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -554,16 +554,33 @@ CoreKeyboardProc(DeviceIntPtr pDev, int what)
 static int
 CorePointerProc(DeviceIntPtr pDev, int what)
 {
-    BYTE map[33];
+#define NBUTTONS 32
+#define NAXES 2
+    BYTE map[NBUTTONS + 1];
     int i = 0;
+    Atom btn_labels[NBUTTONS] = {0};
+    Atom axes_labels[NAXES] = {0};
 
     switch (what) {
     case DEVICE_INIT:
-        for (i = 1; i <= 32; i++)
+        for (i = 1; i <= NBUTTONS; i++)
             map[i] = i;
-        if (!InitPointerDeviceStruct((DevicePtr)pDev, map, 32,
+
+	btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
+	btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
+	btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
+	btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
+	btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
+	btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
+	btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
+	/* don't know about the rest */
+
+	axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
+	axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
+
+        if (!InitPointerDeviceStruct((DevicePtr)pDev, map, NBUTTONS, btn_labels,
                                 (PtrCtrlProcPtr)NoopDDA,
-                                GetMotionHistorySize(), 2))
+                                GetMotionHistorySize(), NAXES, axes_labels))
         {
             ErrorF("Could not initialize device '%s'. Out of memory.\n",
                    pDev->name);
@@ -583,6 +600,9 @@ CorePointerProc(DeviceIntPtr pDev, int what)
     }
 
     return Success;
+
+#undef NBUTTONS
+#undef NAXES
 }
 
 /**
@@ -1133,7 +1153,7 @@ SetKeySymsMap(KeySymsPtr dst, KeySymsPtr src)
 }
 
 _X_EXPORT Bool
-InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons,
+InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons, Atom* labels,
                             CARD8 *map)
 {
     ButtonClassPtr butc;
@@ -1146,12 +1166,13 @@ InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons,
     butc->sourceid = dev->id;
     for (i = 1; i <= numButtons; i++)
 	butc->map[i] = map[i];
+    memcpy(butc->labels, labels, numButtons * sizeof(Atom));
     dev->button = butc;
     return TRUE;
 }
 
 Bool
-InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes,
+InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels,
                               int numMotionEvents, int mode)
 {
     int i;
@@ -1190,7 +1211,7 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes,
     AllocateMotionHistory(dev);
 
     for (i=0; i<numAxes; i++) {
-        InitValuatorAxisStruct(dev, i, NO_AXIS_LIMITS, NO_AXIS_LIMITS,
+        InitValuatorAxisStruct(dev, i, labels[i], NO_AXIS_LIMITS, NO_AXIS_LIMITS,
                                0, 0, 0);
 	valc->axisVal[i]=0;
     }
@@ -1459,14 +1480,14 @@ InitIntegerFeedbackClassDeviceStruct (DeviceIntPtr dev, IntegerCtrlProcPtr contr
 }
 
 Bool
-InitPointerDeviceStruct(DevicePtr device, CARD8 *map, int numButtons,
+InitPointerDeviceStruct(DevicePtr device, CARD8 *map, int numButtons, Atom* btn_labels,
                         PtrCtrlProcPtr controlProc, int numMotionEvents,
-                        int numAxes)
+                        int numAxes, Atom *axes_labels)
 {
     DeviceIntPtr dev = (DeviceIntPtr)device;
 
-    return(InitButtonClassDeviceStruct(dev, numButtons, map) &&
-	   InitValuatorClassDeviceStruct(dev, numAxes,
+    return(InitButtonClassDeviceStruct(dev, numButtons, btn_labels, map) &&
+	   InitValuatorClassDeviceStruct(dev, numAxes, axes_labels,
 					 numMotionEvents, 0) &&
 	   InitPtrFeedbackClassDeviceStruct(dev, controlProc));
 }
diff --git a/dix/getevents.c b/dix/getevents.c
index 9b1908c..7c018c1 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -214,7 +214,7 @@ CreateClassesChangedEvent(EventList* event,
     {
         dce->buttons.num_buttons = slave->button->numButtons;
         for (i = 0; i < dce->buttons.num_buttons; i++)
-            dce->buttons.names[i] = 0; /* FIXME */
+            dce->buttons.names[i] = slave->button->labels[i];
     }
     if (slave->valuator)
     {
@@ -226,7 +226,7 @@ CreateClassesChangedEvent(EventList* event,
             dce->valuators[i].resolution = slave->valuator->axes[i].resolution;
             /* This should, eventually, be a per-axis mode */
             dce->valuators[i].mode = slave->valuator->mode;
-            dce->valuators[i].name = 0; /* FIXME: */
+            dce->valuators[i].name = slave->valuator->axes[i].label;
         }
     }
     if (slave->key)
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 740852e..5e7ff53 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -46,6 +46,7 @@
 #include "exevents.h"
 #include "extinit.h"
 #include "exglobals.h"
+#include "xserver-properties.h"
 
 #define AtomFromName(x) MakeAtom(x, strlen(x), 1)
 
@@ -382,6 +383,8 @@ KdPointerProc(DeviceIntPtr pDevice, int onoff)
     DevicePtr       pDev = (DevicePtr)pDevice;
     KdPointerInfo   *pi;
     Atom            xiclass;
+    Atom            *btn_labels;
+    Atom            *axes_labels;
 
     if (!pDev)
 	return BadImplementation;
@@ -429,9 +432,47 @@ KdPointerProc(DeviceIntPtr pDevice, int onoff)
             return !Success;
         }
 
-	InitPointerDeviceStruct(pDev, pi->map, pi->nButtons,
+	btn_labels = xcalloc(pi->nButtons, sizeof(Atom));
+	if (!btn_labels)
+	    return BadAlloc;
+	axes_labels = xcalloc(pi->nAxes, sizeof(Atom));
+	if (!axes_labels) {
+	    xfree(btn_labels);
+	    return BadAlloc;
+	}
+
+	switch(pi->nAxes)
+	{
+	    default:
+	    case 7:
+		btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
+	    case 6:
+		btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
+	    case 5:
+		btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
+	    case 4:
+		btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
+	    case 3:
+		btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
+	    case 2:
+		btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
+	    case 1:
+		btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
+	    case 0:
+		break;
+	}
+
+	if (pi->nAxes >= 2) {
+	    axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
+	    axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
+	}
+
+	InitPointerDeviceStruct(pDev, pi->map, pi->nButtons, btn_labels,
 	    (PtrCtrlProcPtr)NoopDDA,
-	    GetMotionHistorySize(), pi->nAxes);
+	    GetMotionHistorySize(), pi->nAxes, axes_labels);
+
+        xfree(btn_labels);
+        xfree(axes_labels);
 
         if (pi->inputClass == KD_TOUCHSCREEN) {
             InitAbsoluteClassDeviceStruct(pDevice);
diff --git a/hw/vfb/InitInput.c b/hw/vfb/InitInput.c
index 4c8c996..7f2d56f 100644
--- a/hw/vfb/InitInput.c
+++ b/hw/vfb/InitInput.c
@@ -41,6 +41,8 @@ from The Open Group.
 #include "lk201kbd.h"
 #include "xkbsrv.h"
 #include <X11/keysym.h>
+#include "xserver-properties.h"
+#include "exevents.h"
 
 Bool
 LegalModifier(unsigned int key, DeviceIntPtr pDev)
@@ -87,8 +89,13 @@ vfbKeybdProc(DeviceIntPtr pDevice, int onoff)
 static int
 vfbMouseProc(DeviceIntPtr pDevice, int onoff)
 {
-    BYTE map[4];
+#define NBUTTONS 3
+#define NAXES 2
+
+    BYTE map[NBUTTONS + 1];
     DevicePtr pDev = (DevicePtr)pDevice;
+    Atom btn_labels[NBUTTONS] = {0};
+    Atom axes_labels[NAXES] = {0};
 
     switch (onoff)
     {
@@ -96,8 +103,16 @@ vfbMouseProc(DeviceIntPtr pDevice, int onoff)
 	    map[1] = 1;
 	    map[2] = 2;
 	    map[3] = 3;
-	    InitPointerDeviceStruct(pDev, map, 3,
-		(PtrCtrlProcPtr)NoopDDA, GetMotionHistorySize(), 2);
+
+            btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
+            btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
+            btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
+
+            axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
+            axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
+
+	    InitPointerDeviceStruct(pDev, map, NBUTTONS, btn_labels,
+		(PtrCtrlProcPtr)NoopDDA, GetMotionHistorySize(), NAXES, axes_labels);
 	    break;
 
     case DEVICE_ON:
@@ -112,6 +127,9 @@ vfbMouseProc(DeviceIntPtr pDevice, int onoff)
 	break;
     }
     return Success;
+
+#undef NBUTTONS
+#undef NAXES
 }
 
 void
diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index 5d36cec..ded5216 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(5, 0)
-#define ABI_XINPUT_VERSION	SET_ABI_VERSION(6, 0)
+#define ABI_XINPUT_VERSION	SET_ABI_VERSION(7, 0)
 #define ABI_EXTENSION_VERSION	SET_ABI_VERSION(2, 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 39186ac..cb1e920 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -1010,13 +1010,13 @@ xf86XInputSetScreen(LocalDevicePtr	local,
 
 
 void
-xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, int minval, int maxval,
+xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval, int maxval,
 			   int resolution, int min_res, int max_res)
 {
     if (!dev || !dev->valuator)
         return;
 
-    InitValuatorAxisStruct(dev, axnum, minval, maxval, resolution, min_res,
+    InitValuatorAxisStruct(dev, axnum, label, minval, maxval, resolution, min_res,
 			   max_res);
 }
 
diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index 04c663f..0ad5664 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -171,7 +171,7 @@ extern _X_EXPORT LocalDevicePtr xf86FirstLocalDevice(void);
 extern _X_EXPORT int xf86ScaleAxis(int Cx, int Sxhigh, int Sxlow, int Rxhigh, int Rxlow);
 extern _X_EXPORT void xf86XInputSetScreen(LocalDevicePtr local, int screen_number, int x, int y);
 extern _X_EXPORT void xf86ProcessCommonOptions(InputInfoPtr pInfo, pointer options);
-extern _X_EXPORT void xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, int minval,
+extern _X_EXPORT void xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval,
 				int maxval, int resolution, int min_res,
 				int max_res);
 extern _X_EXPORT void xf86InitValuatorDefaults(DeviceIntPtr dev, int axnum);
diff --git a/hw/xnest/Pointer.c b/hw/xnest/Pointer.c
index 8f764a6..c5d361c 100644
--- a/hw/xnest/Pointer.c
+++ b/hw/xnest/Pointer.c
@@ -33,6 +33,8 @@ is" without express or implied warranty.
 #include "Pointer.h"
 #include "Args.h"
 
+#include "xserver-properties.h"
+
 DeviceIntPtr xnestPointerDevice = NULL;
 
 void
@@ -46,6 +48,8 @@ int
 xnestPointerProc(DeviceIntPtr pDev, int onoff)
 {
   CARD8 map[MAXBUTTONS];
+  Atom btn_labels[MAXBUTTONS] = {0};
+  Atom axes_labels[2] = {0};
   int nmap;
   int i;
 
@@ -55,9 +59,21 @@ xnestPointerProc(DeviceIntPtr pDev, int onoff)
       nmap = XGetPointerMapping(xnestDisplay, map, MAXBUTTONS);
       for (i = 0; i <= nmap; i++)
 	map[i] = i; /* buttons are already mapped */
-      InitPointerDeviceStruct(&pDev->public, map, nmap,
+
+      btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
+      btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
+      btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
+      btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
+      btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
+      btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
+      btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
+
+      axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
+      axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
+
+      InitPointerDeviceStruct(&pDev->public, map, nmap, btn_labels,
 			      xnestChangePointerControl,
-			      GetMotionHistorySize(), 2);
+			      GetMotionHistorySize(), 2, axes_labels);
       break;
     case DEVICE_ON: 
       xnestEventMask |= XNEST_POINTER_EVENT_MASK;
diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index f016682..fdbdfe4 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -51,6 +51,8 @@
 #include "exevents.h"
 #include "extinit.h"
 
+#include "xserver-properties.h"
+
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/syslimits.h>
@@ -336,17 +338,35 @@ static Bool DarwinAddScreen(int index, ScreenPtr pScreen, int argc, char **argv)
  * DarwinMouseProc: Handle the initialization, etc. of a mouse
  */
 static int DarwinMouseProc(DeviceIntPtr pPointer, int what) {
+#define NBUTTONS 7
+#define NAXES 2
 	// 7 buttons: left, right, middle, then four scroll wheel "buttons"
-    CARD8 map[8] = {0, 1, 2, 3, 4, 5, 6, 7};
-    
+    CARD8 map[NBUTTONS + 1] = {0, 1, 2, 3, 4, 5, 6, 7};
+    Atom btn_labels[NAXES] = {0};
+    Atom axes_labels[NBUTTONS] = {0};
+
     switch (what) {
         case DEVICE_INIT:
             pPointer->public.on = FALSE;
-            
+
+            btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
+            btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
+            btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
+            btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
+            btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
+            btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
+            btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
+
+            axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
+            axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
+
+
             // Set button map.
-            InitPointerDeviceStruct((DevicePtr)pPointer, map, 7,
+            InitPointerDeviceStruct((DevicePtr)pPointer, map, NBUTTONS,
+                                    btn_labels,
                                     (PtrCtrlProcPtr)NoopDDA,
-                                    GetMotionHistorySize(), 2);
+                                    GetMotionHistorySize(), NAXES,
+                                    axes_labels);
             pPointer->valuator->mode = Absolute; // Relative
             InitAbsoluteClassDeviceStruct(pPointer);
 //            InitValuatorAxisStruct(pPointer, 0, 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
@@ -364,28 +384,43 @@ static int DarwinMouseProc(DeviceIntPtr pPointer, int what) {
     }
     
     return Success;
+#undef NBUTTONS
+#undef NAXES
 }
 
 static int DarwinTabletProc(DeviceIntPtr pPointer, int what) {
-    CARD8 map[4] = {0, 1, 2, 3};
-    
+#define NBUTTONS 3
+#define NAXES 5
+    CARD8 map[NBUTTONS + 1] = {0, 1, 2, 3};
+    Atom axes_labels[NAXES] = {0};
+    Atom btn_labels[NBUTTONS] = {0};
+
     switch (what) {
         case DEVICE_INIT:
             pPointer->public.on = FALSE;
-            
+
+            btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
+            btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
+            btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
+
+            axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
+            axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
+
             // Set button map.
-            InitPointerDeviceStruct((DevicePtr)pPointer, map, 3,
+            InitPointerDeviceStruct((DevicePtr)pPointer, map, NBUTTONS,
+                                    btn_labels,
                                     (PtrCtrlProcPtr)NoopDDA,
-                                    GetMotionHistorySize(), 5);
+                                    GetMotionHistorySize(), NAXES,
+                                    axes_labels);
             pPointer->valuator->mode = Absolute; // Relative
             InitProximityClassDeviceStruct(pPointer);
 			InitAbsoluteClassDeviceStruct(pPointer);
 
-            InitValuatorAxisStruct(pPointer, 0, 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
-            InitValuatorAxisStruct(pPointer, 1, 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
-            InitValuatorAxisStruct(pPointer, 2, 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
-            InitValuatorAxisStruct(pPointer, 3, -XQUARTZ_VALUATOR_LIMIT, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
-            InitValuatorAxisStruct(pPointer, 4, -XQUARTZ_VALUATOR_LIMIT, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
+            InitValuatorAxisStruct(pPointer, 0, axes_labels[0], 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
+            InitValuatorAxisStruct(pPointer, 1, axes_labels[1], 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
+            InitValuatorAxisStruct(pPointer, 2, axes_labels[2], 0, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
+            InitValuatorAxisStruct(pPointer, 3, axes_labels[3], -XQUARTZ_VALUATOR_LIMIT, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
+            InitValuatorAxisStruct(pPointer, 4, axes_labels[4], -XQUARTZ_VALUATOR_LIMIT, XQUARTZ_VALUATOR_LIMIT, 1, 0, 1);
 //          pPointer->use = IsXExtensionDevice;
             break;
         case DEVICE_ON:
@@ -399,6 +434,8 @@ static int DarwinTabletProc(DeviceIntPtr pPointer, int what) {
             return Success;
     }
     return Success;
+#undef NBUTTONS
+#undef NAXES
 }
 
 /*
diff --git a/hw/xwin/winmouse.c b/hw/xwin/winmouse.c
index 9cfc945..e6d8913 100644
--- a/hw/xwin/winmouse.c
+++ b/hw/xwin/winmouse.c
@@ -38,6 +38,8 @@
 
 #if defined(XFree86Server)
 #include "inputstr.h"
+#include "exevents.h" /* for button/axes labels */
+#include "xserver-properties.h"
 
 /* Peek the internal button mapping */
 static CARD8 const *g_winMouseButtonMap = NULL;
@@ -70,6 +72,8 @@ winMouseProc (DeviceIntPtr pDeviceInt, int iState)
   int			lngWheelEvents = 2;
   CARD8			*map;
   DevicePtr		pDevice = (DevicePtr) pDeviceInt;
+  Atom *btn_labels;
+  Atom axes_labels[2];
 
   switch (iState)
     {
@@ -97,13 +101,27 @@ winMouseProc (DeviceIntPtr pDeviceInt, int iState)
       map[0] = 0;
       for (i=1; i <= lngMouseButtons + lngWheelEvents; i++)
       	map[i] = i;
+
+      btn_labels = calloc((lngMouseButtons + lngWheelEvents), sizeof(Atom));
+      btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
+      btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
+      btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
+      btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
+      btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
+
+      axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
+      axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
+
       InitPointerDeviceStruct (pDevice,
+			       btn_labels,
 			       map,
 			       lngMouseButtons + lngWheelEvents,
 			       winMouseCtrl,
 			       GetMotionHistorySize(),
-			       2);
+			       2,
+			       axes_labels);
       free(map);
+      free(btn_labels);
 
 #if defined(XFree86Server)
       g_winMouseButtonMap = pDeviceInt->button->map;
diff --git a/include/exevents.h b/include/exevents.h
index 80eaa76..861d0dd 100644
--- a/include/exevents.h
+++ b/include/exevents.h
@@ -73,6 +73,7 @@ extern _X_EXPORT int InitProximityClassDeviceStruct(
 extern _X_EXPORT void InitValuatorAxisStruct(
 	DeviceIntPtr           /* dev */,
 	int                    /* axnum */,
+	Atom                   /* label */,
 	int                    /* minval */,
 	int                    /* maxval */,
 	int                    /* resolution */,
diff --git a/include/input.h b/include/input.h
index b3d56b3..9711fa8 100644
--- a/include/input.h
+++ b/include/input.h
@@ -274,11 +274,13 @@ extern _X_EXPORT Bool SetKeySymsMap(
 extern _X_EXPORT Bool InitButtonClassDeviceStruct(
     DeviceIntPtr /*device*/,
     int /*numButtons*/,
+    Atom* /* labels */,
     CARD8* /*map*/);
 
 extern _X_EXPORT Bool InitValuatorClassDeviceStruct(
     DeviceIntPtr /*device*/,
     int /*numAxes*/,
+    Atom* /* labels */,
     int /*numMotionEvents*/,
     int /*mode*/);
 
@@ -351,9 +353,11 @@ extern _X_EXPORT Bool InitPointerDeviceStruct(
     DevicePtr /*device*/,
     CARD8* /*map*/,
     int /*numButtons*/,
+    Atom* /* btn_labels */,
     PtrCtrlProcPtr /*controlProc*/,
     int /*numMotionEvents*/,
-    int /*numAxes*/);
+    int /*numAxes*/,
+    Atom* /* axes_labels */);
 
 extern _X_EXPORT Bool InitKeyboardDeviceStruct(
     DeviceIntPtr /*device*/,
diff --git a/include/inputstr.h b/include/inputstr.h
index 23c34a5..b284ea4 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -215,6 +215,7 @@ typedef struct _AxisInfo {
     int		max_resolution;
     int		min_value;
     int		max_value;
+    Atom	label;
 } AxisInfo, *AxisInfoPtr;
 
 typedef struct _ValuatorAccelerationRec {
@@ -254,6 +255,7 @@ typedef struct _ButtonClassRec {
     CARD8		postdown[DOWN_LENGTH];
     CARD8		map[MAP_LENGTH];
     union _XkbAction    *xkb_acts;
+    Atom		labels[MAX_BUTTONS];
 } ButtonClassRec, *ButtonClassPtr;
 
 typedef struct _FocusClassRec {
commit 17f9723f488d0470e3879c6b0dfdba61544cdd7b
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Jun 17 08:37:44 2009 +1000

    input: bump to ints for deviceids - XI2 requires 16-bit deviceids.
    
    Note: ABI break, but ABI_XINPUT_VERSION has NOT been bumped. Recompile input
    drivers.
    
    Revert "Xi: return BadImplementation for deviceids 256 and above"
    This reverts commit 2b459f44f3edaea137df9a28bc7adfeb1b9f1df7.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xiallowev.c b/Xi/xiallowev.c
index dd52c53..3077e1a 100644
--- a/Xi/xiallowev.c
+++ b/Xi/xiallowev.c
@@ -65,12 +65,6 @@ ProcXIAllowEvents(ClientPtr client)
     REQUEST(xXIAllowEventsReq);
     REQUEST_SIZE_MATCH(xXIAllowEventsReq);
 
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
     ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
     if (ret != Success)
 	return ret;
diff --git a/Xi/xichangecursor.c b/Xi/xichangecursor.c
index ee2d65d..7517d2c 100644
--- a/Xi/xichangecursor.c
+++ b/Xi/xichangecursor.c
@@ -74,12 +74,6 @@ int ProcXIChangeCursor(ClientPtr client)
     REQUEST(xXIChangeCursorReq);
     REQUEST_SIZE_MATCH(xXIChangeCursorReq);
 
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
     rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixSetAttrAccess);
     if (rc != Success)
         return rc;
diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
index 944bb30..ef6c394 100644
--- a/Xi/xichangehierarchy.c
+++ b/Xi/xichangehierarchy.c
@@ -238,12 +238,6 @@ ProcXIChangeHierarchy(ClientPtr client)
                             r->return_mode != XIFloating)
                         return BadValue;
 
-                    if (r->deviceid > 0xFF) /* FIXME */
-                    {
-                        client->errorValue = r->deviceid;
-                        return BadImplementation;
-                    }
-
                     rc = dixLookupDevice(&ptr, r->deviceid, client,
                                          DixDestroyAccess);
                     if (rc != Success)
@@ -344,12 +338,6 @@ ProcXIChangeHierarchy(ClientPtr client)
                                      newptr,
                                      newkeybd;
 
-                        if (r->return_pointer > 0xFF) /* FIXME */
-                        {
-                            client->errorValue = r->deviceid;
-                            return BadImplementation;
-                        }
-
                         rc = dixLookupDevice(&newptr, r->return_pointer,
                                              client, DixWriteAccess);
                         if (rc != Success)
@@ -362,12 +350,6 @@ ProcXIChangeHierarchy(ClientPtr client)
                             goto unwind;
                         }
 
-                        if (r->return_keyboard > 0xFF) /* FIXME */
-                        {
-                            client->errorValue = r->deviceid;
-                            return BadImplementation;
-                        }
-
                         rc = dixLookupDevice(&newkeybd, r->return_keyboard,
                                              client, DixWriteAccess);
                         if (rc != Success)
@@ -431,12 +413,6 @@ ProcXIChangeHierarchy(ClientPtr client)
                     xXIDetachSlaveInfo* c = (xXIDetachSlaveInfo*)any;
                     DeviceIntPtr *xtstdevice;
 
-                    if (c->deviceid > 0xFF) /* FIXME */
-                    {
-                        client->errorValue = c->deviceid;
-                        return BadImplementation;
-                    }
-
                     rc = dixLookupDevice(&ptr, c->deviceid, client,
                                           DixWriteAccess);
                     if (rc != Success)
@@ -470,17 +446,6 @@ ProcXIChangeHierarchy(ClientPtr client)
                     DeviceIntPtr newmaster;
                     DeviceIntPtr *xtstdevice;
 
-                    if (c->deviceid > 0xFF) /* FIXME */
-                    {
-                        client->errorValue = c->deviceid;
-                        return BadImplementation;
-                    }
-                    if (c->new_master > 0xFF) /* FIXME */
-                    {
-                        client->errorValue = c->new_master;
-                        return BadImplementation;
-                    }
-
                     rc = dixLookupDevice(&ptr, c->deviceid, client,
                                           DixWriteAccess);
                     if (rc != Success)
diff --git a/Xi/xigrabdev.c b/Xi/xigrabdev.c
index a825a89..95beb83 100644
--- a/Xi/xigrabdev.c
+++ b/Xi/xigrabdev.c
@@ -70,9 +70,6 @@ ProcXIGrabDevice(ClientPtr client)
     REQUEST(xXIGrabDeviceReq);
     REQUEST_AT_LEAST_SIZE(xXIGrabDeviceReq);
 
-    if (stuff->deviceid > 0xFF) /* FIXME */
-        return BadImplementation;
-
     ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess);
     if (ret != Success)
 	return ret;
@@ -132,12 +129,6 @@ ProcXIUngrabDevice(ClientPtr client)
 
     REQUEST(xXIUngrabDeviceReq);
 
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
     ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
     if (ret != Success)
 	return ret;
diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
index a5a9570..df0f5be 100644
--- a/Xi/xipassivegrab.c
+++ b/Xi/xipassivegrab.c
@@ -90,9 +90,6 @@ ProcXIPassiveGrabDevice(ClientPtr client)
     REQUEST(xXIPassiveGrabDeviceReq);
     REQUEST_AT_LEAST_SIZE(xXIPassiveGrabDeviceReq);
 
-    if (stuff->deviceid > 0xFF) /* FIXME */
-        return BadImplementation;
-
     if (stuff->deviceid == XIAllDevices)
         dev = inputInfo.all_devices;
     else if (stuff->deviceid == XIAllMasterDevices)
@@ -263,12 +260,6 @@ ProcXIPassiveUngrabDevice(ClientPtr client)
     REQUEST(xXIPassiveUngrabDeviceReq);
     REQUEST_AT_LEAST_SIZE(xXIPassiveUngrabDeviceReq);
 
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
     rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess);
     if (rc != Success)
 	return rc;
diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c
index dc54d10..cd49460 100644
--- a/Xi/xiproperty.c
+++ b/Xi/xiproperty.c
@@ -1102,12 +1102,6 @@ ProcXIListProperties(ClientPtr client)
     REQUEST(xXIListPropertiesReq);
     REQUEST_SIZE_MATCH(xXIListPropertiesReq);
 
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
     rc = dixLookupDevice (&dev, stuff->deviceid, client, DixReadAccess);
     if (rc != Success)
         return rc;
@@ -1142,12 +1136,6 @@ ProcXIChangeProperty(ClientPtr client)
 
     REQUEST(xXIChangePropertyReq);
     REQUEST_AT_LEAST_SIZE(xXIChangePropertyReq);
-
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
     UpdateCurrentTime();
 
     rc = dixLookupDevice (&dev, stuff->deviceid, client, DixWriteAccess);
@@ -1176,13 +1164,6 @@ ProcXIDeleteProperty(ClientPtr client)
     REQUEST(xXIDeletePropertyReq);
 
     REQUEST_SIZE_MATCH(xXIDeletePropertyReq);
-
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
     UpdateCurrentTime();
     rc =  dixLookupDevice (&dev, stuff->deviceid, client, DixWriteAccess);
     if (rc != Success)
@@ -1211,13 +1192,6 @@ ProcXIGetProperty(ClientPtr client)
     Atom                        type;
 
     REQUEST_SIZE_MATCH(xXIGetPropertyReq);
-
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
     if (stuff->delete)
         UpdateCurrentTime();
     rc = dixLookupDevice (&dev, stuff->deviceid, client,
diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
index 2e480f5..cc57815 100644
--- a/Xi/xiquerydevice.c
+++ b/Xi/xiquerydevice.c
@@ -70,12 +70,6 @@ ProcXIQueryDevice(ClientPtr client)
     REQUEST(xXIQueryDeviceReq);
     REQUEST_SIZE_MATCH(xXIQueryDeviceReq);
 
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
     if (stuff->deviceid != XIAllDevices && stuff->deviceid != XIAllMasterDevices)
     {
         rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
diff --git a/Xi/xiquerypointer.c b/Xi/xiquerypointer.c
index 1d00b9e..e770e84 100644
--- a/Xi/xiquerypointer.c
+++ b/Xi/xiquerypointer.c
@@ -81,12 +81,6 @@ ProcXIQueryPointer(ClientPtr client)
     REQUEST(xXIQueryPointerReq);
     REQUEST_SIZE_MATCH(xXIQueryPointerReq);
 
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
     rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixReadAccess);
     if (rc != Success)
         return rc;
diff --git a/Xi/xiselectev.c b/Xi/xiselectev.c
index 7a16e85..a8763a2 100644
--- a/Xi/xiselectev.c
+++ b/Xi/xiselectev.c
@@ -85,12 +85,6 @@ ProcXISelectEvents(ClientPtr client)
     num_masks = stuff->num_masks;
     while(num_masks--)
     {
-        if (evmask->deviceid > 0xFF) /* FIXME */
-        {
-            client->errorValue = evmask->deviceid;
-            return BadImplementation;
-        }
-
         if (evmask->deviceid != XIAllDevices &&
             evmask->deviceid != XIAllMasterDevices)
             rc = dixLookupDevice(&dev, evmask->deviceid, client, DixReadAccess);
diff --git a/Xi/xisetclientpointer.c b/Xi/xisetclientpointer.c
index 2648074..afc13d6 100644
--- a/Xi/xisetclientpointer.c
+++ b/Xi/xisetclientpointer.c
@@ -71,11 +71,6 @@ ProcXISetClientPointer(ClientPtr client)
     REQUEST(xXISetClientPointerReq);
     REQUEST_SIZE_MATCH(xXISetClientPointerReq);
 
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
 
     rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixWriteAccess);
     if (rc != Success)
diff --git a/Xi/xisetdevfocus.c b/Xi/xisetdevfocus.c
index cd1f6a6..32f7e59 100644
--- a/Xi/xisetdevfocus.c
+++ b/Xi/xisetdevfocus.c
@@ -75,12 +75,6 @@ ProcXISetFocus(ClientPtr client)
     REQUEST(xXISetFocusReq);
     REQUEST_AT_LEAST_SIZE(xXISetFocusReq);
 
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
     ret = dixLookupDevice(&dev, stuff->deviceid, client, DixSetFocusAccess);
     if (ret != Success)
 	return ret;
@@ -101,12 +95,6 @@ ProcXIGetFocus(ClientPtr client)
     REQUEST(xXIGetFocusReq);
     REQUEST_AT_LEAST_SIZE(xXIGetFocusReq);
 
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
     ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGetFocusAccess);
     if (ret != Success)
 	return ret;
diff --git a/Xi/xiwarppointer.c b/Xi/xiwarppointer.c
index f3acfe4..105c87a 100644
--- a/Xi/xiwarppointer.c
+++ b/Xi/xiwarppointer.c
@@ -76,12 +76,6 @@ ProcXIWarpPointer(ClientPtr client)
     REQUEST(xXIWarpPointerReq);
     REQUEST_SIZE_MATCH(xXIWarpPointerReq);
 
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
     /* FIXME: panoramix stuff is missing, look at ProcWarpPointer */
 
     rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixWriteAccess);
diff --git a/dix/devices.c b/dix/devices.c
index 5d4d3b2..517829a 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1050,11 +1050,11 @@ dixLookupDevice(DeviceIntPtr *pDev, int id, ClientPtr client, Mask access_mode)
     *pDev = NULL;
 
     for (dev=inputInfo.devices; dev; dev=dev->next) {
-        if (dev->id == (CARD8)id)
+        if (dev->id == id)
             goto found;
     }
     for (dev=inputInfo.off_devices; dev; dev=dev->next) {
-        if (dev->id == (CARD8)id)
+        if (dev->id == id)
 	    goto found;
     }
     return BadDevice;
diff --git a/include/inputstr.h b/include/inputstr.h
index 10062ad..23c34a5 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -489,7 +489,7 @@ typedef struct _DeviceIntRec {
     int         type;                   /* MASTER_POINTER, MASTER_KEYBOARD, SLAVE */
     Atom		xinput_type;
     char		*name;
-    CARD8		id;
+    int			id;
     KeyClassPtr		key;
     ValuatorClassPtr	valuator;
     ButtonClassPtr	button;
commit cbeb73e2055f6c013c8fe6325851f2631170137d
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jun 16 10:51:52 2009 +1000

    Xi: return current valuator values in XIQueryDevice.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
index 2c01863..2e480f5 100644
--- a/Xi/xiquerydevice.c
+++ b/Xi/xiquerydevice.c
@@ -324,6 +324,8 @@ ListValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info, int axisnumber)
     info->min.frac = 0;
     info->max.integral = v->axes[axisnumber].max_value;
     info->max.frac = 0;
+    info->value.integral = (int)v->axisVal[axisnumber];
+    info->value.frac = (int)(v->axisVal[axisnumber] * (1 << 16) * (1 << 16));
     info->resolution = v->axes[axisnumber].resolution;
     info->number = axisnumber;
     info->mode = v->mode; /* Server doesn't have per-axis mode yet */
commit 80837dbefd9d5e96ab5c1f4b4c2d5c66ce17ce67
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jun 16 10:51:17 2009 +1000

    input: change axisVal from uint to double.
    
    With subpixel support, uint just doesn't cut it.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 0d8322a..dc9eba7 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -539,7 +539,7 @@ DeepCopyPointerClasses(DeviceIntPtr from, DeviceIntPtr to)
 
         to->valuator = xrealloc(to->valuator, sizeof(ValuatorClassRec) +
                 from->valuator->numAxes * sizeof(AxisInfo) +
-                from->valuator->numAxes * sizeof(unsigned int));
+                from->valuator->numAxes * sizeof(double));
         v = to->valuator;
         if (!v)
             FatalError("[Xi] no memory for class shift.\n");
@@ -548,7 +548,7 @@ DeepCopyPointerClasses(DeviceIntPtr from, DeviceIntPtr to)
         v->axes = (AxisInfoPtr)&v[1];
         memcpy(v->axes, from->valuator->axes, v->numAxes * sizeof(AxisInfo));
 
-        v->axisVal = (int*)(v->axes + from->valuator->numAxes);
+        v->axisVal = (double*)(v->axes + from->valuator->numAxes);
         v->sourceid = from->id;
     } else if (to->valuator && !from->valuator)
     {
@@ -844,6 +844,7 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
         {
             /* XXX: Relative/Absolute mode */
             v->axisVal[i] = event->valuators.data[i];
+            v->axisVal[i] += event->valuators.data_frac[i];
         }
     }
 
diff --git a/Xi/queryst.c b/Xi/queryst.c
index 2b20837..c6858e4 100644
--- a/Xi/queryst.c
+++ b/Xi/queryst.c
@@ -85,7 +85,7 @@ ProcXQueryDeviceState(ClientPtr client)
     xValuatorState *tv;
     xQueryDeviceStateReply rep;
     DeviceIntPtr dev;
-    int *values;
+    double *values;
 
     REQUEST(xQueryDeviceStateReq);
     REQUEST_SIZE_MATCH(xQueryDeviceStateReq);
diff --git a/dix/devices.c b/dix/devices.c
index a5b111c..5d4d3b2 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1170,7 +1170,7 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes,
 
     valc = (ValuatorClassPtr)xcalloc(1, sizeof(ValuatorClassRec) +
 				    numAxes * sizeof(AxisInfo) +
-				    numAxes * sizeof(unsigned int));
+				    numAxes * sizeof(double));
     if (!valc)
 	return FALSE;
 
@@ -1184,7 +1184,7 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes,
     valc->numAxes = numAxes;
     valc->mode = mode;
     valc->axes = (AxisInfoPtr)(valc + 1);
-    valc->axisVal = (int *)(valc->axes + numAxes);
+    valc->axisVal = (double *)(valc->axes + numAxes);
     dev->valuator = valc;
 
     AllocateMotionHistory(dev);
diff --git a/include/inputstr.h b/include/inputstr.h
index d7aedac..10062ad 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -235,7 +235,7 @@ typedef struct _ValuatorClassRec {
 
     AxisInfoPtr 	  axes;
     unsigned short	  numAxes;
-    int			  *axisVal; /* always absolute, but device-coord system */
+    double		  *axisVal; /* always absolute, but device-coord system */
     CARD8	 	  mode;
     ValuatorAccelerationRec	accelScheme;
 } ValuatorClassRec, *ValuatorClassPtr;
commit 25b6fc4a42f7698e6ae0b16becb316bfd7835d05
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jun 16 10:48:48 2009 +1000

    Xi: last_valuator is used like an index, so range it accordingly.
    
    The previous code would always skip the last valuator due to a wrong
    upper boundary in the loop. last_valuator is the index of the last set
    valuator - which also means it must be initialized to -1, not 0.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 821644d..0d8322a 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -818,7 +818,7 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
 
     /* Update device axis */
     /* Check valuators first */
-    last_valuator = 0;
+    last_valuator = -1;
     for (i = 0; i < MAX_VALUATORS; i++)
     {
         if (BitIsOn(&event->valuators.mask, i))
@@ -838,7 +838,7 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
         }
     }
 
-    for (i = 0; i < last_valuator && i < v->numAxes; i++)
+    for (i = 0; i <= last_valuator && i < v->numAxes; i++)
     {
         if (BitIsOn(&event->valuators.mask, i))
         {
commit 3fc762ea9474cf92f6b7ef60dd0bb68f59385272
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jun 16 10:48:03 2009 +1000

    Xi: Motion events update the device state too.
    
    Without this line the device's axis values don't get updated properly for
    pure motion events.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index e404b84..821644d 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -796,6 +796,7 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent* event)
         case ET_DeviceChanged:
             ChangeMasterDeviceClasses(device, (DeviceChangedEvent*)event);
             return DONT_PROCESS; /* event has been sent already */
+        case ET_Motion:
         case ET_ButtonPress:
         case ET_ButtonRelease:
         case ET_KeyPress:
commit ad6347afead500fefb34131841f4beb5b03ad4ec
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jun 16 16:35:40 2009 +1000

    Xi: don't use a constant number for class sizes - use sizeof instead
    
    The protocol is still changing, and having to debug crap like this is
    annoying.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
index 98325e1..2c01863 100644
--- a/Xi/xiquerydevice.c
+++ b/Xi/xiquerydevice.c
@@ -237,7 +237,7 @@ ListButtonInfo(DeviceIntPtr dev, xXIButtonInfo* info)
 
     info->type = ButtonClass;
     info->num_buttons = dev->button->numButtons;
-    info->length = 2 + mask_len + info->num_buttons;
+    info->length = sizeof(xXIButtonInfo)/4 + mask_len + info->num_buttons;
     info->sourceid = dev->button->sourceid;
 
     bits = (unsigned char*)&info[1];
@@ -281,7 +281,7 @@ ListKeyInfo(DeviceIntPtr dev, xXIKeyInfo* info)
 
     info->type = KeyClass;
     info->num_keycodes = xkb->max_key_code - xkb->min_key_code + 1;
-    info->length = 2 + info->num_keycodes;
+    info->length = sizeof(xXIKeyInfo)/4 + info->num_keycodes;
     info->sourceid = dev->key->sourceid;
 
     kc = (uint32_t*)&info[1];
commit d5a15e65b7d2fdda14fb719e3ebf076cce896386
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Sun Jun 14 09:15:42 2009 +1000

    Xi: include button state in XIButtonInfo.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 107ffce..e404b84 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -686,6 +686,7 @@ XISendDeviceChangedEvent(DeviceIntPtr device, DeviceIntPtr master, DeviceChanged
     {
         len += sizeof(xXIButtonInfo);
         len += dce->buttons.num_buttons * sizeof(Atom); /* button names */
+        len += ((((dce->buttons.num_buttons + 7)/8) + 3)/4) * 4;
     }
     if (dce->num_valuators)
         len += sizeof(xXIValuatorInfo) * dce->num_valuators;
diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
index b523f38..98325e1 100644
--- a/Xi/xiquerydevice.c
+++ b/Xi/xiquerydevice.c
@@ -205,6 +205,7 @@ SizeDeviceClasses(DeviceIntPtr dev)
     {
         len += sizeof(xXIButtonInfo);
         len += dev->button->numButtons * sizeof(Atom);
+        len += ((((dev->button->numButtons + 7)/8) + 3)/4) * 4;
     }
 
     if (dev->key)
@@ -228,11 +229,24 @@ SizeDeviceClasses(DeviceIntPtr dev)
 int
 ListButtonInfo(DeviceIntPtr dev, xXIButtonInfo* info)
 {
+    unsigned char *bits;
+    int mask_len;
+    int i;
+
+    mask_len = (((dev->button->numButtons + 7)/8) + 3)/4; /* 4-byte units*/
+
     info->type = ButtonClass;
     info->num_buttons = dev->button->numButtons;
-    info->length = 2 + info->num_buttons;
+    info->length = 2 + mask_len + info->num_buttons;
     info->sourceid = dev->button->sourceid;
 
+    bits = (unsigned char*)&info[1];
+    memset(bits, 0, mask_len * 4);
+
+    for (i = 0; dev && dev->button && i < dev->button->numButtons; i++)
+        if (BitIsOn(dev->button->down, i))
+            SetBit(bits, i);
+
     /** XXX: button labels */
 
     return info->length * 4;
commit 01241b4247a7ad0974d48412cc0d88e1a09a3c49
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Sun Jun 7 19:43:11 2009 +1000

    Xi: Add support for sourceid in the device classes.

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 24fd11f..107ffce 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -199,6 +199,8 @@ CopyKeyClass(DeviceIntPtr device, DeviceIntPtr master)
     if (device == master)
         return;
 
+    mk->sourceid = device->id;
+
     for (i = 0; i < 8; i++)
         mk->modifierKeyCount[i] = dk->modifierKeyCount[i];
 
@@ -470,6 +472,7 @@ DeepCopyKeyboardClasses(DeviceIntPtr from, DeviceIntPtr to)
                 FatalError("[Xi] no memory for trace.\n");
             memcpy(to->focus->trace, from->focus->trace,
                     from->focus->traceSize * sizeof(WindowPtr));
+            to->focus->sourceid = from->id;
         }
     } else if (to->focus)
     {
@@ -546,6 +549,7 @@ DeepCopyPointerClasses(DeviceIntPtr from, DeviceIntPtr to)
         memcpy(v->axes, from->valuator->axes, v->numAxes * sizeof(AxisInfo));
 
         v->axisVal = (int*)(v->axes + from->valuator->numAxes);
+        v->sourceid = from->id;
     } else if (to->valuator && !from->valuator)
     {
         ClassesPtr classes;
@@ -582,6 +586,8 @@ DeepCopyPointerClasses(DeviceIntPtr from, DeviceIntPtr to)
                     sizeof(XkbAction));
         } else
             xfree(to->button->xkb_acts);
+
+        to->button->sourceid = from->id;
     } else if (to->button && !from->button)
     {
         ClassesPtr classes;
@@ -606,6 +612,7 @@ DeepCopyPointerClasses(DeviceIntPtr from, DeviceIntPtr to)
                 classes->proximity = NULL;
         }
         memcpy(to->proximity, from->proximity, sizeof(ProximityClassRec));
+        to->proximity->sourceid = from->id;
     } else if (to->proximity)
     {
         ClassesPtr classes;
@@ -630,6 +637,7 @@ DeepCopyPointerClasses(DeviceIntPtr from, DeviceIntPtr to)
                 classes->absolute = NULL;
         }
         memcpy(to->absolute, from->absolute, sizeof(AbsoluteClassRec));
+        to->absolute->sourceid = from->id;
     } else if (to->absolute)
     {
         ClassesPtr classes;
@@ -1127,6 +1135,7 @@ InitProximityClassDeviceStruct(DeviceIntPtr dev)
     proxc = (ProximityClassPtr) xalloc(sizeof(ProximityClassRec));
     if (!proxc)
 	return FALSE;
+    proxc->sourceid = dev->id;
     dev->proximity = proxc;
     return TRUE;
 }
diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
index 07ddfa1..b523f38 100644
--- a/Xi/xiquerydevice.c
+++ b/Xi/xiquerydevice.c
@@ -231,6 +231,7 @@ ListButtonInfo(DeviceIntPtr dev, xXIButtonInfo* info)
     info->type = ButtonClass;
     info->num_buttons = dev->button->numButtons;
     info->length = 2 + info->num_buttons;
+    info->sourceid = dev->button->sourceid;
 
     /** XXX: button labels */
 
@@ -245,6 +246,7 @@ SwapButtonInfo(DeviceIntPtr dev, xXIButtonInfo* info)
     int i;
     swaps(&info->type, n);
     swaps(&info->length, n);
+    swaps(&info->sourceid, n);
 
     for (i = 0, btn = (Atom*)&info[1]; i < info->num_buttons; i++, btn++)
         swaps(btn, n);
@@ -266,6 +268,7 @@ ListKeyInfo(DeviceIntPtr dev, xXIKeyInfo* info)
     info->type = KeyClass;
     info->num_keycodes = xkb->max_key_code - xkb->min_key_code + 1;
     info->length = 2 + info->num_keycodes;
+    info->sourceid = dev->key->sourceid;
 
     kc = (uint32_t*)&info[1];
     for (i = xkb->min_key_code; i <= xkb->max_key_code; i++, kc++)
@@ -282,6 +285,7 @@ SwapKeyInfo(DeviceIntPtr dev, xXIKeyInfo* info)
     int i;
     swaps(&info->type, n);
     swaps(&info->length, n);
+    swaps(&info->sourceid, n);
 
     for (i = 0, key = (uint32_t*)&info[1]; i < info->num_keycodes; i++, key++)
         swapl(key, n);
@@ -309,6 +313,7 @@ ListValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info, int axisnumber)
     info->resolution = v->axes[axisnumber].resolution;
     info->number = axisnumber;
     info->mode = v->mode; /* Server doesn't have per-axis mode yet */
+    info->sourceid = v->sourceid;
 
     return info->length * 4;
 }
@@ -325,6 +330,7 @@ SwapValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info)
     swapl(&info->max.integral, n);
     swapl(&info->max.frac, n);
     swaps(&info->number, n);
+    swaps(&info->sourceid, n);
 }
 
 int GetDeviceUse(DeviceIntPtr dev, uint16_t *attachment)
diff --git a/dix/devices.c b/dix/devices.c
index 2b03588..a5b111c 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1143,6 +1143,7 @@ InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons,
     if (!butc)
 	return FALSE;
     butc->numButtons = numButtons;
+    butc->sourceid = dev->id;
     for (i = 1; i <= numButtons; i++)
 	butc->map[i] = map[i];
     dev->button = butc;
@@ -1173,6 +1174,7 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes,
     if (!valc)
 	return FALSE;
 
+    valc->sourceid = dev->id;
     valc->motion = NULL;
     valc->first_motion = 0;
     valc->last_motion = 0;
@@ -1300,6 +1302,8 @@ InitAbsoluteClassDeviceStruct(DeviceIntPtr dev)
     abs->following = 0;
     abs->screen = 0;
 
+    abs->sourceid = dev->id;
+
     dev->absolute = abs;
 
     return TRUE;
@@ -1319,6 +1323,7 @@ InitFocusClassDeviceStruct(DeviceIntPtr dev)
     focc->trace = (WindowPtr *)NULL;
     focc->traceSize = 0;
     focc->traceGood = 0;
+    focc->sourceid = dev->id;
     dev->focus = focc;
     return TRUE;
 }
diff --git a/include/inputstr.h b/include/inputstr.h
index ffeedb1..d7aedac 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -202,6 +202,7 @@ typedef struct _GrabRec {
 } GrabRec;
 
 typedef struct _KeyClassRec {
+    int			sourceid;
     CARD8		down[DOWN_LENGTH];
     CARD8		postdown[DOWN_LENGTH];
     int                 modifierKeyCount[8];
@@ -224,6 +225,7 @@ typedef struct _ValuatorAccelerationRec {
 } ValuatorAccelerationRec, *ValuatorAccelerationPtr;
 
 typedef struct _ValuatorClassRec {
+    int                   sourceid;
     int		 	  numMotionEvents;
     int                   first_motion;
     int                   last_motion;
@@ -239,6 +241,7 @@ typedef struct _ValuatorClassRec {
 } ValuatorClassRec, *ValuatorClassPtr;
 
 typedef struct _ButtonClassRec {
+    int			sourceid;
     CARD8		numButtons;
     CARD8		buttonsDown;	/* number of buttons currently down
                                            This counts logical buttons, not
@@ -254,6 +257,7 @@ typedef struct _ButtonClassRec {
 } ButtonClassRec, *ButtonClassPtr;
 
 typedef struct _FocusClassRec {
+    int		sourceid;
     WindowPtr	win; /* May be set to a int constant (e.g. PointerRootWin)! */
     int		revert;
     TimeStamp	time;
@@ -263,10 +267,12 @@ typedef struct _FocusClassRec {
 } FocusClassRec, *FocusClassPtr;
 
 typedef struct _ProximityClassRec {
+    int		sourceid;
     char	pad;
 } ProximityClassRec, *ProximityClassPtr;
 
 typedef struct _AbsoluteClassRec {
+    int         sourceid;
     /* Calibration. */
     int         min_x;
     int         max_x;
diff --git a/xkb/xkbInit.c b/xkb/xkbInit.c
index e707f7a..86a7a11 100644
--- a/xkb/xkbInit.c
+++ b/xkb/xkbInit.c
@@ -522,6 +522,7 @@ InitKeyboardDeviceStruct(DeviceIntPtr dev, XkbRMLVOSet *rmlvo,
         ErrorF("XKB: Failed to allocate key class\n");
         return False;
     }
+    dev->key->sourceid = dev->id;
 
     dev->kbdfeed = xcalloc(1, sizeof(*dev->kbdfeed));
     if (!dev->kbdfeed) {
commit d230742ea820a21a3f1ed0c58b5e6d8680b2f2aa
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jun 16 12:13:16 2009 +1000

    Xi: namespace XI2 files.
    
    Some files (notably those merged with MPX before XI2 came along) didn't use
    a 'xi' prefix. This patch changes all of them to meaningful names.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/Makefile.am b/Xi/Makefile.am
index 56404b6..69c7886 100644
--- a/Xi/Makefile.am
+++ b/Xi/Makefile.am
@@ -5,12 +5,8 @@ AM_CFLAGS = $(DIX_CFLAGS)
 libXi_la_SOURCES =	\
 	allowev.c \
 	allowev.h \
-        chdevcur.c \
-        chdevcur.h \
 	chgdctl.c \
 	chgdctl.h \
-        chdevhier.c \
-        chdevhier.h \
 	chgfctl.c \
 	chgfctl.h \
 	chgkbd.c \
@@ -30,8 +26,6 @@ libXi_la_SOURCES =	\
 	extinit.c \
 	getbmap.c \
 	getbmap.h \
-	getcptr.c \
-	getcptr.h \
 	getdctl.c \
 	getdctl.h \
 	getfctl.c \
@@ -60,12 +54,6 @@ libXi_la_SOURCES =	\
 	listdev.h \
 	opendev.c \
 	opendev.h \
-	querydev.c \
-	querydev.h \
-	queryversion.h \
-	queryversion.c \
-	querydp.c \
-	querydp.h \
 	queryst.c \
 	queryst.h \
 	selectev.c \
@@ -74,8 +62,6 @@ libXi_la_SOURCES =	\
 	sendexev.h \
 	setbmap.c \
 	setbmap.h \
-	setcptr.c \
-	setcptr.h \
 	setdval.c \
 	setdval.h \
 	setfocus.c \
@@ -90,19 +76,33 @@ libXi_la_SOURCES =	\
 	ungrdevb.h \
 	ungrdevk.c \
 	ungrdevk.h \
-	warpdevp.c \
-	warpdevp.h \
 	xiallowev.c \
 	xiallowev.h \
+	xichangecursor.c \
+	xichangecursor.h \
+	xichangehierarchy.c \
+	xichangehierarchy.h \
+	xigetclientpointer.c \
+	xigetclientpointer.h \
 	xigrabdev.c \
 	xigrabdev.h \
 	xipassivegrab.h \
 	xipassivegrab.c \
 	xiproperty.c \
 	xiproperty.h \
+	xiquerydevice.c \
+	xiquerydevice.h \
+	xiquerypointer.c \
+	xiquerypointer.h \
+	xiqueryversion.c \
+	xiqueryversion.h \
 	xiselectev.c \
 	xiselectev.h \
+	xisetclientpointer.c \
+	xisetclientpointer.h \
 	xisetdevfocus.c \
-	xisetdevfocus.h
+	xisetdevfocus.h \
+	xiwarppointer.c \
+	xiwarppointer.h
 
 EXTRA_DIST = stubs.c
diff --git a/Xi/chdevcur.c b/Xi/chdevcur.c
deleted file mode 100644
index 9dba78b..0000000
--- a/Xi/chdevcur.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright 2007-2008 Peter Hutterer
- *
- * 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: Peter Hutterer, University of South Australia, NICTA
- */
-
-/***********************************************************************
- *
- * Request to change a given device pointer's cursor.
- *
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/X.h>	/* for inputstr.h    */
-#include <X11/Xproto.h>	/* Request macro     */
-#include "inputstr.h"	/* DeviceIntPtr      */
-#include "windowstr.h"	/* window structure  */
-#include "scrnintstr.h"	/* screen structure  */
-#include <X11/extensions/XI.h>
-#include <X11/extensions/XI2proto.h>
-#include "extnsionst.h"
-#include "exevents.h"
-#include "exglobals.h"
-#include "input.h"
-
-#include "chdevcur.h"
-
-/***********************************************************************
- *
- * This procedure allows a client to set one pointer's cursor.
- *
- */
-
-int
-SProcXIChangeCursor(ClientPtr client)
-{
-    char n;
-
-    REQUEST(xXIChangeCursorReq);
-    swaps(&stuff->length, n);
-    REQUEST_SIZE_MATCH(xXIChangeCursorReq);
-    return (ProcXIChangeCursor(client));
-}
-
-int ProcXIChangeCursor(ClientPtr client)
-{
-    int rc;
-    WindowPtr pWin    = NULL;
-    DeviceIntPtr pDev = NULL;
-    CursorPtr pCursor = NULL;
-
-    REQUEST(xXIChangeCursorReq);
-    REQUEST_SIZE_MATCH(xXIChangeCursorReq);
-
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
-    rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixSetAttrAccess);
-    if (rc != Success)
-        return rc;
-
-    if (stuff->win != None)
-    {
-        rc = dixLookupWindow(&pWin, stuff->win, client, DixSetAttrAccess);
-        if (rc != Success)
-            return rc;
-    }
-
-    if (stuff->cursor == None)
-    {
-        if (pWin == WindowTable[pWin->drawable.pScreen->myNum])
-            pCursor = rootCursor;
-        else
-            pCursor = (CursorPtr)None;
-    }
-    else
-    {
-	rc = dixLookupResourceByType((pointer *)&pCursor, stuff->cursor,
-				     RT_CURSOR, client, DixReadAccess);
-	if (rc != Success)
-	    return (rc == BadValue) ? BadCursor : rc;
-    }
-
-    ChangeWindowDeviceCursor(pWin, pDev, pCursor);
-
-    return Success;
-}
-
diff --git a/Xi/chdevcur.h b/Xi/chdevcur.h
deleted file mode 100644
index dc6ccb1..0000000
--- a/Xi/chdevcur.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2007-2008 Peter Hutterer
- *
- * 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: Peter Hutterer, University of South Australia, NICTA
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifndef CHDEVCUR_H
-#define CHDEVCUR_H 1
-
-int SProcXIChangeCursor(ClientPtr /* client */);
-int ProcXIChangeCursor(ClientPtr /* client */);
-
-#endif /* CHDEVCUR_H */
diff --git a/Xi/chdevhier.c b/Xi/chdevhier.c
deleted file mode 100644
index 3f2bb93..0000000
--- a/Xi/chdevhier.c
+++ /dev/null
@@ -1,540 +0,0 @@
-/*
- * Copyright 2007-2008 Peter Hutterer
- * Copyright 2009 Red Hat, Inc.
- *
- * 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: Peter Hutterer, University of South Australia, NICTA
- */
-
-/***********************************************************************
- *
- * Request change in the device hierarchy.
- *
- */
-
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/X.h>	/* for inputstr.h    */
-#include <X11/Xproto.h>	/* Request macro     */
-#include "inputstr.h"	/* DeviceIntPtr      */
-#include "windowstr.h"	/* window structure  */
-#include "scrnintstr.h"	/* screen structure  */
-#include <X11/extensions/XI.h>
-#include <X11/extensions/XI2proto.h>
-#include <X11/extensions/geproto.h>
-#include "extnsionst.h"
-#include "exevents.h"
-#include "exglobals.h"
-#include "geext.h"
-#include "xace.h"
-#include "querydev.h" /* for GetDeviceUse */
-
-#include "xkbsrv.h"
-
-#include "chdevhier.h"
-
-extern DevPrivateKey XTstDevicePrivateKey;
-
-/**
- * Send the current state of the device hierarchy to all clients.
- */
-void XISendDeviceHierarchyEvent(int flags[MAXDEVICES])
-{
-    xXIHierarchyEvent *ev;
-    xXIHierarchyInfo *info;
-    DeviceIntRec dummyDev;
-    DeviceIntPtr dev;
-    int i;
-
-    if (!flags)
-        return;
-
-    ev = xcalloc(1, sizeof(xXIHierarchyEvent) +
-                 MAXDEVICES * sizeof(xXIHierarchyInfo));
-    ev->type = GenericEvent;
-    ev->extension = IReqCode;
-    ev->evtype = XI_HierarchyChanged;
-    ev->time = GetTimeInMillis();
-    ev->flags = 0;
-    ev->num_info = inputInfo.numDevices;
-
-    info = (xXIHierarchyInfo*)&ev[1];
-    for (dev = inputInfo.devices; dev; dev = dev->next)
-    {
-        info->deviceid = dev->id;
-        info->enabled = dev->enabled;
-        info->use = GetDeviceUse(dev, &info->attachment);
-        info->flags = flags[dev->id];
-        ev->flags |= info->flags;
-        info++;
-    }
-    for (dev = inputInfo.off_devices; dev; dev = dev->next)
-    {
-        info->deviceid = dev->id;
-        info->enabled = dev->enabled;
-        info->use = GetDeviceUse(dev, &info->attachment);
-        info->flags = flags[dev->id];
-        ev->flags |= info->flags;
-        info++;
-    }
-
-
-    for (i = 0; i < MAXDEVICES; i++)
-    {
-        if (flags[i] & (XIMasterRemoved | XISlaveRemoved))
-        {
-            info->deviceid = i;
-            info->enabled = FALSE;
-            info->flags = flags[i];
-            info->use = 0;
-            ev->flags |= info->flags;
-            ev->num_info++;
-            info++;
-        }
-    }
-
-    ev->length = (ev->num_info * sizeof(xXIHierarchyInfo))/4;
-
-    dummyDev.id = XIAllDevices;
-    SendEventToAllWindows(&dummyDev, (XI_HierarchyChangedMask >> 8), (xEvent*)ev, 1);
-}
-
-
-/***********************************************************************
- *
- * This procedure allows a client to change the device hierarchy through
- * adding new master devices, removing them, etc.
- *
- */
-
-int SProcXIChangeHierarchy(ClientPtr client)
-{
-    char n;
-
-    REQUEST(xXIChangeHierarchyReq);
-    swaps(&stuff->length, n);
-    return (ProcXIChangeHierarchy(client));
-}
-
-#define SWAPIF(cmd) if (client->swapped) { cmd; }
-
-int
-ProcXIChangeHierarchy(ClientPtr client)
-{
-    DeviceIntPtr ptr, keybd, xtstptr, xtstkeybd;
-    xXIAnyHierarchyChangeInfo *any;
-    int required_len = sizeof(xXIChangeHierarchyReq);
-    char n;
-    int rc = Success;
-    int flags[MAXDEVICES] = {0};
-
-    REQUEST(xXIChangeHierarchyReq);
-    REQUEST_AT_LEAST_SIZE(xXIChangeHierarchyReq);
-
-    if (!stuff->num_changes)
-        return rc;
-
-    any = (xXIAnyHierarchyChangeInfo*)&stuff[1];
-    while(stuff->num_changes--)
-    {
-        SWAPIF(swapl(&any->type, n));
-        SWAPIF(swaps(&any->length, n));
-
-        required_len += any->length;
-        if ((stuff->length * 4) < required_len)
-            return BadLength;
-
-        switch(any->type)
-        {
-            case XIAddMaster:
-                {
-                    xXIAddMasterInfo* c = (xXIAddMasterInfo*)any;
-                    char* name;
-
-                    SWAPIF(swaps(&c->name_len, n));
-                    name = xcalloc(c->name_len + 1, sizeof(char));
-                    strncpy(name, (char*)&c[1], c->name_len);
-
-
-                    rc = AllocDevicePair(client, name, &ptr, &keybd, TRUE);
-                    if (rc != Success)
-                    {
-                        xfree(name);
-                        goto unwind;
-                    }
-
-                    if (!c->send_core)
-                        ptr->coreEvents = keybd->coreEvents =  FALSE;
-
-		    /* Allocate virtual slave devices for xtest events */
-                    rc = AllocXtstDevice(client, name, &xtstptr, &xtstkeybd);
-                    if (rc != Success)
-                    {
-
-                        xfree(name);
-                        goto unwind;
-                    }
-
-                    ActivateDevice(ptr, FALSE);
-                    ActivateDevice(keybd, FALSE);
-                    flags[ptr->id] |= XIMasterAdded;
-                    flags[keybd->id] |= XIMasterAdded;
-
-                    ActivateDevice(xtstptr, FALSE);
-                    ActivateDevice(xtstkeybd, FALSE);
-                    flags[xtstptr->id] |= XISlaveAdded;
-                    flags[xtstkeybd->id] |= XISlaveAdded;
-
-                    if (c->enable)
-                    {
-                        EnableDevice(ptr, FALSE);
-                        EnableDevice(keybd, FALSE);
-                        flags[ptr->id] |= XIDeviceEnabled;
-                        flags[keybd->id] |= XIDeviceEnabled;
-
-                        EnableDevice(xtstptr, FALSE);
-                        EnableDevice(xtstkeybd, FALSE);
-                        flags[xtstptr->id] |= XIDeviceEnabled;
-                        flags[xtstkeybd->id] |= XIDeviceEnabled;
-                    }
-
-                    /* Attach the XTest virtual devices to the newly
-                       created master device */
-                    AttachDevice(NULL, xtstptr, ptr);
-                    AttachDevice(NULL, xtstkeybd, keybd);
-                    flags[xtstptr->id] |= XISlaveAttached;
-                    flags[xtstkeybd->id] |= XISlaveAttached;
-
-                    xfree(name);
-                }
-                break;
-            case XIRemoveMaster:
-                {
-                    xXIRemoveMasterInfo* r = (xXIRemoveMasterInfo*)any;
-                    DeviceIntPtr xtstdevice;
-
-                    if (r->return_mode != XIAttachToMaster &&
-                            r->return_mode != XIFloating)
-                        return BadValue;
-
-                    if (r->deviceid > 0xFF) /* FIXME */
-                    {
-                        client->errorValue = r->deviceid;
-                        return BadImplementation;
-                    }
-
-                    rc = dixLookupDevice(&ptr, r->deviceid, client,
-                                         DixDestroyAccess);
-                    if (rc != Success)
-                        goto unwind;
-
-                    if (!IsMaster(ptr))
-                    {
-                        client->errorValue = r->deviceid;
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-
-                    /* XXX: For now, don't allow removal of VCP, VCK */
-                    if (ptr == inputInfo.pointer ||
-                            ptr == inputInfo.keyboard)
-                    {
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-
-                    for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
-                        if( !IsMaster(xtstdevice) && xtstdevice->u.master == ptr &&
-                            dixLookupPrivate(&xtstdevice->devPrivates, XTstDevicePrivateKey ))
-                            break;
-
-                    rc = dixLookupDevice(&xtstptr, xtstdevice->id, client,
-                                         DixDestroyAccess);
-                    if (rc != Success)
-                        goto unwind;
-
-                    /* find keyboards to destroy */
-                    if (IsPointerDevice(ptr))
-                    {
-                        rc = dixLookupDevice(&keybd,
-                                             ptr->spriteInfo->paired->id,
-                                             client,
-                                             DixDestroyAccess);
-                        if (rc != Success)
-                            goto unwind;
-
-                    }
-                    else
-                    {
-                        keybd = ptr;
-                        rc = dixLookupDevice(&ptr,
-                                             keybd->spriteInfo->paired->id,
-                                             client,
-                                             DixDestroyAccess);
-                        if (rc != Success)
-                            goto unwind;
-
-                    }
-
-                    /* handle xtst pointer / keyboard slave devices */
-                    if ( IsPointerDevice(xtstptr))
-                    {
-                        /* Search the matching keyboard */
-                        for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
-                            if( !IsMaster(xtstdevice) &&
-                                xtstdevice->u.master == keybd &&
-                                IsKeyboardDevice(xtstdevice) &&
-                                dixLookupPrivate(&xtstdevice->devPrivates, XTstDevicePrivateKey ))
-                                break;
-
-                        rc = dixLookupDevice(&xtstkeybd,
-                                             xtstdevice->id,
-                                             client,
-                                             DixDestroyAccess);
-
-                        if (rc != Success)
-                            goto unwind;
-                    }
-                    else
-                    {
-                        xtstkeybd = xtstptr;
-                        /* Search the matching pointer */
-                        for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
-                            if( !IsMaster(xtstdevice) &&
-                                xtstdevice->u.master == ptr &&
-                                IsPointerDevice(xtstdevice) &&
-                                dixLookupPrivate(&xtstdevice->devPrivates, XTstDevicePrivateKey )
-                              )
-                                break;
-                        rc = dixLookupDevice(&xtstptr,
-                                             xtstdevice->id,
-                                             client,
-                                             DixDestroyAccess);
-
-                        if (rc != Success)
-                            goto unwind;
-                    }
-
-                    /* Disabling sends the devices floating, reattach them if
-                     * desired. */
-                    if (r->return_mode == XIAttachToMaster)
-                    {
-                        DeviceIntPtr attached,
-                                     newptr,
-                                     newkeybd;
-
-                        if (r->return_pointer > 0xFF) /* FIXME */
-                        {
-                            client->errorValue = r->deviceid;
-                            return BadImplementation;
-                        }
-
-                        rc = dixLookupDevice(&newptr, r->return_pointer,
-                                             client, DixWriteAccess);
-                        if (rc != Success)
-                            goto unwind;
-
-                        if (!IsMaster(newptr))
-                        {
-                            client->errorValue = r->return_pointer;
-                            rc = BadDevice;
-                            goto unwind;
-                        }
-
-                        if (r->return_keyboard > 0xFF) /* FIXME */
-                        {
-                            client->errorValue = r->deviceid;
-                            return BadImplementation;
-                        }
-
-                        rc = dixLookupDevice(&newkeybd, r->return_keyboard,
-                                             client, DixWriteAccess);
-                        if (rc != Success)
-                            goto unwind;
-
-                        if (!IsMaster(newkeybd))
-                        {
-                            client->errorValue = r->return_keyboard;
-                            rc = BadDevice;
-                            goto unwind;
-                        }
-
-                        for (attached = inputInfo.devices;
-                                attached;
-                                attached = attached->next)
-                        {
-                            if (!IsMaster(attached)) {
-                                if (attached->u.master == ptr)
-                                {
-                                    AttachDevice(client, attached, newptr);
-                                    flags[attached->id] |= XISlaveAttached;
-                                }
-                                if (attached->u.master == keybd)
-                                {
-                                    AttachDevice(client, attached, newkeybd);
-                                    flags[attached->id] |= XISlaveAttached;
-                                }
-                            }
-                        }
-                    }
-
-                    /* can't disable until we removed pairing */
-                    keybd->spriteInfo->paired = NULL;
-                    ptr->spriteInfo->paired = NULL;
-                    xtstptr->spriteInfo->paired = NULL;
-                    xtstkeybd->spriteInfo->paired = NULL;
-
-                    /* disable the remove the devices, xtst devices must be done first
-                       else the sprites they rely on will be destroyed  */
-                    DisableDevice(xtstptr, FALSE);
-                    DisableDevice(xtstkeybd, FALSE);
-                    DisableDevice(keybd, FALSE);
-                    DisableDevice(ptr, FALSE);
-                    flags[xtstptr->id] |= XIDeviceDisabled | XISlaveDetached;
-                    flags[xtstkeybd->id] |= XIDeviceDisabled | XISlaveDetached;
-                    flags[keybd->id] |= XIDeviceDisabled;
-                    flags[ptr->id] |= XIDeviceDisabled;
-
-                    RemoveDevice(xtstptr, FALSE);
-                    RemoveDevice(xtstkeybd, FALSE);
-                    RemoveDevice(keybd, FALSE);
-                    RemoveDevice(ptr, FALSE);
-                    flags[xtstptr->id] |= XISlaveRemoved;
-                    flags[xtstkeybd->id] |= XISlaveRemoved;
-                    flags[keybd->id] |= XIMasterRemoved;
-                    flags[ptr->id] |= XIMasterRemoved;
-                }
-                break;
-            case XIDetachSlave:
-                {
-                    xXIDetachSlaveInfo* c = (xXIDetachSlaveInfo*)any;
-                    DeviceIntPtr *xtstdevice;
-
-                    if (c->deviceid > 0xFF) /* FIXME */
-                    {
-                        client->errorValue = c->deviceid;
-                        return BadImplementation;
-                    }
-
-                    rc = dixLookupDevice(&ptr, c->deviceid, client,
-                                          DixWriteAccess);
-                    if (rc != Success)
-                       goto unwind;
-
-                    if (IsMaster(ptr))
-                    {
-                        client->errorValue = c->deviceid;
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-
-                    xtstdevice = dixLookupPrivate( &ptr->devPrivates,
-                                                   XTstDevicePrivateKey );
-
-                    /* Don't allow changes to Xtst Devices, these are fixed */
-                    if( xtstdevice )
-                    {
-                        client->errorValue = c->deviceid;
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-
-                    AttachDevice(client, ptr, NULL);
-                    flags[ptr->id] |= XISlaveDetached;
-                }
-                break;
-            case XIAttachSlave:
-                {
-                    xXIAttachSlaveInfo* c = (xXIAttachSlaveInfo*)any;
-                    DeviceIntPtr newmaster;
-                    DeviceIntPtr *xtstdevice;
-
-                    if (c->deviceid > 0xFF) /* FIXME */
-                    {
-                        client->errorValue = c->deviceid;
-                        return BadImplementation;
-                    }
-                    if (c->new_master > 0xFF) /* FIXME */
-                    {
-                        client->errorValue = c->new_master;
-                        return BadImplementation;
-                    }
-
-                    rc = dixLookupDevice(&ptr, c->deviceid, client,
-                                          DixWriteAccess);
-                    if (rc != Success)
-                       goto unwind;
-
-                    if (IsMaster(ptr))
-                    {
-                        client->errorValue = c->deviceid;
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-
-                    xtstdevice = dixLookupPrivate( &ptr->devPrivates,
-                                                   XTstDevicePrivateKey );
-
-                    /* Don't allow changes to Xtst Devices, these are fixed */
-                    if( xtstdevice )
-                    {
-                        client->errorValue = c->deviceid;
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-
-                    rc = dixLookupDevice(&newmaster, c->new_master,
-                            client, DixWriteAccess);
-                    if (rc != Success)
-                        goto unwind;
-                    if (!IsMaster(newmaster))
-                    {
-                        client->errorValue = c->new_master;
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-
-                    if (!((IsPointerDevice(newmaster) &&
-                                    IsPointerDevice(ptr)) ||
-                                (IsKeyboardDevice(newmaster) &&
-                                 IsKeyboardDevice(ptr))))
-                    {
-                        rc = BadDevice;
-                        goto unwind;
-                    }
-                    AttachDevice(client, ptr, newmaster);
-                    flags[ptr->id] |= XISlaveAttached;
-                }
-                break;
-        }
-
-        any = (xXIAnyHierarchyChangeInfo*)((char*)any + any->length * 4);
-    }
-
-unwind:
-
-    XISendDeviceHierarchyEvent(flags);
-    return rc;
-}
-
diff --git a/Xi/chdevhier.h b/Xi/chdevhier.h
deleted file mode 100644
index b46cfb4..0000000
--- a/Xi/chdevhier.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2007-2008 Peter Hutterer
- *
- * 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: Peter Hutterer, University of South Australia, NICTA
- */
-
-/***********************************************************************
- *
- * Request change in the device hierarchy.
- *
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifndef CHDEVHIER_H
-#define CHDEVHIER_H 1
-
-int SProcXIChangeHierarchy(ClientPtr /* client */);
-int ProcXIChangeHierarchy(ClientPtr /* client */);
-
-void XISendDeviceHierarchyEvent(int flags[]);
-
-#endif
diff --git a/Xi/exevents.c b/Xi/exevents.c
index 23d8ee8..24fd11f 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -74,7 +74,7 @@ SOFTWARE.
 #include "scrnintstr.h"
 #include "listdev.h" /* for CopySwapXXXClass */
 #include "xace.h"
-#include "querydev.h" /* For List*Info */
+#include "xiquerydevice.h" /* For List*Info */
 #include "eventconvert.h"
 
 #include <X11/extensions/XKBproto.h>
diff --git a/Xi/extinit.c b/Xi/extinit.c
index 0550bd4..20d49e1 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -75,9 +75,7 @@ SOFTWARE.
 
 /* modules local to Xi */
 #include "allowev.h"
-#include "chdevcur.h"
 #include "chgdctl.h"
-#include "chdevhier.h"
 #include "chgfctl.h"
 #include "chgkbd.h"
 #include "chgprop.h"
@@ -86,7 +84,6 @@ SOFTWARE.
 #include "devbell.h"
 #include "getbmap.h"
 #include "getbmap.h"
-#include "getcptr.h"
 #include "getdctl.h"
 #include "getfctl.h"
 #include "getfocus.h"
@@ -102,15 +99,11 @@ SOFTWARE.
 #include "gtmotion.h"
 #include "listdev.h"
 #include "opendev.h"
-#include "querydp.h"
 #include "queryst.h"
-#include "querydev.h"
-#include "queryversion.h"
 #include "selectev.h"
 #include "sendexev.h"
 #include "chgkmap.h"
 #include "setbmap.h"
-#include "setcptr.h"
 #include "setdval.h"
 #include "setfocus.h"
 #include "setmmap.h"
@@ -118,13 +111,20 @@ SOFTWARE.
 #include "ungrdev.h"
 #include "ungrdevb.h"
 #include "ungrdevk.h"
-#include "warpdevp.h"
 #include "xiallowev.h"
 #include "xiselectev.h"
 #include "xigrabdev.h"
 #include "xipassivegrab.h"
 #include "xisetdevfocus.h"
 #include "xiproperty.h"
+#include "xichangecursor.h"
+#include "xichangehierarchy.h"
+#include "xigetclientpointer.h"
+#include "xiquerydevice.h"
+#include "xiquerypointer.h"
+#include "xiqueryversion.h"
+#include "xisetclientpointer.h"
+#include "xiwarppointer.h"
 
 
 /* Masks for XI events have to be aligned with core event (partially anyway).
diff --git a/Xi/getcptr.c b/Xi/getcptr.c
deleted file mode 100644
index 92fae82..0000000
--- a/Xi/getcptr.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2007-2008 Peter Hutterer
- *
- * 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: Peter Hutterer, University of South Australia, NICTA
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/X.h>	/* for inputstr.h    */
-#include <X11/Xproto.h>	/* Request macro     */
-#include "inputstr.h"	/* DeviceIntPtr      */
-#include "windowstr.h"	/* window structure  */
-#include "scrnintstr.h"	/* screen structure  */
-#include <X11/extensions/XI.h>
-#include <X11/extensions/XI2proto.h>
-#include "extnsionst.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
-#include "exevents.h"
-#include "exglobals.h"
-
-#include "getcptr.h"
-
-/***********************************************************************
- * This procedure allows a client to query another client's client pointer
- * setting.
- */
-
-int
-SProcXIGetClientPointer(ClientPtr client)
-{
-    char n;
-    REQUEST(xXIGetClientPointerReq);
-
-    swaps(&stuff->length, n);
-    swapl(&stuff->win, n);
-    return ProcXIGetClientPointer(client);
-}
-
-int ProcXIGetClientPointer(ClientPtr client)
-{
-    int rc;
-    ClientPtr winclient;
-    xXIGetClientPointerReply rep;
-    REQUEST(xXIGetClientPointerReq);
-    REQUEST_SIZE_MATCH(xXIGetClientPointerReq);
-
-    if (stuff->win != None)
-    {
-        rc = dixLookupClient(&winclient, stuff->win, client,
-                DixWriteAccess);
-
-        if (rc != Success)
-            return BadWindow;
-    } else
-        winclient = client;
-
-    rep.repType = X_Reply;
-    rep.RepType = X_XIGetClientPointer;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.set = (winclient->clientPtr != NULL);
-    rep.deviceid = (winclient->clientPtr) ? winclient->clientPtr->id : 0;
-
-    WriteReplyToClient(client, sizeof(xXIGetClientPointerReply), &rep);
-    return Success;
-}
-
-/***********************************************************************
- *
- * This procedure writes the reply for the XGetClientPointer function,
- * if the client and server have a different byte ordering.
- *
- */
-
-void
-SRepXIGetClientPointer(ClientPtr client, int size,
-        xXIGetClientPointerReply* rep)
-{
-    char n;
-    swaps(&rep->sequenceNumber, n);
-    swapl(&rep->length, n);
-    swaps(&rep->deviceid, n);
-    WriteToClient(client, size, (char *)rep);
-}
-
diff --git a/Xi/getcptr.h b/Xi/getcptr.h
deleted file mode 100644
index 1539aa8..0000000
--- a/Xi/getcptr.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2007-2008 Peter Hutterer
- *
- * 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: Peter Hutterer, University of South Australia, NICTA
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifndef GETCPTR_H
-#define GETCPTR_H 1
-int SProcXIGetClientPointer(ClientPtr /* client */);
-int ProcXIGetClientPointer(ClientPtr /* client */);
-void SRepXIGetClientPointer(ClientPtr /* client */,
-        int /* size */,
-        xXIGetClientPointerReply* /* rep */);
-
-#endif /* GETCPTR_H */
diff --git a/Xi/querydev.c b/Xi/querydev.c
deleted file mode 100644
index fd5e463..0000000
--- a/Xi/querydev.c
+++ /dev/null
@@ -1,451 +0,0 @@
-/*
- * Copyright © 2009 Red Hat, Inc.
- *
- * 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.
- *
- * Authors: Peter Hutterer
- *
- */
-
-/**
- * @file Protocol handling for the XIQueryDevice request/reply.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "inputstr.h"
-#include <X11/X.h>
-#include <X11/extensions/XI2proto.h>
-#include "xkbstr.h"
-#include "xkbsrv.h"
-#include "xserver-properties.h"
-#include "exevents.h"
-
-#include "querydev.h"
-
-static int ListDeviceInfo(DeviceIntPtr dev, xXIDeviceInfo* info);
-static int SizeDeviceInfo(DeviceIntPtr dev);
-static void SwapDeviceInfo(DeviceIntPtr dev, xXIDeviceInfo* info);
-int
-SProcXIQueryDevice(ClientPtr client)
-{
-    char n;
-
-    REQUEST(xXIQueryDeviceReq);
-
-    swaps(&stuff->length, n);
-    swaps(&stuff->deviceid, n);
-
-    return ProcXIQueryDevice(client);
-}
-
-int
-ProcXIQueryDevice(ClientPtr client)
-{
-    xXIQueryDeviceReply rep;
-    DeviceIntPtr dev = NULL;
-    int rc = Success;
-    int len = 0;
-    char *info, *ptr;
-
-    REQUEST(xXIQueryDeviceReq);
-    REQUEST_SIZE_MATCH(xXIQueryDeviceReq);
-
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
-    if (stuff->deviceid != XIAllDevices && stuff->deviceid != XIAllMasterDevices)
-    {
-        rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
-        if (rc != Success)
-        {
-            client->errorValue = stuff->deviceid;
-            return rc;
-        }
-    }
-
-    if (dev)
-        len += SizeDeviceInfo(dev);
-    else
-    {
-        len = 0;
-        for (dev = inputInfo.devices; dev; dev = dev->next)
-        {
-            if (stuff->deviceid == XIAllDevices ||
-                (stuff->deviceid == XIAllMasterDevices && IsMaster(dev)))
-                len += SizeDeviceInfo(dev);
-        }
-
-        for (dev = inputInfo.off_devices; dev; dev = dev->next)
-        {
-            if (stuff->deviceid == XIAllDevices ||
-                (stuff->deviceid == XIAllMasterDevices && IsMaster(dev)))
-                len += SizeDeviceInfo(dev);
-        }
-
-        dev = NULL;
-    }
-
-    info = xcalloc(1, len);
-    if (!info)
-        return BadAlloc;
-
-    memset(&rep, 0, sizeof(xXIQueryDeviceReply));
-    rep.repType = X_Reply;
-    rep.RepType = X_XIQueryDevice;
-    rep.sequenceNumber = client->sequence;
-    rep.length = len/4;
-    rep.num_devices = 0;
-
-    ptr = info;
-    if (dev)
-    {
-        len = ListDeviceInfo(dev, (xXIDeviceInfo*)info);
-        if (client->swapped)
-            SwapDeviceInfo(dev, (xXIDeviceInfo*)info);
-        info += len;
-        rep.num_devices = 1;
-    } else
-    {
-        for (dev = inputInfo.devices; dev; dev = dev->next)
-        {
-            if (stuff->deviceid == XIAllDevices ||
-                    (stuff->deviceid == XIAllMasterDevices && IsMaster(dev)))
-            {
-                len = ListDeviceInfo(dev, (xXIDeviceInfo*)info);
-                if (client->swapped)
-                    SwapDeviceInfo(dev, (xXIDeviceInfo*)info);
-                info += len;
-                rep.num_devices++;
-            }
-        }
-
-        for (dev = inputInfo.off_devices; dev; dev = dev->next)
-        {
-            if (stuff->deviceid == XIAllDevices ||
-                    (stuff->deviceid == XIAllMasterDevices && IsMaster(dev)))
-            {
-                len = ListDeviceInfo(dev, (xXIDeviceInfo*)info);
-                if (client->swapped)
-                    SwapDeviceInfo(dev, (xXIDeviceInfo*)info);
-                info += len;
-                rep.num_devices++;
-            }
-        }
-    }
-
-    WriteReplyToClient(client, sizeof(xXIQueryDeviceReply), &rep);
-    WriteToClient(client, rep.length * 4, ptr);
-    return rc;
-}
-
-void
-SRepXIQueryDevice(ClientPtr client, int size, xXIQueryDeviceReply *rep)
-{
-    char n;
-
-    swaps(&rep->sequenceNumber, n);
-    swapl(&rep->length, n);
-    swaps(&rep->num_devices, n);
-
-    /* Device info is already swapped, see ProcXIQueryDevice */
-
-    WriteToClient(client, size, (char *)rep);
-}
-
-
-
-/**
- * @return The number of bytes needed to store this device's xXIDeviceInfo
- * (and its classes).
- */
-static int
-SizeDeviceInfo(DeviceIntPtr dev)
-{
-    int len = sizeof(xXIDeviceInfo);
-
-    /* 4-padded name */
-    len += (((strlen(dev->name) + 3)/4)*4);
-
-    return len + SizeDeviceClasses(dev);
-
-}
-
-/*
- * @return The number of bytes needed to store this device's classes.
- */
-int
-SizeDeviceClasses(DeviceIntPtr dev)
-{
-    int len = 0;
-
-    if (dev->button)
-    {
-        len += sizeof(xXIButtonInfo);
-        len += dev->button->numButtons * sizeof(Atom);
-    }
-
-    if (dev->key)
-    {
-        XkbDescPtr xkb = dev->key->xkbInfo->desc;
-        len += sizeof(xXIKeyInfo);
-        len += (xkb->max_key_code - xkb->min_key_code + 1) * sizeof(uint32_t);
-    }
-
-    if (dev->valuator)
-        len += sizeof(xXIValuatorInfo) * dev->valuator->numAxes;
-
-    return len;
-}
-
-
-/**
- * Write button information into info.
- * @return Number of bytes written into info.
- */
-int
-ListButtonInfo(DeviceIntPtr dev, xXIButtonInfo* info)
-{
-    info->type = ButtonClass;
-    info->num_buttons = dev->button->numButtons;
-    info->length = 2 + info->num_buttons;
-
-    /** XXX: button labels */
-
-    return info->length * 4;
-}
-
-static void
-SwapButtonInfo(DeviceIntPtr dev, xXIButtonInfo* info)
-{
-    char n;
-    Atom *btn;
-    int i;
-    swaps(&info->type, n);
-    swaps(&info->length, n);
-
-    for (i = 0, btn = (Atom*)&info[1]; i < info->num_buttons; i++, btn++)
-        swaps(btn, n);
-
-    swaps(&info->num_buttons, n);
-}
-
-/**
- * Write key information into info.
- * @return Number of bytes written into info.
- */
-int
-ListKeyInfo(DeviceIntPtr dev, xXIKeyInfo* info)
-{
-    int i;
-    XkbDescPtr xkb = dev->key->xkbInfo->desc;
-    uint32_t *kc;
-
-    info->type = KeyClass;
-    info->num_keycodes = xkb->max_key_code - xkb->min_key_code + 1;
-    info->length = 2 + info->num_keycodes;
-
-    kc = (uint32_t*)&info[1];
-    for (i = xkb->min_key_code; i <= xkb->max_key_code; i++, kc++)
-        *kc = i;
-
-    return info->length * 4;
-}
-
-static void
-SwapKeyInfo(DeviceIntPtr dev, xXIKeyInfo* info)
-{
-    char n;
-    uint32_t *key;
-    int i;
-    swaps(&info->type, n);
-    swaps(&info->length, n);
-
-    for (i = 0, key = (uint32_t*)&info[1]; i < info->num_keycodes; i++, key++)
-        swapl(key, n);
-
-    swaps(&info->num_keycodes, n);
-}
-
-/**
- * List axis information for the given axis.
- *
- * @return The number of bytes written into info.
- */
-int
-ListValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info, int axisnumber)
-{
-    ValuatorClassPtr v = dev->valuator;
-
-    info->type = ValuatorClass;
-    info->length = sizeof(xXIValuatorInfo)/4;
-    info->name = XIGetKnownProperty(AXIS_LABEL_PROP_REL_MISC); /* XXX */
-    info->min.integral = v->axes[axisnumber].min_value;
-    info->min.frac = 0;
-    info->max.integral = v->axes[axisnumber].max_value;
-    info->max.frac = 0;
-    info->resolution = v->axes[axisnumber].resolution;
-    info->number = axisnumber;
-    info->mode = v->mode; /* Server doesn't have per-axis mode yet */
-
-    return info->length * 4;
-}
-
-static void
-SwapValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info)
-{
-    char n;
-    swaps(&info->type, n);
-    swaps(&info->length, n);
-    swapl(&info->name, n);
-    swapl(&info->min.integral, n);
-    swapl(&info->min.frac, n);
-    swapl(&info->max.integral, n);
-    swapl(&info->max.frac, n);
-    swaps(&info->number, n);
-}
-
-int GetDeviceUse(DeviceIntPtr dev, uint16_t *attachment)
-{
-    DeviceIntPtr master = dev->u.master;
-    int use;
-
-    if (IsMaster(dev))
-    {
-        DeviceIntPtr paired = GetPairedDevice(dev);
-        use = IsPointerDevice(dev) ? XIMasterPointer : XIMasterKeyboard;
-        *attachment = (paired ? paired->id : 0);
-    } else if (master)
-    {
-        use = IsPointerDevice(master) ? XISlavePointer : XISlaveKeyboard;
-        *attachment = master->id;
-    } else
-        use = XIFloatingSlave;
-
-    return use;
-}
-
-/**
- * Write the info for device dev into the buffer pointed to by info.
- *
- * @return The number of bytes used.
- */
-static int
-ListDeviceInfo(DeviceIntPtr dev, xXIDeviceInfo* info)
-{
-    char *any = (char*)&info[1];
-    int len = 0, total_len = 0;
-
-    info->deviceid = dev->id;
-    info->use = GetDeviceUse(dev, &info->attachment);
-    info->num_classes = 0;
-    info->name_len = strlen(dev->name);
-    info->enabled = dev->enabled;
-    total_len = sizeof(xXIDeviceInfo);
-
-    len = ((info->name_len + 3)/4) * 4;
-    memset(any, 0, len);
-    strncpy(any, dev->name, info->name_len);
-    any += len;
-    total_len += len;
-
-    return total_len + ListDeviceClasses(dev, any, &info->num_classes);
-}
-
-/**
- * Write the class info of the device into the memory pointed to by any, set
- * nclasses to the number of classes in total and return the number of bytes
- * written.
- */
-int
-ListDeviceClasses(DeviceIntPtr dev, char *any, uint16_t *nclasses)
-{
-    int total_len = 0;
-    int len;
-    int i;
-
-    if (dev->button)
-    {
-        (*nclasses)++;
-        len = ListButtonInfo(dev, (xXIButtonInfo*)any);
-        any += len;
-        total_len += len;
-    }
-
-    if (dev->key)
-    {
-        (*nclasses)++;
-        len = ListKeyInfo(dev, (xXIKeyInfo*)any);
-        any += len;
-        total_len += len;
-    }
-
-    for (i = 0; dev->valuator && i < dev->valuator->numAxes; i++)
-    {
-        (*nclasses)++;
-        len = ListValuatorInfo(dev, (xXIValuatorInfo*)any, i);
-        any += len;
-        total_len += len;
-    }
-
-    return total_len;
-}
-
-static void
-SwapDeviceInfo(DeviceIntPtr dev, xXIDeviceInfo* info)
-{
-    char n;
-    char *any = (char*)&info[1];
-    int i;
-
-    /* Skip over name */
-    any += (((info->name_len + 3)/4) * 4);
-
-    for (i = 0; i < info->num_classes; i++)
-    {
-        int len = ((xXIAnyInfo*)any)->length;
-        switch(((xXIAnyInfo*)any)->type)
-        {
-            case XIButtonClass:
-                SwapButtonInfo(dev, (xXIButtonInfo*)any);
-                break;
-            case XIKeyClass:
-                SwapKeyInfo(dev, (xXIKeyInfo*)any);
-                break;
-            case XIValuatorClass:
-                SwapValuatorInfo(dev, (xXIValuatorInfo*)any);
-                break;
-        }
-
-        any += len * 4;
-    }
-
-    swaps(&info->deviceid, n);
-    swaps(&info->use, n);
-    swaps(&info->attachment, n);
-    swaps(&info->num_classes, n);
-    swaps(&info->name_len, n);
-
-}
diff --git a/Xi/querydev.h b/Xi/querydev.h
deleted file mode 100644
index 34e87bd..0000000
--- a/Xi/querydev.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright © 2009 Red Hat, Inc.
- *
- * 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.
- *
- * Authors: Peter Hutterer
- *
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifndef QUERYDEV_H
-#define QUERYDEV_H 1
-
-#include <X11/extensions/XI2proto.h>
-
-int SProcXIQueryDevice(ClientPtr client);
-int ProcXIQueryDevice(ClientPtr client);
-void SRepXIQueryDevice(ClientPtr client, int size, xXIQueryDeviceReply *rep);
-int SizeDeviceClasses(DeviceIntPtr dev);
-int ListDeviceClasses(DeviceIntPtr dev, char* any, uint16_t* nclasses);
-int GetDeviceUse(DeviceIntPtr dev, uint16_t *attachment);
-int ListButtonInfo(DeviceIntPtr dev, xXIButtonInfo* info);
-int ListKeyInfo(DeviceIntPtr dev, xXIKeyInfo* info);
-int ListValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info, int axisnumber);
-#endif /* QUERYDEV_H */
diff --git a/Xi/querydp.c b/Xi/querydp.c
deleted file mode 100644
index e5bf98d..0000000
--- a/Xi/querydp.c
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Copyright 2007-2008 Peter Hutterer
- *
- * 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: Peter Hutterer, University of South Australia, NICTA
- */
-
-/***********************************************************************
- *
- * Request to query the pointer location of an extension input device.
- *
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/X.h>	/* for inputstr.h    */
-#include <X11/Xproto.h>	/* Request macro     */
-#include "inputstr.h"	/* DeviceIntPtr      */
-#include "windowstr.h"	/* window structure  */
-#include <X11/extensions/XI.h>
-#include <X11/extensions/XI2proto.h>
-#include "extnsionst.h"
-#include "exevents.h"
-#include "exglobals.h"
-#include "eventconvert.h"
-#include "xkbsrv.h"
-
-#ifdef PANORAMIX
-#include "panoramiXsrv.h"
-#endif
-
-#include "querydp.h"
-
-/***********************************************************************
- *
- * This procedure allows a client to query the pointer of a device.
- *
- */
-
-int
-SProcXIQueryPointer(ClientPtr client)
-{
-    char n;
-
-    REQUEST(xXIQueryPointerReq);
-    swaps(&stuff->length, n);
-    return (ProcXIQueryPointer(client));
-}
-
-int
-ProcXIQueryPointer(ClientPtr client)
-{
-    int rc;
-    xXIQueryPointerReply rep;
-    DeviceIntPtr pDev, kbd;
-    WindowPtr pWin, t;
-    SpritePtr pSprite;
-    XkbStatePtr state;
-    char *buttons = NULL;
-
-    REQUEST(xXIQueryPointerReq);
-    REQUEST_SIZE_MATCH(xXIQueryPointerReq);
-
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
-    rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixReadAccess);
-    if (rc != Success)
-        return rc;
-
-    if (pDev->valuator == NULL)
-    {
-        client->errorValue = stuff->deviceid;
-        return BadDevice;
-    }
-
-    rc = dixLookupWindow(&pWin, stuff->win, client, DixReadAccess);
-    if (rc != Success)
-    {
-        SendErrorToClient(client, IReqCode, X_XIQueryPointer,
-                stuff->win, rc);
-        return Success;
-    }
-
-    if (pDev->valuator->motionHintWindow)
-        MaybeStopHint(pDev, client);
-
-    kbd = GetPairedDevice(pDev);
-
-    pSprite = pDev->spriteInfo->sprite;
-    rep.repType = X_Reply;
-    rep.RepType = X_XIQueryPointer;
-    rep.length = 5;
-    rep.sequenceNumber = client->sequence;
-    rep.root = (GetCurrentRootWindow(pDev))->drawable.id;
-    rep.root_x = FP1616(pSprite->hot.x, 0);
-    rep.root_y = FP1616(pSprite->hot.y, 0);
-    rep.child = None;
-
-    state = &kbd->key->xkbInfo->prev_state;
-    rep.mods.base_mods = state->base_mods;
-    rep.mods.latched_mods = state->latched_mods;
-    rep.mods.locked_mods = state->locked_mods;
-
-    rep.group.base_group = state->base_group;
-    rep.group.latched_group = state->latched_group;
-    rep.group.locked_group = state->locked_group;
-
-    if (pDev->button)
-    {
-        int i, down;
-        rep.buttons_len = (((pDev->button->numButtons + 7)/8) + 3)/4;
-        rep.length += rep.buttons_len;
-        buttons = xcalloc(rep.buttons_len, 4);
-        if (!buttons)
-            return BadAlloc;
-
-        down = pDev->button->buttonsDown;
-
-        for (i = 0; i < pDev->button->numButtons && down; i++)
-        {
-            if (BitIsOn(pDev->button->down, i))
-            {
-                SetBit(buttons, i);
-                down--;
-            }
-        }
-    } else
-        rep.buttons_len = 0;
-
-    if (pSprite->hot.pScreen == pWin->drawable.pScreen)
-    {
-        rep.same_screen = xTrue;
-        rep.win_x = FP1616(pSprite->hot.x - pWin->drawable.x, 0);
-        rep.win_y = FP1616(pSprite->hot.y - pWin->drawable.y, 0);
-        for (t = pSprite->win; t; t = t->parent)
-            if (t->parent == pWin)
-            {
-                rep.child = t->drawable.id;
-                break;
-            }
-    } else
-    {
-        rep.same_screen = xFalse;
-        rep.win_x = 0;
-        rep.win_y = 0;
-    }
-
-#ifdef PANORAMIX
-    if(!noPanoramiXExtension) {
-        rep.root_x += FP1616(panoramiXdataPtr[0].x, 0);
-        rep.root_y += FP1616(panoramiXdataPtr[0].y, 0);
-        if (stuff->win == rep.root)
-        {
-            rep.win_x += FP1616(panoramiXdataPtr[0].x, 0);
-            rep.win_y += FP1616(panoramiXdataPtr[0].y, 0);
-        }
-    }
-#endif
-
-    WriteReplyToClient(client, sizeof(xXIQueryPointerReply), &rep);
-    if (buttons)
-        WriteToClient(client, rep.buttons_len * 4, buttons);
-
-    xfree(buttons);
-
-    return Success;
-}
-
-/***********************************************************************
- *
- * This procedure writes the reply for the XIQueryPointer function,
- * if the client and server have a different byte ordering.
- *
- */
-
-void
-SRepXIQueryPointer(ClientPtr client, int size,
-                   xXIQueryPointerReply * rep)
-{
-    char n;
-
-    swaps(&rep->sequenceNumber, n);
-    swapl(&rep->length, n);
-    WriteToClient(client, size, (char *)rep);
-}
-
diff --git a/Xi/querydp.h b/Xi/querydp.h
deleted file mode 100644
index ea22376..0000000
--- a/Xi/querydp.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2007-2008 Peter Hutterer
- *
- * 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: Peter Hutterer, University of South Australia, NICTA
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifndef QUERYDP_H
-#define QUERYDP_H 1
-
-int SProcXIQueryPointer(ClientPtr /* client */);
-int ProcXIQueryPointer(ClientPtr /* client */);
-void SRepXIQueryPointer(ClientPtr /* client */ ,
-			int /* size */ ,
-			xXIQueryPointerReply *	/* rep */);
-
-#endif /* QUERYDP_H */
diff --git a/Xi/queryversion.c b/Xi/queryversion.c
deleted file mode 100644
index 4d644a9..0000000
--- a/Xi/queryversion.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright © 2009 Red Hat, Inc.
- *
- * 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.
- *
- * Authors: Peter Hutterer
- *
- */
-
-/**
- * @file queryversion.c
- * Protocol handling for the XIQueryVersion request/reply.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-
-#include "inputstr.h"
-
-#include <X11/Xmd.h>
-#include <X11/X.h>
-#include <X11/extensions/XI2proto.h>
-
-#include "exglobals.h"
-#include "exevents.h"
-#include "queryversion.h"
-#include "misc.h"
-
-extern XExtensionVersion XIVersion; /* defined in getvers.c */
-/**
- * Return the supported XI version.
- *
- * Saves the version the client claims to support as well, for future
- * reference.
- */
-int
-ProcXIQueryVersion(ClientPtr client)
-{
-    xXIQueryVersionReply rep;
-    XIClientPtr pXIClient;
-    int major, minor;
-    unsigned int sversion, cversion;
-
-    REQUEST(xXIQueryVersionReq);
-    REQUEST_SIZE_MATCH(xXIQueryVersionReq);
-
-    /* This request only exists after XI2 */
-    if (stuff->major_version < 2)
-    {
-        client->errorValue = stuff->major_version;
-        return BadValue;
-    }
-
-    pXIClient = dixLookupPrivate(&client->devPrivates, XIClientPrivateKey);
-
-    sversion = XIVersion.major_version * 1000 + XIVersion.minor_version;
-    cversion = stuff->major_version * 1000 + stuff->minor_version;
-
-    if (sversion > cversion)
-    {
-        major = stuff->major_version;
-        minor = stuff->minor_version;
-    } else
-    {
-        major = XIVersion.major_version;
-        minor = XIVersion.minor_version;
-    }
-
-    pXIClient->major_version = major;
-    pXIClient->minor_version = minor;
-
-    memset(&rep, 0, sizeof(xXIQueryVersionReply));
-    rep.repType = X_Reply;
-    rep.RepType = X_XIQueryVersion;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.major_version = major;
-    rep.minor_version = minor;
-
-    WriteReplyToClient(client, sizeof(xXIQueryVersionReply), &rep);
-
-    return Success;
-}
-
-/* Swapping routines */
-
-int
-SProcXIQueryVersion(ClientPtr client)
-{
-    char n;
-
-    REQUEST(xXIQueryVersionReq);
-    swaps(&stuff->length, n);
-    REQUEST_AT_LEAST_SIZE(xXIQueryVersionReq);
-    swaps(&stuff->major_version, n);
-    swaps(&stuff->minor_version, n);
-    return (ProcXIQueryVersion(client));
-}
-
-void
-SRepXIQueryVersion(ClientPtr client, int size, xXIQueryVersionReply *rep)
-{
-    char n;
-    swaps(&rep->sequenceNumber, n);
-    swapl(&rep->length, n);
-    swaps(&rep->major_version, n);
-    swaps(&rep->minor_version, n);
-    WriteToClient(client, size, (char *)rep);
-}
diff --git a/Xi/queryversion.h b/Xi/queryversion.h
deleted file mode 100644
index 06bb729..0000000
--- a/Xi/queryversion.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright © 2009 Red Hat, Inc.
- *
- * 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.
- *
- * Authors: Peter Hutterer
- *
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/extensions/XI2proto.h>
-
-#ifndef QUERYVERSION_H
-#define QUERYVERSION_H 1
-
-int SProcXIQueryVersion(ClientPtr client);
-int ProcXIQueryVersion(ClientPtr client);
-void SRepXIQueryVersion(ClientPtr client, int size, xXIQueryVersionReply* rep);
-
-#endif /* QUERYVERSION_H */
diff --git a/Xi/setcptr.c b/Xi/setcptr.c
deleted file mode 100644
index d23b2d8..0000000
--- a/Xi/setcptr.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright 2007-2008 Peter Hutterer
- *
- * 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: Peter Hutterer, University of South Australia, NICTA
- */
-
-/***********************************************************************
- *
- * Request to set the client pointer for the owner of the given window.
- * All subsequent calls that are ambiguous will choose the client pointer as
- * default value.
- */
-
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/X.h>	/* for inputstr.h    */
-#include <X11/Xproto.h>	/* Request macro     */
-#include "inputstr.h"	/* DeviceIntPtr      */
-#include "windowstr.h"	/* window structure  */
-#include "scrnintstr.h"	/* screen structure  */
-#include <X11/extensions/XI.h>
-#include <X11/extensions/XI2proto.h>
-#include "extnsionst.h"
-#include "exevents.h"
-#include "exglobals.h"
-
-#include "setcptr.h"
-
-int
-SProcXISetClientPointer(ClientPtr client)
-{
-    char n;
-
-    REQUEST(xXISetClientPointerReq);
-    swaps(&stuff->length, n);
-    swapl(&stuff->win, n);
-    swaps(&stuff->deviceid, n);
-    REQUEST_SIZE_MATCH(xXISetClientPointerReq);
-    return (ProcXISetClientPointer(client));
-}
-
-int
-ProcXISetClientPointer(ClientPtr client)
-{
-    DeviceIntPtr pDev;
-    ClientPtr targetClient;
-    int rc;
-
-    REQUEST(xXISetClientPointerReq);
-    REQUEST_SIZE_MATCH(xXISetClientPointerReq);
-
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
-    rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixWriteAccess);
-    if (rc != Success)
-    {
-        client->errorValue = stuff->deviceid;
-        return rc;
-    }
-
-    if (!IsMaster(pDev))
-    {
-        client->errorValue = stuff->deviceid;
-        return BadDevice;
-    }
-
-    pDev = GetMaster(pDev, MASTER_POINTER);
-
-    if (stuff->win != None)
-    {
-        rc = dixLookupClient(&targetClient, stuff->win, client,
-                DixWriteAccess);
-
-        if (rc != Success)
-            return BadWindow;
-
-    } else
-        targetClient = client;
-
-    if (!SetClientPointer(targetClient, pDev))
-    {
-        client->errorValue = stuff->deviceid;
-        return BadDevice;
-    }
-
-    return Success;
-}
diff --git a/Xi/setcptr.h b/Xi/setcptr.h
deleted file mode 100644
index 5968d98..0000000
--- a/Xi/setcptr.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2007-2008 Peter Hutterer
- *
- * 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: Peter Hutterer, University of South Australia, NICTA
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifndef SETCPTR_H
-#define SETCPTR_H 1
-
-int SProcXISetClientPointer(ClientPtr /* client */);
-int ProcXISetClientPointer(ClientPtr /* client */);
-
-#endif /* SETCPTR_H */
diff --git a/Xi/warpdevp.c b/Xi/warpdevp.c
deleted file mode 100644
index bb45bda..0000000
--- a/Xi/warpdevp.c
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright 2007-2008 Peter Hutterer
- *
- * 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: Peter Hutterer, University of South Australia, NICTA
- */
-
-/***********************************************************************
- *
- * Request to Warp the pointer location of an extension input device.
- *
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/X.h>	/* for inputstr.h    */
-#include <X11/Xproto.h>	/* Request macro     */
-#include "inputstr.h"	/* DeviceIntPtr      */
-#include "windowstr.h"	/* window structure  */
-#include "scrnintstr.h"	/* screen structure  */
-#include <X11/extensions/XI.h>
-#include <X11/extensions/XI2proto.h>
-#include "extnsionst.h"
-#include "exevents.h"
-#include "exglobals.h"
-#include "mipointer.h" /* for miPointerUpdateSprite */
-
-
-#include "warpdevp.h"
-/***********************************************************************
- *
- * This procedure allows a client to warp the pointer of a device.
- *
- */
-
-int
-SProcXIWarpPointer(ClientPtr client)
-{
-    char n;
-
-    REQUEST(xXIWarpPointerReq);
-    swaps(&stuff->length, n);
-    return (ProcXIWarpPointer(client));
-}
-
-int
-ProcXIWarpPointer(ClientPtr client)
-{
-    int rc;
-    int x, y;
-    WindowPtr dest = NULL;
-    DeviceIntPtr pDev;
-    SpritePtr pSprite;
-    ScreenPtr newScreen;
-
-    REQUEST(xXIWarpPointerReq);
-    REQUEST_SIZE_MATCH(xXIWarpPointerReq);
-
-    if (stuff->deviceid > 0xFF) /* FIXME */
-    {
-        client->errorValue = stuff->deviceid;
-        return BadImplementation;
-    }
-
-    /* FIXME: panoramix stuff is missing, look at ProcWarpPointer */
-
-    rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixWriteAccess);
-
-    if (rc != Success)
-        return rc;
-
-    if (stuff->dst_win != None)
-    {
-        rc = dixLookupWindow(&dest, stuff->dst_win, client, DixReadAccess);
-        if (rc != Success)
-        {
-            return rc;
-        }
-    }
-
-    pSprite = pDev->spriteInfo->sprite;
-    x = pSprite->hotPhys.x;
-    y = pSprite->hotPhys.y;
-
-    if (stuff->src_win != None)
-    {
-        int winX, winY;
-        WindowPtr src;
-
-        rc = dixLookupWindow(&src, stuff->src_win, client, DixReadAccess);
-        if (rc != Success)
-        {
-            return rc;
-        }
-
-        winX = src->drawable.x;
-        winY = src->drawable.y;
-        if (src->drawable.pScreen != pSprite->hotPhys.pScreen ||
-                x < winX + stuff->src_x ||
-                y < winY + stuff->src_y ||
-                (stuff->src_width != 0 &&
-                 winX + stuff->src_x + (int)stuff->src_width < 0) ||
-                (stuff->src_height != 0 &&
-                 winY + stuff->src_y + (int)stuff->src_height < y) ||
-                !PointInWindowIsVisible(src, x, y))
-            return Success;
-    }
-
-    if (dest)
-    {
-        x = dest->drawable.x;
-        y = dest->drawable.y;
-        newScreen = dest->drawable.pScreen;
-    } else
-        newScreen = pSprite->hotPhys.pScreen;
-
-    x += stuff->dst_x;
-    y += stuff->dst_y;
-
-    if (x < 0)
-        x = 0;
-    else if (x > newScreen->width)
-        x = newScreen->width - 1;
-
-    if (y < 0)
-        y = 0;
-    else if (y > newScreen->height)
-        y = newScreen->height - 1;
-
-    if (newScreen == pSprite->hotPhys.pScreen)
-    {
-        if (x < pSprite->physLimits.x1)
-            x = pSprite->physLimits.x1;
-        else if (x >= pSprite->physLimits.x2)
-            x = pSprite->physLimits.x2 - 1;
-
-        if (y < pSprite->physLimits.y1)
-            y = pSprite->physLimits.y1;
-        else if (y >= pSprite->physLimits.y2)
-            y = pSprite->physLimits.y2 - 1;
-
-        if (pSprite->hotShape)
-            ConfineToShape(pDev, pSprite->hotShape, &x, &y);
-        (*newScreen->SetCursorPosition)(pDev, newScreen, x, y, TRUE);
-    } else if (!PointerConfinedToScreen(pDev))
-    {
-        NewCurrentScreen(pDev, newScreen, x, y);
-    }
-
-    /* if we don't update the device, we get a jump next time it moves */
-    pDev->last.valuators[0] = x;
-    pDev->last.valuators[1] = y;
-    miPointerUpdateSprite(pDev);
-
-    /* FIXME: XWarpPointer is supposed to generate an event. It doesn't do it
-       here though. */
-    return Success;
-}
-
diff --git a/Xi/warpdevp.h b/Xi/warpdevp.h
deleted file mode 100644
index aafc739..0000000
--- a/Xi/warpdevp.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2007-2008 Peter Hutterer
- *
- * 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: Peter Hutterer, University of South Australia, NICTA
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifndef WARPDEVP_H
-#define WARPDEVP_H 1
-
-int SProcXIWarpPointer(ClientPtr /* client */);
-int ProcXIWarpPointer(ClientPtr	/* client */);
-
-#endif /* WARPDEVP_H */
diff --git a/Xi/xichangecursor.c b/Xi/xichangecursor.c
new file mode 100644
index 0000000..ee2d65d
--- /dev/null
+++ b/Xi/xichangecursor.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2007-2008 Peter Hutterer
+ *
+ * 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: Peter Hutterer, University of South Australia, NICTA
+ */
+
+/***********************************************************************
+ *
+ * Request to change a given device pointer's cursor.
+ *
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/X.h>	/* for inputstr.h    */
+#include <X11/Xproto.h>	/* Request macro     */
+#include "inputstr.h"	/* DeviceIntPtr      */
+#include "windowstr.h"	/* window structure  */
+#include "scrnintstr.h"	/* screen structure  */
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XI2proto.h>
+#include "extnsionst.h"
+#include "exevents.h"
+#include "exglobals.h"
+#include "input.h"
+
+#include "xichangecursor.h"
+
+/***********************************************************************
+ *
+ * This procedure allows a client to set one pointer's cursor.
+ *
+ */
+
+int
+SProcXIChangeCursor(ClientPtr client)
+{
+    char n;
+
+    REQUEST(xXIChangeCursorReq);
+    swaps(&stuff->length, n);
+    REQUEST_SIZE_MATCH(xXIChangeCursorReq);
+    return (ProcXIChangeCursor(client));
+}
+
+int ProcXIChangeCursor(ClientPtr client)
+{
+    int rc;
+    WindowPtr pWin    = NULL;
+    DeviceIntPtr pDev = NULL;
+    CursorPtr pCursor = NULL;
+
+    REQUEST(xXIChangeCursorReq);
+    REQUEST_SIZE_MATCH(xXIChangeCursorReq);
+
+    if (stuff->deviceid > 0xFF) /* FIXME */
+    {
+        client->errorValue = stuff->deviceid;
+        return BadImplementation;
+    }
+
+    rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixSetAttrAccess);
+    if (rc != Success)
+        return rc;
+
+    if (stuff->win != None)
+    {
+        rc = dixLookupWindow(&pWin, stuff->win, client, DixSetAttrAccess);
+        if (rc != Success)
+            return rc;
+    }
+
+    if (stuff->cursor == None)
+    {
+        if (pWin == WindowTable[pWin->drawable.pScreen->myNum])
+            pCursor = rootCursor;
+        else
+            pCursor = (CursorPtr)None;
+    }
+    else
+    {
+	rc = dixLookupResourceByType((pointer *)&pCursor, stuff->cursor,
+				     RT_CURSOR, client, DixReadAccess);
+	if (rc != Success)
+	    return (rc == BadValue) ? BadCursor : rc;
+    }
+
+    ChangeWindowDeviceCursor(pWin, pDev, pCursor);
+
+    return Success;
+}
+
diff --git a/Xi/xichangecursor.h b/Xi/xichangecursor.h
new file mode 100644
index 0000000..dc6ccb1
--- /dev/null
+++ b/Xi/xichangecursor.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2007-2008 Peter Hutterer
+ *
+ * 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: Peter Hutterer, University of South Australia, NICTA
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifndef CHDEVCUR_H
+#define CHDEVCUR_H 1
+
+int SProcXIChangeCursor(ClientPtr /* client */);
+int ProcXIChangeCursor(ClientPtr /* client */);
+
+#endif /* CHDEVCUR_H */
diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
new file mode 100644
index 0000000..944bb30
--- /dev/null
+++ b/Xi/xichangehierarchy.c
@@ -0,0 +1,540 @@
+/*
+ * Copyright 2007-2008 Peter Hutterer
+ * Copyright 2009 Red Hat, Inc.
+ *
+ * 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: Peter Hutterer, University of South Australia, NICTA
+ */
+
+/***********************************************************************
+ *
+ * Request change in the device hierarchy.
+ *
+ */
+
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/X.h>	/* for inputstr.h    */
+#include <X11/Xproto.h>	/* Request macro     */
+#include "inputstr.h"	/* DeviceIntPtr      */
+#include "windowstr.h"	/* window structure  */
+#include "scrnintstr.h"	/* screen structure  */
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XI2proto.h>
+#include <X11/extensions/geproto.h>
+#include "extnsionst.h"
+#include "exevents.h"
+#include "exglobals.h"
+#include "geext.h"
+#include "xace.h"
+#include "xiquerydevice.h" /* for GetDeviceUse */
+
+#include "xkbsrv.h"
+
+#include "xichangehierarchy.h"
+
+extern DevPrivateKey XTstDevicePrivateKey;
+
+/**
+ * Send the current state of the device hierarchy to all clients.
+ */
+void XISendDeviceHierarchyEvent(int flags[MAXDEVICES])
+{
+    xXIHierarchyEvent *ev;
+    xXIHierarchyInfo *info;
+    DeviceIntRec dummyDev;
+    DeviceIntPtr dev;
+    int i;
+
+    if (!flags)
+        return;
+
+    ev = xcalloc(1, sizeof(xXIHierarchyEvent) +
+                 MAXDEVICES * sizeof(xXIHierarchyInfo));
+    ev->type = GenericEvent;
+    ev->extension = IReqCode;
+    ev->evtype = XI_HierarchyChanged;
+    ev->time = GetTimeInMillis();
+    ev->flags = 0;
+    ev->num_info = inputInfo.numDevices;
+
+    info = (xXIHierarchyInfo*)&ev[1];
+    for (dev = inputInfo.devices; dev; dev = dev->next)
+    {
+        info->deviceid = dev->id;
+        info->enabled = dev->enabled;
+        info->use = GetDeviceUse(dev, &info->attachment);
+        info->flags = flags[dev->id];
+        ev->flags |= info->flags;
+        info++;
+    }
+    for (dev = inputInfo.off_devices; dev; dev = dev->next)
+    {
+        info->deviceid = dev->id;
+        info->enabled = dev->enabled;
+        info->use = GetDeviceUse(dev, &info->attachment);
+        info->flags = flags[dev->id];
+        ev->flags |= info->flags;
+        info++;
+    }
+
+
+    for (i = 0; i < MAXDEVICES; i++)
+    {
+        if (flags[i] & (XIMasterRemoved | XISlaveRemoved))
+        {
+            info->deviceid = i;
+            info->enabled = FALSE;
+            info->flags = flags[i];
+            info->use = 0;
+            ev->flags |= info->flags;
+            ev->num_info++;
+            info++;
+        }
+    }
+
+    ev->length = (ev->num_info * sizeof(xXIHierarchyInfo))/4;
+
+    dummyDev.id = XIAllDevices;
+    SendEventToAllWindows(&dummyDev, (XI_HierarchyChangedMask >> 8), (xEvent*)ev, 1);
+}
+
+
+/***********************************************************************
+ *
+ * This procedure allows a client to change the device hierarchy through
+ * adding new master devices, removing them, etc.
+ *
+ */
+
+int SProcXIChangeHierarchy(ClientPtr client)
+{
+    char n;
+
+    REQUEST(xXIChangeHierarchyReq);
+    swaps(&stuff->length, n);
+    return (ProcXIChangeHierarchy(client));
+}
+
+#define SWAPIF(cmd) if (client->swapped) { cmd; }
+
+int
+ProcXIChangeHierarchy(ClientPtr client)
+{
+    DeviceIntPtr ptr, keybd, xtstptr, xtstkeybd;
+    xXIAnyHierarchyChangeInfo *any;
+    int required_len = sizeof(xXIChangeHierarchyReq);
+    char n;
+    int rc = Success;
+    int flags[MAXDEVICES] = {0};
+
+    REQUEST(xXIChangeHierarchyReq);
+    REQUEST_AT_LEAST_SIZE(xXIChangeHierarchyReq);
+
+    if (!stuff->num_changes)
+        return rc;
+
+    any = (xXIAnyHierarchyChangeInfo*)&stuff[1];
+    while(stuff->num_changes--)
+    {
+        SWAPIF(swapl(&any->type, n));
+        SWAPIF(swaps(&any->length, n));
+
+        required_len += any->length;
+        if ((stuff->length * 4) < required_len)
+            return BadLength;
+
+        switch(any->type)
+        {
+            case XIAddMaster:
+                {
+                    xXIAddMasterInfo* c = (xXIAddMasterInfo*)any;
+                    char* name;
+
+                    SWAPIF(swaps(&c->name_len, n));
+                    name = xcalloc(c->name_len + 1, sizeof(char));
+                    strncpy(name, (char*)&c[1], c->name_len);
+
+
+                    rc = AllocDevicePair(client, name, &ptr, &keybd, TRUE);
+                    if (rc != Success)
+                    {
+                        xfree(name);
+                        goto unwind;
+                    }
+
+                    if (!c->send_core)
+                        ptr->coreEvents = keybd->coreEvents =  FALSE;
+
+		    /* Allocate virtual slave devices for xtest events */
+                    rc = AllocXtstDevice(client, name, &xtstptr, &xtstkeybd);
+                    if (rc != Success)
+                    {
+
+                        xfree(name);
+                        goto unwind;
+                    }
+
+                    ActivateDevice(ptr, FALSE);
+                    ActivateDevice(keybd, FALSE);
+                    flags[ptr->id] |= XIMasterAdded;
+                    flags[keybd->id] |= XIMasterAdded;
+
+                    ActivateDevice(xtstptr, FALSE);
+                    ActivateDevice(xtstkeybd, FALSE);
+                    flags[xtstptr->id] |= XISlaveAdded;
+                    flags[xtstkeybd->id] |= XISlaveAdded;
+
+                    if (c->enable)
+                    {
+                        EnableDevice(ptr, FALSE);
+                        EnableDevice(keybd, FALSE);
+                        flags[ptr->id] |= XIDeviceEnabled;
+                        flags[keybd->id] |= XIDeviceEnabled;
+
+                        EnableDevice(xtstptr, FALSE);
+                        EnableDevice(xtstkeybd, FALSE);
+                        flags[xtstptr->id] |= XIDeviceEnabled;
+                        flags[xtstkeybd->id] |= XIDeviceEnabled;
+                    }
+
+                    /* Attach the XTest virtual devices to the newly
+                       created master device */
+                    AttachDevice(NULL, xtstptr, ptr);
+                    AttachDevice(NULL, xtstkeybd, keybd);
+                    flags[xtstptr->id] |= XISlaveAttached;
+                    flags[xtstkeybd->id] |= XISlaveAttached;
+
+                    xfree(name);
+                }
+                break;
+            case XIRemoveMaster:
+                {
+                    xXIRemoveMasterInfo* r = (xXIRemoveMasterInfo*)any;
+                    DeviceIntPtr xtstdevice;
+
+                    if (r->return_mode != XIAttachToMaster &&
+                            r->return_mode != XIFloating)
+                        return BadValue;
+
+                    if (r->deviceid > 0xFF) /* FIXME */
+                    {
+                        client->errorValue = r->deviceid;
+                        return BadImplementation;
+                    }
+
+                    rc = dixLookupDevice(&ptr, r->deviceid, client,
+                                         DixDestroyAccess);
+                    if (rc != Success)
+                        goto unwind;
+
+                    if (!IsMaster(ptr))
+                    {
+                        client->errorValue = r->deviceid;
+                        rc = BadDevice;
+                        goto unwind;
+                    }
+
+                    /* XXX: For now, don't allow removal of VCP, VCK */
+                    if (ptr == inputInfo.pointer ||
+                            ptr == inputInfo.keyboard)
+                    {
+                        rc = BadDevice;
+                        goto unwind;
+                    }
+
+                    for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
+                        if( !IsMaster(xtstdevice) && xtstdevice->u.master == ptr &&
+                            dixLookupPrivate(&xtstdevice->devPrivates, XTstDevicePrivateKey ))
+                            break;
+
+                    rc = dixLookupDevice(&xtstptr, xtstdevice->id, client,
+                                         DixDestroyAccess);
+                    if (rc != Success)
+                        goto unwind;
+
+                    /* find keyboards to destroy */
+                    if (IsPointerDevice(ptr))
+                    {
+                        rc = dixLookupDevice(&keybd,
+                                             ptr->spriteInfo->paired->id,
+                                             client,
+                                             DixDestroyAccess);
+                        if (rc != Success)
+                            goto unwind;
+
+                    }
+                    else
+                    {
+                        keybd = ptr;
+                        rc = dixLookupDevice(&ptr,
+                                             keybd->spriteInfo->paired->id,
+                                             client,
+                                             DixDestroyAccess);
+                        if (rc != Success)
+                            goto unwind;
+
+                    }
+
+                    /* handle xtst pointer / keyboard slave devices */
+                    if ( IsPointerDevice(xtstptr))
+                    {
+                        /* Search the matching keyboard */
+                        for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
+                            if( !IsMaster(xtstdevice) &&
+                                xtstdevice->u.master == keybd &&
+                                IsKeyboardDevice(xtstdevice) &&
+                                dixLookupPrivate(&xtstdevice->devPrivates, XTstDevicePrivateKey ))
+                                break;
+
+                        rc = dixLookupDevice(&xtstkeybd,
+                                             xtstdevice->id,
+                                             client,
+                                             DixDestroyAccess);
+
+                        if (rc != Success)
+                            goto unwind;
+                    }
+                    else
+                    {
+                        xtstkeybd = xtstptr;
+                        /* Search the matching pointer */
+                        for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
+                            if( !IsMaster(xtstdevice) &&
+                                xtstdevice->u.master == ptr &&
+                                IsPointerDevice(xtstdevice) &&
+                                dixLookupPrivate(&xtstdevice->devPrivates, XTstDevicePrivateKey )
+                              )
+                                break;
+                        rc = dixLookupDevice(&xtstptr,
+                                             xtstdevice->id,
+                                             client,
+                                             DixDestroyAccess);
+
+                        if (rc != Success)
+                            goto unwind;
+                    }
+
+                    /* Disabling sends the devices floating, reattach them if
+                     * desired. */
+                    if (r->return_mode == XIAttachToMaster)
+                    {
+                        DeviceIntPtr attached,
+                                     newptr,
+                                     newkeybd;
+
+                        if (r->return_pointer > 0xFF) /* FIXME */
+                        {
+                            client->errorValue = r->deviceid;
+                            return BadImplementation;
+                        }
+
+                        rc = dixLookupDevice(&newptr, r->return_pointer,
+                                             client, DixWriteAccess);
+                        if (rc != Success)
+                            goto unwind;
+
+                        if (!IsMaster(newptr))
+                        {
+                            client->errorValue = r->return_pointer;
+                            rc = BadDevice;
+                            goto unwind;
+                        }
+
+                        if (r->return_keyboard > 0xFF) /* FIXME */
+                        {
+                            client->errorValue = r->deviceid;
+                            return BadImplementation;
+                        }
+
+                        rc = dixLookupDevice(&newkeybd, r->return_keyboard,
+                                             client, DixWriteAccess);
+                        if (rc != Success)
+                            goto unwind;
+
+                        if (!IsMaster(newkeybd))
+                        {
+                            client->errorValue = r->return_keyboard;
+                            rc = BadDevice;
+                            goto unwind;
+                        }
+
+                        for (attached = inputInfo.devices;
+                                attached;
+                                attached = attached->next)
+                        {
+                            if (!IsMaster(attached)) {
+                                if (attached->u.master == ptr)
+                                {
+                                    AttachDevice(client, attached, newptr);
+                                    flags[attached->id] |= XISlaveAttached;
+                                }
+                                if (attached->u.master == keybd)
+                                {
+                                    AttachDevice(client, attached, newkeybd);
+                                    flags[attached->id] |= XISlaveAttached;
+                                }
+                            }
+                        }
+                    }
+
+                    /* can't disable until we removed pairing */
+                    keybd->spriteInfo->paired = NULL;
+                    ptr->spriteInfo->paired = NULL;
+                    xtstptr->spriteInfo->paired = NULL;
+                    xtstkeybd->spriteInfo->paired = NULL;
+
+                    /* disable the remove the devices, xtst devices must be done first
+                       else the sprites they rely on will be destroyed  */
+                    DisableDevice(xtstptr, FALSE);
+                    DisableDevice(xtstkeybd, FALSE);
+                    DisableDevice(keybd, FALSE);
+                    DisableDevice(ptr, FALSE);
+                    flags[xtstptr->id] |= XIDeviceDisabled | XISlaveDetached;
+                    flags[xtstkeybd->id] |= XIDeviceDisabled | XISlaveDetached;
+                    flags[keybd->id] |= XIDeviceDisabled;
+                    flags[ptr->id] |= XIDeviceDisabled;
+
+                    RemoveDevice(xtstptr, FALSE);
+                    RemoveDevice(xtstkeybd, FALSE);
+                    RemoveDevice(keybd, FALSE);
+                    RemoveDevice(ptr, FALSE);
+                    flags[xtstptr->id] |= XISlaveRemoved;
+                    flags[xtstkeybd->id] |= XISlaveRemoved;
+                    flags[keybd->id] |= XIMasterRemoved;
+                    flags[ptr->id] |= XIMasterRemoved;
+                }
+                break;
+            case XIDetachSlave:
+                {
+                    xXIDetachSlaveInfo* c = (xXIDetachSlaveInfo*)any;
+                    DeviceIntPtr *xtstdevice;
+
+                    if (c->deviceid > 0xFF) /* FIXME */
+                    {
+                        client->errorValue = c->deviceid;
+                        return BadImplementation;
+                    }
+
+                    rc = dixLookupDevice(&ptr, c->deviceid, client,
+                                          DixWriteAccess);
+                    if (rc != Success)
+                       goto unwind;
+
+                    if (IsMaster(ptr))
+                    {
+                        client->errorValue = c->deviceid;
+                        rc = BadDevice;
+                        goto unwind;
+                    }
+
+                    xtstdevice = dixLookupPrivate( &ptr->devPrivates,
+                                                   XTstDevicePrivateKey );
+
+                    /* Don't allow changes to Xtst Devices, these are fixed */
+                    if( xtstdevice )
+                    {
+                        client->errorValue = c->deviceid;
+                        rc = BadDevice;
+                        goto unwind;
+                    }
+
+                    AttachDevice(client, ptr, NULL);
+                    flags[ptr->id] |= XISlaveDetached;
+                }
+                break;
+            case XIAttachSlave:
+                {
+                    xXIAttachSlaveInfo* c = (xXIAttachSlaveInfo*)any;
+                    DeviceIntPtr newmaster;
+                    DeviceIntPtr *xtstdevice;
+
+                    if (c->deviceid > 0xFF) /* FIXME */
+                    {
+                        client->errorValue = c->deviceid;
+                        return BadImplementation;
+                    }
+                    if (c->new_master > 0xFF) /* FIXME */
+                    {
+                        client->errorValue = c->new_master;
+                        return BadImplementation;
+                    }
+
+                    rc = dixLookupDevice(&ptr, c->deviceid, client,
+                                          DixWriteAccess);
+                    if (rc != Success)
+                       goto unwind;
+
+                    if (IsMaster(ptr))
+                    {
+                        client->errorValue = c->deviceid;
+                        rc = BadDevice;
+                        goto unwind;
+                    }
+
+                    xtstdevice = dixLookupPrivate( &ptr->devPrivates,
+                                                   XTstDevicePrivateKey );
+
+                    /* Don't allow changes to Xtst Devices, these are fixed */
+                    if( xtstdevice )
+                    {
+                        client->errorValue = c->deviceid;
+                        rc = BadDevice;
+                        goto unwind;
+                    }
+
+                    rc = dixLookupDevice(&newmaster, c->new_master,
+                            client, DixWriteAccess);
+                    if (rc != Success)
+                        goto unwind;
+                    if (!IsMaster(newmaster))
+                    {
+                        client->errorValue = c->new_master;
+                        rc = BadDevice;
+                        goto unwind;
+                    }
+
+                    if (!((IsPointerDevice(newmaster) &&
+                                    IsPointerDevice(ptr)) ||
+                                (IsKeyboardDevice(newmaster) &&
+                                 IsKeyboardDevice(ptr))))
+                    {
+                        rc = BadDevice;
+                        goto unwind;
+                    }
+                    AttachDevice(client, ptr, newmaster);
+                    flags[ptr->id] |= XISlaveAttached;
+                }
+                break;
+        }
+
+        any = (xXIAnyHierarchyChangeInfo*)((char*)any + any->length * 4);
+    }
+
+unwind:
+
+    XISendDeviceHierarchyEvent(flags);
+    return rc;
+}
+
diff --git a/Xi/xichangehierarchy.h b/Xi/xichangehierarchy.h
new file mode 100644
index 0000000..b46cfb4
--- /dev/null
+++ b/Xi/xichangehierarchy.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2007-2008 Peter Hutterer
+ *
+ * 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: Peter Hutterer, University of South Australia, NICTA
+ */
+
+/***********************************************************************
+ *
+ * Request change in the device hierarchy.
+ *
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifndef CHDEVHIER_H
+#define CHDEVHIER_H 1
+
+int SProcXIChangeHierarchy(ClientPtr /* client */);
+int ProcXIChangeHierarchy(ClientPtr /* client */);
+
+void XISendDeviceHierarchyEvent(int flags[]);
+
+#endif
diff --git a/Xi/xigetclientpointer.c b/Xi/xigetclientpointer.c
new file mode 100644
index 0000000..859d3fd
--- /dev/null
+++ b/Xi/xigetclientpointer.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2007-2008 Peter Hutterer
+ *
+ * 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: Peter Hutterer, University of South Australia, NICTA
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/X.h>	/* for inputstr.h    */
+#include <X11/Xproto.h>	/* Request macro     */
+#include "inputstr.h"	/* DeviceIntPtr      */
+#include "windowstr.h"	/* window structure  */
+#include "scrnintstr.h"	/* screen structure  */
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XI2proto.h>
+#include "extnsionst.h"
+#include "extinit.h"	/* LookupDeviceIntRec */
+#include "exevents.h"
+#include "exglobals.h"
+
+#include "xigetclientpointer.h"
+
+/***********************************************************************
+ * This procedure allows a client to query another client's client pointer
+ * setting.
+ */
+
+int
+SProcXIGetClientPointer(ClientPtr client)
+{
+    char n;
+    REQUEST(xXIGetClientPointerReq);
+
+    swaps(&stuff->length, n);
+    swapl(&stuff->win, n);
+    return ProcXIGetClientPointer(client);
+}
+
+int ProcXIGetClientPointer(ClientPtr client)
+{
+    int rc;
+    ClientPtr winclient;
+    xXIGetClientPointerReply rep;
+    REQUEST(xXIGetClientPointerReq);
+    REQUEST_SIZE_MATCH(xXIGetClientPointerReq);
+
+    if (stuff->win != None)
+    {
+        rc = dixLookupClient(&winclient, stuff->win, client,
+                DixWriteAccess);
+
+        if (rc != Success)
+            return BadWindow;
+    } else
+        winclient = client;
+
+    rep.repType = X_Reply;
+    rep.RepType = X_XIGetClientPointer;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.set = (winclient->clientPtr != NULL);
+    rep.deviceid = (winclient->clientPtr) ? winclient->clientPtr->id : 0;
+
+    WriteReplyToClient(client, sizeof(xXIGetClientPointerReply), &rep);
+    return Success;
+}
+
+/***********************************************************************
+ *
+ * This procedure writes the reply for the XGetClientPointer function,
+ * if the client and server have a different byte ordering.
+ *
+ */
+
+void
+SRepXIGetClientPointer(ClientPtr client, int size,
+        xXIGetClientPointerReply* rep)
+{
+    char n;
+    swaps(&rep->sequenceNumber, n);
+    swapl(&rep->length, n);
+    swaps(&rep->deviceid, n);
+    WriteToClient(client, size, (char *)rep);
+}
+
diff --git a/Xi/xigetclientpointer.h b/Xi/xigetclientpointer.h
new file mode 100644
index 0000000..1539aa8
--- /dev/null
+++ b/Xi/xigetclientpointer.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2007-2008 Peter Hutterer
+ *
+ * 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: Peter Hutterer, University of South Australia, NICTA
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifndef GETCPTR_H
+#define GETCPTR_H 1
+int SProcXIGetClientPointer(ClientPtr /* client */);
+int ProcXIGetClientPointer(ClientPtr /* client */);
+void SRepXIGetClientPointer(ClientPtr /* client */,
+        int /* size */,
+        xXIGetClientPointerReply* /* rep */);
+
+#endif /* GETCPTR_H */
diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
new file mode 100644
index 0000000..07ddfa1
--- /dev/null
+++ b/Xi/xiquerydevice.c
@@ -0,0 +1,451 @@
+/*
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * Authors: Peter Hutterer
+ *
+ */
+
+/**
+ * @file Protocol handling for the XIQueryDevice request/reply.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "inputstr.h"
+#include <X11/X.h>
+#include <X11/extensions/XI2proto.h>
+#include "xkbstr.h"
+#include "xkbsrv.h"
+#include "xserver-properties.h"
+#include "exevents.h"
+
+#include "xiquerydevice.h"
+
+static int ListDeviceInfo(DeviceIntPtr dev, xXIDeviceInfo* info);
+static int SizeDeviceInfo(DeviceIntPtr dev);
+static void SwapDeviceInfo(DeviceIntPtr dev, xXIDeviceInfo* info);
+int
+SProcXIQueryDevice(ClientPtr client)
+{
+    char n;
+
+    REQUEST(xXIQueryDeviceReq);
+
+    swaps(&stuff->length, n);
+    swaps(&stuff->deviceid, n);
+
+    return ProcXIQueryDevice(client);
+}
+
+int
+ProcXIQueryDevice(ClientPtr client)
+{
+    xXIQueryDeviceReply rep;
+    DeviceIntPtr dev = NULL;
+    int rc = Success;
+    int len = 0;
+    char *info, *ptr;
+
+    REQUEST(xXIQueryDeviceReq);
+    REQUEST_SIZE_MATCH(xXIQueryDeviceReq);
+
+    if (stuff->deviceid > 0xFF) /* FIXME */
+    {
+        client->errorValue = stuff->deviceid;
+        return BadImplementation;
+    }
+
+    if (stuff->deviceid != XIAllDevices && stuff->deviceid != XIAllMasterDevices)
+    {
+        rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
+        if (rc != Success)
+        {
+            client->errorValue = stuff->deviceid;
+            return rc;
+        }
+    }
+
+    if (dev)
+        len += SizeDeviceInfo(dev);
+    else
+    {
+        len = 0;
+        for (dev = inputInfo.devices; dev; dev = dev->next)
+        {
+            if (stuff->deviceid == XIAllDevices ||
+                (stuff->deviceid == XIAllMasterDevices && IsMaster(dev)))
+                len += SizeDeviceInfo(dev);
+        }
+
+        for (dev = inputInfo.off_devices; dev; dev = dev->next)
+        {
+            if (stuff->deviceid == XIAllDevices ||
+                (stuff->deviceid == XIAllMasterDevices && IsMaster(dev)))
+                len += SizeDeviceInfo(dev);
+        }
+
+        dev = NULL;
+    }
+
+    info = xcalloc(1, len);
+    if (!info)
+        return BadAlloc;
+
+    memset(&rep, 0, sizeof(xXIQueryDeviceReply));
+    rep.repType = X_Reply;
+    rep.RepType = X_XIQueryDevice;
+    rep.sequenceNumber = client->sequence;
+    rep.length = len/4;
+    rep.num_devices = 0;
+
+    ptr = info;
+    if (dev)
+    {
+        len = ListDeviceInfo(dev, (xXIDeviceInfo*)info);
+        if (client->swapped)
+            SwapDeviceInfo(dev, (xXIDeviceInfo*)info);
+        info += len;
+        rep.num_devices = 1;
+    } else
+    {
+        for (dev = inputInfo.devices; dev; dev = dev->next)
+        {
+            if (stuff->deviceid == XIAllDevices ||
+                    (stuff->deviceid == XIAllMasterDevices && IsMaster(dev)))
+            {
+                len = ListDeviceInfo(dev, (xXIDeviceInfo*)info);
+                if (client->swapped)
+                    SwapDeviceInfo(dev, (xXIDeviceInfo*)info);
+                info += len;
+                rep.num_devices++;
+            }
+        }
+
+        for (dev = inputInfo.off_devices; dev; dev = dev->next)
+        {
+            if (stuff->deviceid == XIAllDevices ||
+                    (stuff->deviceid == XIAllMasterDevices && IsMaster(dev)))
+            {
+                len = ListDeviceInfo(dev, (xXIDeviceInfo*)info);
+                if (client->swapped)
+                    SwapDeviceInfo(dev, (xXIDeviceInfo*)info);
+                info += len;
+                rep.num_devices++;
+            }
+        }
+    }
+
+    WriteReplyToClient(client, sizeof(xXIQueryDeviceReply), &rep);
+    WriteToClient(client, rep.length * 4, ptr);
+    return rc;
+}
+
+void
+SRepXIQueryDevice(ClientPtr client, int size, xXIQueryDeviceReply *rep)
+{
+    char n;
+
+    swaps(&rep->sequenceNumber, n);
+    swapl(&rep->length, n);
+    swaps(&rep->num_devices, n);
+
+    /* Device info is already swapped, see ProcXIQueryDevice */
+
+    WriteToClient(client, size, (char *)rep);
+}
+
+
+
+/**
+ * @return The number of bytes needed to store this device's xXIDeviceInfo
+ * (and its classes).
+ */
+static int
+SizeDeviceInfo(DeviceIntPtr dev)
+{
+    int len = sizeof(xXIDeviceInfo);
+
+    /* 4-padded name */
+    len += (((strlen(dev->name) + 3)/4)*4);
+
+    return len + SizeDeviceClasses(dev);
+
+}
+
+/*
+ * @return The number of bytes needed to store this device's classes.
+ */
+int
+SizeDeviceClasses(DeviceIntPtr dev)
+{
+    int len = 0;
+
+    if (dev->button)
+    {
+        len += sizeof(xXIButtonInfo);
+        len += dev->button->numButtons * sizeof(Atom);
+    }
+
+    if (dev->key)
+    {
+        XkbDescPtr xkb = dev->key->xkbInfo->desc;
+        len += sizeof(xXIKeyInfo);
+        len += (xkb->max_key_code - xkb->min_key_code + 1) * sizeof(uint32_t);
+    }
+
+    if (dev->valuator)
+        len += sizeof(xXIValuatorInfo) * dev->valuator->numAxes;
+
+    return len;
+}
+
+
+/**
+ * Write button information into info.
+ * @return Number of bytes written into info.
+ */
+int
+ListButtonInfo(DeviceIntPtr dev, xXIButtonInfo* info)
+{
+    info->type = ButtonClass;
+    info->num_buttons = dev->button->numButtons;
+    info->length = 2 + info->num_buttons;
+
+    /** XXX: button labels */
+
+    return info->length * 4;
+}
+
+static void
+SwapButtonInfo(DeviceIntPtr dev, xXIButtonInfo* info)
+{
+    char n;
+    Atom *btn;
+    int i;
+    swaps(&info->type, n);
+    swaps(&info->length, n);
+
+    for (i = 0, btn = (Atom*)&info[1]; i < info->num_buttons; i++, btn++)
+        swaps(btn, n);
+
+    swaps(&info->num_buttons, n);
+}
+
+/**
+ * Write key information into info.
+ * @return Number of bytes written into info.
+ */
+int
+ListKeyInfo(DeviceIntPtr dev, xXIKeyInfo* info)
+{
+    int i;
+    XkbDescPtr xkb = dev->key->xkbInfo->desc;
+    uint32_t *kc;
+
+    info->type = KeyClass;
+    info->num_keycodes = xkb->max_key_code - xkb->min_key_code + 1;
+    info->length = 2 + info->num_keycodes;
+
+    kc = (uint32_t*)&info[1];
+    for (i = xkb->min_key_code; i <= xkb->max_key_code; i++, kc++)
+        *kc = i;
+
+    return info->length * 4;
+}
+
+static void
+SwapKeyInfo(DeviceIntPtr dev, xXIKeyInfo* info)
+{
+    char n;
+    uint32_t *key;
+    int i;
+    swaps(&info->type, n);
+    swaps(&info->length, n);
+
+    for (i = 0, key = (uint32_t*)&info[1]; i < info->num_keycodes; i++, key++)
+        swapl(key, n);
+
+    swaps(&info->num_keycodes, n);
+}
+
+/**
+ * List axis information for the given axis.
+ *
+ * @return The number of bytes written into info.
+ */
+int
+ListValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info, int axisnumber)
+{
+    ValuatorClassPtr v = dev->valuator;
+
+    info->type = ValuatorClass;
+    info->length = sizeof(xXIValuatorInfo)/4;
+    info->name = XIGetKnownProperty(AXIS_LABEL_PROP_REL_MISC); /* XXX */
+    info->min.integral = v->axes[axisnumber].min_value;
+    info->min.frac = 0;
+    info->max.integral = v->axes[axisnumber].max_value;
+    info->max.frac = 0;
+    info->resolution = v->axes[axisnumber].resolution;
+    info->number = axisnumber;
+    info->mode = v->mode; /* Server doesn't have per-axis mode yet */
+
+    return info->length * 4;
+}
+
+static void
+SwapValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info)
+{
+    char n;
+    swaps(&info->type, n);
+    swaps(&info->length, n);
+    swapl(&info->name, n);
+    swapl(&info->min.integral, n);
+    swapl(&info->min.frac, n);
+    swapl(&info->max.integral, n);
+    swapl(&info->max.frac, n);
+    swaps(&info->number, n);
+}
+
+int GetDeviceUse(DeviceIntPtr dev, uint16_t *attachment)
+{
+    DeviceIntPtr master = dev->u.master;
+    int use;
+
+    if (IsMaster(dev))
+    {
+        DeviceIntPtr paired = GetPairedDevice(dev);
+        use = IsPointerDevice(dev) ? XIMasterPointer : XIMasterKeyboard;
+        *attachment = (paired ? paired->id : 0);
+    } else if (master)
+    {
+        use = IsPointerDevice(master) ? XISlavePointer : XISlaveKeyboard;
+        *attachment = master->id;
+    } else
+        use = XIFloatingSlave;
+
+    return use;
+}
+
+/**
+ * Write the info for device dev into the buffer pointed to by info.
+ *
+ * @return The number of bytes used.
+ */
+static int
+ListDeviceInfo(DeviceIntPtr dev, xXIDeviceInfo* info)
+{
+    char *any = (char*)&info[1];
+    int len = 0, total_len = 0;
+
+    info->deviceid = dev->id;
+    info->use = GetDeviceUse(dev, &info->attachment);
+    info->num_classes = 0;
+    info->name_len = strlen(dev->name);
+    info->enabled = dev->enabled;
+    total_len = sizeof(xXIDeviceInfo);
+
+    len = ((info->name_len + 3)/4) * 4;
+    memset(any, 0, len);
+    strncpy(any, dev->name, info->name_len);
+    any += len;
+    total_len += len;
+
+    return total_len + ListDeviceClasses(dev, any, &info->num_classes);
+}
+
+/**
+ * Write the class info of the device into the memory pointed to by any, set
+ * nclasses to the number of classes in total and return the number of bytes
+ * written.
+ */
+int
+ListDeviceClasses(DeviceIntPtr dev, char *any, uint16_t *nclasses)
+{
+    int total_len = 0;
+    int len;
+    int i;
+
+    if (dev->button)
+    {
+        (*nclasses)++;
+        len = ListButtonInfo(dev, (xXIButtonInfo*)any);
+        any += len;
+        total_len += len;
+    }
+
+    if (dev->key)
+    {
+        (*nclasses)++;
+        len = ListKeyInfo(dev, (xXIKeyInfo*)any);
+        any += len;
+        total_len += len;
+    }
+
+    for (i = 0; dev->valuator && i < dev->valuator->numAxes; i++)
+    {
+        (*nclasses)++;
+        len = ListValuatorInfo(dev, (xXIValuatorInfo*)any, i);
+        any += len;
+        total_len += len;
+    }
+
+    return total_len;
+}
+
+static void
+SwapDeviceInfo(DeviceIntPtr dev, xXIDeviceInfo* info)
+{
+    char n;
+    char *any = (char*)&info[1];
+    int i;
+
+    /* Skip over name */
+    any += (((info->name_len + 3)/4) * 4);
+
+    for (i = 0; i < info->num_classes; i++)
+    {
+        int len = ((xXIAnyInfo*)any)->length;
+        switch(((xXIAnyInfo*)any)->type)
+        {
+            case XIButtonClass:
+                SwapButtonInfo(dev, (xXIButtonInfo*)any);
+                break;
+            case XIKeyClass:
+                SwapKeyInfo(dev, (xXIKeyInfo*)any);
+                break;
+            case XIValuatorClass:
+                SwapValuatorInfo(dev, (xXIValuatorInfo*)any);
+                break;
+        }
+
+        any += len * 4;
+    }
+
+    swaps(&info->deviceid, n);
+    swaps(&info->use, n);
+    swaps(&info->attachment, n);
+    swaps(&info->num_classes, n);
+    swaps(&info->name_len, n);
+
+}
diff --git a/Xi/xiquerydevice.h b/Xi/xiquerydevice.h
new file mode 100644
index 0000000..34e87bd
--- /dev/null
+++ b/Xi/xiquerydevice.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * Authors: Peter Hutterer
+ *
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifndef QUERYDEV_H
+#define QUERYDEV_H 1
+
+#include <X11/extensions/XI2proto.h>
+
+int SProcXIQueryDevice(ClientPtr client);
+int ProcXIQueryDevice(ClientPtr client);
+void SRepXIQueryDevice(ClientPtr client, int size, xXIQueryDeviceReply *rep);
+int SizeDeviceClasses(DeviceIntPtr dev);
+int ListDeviceClasses(DeviceIntPtr dev, char* any, uint16_t* nclasses);
+int GetDeviceUse(DeviceIntPtr dev, uint16_t *attachment);
+int ListButtonInfo(DeviceIntPtr dev, xXIButtonInfo* info);
+int ListKeyInfo(DeviceIntPtr dev, xXIKeyInfo* info);
+int ListValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo* info, int axisnumber);
+#endif /* QUERYDEV_H */
diff --git a/Xi/xiquerypointer.c b/Xi/xiquerypointer.c
new file mode 100644
index 0000000..1d00b9e
--- /dev/null
+++ b/Xi/xiquerypointer.c
@@ -0,0 +1,210 @@
+/*
+ * Copyright 2007-2008 Peter Hutterer
+ *
+ * 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: Peter Hutterer, University of South Australia, NICTA
+ */
+
+/***********************************************************************
+ *
+ * Request to query the pointer location of an extension input device.
+ *
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/X.h>	/* for inputstr.h    */
+#include <X11/Xproto.h>	/* Request macro     */
+#include "inputstr.h"	/* DeviceIntPtr      */
+#include "windowstr.h"	/* window structure  */
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XI2proto.h>
+#include "extnsionst.h"
+#include "exevents.h"
+#include "exglobals.h"
+#include "eventconvert.h"
+#include "xkbsrv.h"
+
+#ifdef PANORAMIX
+#include "panoramiXsrv.h"
+#endif
+
+#include "xiquerypointer.h"
+
+/***********************************************************************
+ *
+ * This procedure allows a client to query the pointer of a device.
+ *
+ */
+
+int
+SProcXIQueryPointer(ClientPtr client)
+{
+    char n;
+
+    REQUEST(xXIQueryPointerReq);
+    swaps(&stuff->length, n);
+    return (ProcXIQueryPointer(client));
+}
+
+int
+ProcXIQueryPointer(ClientPtr client)
+{
+    int rc;
+    xXIQueryPointerReply rep;
+    DeviceIntPtr pDev, kbd;
+    WindowPtr pWin, t;
+    SpritePtr pSprite;
+    XkbStatePtr state;
+    char *buttons = NULL;
+
+    REQUEST(xXIQueryPointerReq);
+    REQUEST_SIZE_MATCH(xXIQueryPointerReq);
+
+    if (stuff->deviceid > 0xFF) /* FIXME */
+    {
+        client->errorValue = stuff->deviceid;
+        return BadImplementation;
+    }
+
+    rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixReadAccess);
+    if (rc != Success)
+        return rc;
+
+    if (pDev->valuator == NULL)
+    {
+        client->errorValue = stuff->deviceid;
+        return BadDevice;
+    }
+
+    rc = dixLookupWindow(&pWin, stuff->win, client, DixReadAccess);
+    if (rc != Success)
+    {
+        SendErrorToClient(client, IReqCode, X_XIQueryPointer,
+                stuff->win, rc);
+        return Success;
+    }
+
+    if (pDev->valuator->motionHintWindow)
+        MaybeStopHint(pDev, client);
+
+    kbd = GetPairedDevice(pDev);
+
+    pSprite = pDev->spriteInfo->sprite;
+    rep.repType = X_Reply;
+    rep.RepType = X_XIQueryPointer;
+    rep.length = 5;
+    rep.sequenceNumber = client->sequence;
+    rep.root = (GetCurrentRootWindow(pDev))->drawable.id;
+    rep.root_x = FP1616(pSprite->hot.x, 0);
+    rep.root_y = FP1616(pSprite->hot.y, 0);
+    rep.child = None;
+
+    state = &kbd->key->xkbInfo->prev_state;
+    rep.mods.base_mods = state->base_mods;
+    rep.mods.latched_mods = state->latched_mods;
+    rep.mods.locked_mods = state->locked_mods;
+
+    rep.group.base_group = state->base_group;
+    rep.group.latched_group = state->latched_group;
+    rep.group.locked_group = state->locked_group;
+
+    if (pDev->button)
+    {
+        int i, down;
+        rep.buttons_len = (((pDev->button->numButtons + 7)/8) + 3)/4;
+        rep.length += rep.buttons_len;
+        buttons = xcalloc(rep.buttons_len, 4);
+        if (!buttons)
+            return BadAlloc;
+
+        down = pDev->button->buttonsDown;
+
+        for (i = 0; i < pDev->button->numButtons && down; i++)
+        {
+            if (BitIsOn(pDev->button->down, i))
+            {
+                SetBit(buttons, i);
+                down--;
+            }
+        }
+    } else
+        rep.buttons_len = 0;
+
+    if (pSprite->hot.pScreen == pWin->drawable.pScreen)
+    {
+        rep.same_screen = xTrue;
+        rep.win_x = FP1616(pSprite->hot.x - pWin->drawable.x, 0);
+        rep.win_y = FP1616(pSprite->hot.y - pWin->drawable.y, 0);
+        for (t = pSprite->win; t; t = t->parent)
+            if (t->parent == pWin)
+            {
+                rep.child = t->drawable.id;
+                break;
+            }
+    } else
+    {
+        rep.same_screen = xFalse;
+        rep.win_x = 0;
+        rep.win_y = 0;
+    }
+
+#ifdef PANORAMIX
+    if(!noPanoramiXExtension) {
+        rep.root_x += FP1616(panoramiXdataPtr[0].x, 0);
+        rep.root_y += FP1616(panoramiXdataPtr[0].y, 0);
+        if (stuff->win == rep.root)
+        {
+            rep.win_x += FP1616(panoramiXdataPtr[0].x, 0);
+            rep.win_y += FP1616(panoramiXdataPtr[0].y, 0);
+        }
+    }
+#endif
+
+    WriteReplyToClient(client, sizeof(xXIQueryPointerReply), &rep);
+    if (buttons)
+        WriteToClient(client, rep.buttons_len * 4, buttons);
+
+    xfree(buttons);
+
+    return Success;
+}
+
+/***********************************************************************
+ *
+ * This procedure writes the reply for the XIQueryPointer function,
+ * if the client and server have a different byte ordering.
+ *
+ */
+
+void
+SRepXIQueryPointer(ClientPtr client, int size,
+                   xXIQueryPointerReply * rep)
+{
+    char n;
+
+    swaps(&rep->sequenceNumber, n);
+    swapl(&rep->length, n);
+    WriteToClient(client, size, (char *)rep);
+}
+
diff --git a/Xi/xiquerypointer.h b/Xi/xiquerypointer.h
new file mode 100644
index 0000000..ea22376
--- /dev/null
+++ b/Xi/xiquerypointer.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2007-2008 Peter Hutterer
+ *
+ * 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: Peter Hutterer, University of South Australia, NICTA
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifndef QUERYDP_H
+#define QUERYDP_H 1
+
+int SProcXIQueryPointer(ClientPtr /* client */);
+int ProcXIQueryPointer(ClientPtr /* client */);
+void SRepXIQueryPointer(ClientPtr /* client */ ,
+			int /* size */ ,
+			xXIQueryPointerReply *	/* rep */);
+
+#endif /* QUERYDP_H */
diff --git a/Xi/xiqueryversion.c b/Xi/xiqueryversion.c
new file mode 100644
index 0000000..ae63297
--- /dev/null
+++ b/Xi/xiqueryversion.c
@@ -0,0 +1,128 @@
+/*
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * Authors: Peter Hutterer
+ *
+ */
+
+/**
+ * @file xiqueryversion.c
+ * Protocol handling for the XIQueryVersion request/reply.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+
+#include "inputstr.h"
+
+#include <X11/Xmd.h>
+#include <X11/X.h>
+#include <X11/extensions/XI2proto.h>
+
+#include "exglobals.h"
+#include "exevents.h"
+#include "xiqueryversion.h"
+#include "misc.h"
+
+extern XExtensionVersion XIVersion; /* defined in getvers.c */
+/**
+ * Return the supported XI version.
+ *
+ * Saves the version the client claims to support as well, for future
+ * reference.
+ */
+int
+ProcXIQueryVersion(ClientPtr client)
+{
+    xXIQueryVersionReply rep;
+    XIClientPtr pXIClient;
+    int major, minor;
+    unsigned int sversion, cversion;
+
+    REQUEST(xXIQueryVersionReq);
+    REQUEST_SIZE_MATCH(xXIQueryVersionReq);
+
+    /* This request only exists after XI2 */
+    if (stuff->major_version < 2)
+    {
+        client->errorValue = stuff->major_version;
+        return BadValue;
+    }
+
+    pXIClient = dixLookupPrivate(&client->devPrivates, XIClientPrivateKey);
+
+    sversion = XIVersion.major_version * 1000 + XIVersion.minor_version;
+    cversion = stuff->major_version * 1000 + stuff->minor_version;
+
+    if (sversion > cversion)
+    {
+        major = stuff->major_version;
+        minor = stuff->minor_version;
+    } else
+    {
+        major = XIVersion.major_version;
+        minor = XIVersion.minor_version;
+    }
+
+    pXIClient->major_version = major;
+    pXIClient->minor_version = minor;
+
+    memset(&rep, 0, sizeof(xXIQueryVersionReply));
+    rep.repType = X_Reply;
+    rep.RepType = X_XIQueryVersion;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.major_version = major;
+    rep.minor_version = minor;
+
+    WriteReplyToClient(client, sizeof(xXIQueryVersionReply), &rep);
+
+    return Success;
+}
+
+/* Swapping routines */
+
+int
+SProcXIQueryVersion(ClientPtr client)
+{
+    char n;
+
+    REQUEST(xXIQueryVersionReq);
+    swaps(&stuff->length, n);
+    REQUEST_AT_LEAST_SIZE(xXIQueryVersionReq);
+    swaps(&stuff->major_version, n);
+    swaps(&stuff->minor_version, n);
+    return (ProcXIQueryVersion(client));
+}
+
+void
+SRepXIQueryVersion(ClientPtr client, int size, xXIQueryVersionReply *rep)
+{
+    char n;
+    swaps(&rep->sequenceNumber, n);
+    swapl(&rep->length, n);
+    swaps(&rep->major_version, n);
+    swaps(&rep->minor_version, n);
+    WriteToClient(client, size, (char *)rep);
+}
diff --git a/Xi/xiqueryversion.h b/Xi/xiqueryversion.h
new file mode 100644
index 0000000..06bb729
--- /dev/null
+++ b/Xi/xiqueryversion.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright © 2009 Red Hat, Inc.
+ *
+ * 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.
+ *
+ * Authors: Peter Hutterer
+ *
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/extensions/XI2proto.h>
+
+#ifndef QUERYVERSION_H
+#define QUERYVERSION_H 1
+
+int SProcXIQueryVersion(ClientPtr client);
+int ProcXIQueryVersion(ClientPtr client);
+void SRepXIQueryVersion(ClientPtr client, int size, xXIQueryVersionReply* rep);
+
+#endif /* QUERYVERSION_H */
diff --git a/Xi/xisetclientpointer.c b/Xi/xisetclientpointer.c
new file mode 100644
index 0000000..2648074
--- /dev/null
+++ b/Xi/xisetclientpointer.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2007-2008 Peter Hutterer
+ *
+ * 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: Peter Hutterer, University of South Australia, NICTA
+ */
+
+/***********************************************************************
+ *
+ * Request to set the client pointer for the owner of the given window.
+ * All subsequent calls that are ambiguous will choose the client pointer as
+ * default value.
+ */
+
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/X.h>	/* for inputstr.h    */
+#include <X11/Xproto.h>	/* Request macro     */
+#include "inputstr.h"	/* DeviceIntPtr      */
+#include "windowstr.h"	/* window structure  */
+#include "scrnintstr.h"	/* screen structure  */
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XI2proto.h>
+#include "extnsionst.h"
+#include "exevents.h"
+#include "exglobals.h"
+
+#include "xisetclientpointer.h"
+
+int
+SProcXISetClientPointer(ClientPtr client)
+{
+    char n;
+
+    REQUEST(xXISetClientPointerReq);
+    swaps(&stuff->length, n);
+    swapl(&stuff->win, n);
+    swaps(&stuff->deviceid, n);
+    REQUEST_SIZE_MATCH(xXISetClientPointerReq);
+    return (ProcXISetClientPointer(client));
+}
+
+int
+ProcXISetClientPointer(ClientPtr client)
+{
+    DeviceIntPtr pDev;
+    ClientPtr targetClient;
+    int rc;
+
+    REQUEST(xXISetClientPointerReq);
+    REQUEST_SIZE_MATCH(xXISetClientPointerReq);
+
+    if (stuff->deviceid > 0xFF) /* FIXME */
+    {
+        client->errorValue = stuff->deviceid;
+        return BadImplementation;
+    }
+
+    rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixWriteAccess);
+    if (rc != Success)
+    {
+        client->errorValue = stuff->deviceid;
+        return rc;
+    }
+
+    if (!IsMaster(pDev))
+    {
+        client->errorValue = stuff->deviceid;
+        return BadDevice;
+    }
+
+    pDev = GetMaster(pDev, MASTER_POINTER);
+
+    if (stuff->win != None)
+    {
+        rc = dixLookupClient(&targetClient, stuff->win, client,
+                DixWriteAccess);
+
+        if (rc != Success)
+            return BadWindow;
+
+    } else
+        targetClient = client;
+
+    if (!SetClientPointer(targetClient, pDev))
+    {
+        client->errorValue = stuff->deviceid;
+        return BadDevice;
+    }
+
+    return Success;
+}
diff --git a/Xi/xisetclientpointer.h b/Xi/xisetclientpointer.h
new file mode 100644
index 0000000..5968d98
--- /dev/null
+++ b/Xi/xisetclientpointer.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2007-2008 Peter Hutterer
+ *
+ * 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: Peter Hutterer, University of South Australia, NICTA
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifndef SETCPTR_H
+#define SETCPTR_H 1
+
+int SProcXISetClientPointer(ClientPtr /* client */);
+int ProcXISetClientPointer(ClientPtr /* client */);
+
+#endif /* SETCPTR_H */
diff --git a/Xi/xiwarppointer.c b/Xi/xiwarppointer.c
new file mode 100644
index 0000000..f3acfe4
--- /dev/null
+++ b/Xi/xiwarppointer.c
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2007-2008 Peter Hutterer
+ *
+ * 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: Peter Hutterer, University of South Australia, NICTA
+ */
+
+/***********************************************************************
+ *
+ * Request to Warp the pointer location of an extension input device.
+ *
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/X.h>	/* for inputstr.h    */
+#include <X11/Xproto.h>	/* Request macro     */
+#include "inputstr.h"	/* DeviceIntPtr      */
+#include "windowstr.h"	/* window structure  */
+#include "scrnintstr.h"	/* screen structure  */
+#include <X11/extensions/XI.h>
+#include <X11/extensions/XI2proto.h>
+#include "extnsionst.h"
+#include "exevents.h"
+#include "exglobals.h"
+#include "mipointer.h" /* for miPointerUpdateSprite */
+
+
+#include "xiwarppointer.h"
+/***********************************************************************
+ *
+ * This procedure allows a client to warp the pointer of a device.
+ *
+ */
+
+int
+SProcXIWarpPointer(ClientPtr client)
+{
+    char n;
+
+    REQUEST(xXIWarpPointerReq);
+    swaps(&stuff->length, n);
+    return (ProcXIWarpPointer(client));
+}
+
+int
+ProcXIWarpPointer(ClientPtr client)
+{
+    int rc;
+    int x, y;
+    WindowPtr dest = NULL;
+    DeviceIntPtr pDev;
+    SpritePtr pSprite;
+    ScreenPtr newScreen;
+
+    REQUEST(xXIWarpPointerReq);
+    REQUEST_SIZE_MATCH(xXIWarpPointerReq);
+
+    if (stuff->deviceid > 0xFF) /* FIXME */
+    {
+        client->errorValue = stuff->deviceid;
+        return BadImplementation;
+    }
+
+    /* FIXME: panoramix stuff is missing, look at ProcWarpPointer */
+
+    rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixWriteAccess);
+
+    if (rc != Success)
+        return rc;
+
+    if (stuff->dst_win != None)
+    {
+        rc = dixLookupWindow(&dest, stuff->dst_win, client, DixReadAccess);
+        if (rc != Success)
+        {
+            return rc;
+        }
+    }
+
+    pSprite = pDev->spriteInfo->sprite;
+    x = pSprite->hotPhys.x;
+    y = pSprite->hotPhys.y;
+
+    if (stuff->src_win != None)
+    {
+        int winX, winY;
+        WindowPtr src;
+
+        rc = dixLookupWindow(&src, stuff->src_win, client, DixReadAccess);
+        if (rc != Success)
+        {
+            return rc;
+        }
+
+        winX = src->drawable.x;
+        winY = src->drawable.y;
+        if (src->drawable.pScreen != pSprite->hotPhys.pScreen ||
+                x < winX + stuff->src_x ||
+                y < winY + stuff->src_y ||
+                (stuff->src_width != 0 &&
+                 winX + stuff->src_x + (int)stuff->src_width < 0) ||
+                (stuff->src_height != 0 &&
+                 winY + stuff->src_y + (int)stuff->src_height < y) ||
+                !PointInWindowIsVisible(src, x, y))
+            return Success;
+    }
+
+    if (dest)
+    {
+        x = dest->drawable.x;
+        y = dest->drawable.y;
+        newScreen = dest->drawable.pScreen;
+    } else
+        newScreen = pSprite->hotPhys.pScreen;
+
+    x += stuff->dst_x;
+    y += stuff->dst_y;
+
+    if (x < 0)
+        x = 0;
+    else if (x > newScreen->width)
+        x = newScreen->width - 1;
+
+    if (y < 0)
+        y = 0;
+    else if (y > newScreen->height)
+        y = newScreen->height - 1;
+
+    if (newScreen == pSprite->hotPhys.pScreen)
+    {
+        if (x < pSprite->physLimits.x1)
+            x = pSprite->physLimits.x1;
+        else if (x >= pSprite->physLimits.x2)
+            x = pSprite->physLimits.x2 - 1;
+
+        if (y < pSprite->physLimits.y1)
+            y = pSprite->physLimits.y1;
+        else if (y >= pSprite->physLimits.y2)
+            y = pSprite->physLimits.y2 - 1;
+
+        if (pSprite->hotShape)
+            ConfineToShape(pDev, pSprite->hotShape, &x, &y);
+        (*newScreen->SetCursorPosition)(pDev, newScreen, x, y, TRUE);
+    } else if (!PointerConfinedToScreen(pDev))
+    {
+        NewCurrentScreen(pDev, newScreen, x, y);
+    }
+
+    /* if we don't update the device, we get a jump next time it moves */
+    pDev->last.valuators[0] = x;
+    pDev->last.valuators[1] = y;
+    miPointerUpdateSprite(pDev);
+
+    /* FIXME: XWarpPointer is supposed to generate an event. It doesn't do it
+       here though. */
+    return Success;
+}
+
diff --git a/Xi/xiwarppointer.h b/Xi/xiwarppointer.h
new file mode 100644
index 0000000..aafc739
--- /dev/null
+++ b/Xi/xiwarppointer.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2007-2008 Peter Hutterer
+ *
+ * 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: Peter Hutterer, University of South Australia, NICTA
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifndef WARPDEVP_H
+#define WARPDEVP_H 1
+
+int SProcXIWarpPointer(ClientPtr /* client */);
+int ProcXIWarpPointer(ClientPtr	/* client */);
+
+#endif /* WARPDEVP_H */
diff --git a/dix/devices.c b/dix/devices.c
index 3996ca6..2b03588 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -78,11 +78,11 @@ SOFTWARE.
 #include <X11/extensions/XIproto.h>
 #include "exglobals.h"
 #include "exevents.h"
-#include "querydev.h" /* for SizeDeviceClasses */
+#include "xiquerydevice.h" /* for SizeDeviceClasses */
 #include "xiproperty.h"
 #include "enterleave.h" /* for EnterWindow() */
 #include "xserver-properties.h"
-#include "chdevhier.h" /* For XISendDeviceHierarchyEvent */
+#include "xichangehierarchy.h" /* For XISendDeviceHierarchyEvent */
 
 /** @file
  * This file handles input device-related stuff.
diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index 85ddd61..ac2b0c3 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -45,7 +45,7 @@
 #include "events.h"
 #include "exglobals.h"
 #include "eventconvert.h"
-#include "querydev.h"
+#include "xiquerydevice.h"
 #include "xkbsrv.h"
 
 
commit 4ddb002b6847e8a88e6f13ae0453a35ee79946ae
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Jun 15 15:14:47 2009 +1000

    xfree86: fix two compiler warnings in xf86vmode.c
    
    xf86vmode.c:1578: warning: pointer targets in passing argument 1 of
    ‘SwapShorts’ differ in signedness
    ../../../../include/misc.h:231: note: expected ‘short int *’ but argument is
    of type ‘CARD16 *’
    
    xf86vmode.c:1543: warning: unused variable ‘i’
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index 10b9ed3..bd6c594 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -1540,7 +1540,7 @@ static int
 ProcXF86VidModeGetGammaRamp(ClientPtr client)
 {
     CARD16 *ramp = NULL;
-    int n, length, i;
+    int n, length;
     size_t ramplen;
     xXF86VidModeGetGammaRampReply rep;
     REQUEST(xXF86VidModeGetGammaRampReq);
@@ -1575,7 +1575,7 @@ ProcXF86VidModeGetGammaRamp(ClientPtr client)
 	swaps(&rep.sequenceNumber, n);
 	swapl(&rep.length, n);
 	swaps(&rep.size, n);
-	SwapShorts(ramp, length * 3);
+	SwapShorts((short*)ramp, length * 3);
     }
     WriteToClient(client, sizeof(xXF86VidModeGetGammaRampReply), (char *)&rep);
 
commit 9d039ef5047af2dedff0c583dda11032f71bed01
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Jun 15 15:11:55 2009 +1000

    xfree86: silence a few int10 compiler warnings.
    
    'format ‘%#x’ expects type ‘unsigned int’, but argument 2 has type ‘CARD32’'
    and similar.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/int10/helper_exec.c b/hw/xfree86/int10/helper_exec.c
index 1c89ce5..94b3d2d 100644
--- a/hw/xfree86/int10/helper_exec.c
+++ b/hw/xfree86/int10/helper_exec.c
@@ -219,7 +219,7 @@ port_rep_inb(xf86Int10InfoPtr pInt,
     register int inc = d_f ? -1 : 1;
     CARD32 dst = base;
     if (PRINT_PORT && DEBUG_IO_TRACE())
-	ErrorF(" rep_insb(%#x) %d bytes at %8.8x %s\n",
+	ErrorF(" rep_insb(%#x) %ld bytes at %8.8lx %s\n",
 		port, count, base, d_f ? "up" : "down");
     while (count--) {
 	MEM_WB(pInt, dst, x_inb(port));
@@ -235,7 +235,7 @@ port_rep_inw(xf86Int10InfoPtr pInt,
     register int inc = d_f ? -2 : 2;
     CARD32 dst = base;
     if (PRINT_PORT && DEBUG_IO_TRACE())
-	ErrorF(" rep_insw(%#x) %d bytes at %8.8x %s\n",
+	ErrorF(" rep_insw(%#x) %ld bytes at %8.8lx %s\n",
 	     port, count, base, d_f ? "up" : "down");
     while (count--) {
 	MEM_WW(pInt, dst, x_inw(port));
@@ -251,7 +251,7 @@ port_rep_inl(xf86Int10InfoPtr pInt,
     register int inc = d_f ? -4 : 4;
     CARD32 dst = base;
     if (PRINT_PORT && DEBUG_IO_TRACE())
-	ErrorF(" rep_insl(%#x) %d bytes at %8.8x %s\n",
+	ErrorF(" rep_insl(%#x) %ld bytes at %8.8lx %s\n",
 	     port, count, base, d_f ? "up" : "down");
     while (count--) {
 	MEM_WL(pInt, dst, x_inl(port));
@@ -267,7 +267,7 @@ port_rep_outb(xf86Int10InfoPtr pInt,
     register int inc = d_f ? -1 : 1;
     CARD32 dst = base;
     if (PRINT_PORT && DEBUG_IO_TRACE())
-	ErrorF(" rep_outb(%#x) %d bytes at %8.8x %s\n",
+	ErrorF(" rep_outb(%#x) %ld bytes at %8.8lx %s\n",
 	     port, count, base, d_f ? "up" : "down");
     while (count--) {
 	x_outb(port, MEM_RB(pInt, dst));
@@ -283,7 +283,7 @@ port_rep_outw(xf86Int10InfoPtr pInt,
     register int inc = d_f ? -2 : 2;
     CARD32 dst = base;
     if (PRINT_PORT && DEBUG_IO_TRACE())
-	ErrorF(" rep_outw(%#x) %d bytes at %8.8x %s\n",
+	ErrorF(" rep_outw(%#x) %ld bytes at %8.8lx %s\n",
 	     port, count, base, d_f ? "up" : "down");
     while (count--) {
 	x_outw(port, MEM_RW(pInt, dst));
@@ -299,7 +299,7 @@ port_rep_outl(xf86Int10InfoPtr pInt,
     register int inc = d_f ? -4 : 4;
     CARD32 dst = base;
     if (PRINT_PORT && DEBUG_IO_TRACE())
-	ErrorF(" rep_outl(%#x) %d bytes at %8.8x %s\n",
+	ErrorF(" rep_outl(%#x) %ld bytes at %8.8lx %s\n",
 	     port, count, base, d_f ? "up" : "down");
     while (count--) {
 	x_outl(port, MEM_RL(pInt, dst));
@@ -409,7 +409,7 @@ x_inl(CARD16 port)
     if (!pciCfg1in(port, &val)) {
 	val = inl(Int10Current->ioBase + port);
 	if (PRINT_PORT && DEBUG_IO_TRACE())
-	    ErrorF(" inl(%#x) = %8.8x\n", port, val);
+	    ErrorF(" inl(%#x) = %8.8lx\n", port, val);
     }
     return val;
 }
@@ -419,7 +419,7 @@ x_outl(CARD16 port, CARD32 val)
 {
     if (!pciCfg1out(port, val)) {
 	if (PRINT_PORT && DEBUG_IO_TRACE())
-	    ErrorF(" outl(%#x, %8.8x)\n", port, val);
+	    ErrorF(" outl(%#x, %8.8lx)\n", port, val);
 	outl(Int10Current->ioBase + port, val);
     }
 }
@@ -500,7 +500,7 @@ pciCfg1in(CARD16 addr, CARD32 *val)
 	pci_device_cfg_read_u32(pci_device_for_cfg_address(PciCfg1Addr),
 			val, PCI_OFFSET(PciCfg1Addr));
 	if (PRINT_PORT && DEBUG_IO_TRACE())
-	    ErrorF(" cfg_inl(%#x) = %8.8x\n", PciCfg1Addr, *val);
+	    ErrorF(" cfg_inl(%#lx) = %8.8lx\n", PciCfg1Addr, *val);
 	return 1;
     }
     return 0;
@@ -515,7 +515,7 @@ pciCfg1out(CARD16 addr, CARD32 val)
     }
     if (addr == 0xCFC) {
 	if (PRINT_PORT && DEBUG_IO_TRACE())
-	    ErrorF(" cfg_outl(%#x, %8.8x)\n", PciCfg1Addr, val);
+	    ErrorF(" cfg_outl(%#lx, %8.8lx)\n", PciCfg1Addr, val);
 	pci_device_cfg_write_u32(pci_device_for_cfg_address(PciCfg1Addr),
 			val, PCI_OFFSET(PciCfg1Addr));
 	return 1;
@@ -539,7 +539,7 @@ pciCfg1inw(CARD16 addr, CARD16 *val)
 	pci_device_cfg_read_u16(pci_device_for_cfg_address(PciCfg1Addr),
 			val, PCI_OFFSET(PciCfg1Addr) + offset);
 	if (PRINT_PORT && DEBUG_IO_TRACE())
-	    ErrorF(" cfg_inw(%#x) = %4.4x\n", PciCfg1Addr + offset, *val);
+	    ErrorF(" cfg_inw(%#lx) = %4.4x\n", PciCfg1Addr + offset, *val);
 	return 1;
     }
     return 0;
@@ -560,7 +560,7 @@ pciCfg1outw(CARD16 addr, CARD16 val)
 	const unsigned offset = addr - 0xCFC;
 
 	if (PRINT_PORT && DEBUG_IO_TRACE())
-	    ErrorF(" cfg_outw(%#x, %4.4x)\n", PciCfg1Addr + offset, val);
+	    ErrorF(" cfg_outw(%#lx, %4.4x)\n", PciCfg1Addr + offset, val);
 	pci_device_cfg_write_u16(pci_device_for_cfg_address(PciCfg1Addr),
 			val, PCI_OFFSET(PciCfg1Addr) + offset);
 	return 1;
@@ -584,7 +584,7 @@ pciCfg1inb(CARD16 addr, CARD8 *val)
 	pci_device_cfg_read_u8(pci_device_for_cfg_address(PciCfg1Addr),
 			val, PCI_OFFSET(PciCfg1Addr) + offset);
 	if (PRINT_PORT && DEBUG_IO_TRACE())
-	    ErrorF(" cfg_inb(%#x) = %2.2x\n", PciCfg1Addr + offset, *val);
+	    ErrorF(" cfg_inb(%#lx) = %2.2x\n", PciCfg1Addr + offset, *val);
 	return 1;
     }
     return 0;
@@ -605,7 +605,7 @@ pciCfg1outb(CARD16 addr, CARD8 val)
 	const unsigned offset = addr - 0xCFC;
 
 	if (PRINT_PORT && DEBUG_IO_TRACE())
-	    ErrorF(" cfg_outb(%#x, %2.2x)\n", PciCfg1Addr + offset, val);
+	    ErrorF(" cfg_outb(%#lx, %2.2x)\n", PciCfg1Addr + offset, val);
 	pci_device_cfg_write_u8(pci_device_for_cfg_address(PciCfg1Addr),
 			val, PCI_OFFSET(PciCfg1Addr) + offset);
 	return 1;


More information about the xorg-commit mailing list