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

Jeremy Huddleston jeremyhu at freedesktop.org
Sun Dec 23 17:08:02 PST 2012


 Xext/saver.c                       |    2 
 Xi/Makefile.am                     |    2 
 Xi/exevents.c                      |   47 +
 Xi/extinit.c                       |   47 +
 Xi/gtmotion.c                      |    2 
 Xi/xibarriers.c                    |  916 +++++++++++++++++++++++++++++++++++++
 Xi/xibarriers.h                    |   48 +
 Xi/xichangehierarchy.c             |   16 
 Xi/xiquerydevice.c                 |    4 
 configure.ac                       |    8 
 dix/colormap.c                     |    8 
 dix/devices.c                      |    4 
 dix/dispatch.c                     |    2 
 dix/eventconvert.c                 |   45 +
 dix/events.c                       |   26 +
 dix/getevents.c                    |   15 
 dix/grabs.c                        |    5 
 dix/window.c                       |    2 
 exa/exa.c                          |    4 
 fb/fbgc.c                          |    4 
 glx/glapi.c                        |    2 
 glx/glxdri.c                       |    2 
 glx/indirect_program.c             |    2 
 glx/indirect_texture_compression.c |    4 
 glx/renderpixswap.c                |   20 
 glx/singlepix.c                    |   18 
 glx/singlepixswap.c                |   18 
 glx/xfont.c                        |    2 
 hw/dmx/config/Canvas.c             |    4 
 hw/dmx/dmx_glxvisuals.c            |    4 
 hw/dmx/dmxinit.c                   |    2 
 hw/dmx/dmxwindow.c                 |    2 
 hw/dmx/examples/xinput.c           |    4 
 hw/dmx/glxProxy/glxcmds.c          |   16 
 hw/dmx/glxProxy/glxcmdsswap.c      |    2 
 hw/dmx/glxProxy/glxscreens.c       |    4 
 hw/dmx/glxProxy/glxsingle.c        |    6 
 hw/dmx/glxProxy/glxvendor.c        |    4 
 hw/dmx/glxProxy/renderpixswap.c    |  310 ++++++------
 hw/kdrive/ephyr/XF86dri.c          |   18 
 hw/kdrive/ephyr/ephyrdriext.c      |    4 
 hw/kdrive/ephyr/ephyrhostglx.c     |   10 
 hw/kdrive/ephyr/ephyrhostproxy.c   |    2 
 hw/kdrive/ephyr/ephyrhostvideo.c   |    4 
 hw/kdrive/ephyr/ephyrvideo.c       |    2 
 hw/xfree86/common/xf86cmap.c       |    2 
 hw/xfree86/dri/xf86dri.c           |    4 
 hw/xfree86/i2c/fi1236.c            |   10 
 hw/xfree86/i2c/tda9850.c           |    2 
 hw/xwin/InitOutput.c               |    2 
 hw/xwin/glx/indirect.c             |    4 
 hw/xwin/winclipboardxevents.c      |    6 
 hw/xwin/wincursor.c                |    6 
 hw/xwin/winengine.c                |    2 
 hw/xwin/wingc.c                    |    4 
 hw/xwin/winmsg.c                   |    2 
 hw/xwin/winmultiwindowicons.c      |    2 
 hw/xwin/winmultiwindowshape.c      |    2 
 hw/xwin/winmultiwindowwndproc.c    |    2 
 hw/xwin/winpfbdd.c                 |    8 
 hw/xwin/winpixmap.c                |    2 
 hw/xwin/winscrinit.c               |    2 
 hw/xwin/winsetsp.c                 |    4 
 hw/xwin/winshaddd.c                |    8 
 hw/xwin/winshadddnl.c              |   10 
 hw/xwin/winshadgdi.c               |    2 
 hw/xwin/winwin32rootless.c         |    6 
 hw/xwin/winwin32rootlesswndproc.c  |    6 
 include/dix-config.h.in            |    3 
 include/events.h                   |    1 
 include/eventstr.h                 |   24 
 include/input.h                    |    6 
 include/inputstr.h                 |    2 
 mi/mieq.c                          |    4 
 mi/miinitext.c                     |    9 
 mi/mipointer.c                     |   54 +-
 mi/mipointer.h                     |    3 
 os/access.c                        |    2 
 os/utils.c                         |    2 
 os/xdmcp.c                         |   12 
 test/fixes.c                       |   26 +
 test/input.c                       |    2 
 test/xi2/protocol-eventconvert.c   |  218 ++++++++
 test/xi2/protocol-xiquerydevice.c  |    2 
 test/xi2/protocol-xiselectevents.c |   12 
 xfixes/cursor.c                    |  432 -----------------
 xfixes/xfixes.h                    |   17 
 xkb/xkb.c                          |   36 -
 xkb/xkbout.c                       |    2 
 89 files changed, 1825 insertions(+), 815 deletions(-)

New commits:
commit bd91b05b631f13afd1f7a9d6cbc4f0c5408b523a
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Dec 19 12:47:35 2012 -0800

    Update to version 1.13.99.901 (1.14 RC1)
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index ee0fa78..435a38f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,9 +26,9 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.60)
-AC_INIT([xorg-server], 1.13.99.0, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2012-10-04"
-RELEASE_NAME="Horchata"
+AC_INIT([xorg-server], 1.13.99.901, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2012-12-19"
+RELEASE_NAME="Egg Nog"
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 
commit 2a0b544f5c09f79e4ab04ea8103a5ecf59ee2e7b
Merge: 0eb1559 ba4bb3b
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Dec 19 12:26:00 2012 -0800

    Merge remote-tracking branch 'jeremyhu/master'

commit 0eb1559eb29d11e63c2b33e317590a88d86fe313
Merge: 386e4d7 ea1d76d
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Dec 19 12:21:31 2012 -0800

    Merge remote-tracking branch 'yselkowitz/master'
    
    I checked this patch with diff -w to check that it only affected
    whitespace.

commit 386e4d76baaffe226d2d561ff936509454eb0ac2
Merge: 014a5c8 9ff2e83
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Dec 19 12:17:59 2012 -0800

    Merge remote-tracking branch 'alanc/master'

commit 014a5c8a9d86f2f992183bff9106354fac2c3b0e
Merge: f793b5f 2eefa5d
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Dec 19 12:09:31 2012 -0800

    Merge remote-tracking branch 'whot/barriers'
    
    Conflicts:
    	Xi/xichangehierarchy.c
    
    Small conflict with the patch from
    
    	Xi: don't use devices after removing them
    
    Was easily resolved by hand.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

commit 9ff2e831517875f96477862f979abff394e8d551
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Tue Dec 18 00:41:08 2012 -0800

    EnableDisableExtensionError: Use ARRAY_SIZE rather than sentinel
    
    d785368e0e converted the other miinitext functions to use ARRAY_SIZE,
    and removed the sentinel, but missed EnableDisableExtensionError so
    passing an invalid extension name could cause the server to walk off
    the end off the list looking for a sentinel that wasn't there.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/mi/miinitext.c b/mi/miinitext.c
index 369da5e..81c663a 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -212,10 +212,12 @@ EnableDisableExtension(const char *name, Bool enable)
 void
 EnableDisableExtensionError(const char *name, Bool enable)
 {
-    ExtensionToggle *ext = &ExtensionToggleList[0];
+    ExtensionToggle *ext;
+    int i;
     Bool found = FALSE;
 
-    for (ext = &ExtensionToggleList[0]; ext->name != NULL; ext++) {
+    for (i = 0; i < ARRAY_SIZE(ExtensionToggleList); i++) {
+        ext = &ExtensionToggleList[i];
         if ((strcmp(name, ext->name) == 0) && (ext->disablePtr == NULL)) {
             ErrorF("[mi] Extension \"%s\" can not be disabled\n", name);
             found = TRUE;
@@ -226,7 +228,8 @@ EnableDisableExtensionError(const char *name, Bool enable)
         ErrorF("[mi] Extension \"%s\" is not recognized\n", name);
     ErrorF("[mi] Only the following extensions can be run-time %s:\n",
            enable ? "enabled" : "disabled");
-    for (ext = &ExtensionToggleList[0]; ext->name != NULL; ext++) {
+    for (i = 0; i < ARRAY_SIZE(ExtensionToggleList); i++) {
+        ext = &ExtensionToggleList[i];
         if (ext->disablePtr != NULL) {
             ErrorF("[mi]    %s\n", ext->name);
         }
commit 07a91fa6c6d535f3f05d4c3bd9c4d2b8c382c475
Author: Rob Clark <robdclark at gmail.com>
Date:   Wed Dec 5 23:21:27 2012 +0000

    hw/dmx: fix build without GLX
    
    Fixes this compile break that showed up on arm recently:
    
    dmxinit.c:746:26: error: 'glxSupported' undeclared (first use in this function)
    dmxinit.c:746:26: note: each undeclared identifier is reported only once for each function it appears in
    
    Signed-off-by: Rob Clark <robdclark at gmail.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/hw/dmx/dmxinit.c b/hw/dmx/dmxinit.c
index 7a50aeb..7de402b 100644
--- a/hw/dmx/dmxinit.c
+++ b/hw/dmx/dmxinit.c
@@ -740,10 +740,10 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char *argv[])
     /* Check if GLX extension exists on all back-end servers */
     for (i = 0; i < dmxNumScreens; i++)
         glxSupported &= (dmxScreens[i].glxMajorOpcode > 0);
-#endif
 
     if (serverGeneration == 1)
         dmxAddExtensions(glxSupported);
+#endif
 
     /* Tell dix layer about the backend displays */
     for (i = 0; i < dmxNumScreens; i++) {
commit 5692a1e8f5befd3698134b1a5516a4dadda00115
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Thu Dec 6 16:15:50 2012 -0800

    Support compilers with alternate spellings of typeof
    
    The AC_C_TYPEOF adds a #undef typeof to its autogenerated config.h.in
    template, but b8ab93dfbc7f292 didn't copy that to dix-config.h.in
    when HAVE_TYPEOF was, so the macro could claim typeof support but not
    make it work, when used with compilers like Solaris Studio 12.1 which
    only recognize it as __typeof__.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Acked-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index b270a32..e1cb9eb 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -429,6 +429,9 @@
 /* Define to 1 if typeof works with your compiler. */
 #undef HAVE_TYPEOF
 
+/* Define to __typeof__ if your compiler spells it that way. */
+#undef typeof
+
 /* The compiler supported TLS storage class, prefering initial-exec if tls_model is supported */
 #undef TLS
 
commit f793b5fd3eb16a2ada130367c2ffebeede69a322
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Dec 11 13:36:02 2012 +1000

    dix: don't copy the wrong event mask when activating a passive grab
    
    GrabMask is a union of core, XI1 and XI2 masks. If a XI2 grab is activated,
    the value is a random pointer value, using it as mask has unpredictable
    effects.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/grabs.c b/dix/grabs.c
index fe79674..3b02352 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -219,7 +219,10 @@ CreateGrab(int client, DeviceIntPtr device, DeviceIntPtr modDevice,
     grab->resource = FakeClientID(client);
     grab->device = device;
     grab->window = window;
-    grab->eventMask = mask->core;       /* same for XI */
+    if (grabtype == CORE || grabtype == XI)
+        grab->eventMask = mask->core;       /* same for XI */
+    else
+        grab->eventMask = 0;
     grab->deviceMask = 0;
     grab->ownerEvents = param->ownerEvents;
     grab->keyboardMode = param->this_device_mode;
commit dd3242c87a0a58cba055eb99c0c3fcf03153e4b8
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Dec 14 11:34:15 2012 +1000

    dix: don't allow overriding a grab with a different type of grab (#58255)
    
    If a client has a core grab, don't allow re-grabbing with type XI2, etc.
    This was the intent of the original commit
    xorg-server-1.5.99.1-782-g09f9a86, but ineffective.
    
    X.Org Bug 58255 <http://bugs.freedesktop.org/show_bug.cgi?id=58255>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/events.c b/dix/events.c
index 31f8d87..3836d2f 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -5043,7 +5043,7 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev,
     grab = grabInfo->grab;
     if (grab && grab->grabtype != grabtype)
         *status = AlreadyGrabbed;
-    if (grab && !SameClient(grab, client))
+    else if (grab && !SameClient(grab, client))
         *status = AlreadyGrabbed;
     else if ((!pWin->realized) ||
              (confineTo &&
commit 2eefa5d6e870c57ac6a5930883d8cfe3a3882a43
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 13 14:42:32 2012 +1000

    Xi: if a MD is removed, send a barrier leave event (if applicable)
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index 1714634..7b7b83f 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -714,12 +714,41 @@ static void remove_master_func(pointer res, XID id, pointer devid)
     struct PointerBarrierDevice *pbd;
     struct PointerBarrierClient *barrier;
     struct PointerBarrier *b;
+    DeviceIntPtr dev;
     int *deviceid = devid;
+    int rc;
+    Time ms = GetTimeInMillis();
+
+    rc = dixLookupDevice(&dev, *deviceid, serverClient, DixSendAccess);
+    if (rc != Success)
+        return;
 
     b = res;
     barrier = container_of(b, struct PointerBarrierClient, barrier);
 
     pbd = GetBarrierDevice(barrier, *deviceid);
+
+    if (pbd->hit) {
+        BarrierEvent ev = {
+            .header = ET_Internal,
+            .type =ET_BarrierLeave,
+            .length = sizeof (BarrierEvent),
+            .time = ms,
+            .deviceid = *deviceid,
+            .sourceid = 0,
+            .dx = 0,
+            .dy = 0,
+            .root = barrier->screen->root->drawable.id,
+            .window = barrier->window,
+            .dt = ms - pbd->last_timestamp,
+            .flags = XIBarrierPointerReleased,
+            .event_id = pbd->barrier_event_id,
+            .barrierid = barrier->id,
+        };
+
+        mieqEnqueue(dev, (InternalEvent *) &ev);
+    }
+
     xorg_list_del(&pbd->entry);
     free(pbd);
 }
@@ -731,7 +760,6 @@ void XIBarrierNewMasterDevice(ClientPtr client, int deviceid)
 
 void XIBarrierRemoveMasterDevice(ClientPtr client, int deviceid)
 {
-    /* FIXME: send LeaveNotify */
     FindClientResourcesByType(client, PointerBarrierType, remove_master_func, &deviceid);
 }
 
commit e2423b627ef7e4d08ea0685af5e771ddd2b511ce
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 13 14:04:13 2012 +1000

    Xi: don't store the window pointer in barriers, store the window ID
    
    When a client shuts down and resources are being freed, the window may have
    been freed already, so accessing it to get the window ID is bad. Plus, we
    never care about the window anyway other than for stuffing it into the
    event.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index 7e8b2e6..1714634 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -80,7 +80,7 @@ struct PointerBarrierDevice {
 struct PointerBarrierClient {
     XID id;
     ScreenPtr screen;
-    WindowPtr window;
+    Window window;
     struct PointerBarrier barrier;
     struct xorg_list entry;
     /* num_devices/device_ids are devices the barrier applies to */
@@ -467,7 +467,7 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
         ev.barrierid = c->id;
 
         ev.dt = ms - pbd->last_timestamp;
-        ev.window = c->window->drawable.id;
+        ev.window = c->window;
         pbd->last_timestamp = ms;
 
         /* root x/y is filled in later */
@@ -501,7 +501,7 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
         ev.barrierid = c->id;
 
         ev.dt = ms - pbd->last_timestamp;
-        ev.window = c->window->drawable.id;
+        ev.window = c->window;
         pbd->last_timestamp = ms;
 
         /* root x/y is filled in later */
@@ -566,7 +566,7 @@ CreatePointerBarrierClient(ClientPtr client,
     cs = GetBarrierScreen(screen);
 
     ret->screen = screen;
-    ret->window = pWin;
+    ret->window = stuff->window;
     ret->num_devices = stuff->num_devices;
     if (ret->num_devices > 0)
         ret->device_ids = (int*)&ret[1];
@@ -656,7 +656,7 @@ BarrierFreeBarrier(void *data, XID id)
             /* .deviceid */
             .sourceid = 0,
             .barrierid = c->id,
-            .window = c->window->drawable.id,
+            .window = c->window,
             .root = screen->root->drawable.id,
             .dx = 0,
             .dy = 0,
commit f71c2f895c9e2f9d0d42feaac2a3e1d2deb71f67
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Dec 12 15:41:32 2012 +1000

    Xi: fix per-device barrier handling
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index 048af62..7e8b2e6 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -67,19 +67,28 @@ static DevPrivateKeyRec BarrierScreenPrivateKeyRec;
 
 typedef struct PointerBarrierClient *PointerBarrierClientPtr;
 
+struct PointerBarrierDevice {
+    struct xorg_list entry;
+    int deviceid;
+    Time last_timestamp;
+    int barrier_event_id;
+    int release_event_id;
+    Bool hit;
+    Bool seen;
+};
+
 struct PointerBarrierClient {
     XID id;
     ScreenPtr screen;
     WindowPtr window;
     struct PointerBarrier barrier;
     struct xorg_list entry;
+    /* num_devices/device_ids are devices the barrier applies to */
     int num_devices;
     int *device_ids; /* num_devices */
-    Time last_timestamp;
-    int barrier_event_id;
-    int release_event_id;
-    Bool hit;
-    Bool seen;
+
+    /* per_device keeps track of devices actually blocked by barriers */
+    struct xorg_list per_device;
 };
 
 typedef struct _BarrierScreen {
@@ -90,6 +99,47 @@ typedef struct _BarrierScreen {
 #define GetBarrierScreenIfSet(s) GetBarrierScreen(s)
 #define SetBarrierScreen(s,p) dixSetPrivate(&(s)->devPrivates, BarrierScreenPrivateKey, p)
 
+static struct PointerBarrierDevice *AllocBarrierDevice(void)
+{
+    struct PointerBarrierDevice *pbd = NULL;
+
+    pbd = malloc(sizeof(struct PointerBarrierDevice));
+    if (!pbd)
+        return NULL;
+
+    pbd->deviceid = -1; /* must be set by caller */
+    pbd->barrier_event_id = 1;
+    pbd->release_event_id = 0;
+    pbd->hit = FALSE;
+    pbd->seen = FALSE;
+    xorg_list_init(&pbd->entry);
+
+    return pbd;
+}
+
+static void FreePointerBarrierClient(struct PointerBarrierClient *c)
+{
+    struct PointerBarrierDevice *pbd = NULL, *tmp = NULL;
+
+    xorg_list_for_each_entry_safe(pbd, tmp, &c->per_device, entry) {
+        free(pbd);
+    }
+    free(c);
+}
+
+static struct PointerBarrierDevice *GetBarrierDevice(struct PointerBarrierClient *c, int deviceid)
+{
+    struct PointerBarrierDevice *pbd = NULL;
+
+    xorg_list_for_each_entry(pbd, &c->per_device, entry) {
+        if (pbd->deviceid == deviceid)
+            break;
+    }
+
+    BUG_WARN(!pbd);
+    return pbd;
+}
+
 static BOOL
 barrier_is_horizontal(const struct PointerBarrier *barrier)
 {
@@ -283,9 +333,11 @@ barrier_find_nearest(BarrierScreenPtr cs, DeviceIntPtr dev,
 
     xorg_list_for_each_entry(c, &cs->barriers, entry) {
         struct PointerBarrier *b = &c->barrier;
+        struct PointerBarrierDevice *pbd;
         double distance;
 
-        if (c->seen)
+        pbd = GetBarrierDevice(c, dev->id);
+        if (pbd->seen)
             continue;
 
         if (!barrier_is_blocking_direction(b, dir))
@@ -358,6 +410,7 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
         .root = screen->root->drawable.id,
     };
     InternalEvent *barrier_events = events;
+    DeviceIntPtr master;
 
     if (nevents)
         *nevents = 0;
@@ -365,6 +418,13 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
     if (xorg_list_is_empty(&cs->barriers) || IsFloating(dev))
         goto out;
 
+    /**
+     * This function is only called for slave devices, but pointer-barriers
+     * are for master-devices only. Flip the device to the master here,
+     * continue with that.
+     */
+    master = GetMaster(dev, MASTER_POINTER);
+
     /* How this works:
      * Given the origin and the movement vector, get the nearest barrier
      * to the origin that is blocking the movement.
@@ -375,16 +435,19 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
     dir = barrier_get_direction(current_x, current_y, x, y);
 
     while (dir != 0) {
-        c = barrier_find_nearest(cs, dev, dir, current_x, current_y, x, y);
+        struct PointerBarrierDevice *pbd;
+
+        c = barrier_find_nearest(cs, master, dir, current_x, current_y, x, y);
         if (!c)
             break;
 
         nearest = &c->barrier;
 
-        c->seen = TRUE;
-        c->hit = TRUE;
+        pbd = GetBarrierDevice(c, master->id);
+        pbd->seen = TRUE;
+        pbd->hit = TRUE;
 
-        if (c->barrier_event_id == c->release_event_id)
+        if (pbd->barrier_event_id == pbd->release_event_id)
             continue;
 
         ev.type = ET_BarrierHit;
@@ -400,12 +463,12 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
         }
 
         ev.flags = 0;
-        ev.event_id = c->barrier_event_id;
+        ev.event_id = pbd->barrier_event_id;
         ev.barrierid = c->id;
 
-        ev.dt = ms - c->last_timestamp;
+        ev.dt = ms - pbd->last_timestamp;
         ev.window = c->window->drawable.id;
-        c->last_timestamp = ms;
+        pbd->last_timestamp = ms;
 
         /* root x/y is filled in later */
 
@@ -415,28 +478,31 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
     }
 
     xorg_list_for_each_entry(c, &cs->barriers, entry) {
+        struct PointerBarrierDevice *pbd;
         int flags = 0;
-        c->seen = FALSE;
-        if (!c->hit)
+
+        pbd = GetBarrierDevice(c, master->id);
+        pbd->seen = FALSE;
+        if (!pbd->hit)
             continue;
 
         if (barrier_inside_hit_box(&c->barrier, x, y))
             continue;
 
-        c->hit = FALSE;
+        pbd->hit = FALSE;
 
         ev.type = ET_BarrierLeave;
 
-        if (c->barrier_event_id == c->release_event_id)
+        if (pbd->barrier_event_id == pbd->release_event_id)
             flags |= XIBarrierPointerReleased;
 
         ev.flags = flags;
-        ev.event_id = c->barrier_event_id;
+        ev.event_id = pbd->barrier_event_id;
         ev.barrierid = c->id;
 
-        ev.dt = ms - c->last_timestamp;
+        ev.dt = ms - pbd->last_timestamp;
         ev.window = c->window->drawable.id;
-        c->last_timestamp = ms;
+        pbd->last_timestamp = ms;
 
         /* root x/y is filled in later */
 
@@ -446,7 +512,7 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
 
         /* If we've left the hit box, this is the
          * start of a new event ID. */
-        c->barrier_event_id++;
+        pbd->barrier_event_id++;
     }
 
  out:
@@ -479,6 +545,7 @@ CreatePointerBarrierClient(ClientPtr client,
     int i;
     struct PointerBarrierClient *ret;
     CARD16 *in_devices;
+    DeviceIntPtr dev;
 
     size = sizeof(*ret) + sizeof(DeviceIntPtr) * stuff->num_devices;
     ret = malloc(size);
@@ -487,6 +554,8 @@ CreatePointerBarrierClient(ClientPtr client,
         return BadAlloc;
     }
 
+    xorg_list_init(&ret->per_device);
+
     err = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess);
     if (err != Success) {
         client->errorValue = stuff->window;
@@ -524,11 +593,25 @@ CreatePointerBarrierClient(ClientPtr client,
         ret->device_ids[i] = device_id;
     }
 
+    /* Alloc one per master pointer, they're the ones that can be blocked */
+    xorg_list_init(&ret->per_device);
+    nt_list_for_each_entry(dev, inputInfo.devices, next) {
+        struct PointerBarrierDevice *pbd;
+
+        if (dev->type != MASTER_POINTER)
+            continue;
+
+        pbd = AllocBarrierDevice();
+        if (!pbd) {
+            err = BadAlloc;
+            goto error;
+        }
+        pbd->deviceid = dev->id;
+
+        xorg_list_add(&pbd->entry, &ret->per_device);
+    }
+
     ret->id = stuff->barrier;
-    ret->barrier_event_id = 1;
-    ret->release_event_id = 0;
-    ret->hit = FALSE;
-    ret->seen = FALSE;
     ret->barrier.x1 = stuff->x1;
     ret->barrier.x2 = stuff->x2;
     ret->barrier.y1 = stuff->y1;
@@ -547,7 +630,7 @@ CreatePointerBarrierClient(ClientPtr client,
 
  error:
     *client_out = NULL;
-    free(ret);
+    FreePointerBarrierClient(ret);
     return err;
 }
 
@@ -556,13 +639,15 @@ BarrierFreeBarrier(void *data, XID id)
 {
     struct PointerBarrierClient *c;
     Time ms = GetTimeInMillis();
+    DeviceIntPtr dev = NULL;
+    ScreenPtr screen;
 
     c = container_of(data, struct PointerBarrierClient, barrier);
+    screen = c->screen;
 
-    /* FIXME: this is really broken for multidevice */
-    if (c->hit) {
-        DeviceIntPtr dev = NULL;
-        ScreenPtr screen = c->screen;
+    for (dev = inputInfo.devices; dev; dev = dev->next) {
+        struct PointerBarrierDevice *pbd;
+        int root_x, root_y;
         BarrierEvent ev = {
             .header = ET_Internal,
             .type = ET_BarrierLeave,
@@ -577,36 +662,79 @@ BarrierFreeBarrier(void *data, XID id)
             .dy = 0,
             /* .root_x */
             /* .root_y */
-            .dt = ms - c->last_timestamp,
-            .event_id = c->barrier_event_id,
+            /* .dt */
+            /* .event_id */
             .flags = XIBarrierPointerReleased,
         };
 
-        for (dev = inputInfo.devices; dev; dev = dev->next) {
-            int root_x, root_y;
 
-            if (dev->type != MASTER_POINTER)
-                continue;
+        if (dev->type != MASTER_POINTER)
+            continue;
 
-            if (!barrier_blocks_device(c, dev))
-                continue;
+        pbd = GetBarrierDevice(c, dev->id);
+        if (!pbd->hit)
+            continue;
 
-            ev.deviceid = dev->id;
+        ev.deviceid = dev->id;
+        ev.event_id = pbd->barrier_event_id,
+        ev.dt = ms - pbd->last_timestamp,
 
-            GetSpritePosition(dev, &root_x, &root_y);
-            ev.root_x = root_x;
-            ev.root_y = root_y;
+        GetSpritePosition(dev, &root_x, &root_y);
+        ev.root_x = root_x;
+        ev.root_y = root_y;
 
-            mieqEnqueue(dev, (InternalEvent *) &ev);
-        }
+        mieqEnqueue(dev, (InternalEvent *) &ev);
     }
 
     xorg_list_del(&c->entry);
 
-    free(c);
+    FreePointerBarrierClient(c);
     return Success;
 }
 
+static void add_master_func(pointer res, XID id, pointer devid)
+{
+    struct PointerBarrier *b;
+    struct PointerBarrierClient *barrier;
+    struct PointerBarrierDevice *pbd;
+    int *deviceid = devid;
+
+    b = res;
+    barrier = container_of(b, struct PointerBarrierClient, barrier);
+
+
+    pbd = AllocBarrierDevice();
+    pbd->deviceid = *deviceid;
+
+    xorg_list_add(&pbd->entry, &barrier->per_device);
+}
+
+static void remove_master_func(pointer res, XID id, pointer devid)
+{
+    struct PointerBarrierDevice *pbd;
+    struct PointerBarrierClient *barrier;
+    struct PointerBarrier *b;
+    int *deviceid = devid;
+
+    b = res;
+    barrier = container_of(b, struct PointerBarrierClient, barrier);
+
+    pbd = GetBarrierDevice(barrier, *deviceid);
+    xorg_list_del(&pbd->entry);
+    free(pbd);
+}
+
+void XIBarrierNewMasterDevice(ClientPtr client, int deviceid)
+{
+    FindClientResourcesByType(client, PointerBarrierType, add_master_func, &deviceid);
+}
+
+void XIBarrierRemoveMasterDevice(ClientPtr client, int deviceid)
+{
+    /* FIXME: send LeaveNotify */
+    FindClientResourcesByType(client, PointerBarrierType, remove_master_func, &deviceid);
+}
+
 int
 XICreatePointerBarrier(ClientPtr client,
                        xXFixesCreatePointerBarrierReq * stuff)
@@ -698,14 +826,19 @@ ProcXIBarrierReleasePointer(ClientPtr client)
 
     info = (xXIBarrierReleasePointerInfo*) &stuff[1];
     for (i = 0; i < stuff->num_barriers; i++, info++) {
+        struct PointerBarrierDevice *pbd;
+        DeviceIntPtr dev;
         CARD32 barrier_id, event_id;
         _X_UNUSED CARD32 device_id;
 
         barrier_id = info->barrier;
         event_id = info->eventid;
 
-        /* FIXME: per-device releases */
-        device_id = info->deviceid;
+        err = dixLookupDevice(&dev, info->deviceid, client, DixReadAccess);
+        if (err != Success) {
+            client->errorValue = BadDevice;
+            return err;
+        }
 
         err = dixLookupResourceByType((void **) &b, barrier_id,
                                       PointerBarrierType, client, DixReadAccess);
@@ -717,9 +850,13 @@ ProcXIBarrierReleasePointer(ClientPtr client)
         if (CLIENT_ID(barrier_id) != client->index)
             return BadAccess;
 
+
         barrier = container_of(b, struct PointerBarrierClient, barrier);
-        if (barrier->barrier_event_id == event_id)
-            barrier->release_event_id = event_id;
+
+        pbd = GetBarrierDevice(barrier, dev->id);
+
+        if (pbd->barrier_event_id == event_id)
+            pbd->release_event_id = event_id;
     }
 
     return Success;
diff --git a/Xi/xibarriers.h b/Xi/xibarriers.h
index bdcb0b2..11e84ec 100644
--- a/Xi/xibarriers.h
+++ b/Xi/xibarriers.h
@@ -42,4 +42,7 @@ XIBarrierInit(void);
 int SProcXIBarrierReleasePointer(ClientPtr client);
 int ProcXIBarrierReleasePointer(ClientPtr client);
 
+void XIBarrierNewMasterDevice(ClientPtr client, int deviceid);
+void XIBarrierRemoveMasterDevice(ClientPtr client, int deviceid);
+
 #endif /* _XIBARRIERS_H_ */
diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
index 89f16d8..a2cb832 100644
--- a/Xi/xichangehierarchy.c
+++ b/Xi/xichangehierarchy.c
@@ -52,6 +52,7 @@
 #include "xkbsrv.h"
 
 #include "xichangehierarchy.h"
+#include "xibarriers.h"
 
 /**
  * Send the current state of the device hierarchy to all clients.
@@ -189,6 +190,8 @@ add_master(ClientPtr client, xXIAddMasterInfo * c, int flags[MAXDEVICES])
     flags[XTestptr->id] |= XISlaveAttached;
     flags[XTestkeybd->id] |= XISlaveAttached;
 
+    XIBarrierNewMasterDevice(client, ptr->id);
+
  unwind:
     free(name);
     return rc;
@@ -293,6 +296,8 @@ remove_master(ClientPtr client, xXIRemoveMasterInfo * r, int flags[MAXDEVICES])
         }
     }
 
+    XIBarrierRemoveMasterDevice(client, ptr->id);
+
     /* disable the remove the devices, XTest devices must be done first
        else the sprites they rely on will be destroyed  */
     DisableDevice(XTestptr, FALSE);
@@ -313,6 +318,7 @@ remove_master(ClientPtr client, xXIRemoveMasterInfo * r, int flags[MAXDEVICES])
     flags[keybd->id] |= XIMasterRemoved;
     flags[ptr->id] |= XIMasterRemoved;
 
+
  unwind:
     return rc;
 }
commit 58bff17e43a80eb21b3ff6d4bb1596230e61f707
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 13 11:49:54 2012 +1000

    Xi: don't use devices after removing them
    
    RemoveDevice() frees the DeviceIntPtr, we shouldn't use the pointer after
    that
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
index 89f16d8..4dc3d76 100644
--- a/Xi/xichangehierarchy.c
+++ b/Xi/xichangehierarchy.c
@@ -304,15 +304,16 @@ remove_master(ClientPtr client, xXIRemoveMasterInfo * r, int flags[MAXDEVICES])
     flags[keybd->id] |= XIDeviceDisabled;
     flags[ptr->id] |= XIDeviceDisabled;
 
-    RemoveDevice(XTestptr, FALSE);
-    RemoveDevice(XTestkeybd, FALSE);
-    RemoveDevice(keybd, FALSE);
-    RemoveDevice(ptr, FALSE);
     flags[XTestptr->id] |= XISlaveRemoved;
     flags[XTestkeybd->id] |= XISlaveRemoved;
     flags[keybd->id] |= XIMasterRemoved;
     flags[ptr->id] |= XIMasterRemoved;
 
+    RemoveDevice(XTestptr, FALSE);
+    RemoveDevice(XTestkeybd, FALSE);
+    RemoveDevice(keybd, FALSE);
+    RemoveDevice(ptr, FALSE);
+
  unwind:
     return rc;
 }
commit cc10ac8f0e07854647e1fd7cc70b7e9f8d919fd1
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Dec 10 11:00:46 2012 +1000

    Xi: fix swapping for barrier events
    
    Protocol events don't contain pointers, so it's easier to copy everything
    over, then swap in-place.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/Xi/extinit.c b/Xi/extinit.c
index 606d61c..73b084c 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -845,30 +845,27 @@ STouchOwnershipEvent(xXITouchOwnershipEvent * from, xXITouchOwnershipEvent * to)
 static void
 SBarrierEvent(xXIBarrierEvent * from,
               xXIBarrierEvent * to) {
-    to->type = from->type;
-
-    cpswaps(from->sequenceNumber, to->sequenceNumber);
-    cpswapl(from->length, to->length);
-    cpswaps(from->evtype, to->evtype);
-    cpswapl(from->time, to->time);
-    cpswaps(from->deviceid, to->deviceid);
-    cpswaps(from->sourceid, to->sourceid);
-    cpswapl(from->event, to->event);
-    cpswapl(from->root, to->root);
-    cpswapl(from->root_x, to->root_x);
-    cpswapl(from->root_y, to->root_y);
-
-#define SWAP_FP3232(x, y)                       \
-    do {                                        \
-        cpswapl((x).integral, (y).integral);    \
-        cpswapl((x).frac, (y).frac);            \
-    } while(0)
-
-    SWAP_FP3232(from->dx, to->dx);
-    SWAP_FP3232(from->dy, to->dy);
-    cpswapl(from->dtime, to->dtime);
-    cpswapl(from->barrier, to->barrier);
-    cpswapl(from->eventid, to->eventid);
+
+    *to = *from;
+
+    swaps(&from->sequenceNumber);
+    swapl(&from->length);
+    swaps(&from->evtype);
+    swapl(&from->time);
+    swaps(&from->deviceid);
+    swaps(&from->sourceid);
+    swapl(&from->event);
+    swapl(&from->root);
+    swapl(&from->root_x);
+    swapl(&from->root_y);
+
+    swapl(&from->dx.integral);
+    swapl(&from->dx.frac);
+    swapl(&from->dy.integral);
+    swapl(&from->dy.frac);
+    swapl(&from->dtime);
+    swapl(&from->barrier);
+    swapl(&from->eventid);
 }
 
 /** Event swapping function for XI2 events. */
commit 151d44149a09dd125e25b3d94f22a609f0221548
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Dec 10 10:53:49 2012 +1000

    Xi: swap sequence number and evtype in barrier events
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/Xi/extinit.c b/Xi/extinit.c
index 175d89b..606d61c 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -847,7 +847,9 @@ SBarrierEvent(xXIBarrierEvent * from,
               xXIBarrierEvent * to) {
     to->type = from->type;
 
+    cpswaps(from->sequenceNumber, to->sequenceNumber);
     cpswapl(from->length, to->length);
+    cpswaps(from->evtype, to->evtype);
     cpswapl(from->time, to->time);
     cpswaps(from->deviceid, to->deviceid);
     cpswaps(from->sourceid, to->sourceid);
commit d4065493b211e90b46f9d4178f23f347afd8043f
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Dec 10 11:02:32 2012 +1000

    tests/xi2: at protocol conversion test for barrier events
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c
index bb3177c..3957747 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -984,6 +984,221 @@ test_convert_XITouchOwnershipEvent(void)
     }
 }
 
+static void
+test_XIBarrierEvent(BarrierEvent *in)
+{
+    xXIBarrierEvent *out, *swapped;
+    int count;
+    int rc;
+    int eventlen;
+    FP3232 value;
+
+    rc = EventToXI((InternalEvent*)in, (xEvent**)&out, &count);
+    assert(rc == BadMatch);
+
+    rc = EventToCore((InternalEvent*)in, (xEvent**)&out, &count);
+    assert(rc == BadMatch);
+
+    rc = EventToXI2((InternalEvent*)in, (xEvent**)&out);
+
+    assert(out->type == GenericEvent);
+    assert(out->extension == 0); /* IReqCode defaults to 0 */
+    assert(out->evtype == GetXI2Type(in->type));
+    assert(out->time == in->time);
+    assert(out->deviceid == in->deviceid);
+    assert(out->sourceid == in->sourceid);
+    assert(out->barrier == in->barrierid);
+    assert(out->flags == in->flags);
+    assert(out->event == in->window);
+    assert(out->root == in->root);
+    assert(out->dtime == in->dt);
+    assert(out->eventid == in->event_id);
+    assert(out->root_x == double_to_fp1616(in->root_x));
+    assert(out->root_y == double_to_fp1616(in->root_y));
+
+    value = double_to_fp3232(in->dx);
+    assert(out->dx.integral == value.integral);
+    assert(out->dx.frac == value.frac);
+    value = double_to_fp3232(in->dy);
+    assert(out->dy.integral == value.integral);
+    assert(out->dy.frac == value.frac);
+
+    eventlen = sizeof(xEvent) + out->length * 4;
+    swapped = calloc(1, eventlen);
+    XI2EventSwap((xGenericEvent *) out, (xGenericEvent *) swapped);
+
+    swaps(&swapped->sequenceNumber);
+    swapl(&swapped->length);
+    swaps(&swapped->evtype);
+    swaps(&swapped->deviceid);
+    swapl(&swapped->time);
+    swapl(&swapped->eventid);
+    swapl(&swapped->root);
+    swapl(&swapped->event);
+    swapl(&swapped->barrier);
+    swapl(&swapped->dtime);
+    swaps(&swapped->sourceid);
+    swapl(&swapped->root_x);
+    swapl(&swapped->root_y);
+    swapl(&swapped->dx.integral);
+    swapl(&swapped->dx.frac);
+    swapl(&swapped->dy.integral);
+    swapl(&swapped->dy.frac);
+
+    assert(memcmp(swapped, out, eventlen) == 0);
+
+    free(swapped);
+    free(out);
+}
+
+static void
+test_convert_XIBarrierEvent(void)
+{
+    BarrierEvent in;
+
+    memset(&in, 0, sizeof(in));
+    in.header = ET_Internal;
+    in.type = ET_BarrierHit;
+    in.length = sizeof(in);
+    in.time = 0;
+    in.deviceid = 1;
+    in.sourceid = 2;
+
+    test_XIBarrierEvent(&in);
+
+    in.deviceid = 1;
+    while(in.deviceid & 0xFFFF) {
+        test_XIBarrierEvent(&in);
+        in.deviceid <<= 1;
+    }
+    in.deviceid = 0;
+
+    in.sourceid = 1;
+    while(in.sourceid & 0xFFFF) {
+        test_XIBarrierEvent(&in);
+        in.sourceid <<= 1;
+    }
+    in.sourceid = 0;
+
+    in.flags = 1;
+    while(in.flags) {
+        test_XIBarrierEvent(&in);
+        in.flags <<= 1;
+    }
+
+    in.barrierid = 1;
+    while(in.barrierid) {
+        test_XIBarrierEvent(&in);
+        in.barrierid <<= 1;
+    }
+
+    in.dt = 1;
+    while(in.dt) {
+        test_XIBarrierEvent(&in);
+        in.dt <<= 1;
+    }
+
+    in.event_id = 1;
+    while(in.event_id) {
+        test_XIBarrierEvent(&in);
+        in.event_id <<= 1;
+    }
+
+    in.window = 1;
+    while(in.window) {
+        test_XIBarrierEvent(&in);
+        in.window <<= 1;
+    }
+
+    in.root = 1;
+    while(in.root) {
+        test_XIBarrierEvent(&in);
+        in.root <<= 1;
+    }
+
+    /* pseudo-random 16 bit numbers */
+    in.root_x = 1;
+    test_XIBarrierEvent(&in);
+    in.root_x = 1.3;
+    test_XIBarrierEvent(&in);
+    in.root_x = 264.908;
+    test_XIBarrierEvent(&in);
+    in.root_x = 35638.292;
+    test_XIBarrierEvent(&in);
+
+    in.root_x = -1;
+    test_XIBarrierEvent(&in);
+    in.root_x = -1.3;
+    test_XIBarrierEvent(&in);
+    in.root_x = -264.908;
+    test_XIBarrierEvent(&in);
+    in.root_x = -35638.292;
+    test_XIBarrierEvent(&in);
+
+    in.root_y = 1;
+    test_XIBarrierEvent(&in);
+    in.root_y = 1.3;
+    test_XIBarrierEvent(&in);
+    in.root_y = 264.908;
+    test_XIBarrierEvent(&in);
+    in.root_y = 35638.292;
+    test_XIBarrierEvent(&in);
+
+    in.root_y = -1;
+    test_XIBarrierEvent(&in);
+    in.root_y = -1.3;
+    test_XIBarrierEvent(&in);
+    in.root_y = -264.908;
+    test_XIBarrierEvent(&in);
+    in.root_y = -35638.292;
+    test_XIBarrierEvent(&in);
+
+    /* equally pseudo-random 32 bit numbers */
+    in.dx = 1;
+    test_XIBarrierEvent(&in);
+    in.dx = 1.3;
+    test_XIBarrierEvent(&in);
+    in.dx = 264.908;
+    test_XIBarrierEvent(&in);
+    in.dx = 35638.292;
+    test_XIBarrierEvent(&in);
+    in.dx = 2947813871.2342;
+    test_XIBarrierEvent(&in);
+
+    in.dx = -1;
+    test_XIBarrierEvent(&in);
+    in.dx = -1.3;
+    test_XIBarrierEvent(&in);
+    in.dx = -264.908;
+    test_XIBarrierEvent(&in);
+    in.dx = -35638.292;
+    test_XIBarrierEvent(&in);
+    in.dx = -2947813871.2342;
+    test_XIBarrierEvent(&in);
+
+    in.dy = 1;
+    test_XIBarrierEvent(&in);
+    in.dy = 1.3;
+    test_XIBarrierEvent(&in);
+    in.dy = 264.908;
+    test_XIBarrierEvent(&in);
+    in.dy = 35638.292;
+    test_XIBarrierEvent(&in);
+    in.dy = 2947813871.2342;
+    test_XIBarrierEvent(&in);
+
+    in.dy = -1;
+    test_XIBarrierEvent(&in);
+    in.dy = -1.3;
+    test_XIBarrierEvent(&in);
+    in.dy = -264.908;
+    test_XIBarrierEvent(&in);
+    in.dy = -35638.292;
+    test_XIBarrierEvent(&in);
+    in.dy = -2947813871.2342;
+    test_XIBarrierEvent(&in);
+}
+
 int
 main(int argc, char **argv)
 {
@@ -992,6 +1207,7 @@ main(int argc, char **argv)
     test_convert_XIDeviceEvent();
     test_convert_XIDeviceChangedEvent();
     test_convert_XITouchOwnershipEvent();
+    test_convert_XIBarrierEvent();
 
     return 0;
 }
commit 938187f2fec006daf4cc677df26d5b0b6999b54b
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Dec 7 15:55:59 2012 +1000

    Require inputproto 2.2.99.1
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/configure.ac b/configure.ac
index 38ac240..ee0fa78 100644
--- a/configure.ac
+++ b/configure.ac
@@ -788,7 +788,7 @@ XPROTO="xproto >= 7.0.22"
 RANDRPROTO="randrproto >= 1.4.0"
 RENDERPROTO="renderproto >= 0.11"
 XEXTPROTO="xextproto >= 7.1.99"
-INPUTPROTO="inputproto >= 2.1.99.6"
+INPUTPROTO="inputproto >= 2.2.99.1"
 KBPROTO="kbproto >= 1.0.3"
 FONTSPROTO="fontsproto"
 FIXESPROTO="fixesproto >= 5.0"
commit 78376a9217058aa66e52a0399fc2be469d70ce32
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Dec 7 09:26:13 2012 +1000

    mi: rename mipointer's internal event list
    
    Avoid name shadowing warnings, change the event list to a more specific
    name.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/mi/mipointer.c b/mi/mipointer.c
index 7bc0983..b8503f4 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -98,7 +98,7 @@ static void miPointerDeviceCleanup(DeviceIntPtr pDev, ScreenPtr pScreen);
 static void miPointerMoveNoEvent(DeviceIntPtr pDev, ScreenPtr pScreen, int x,
                                  int y);
 
-static InternalEvent *events;   /* for WarpPointer MotionNotifies */
+static InternalEvent *mipointermove_events;   /* for WarpPointer MotionNotifies */
 
 Bool
 miPointerInitialize(ScreenPtr pScreen,
@@ -143,7 +143,7 @@ miPointerInitialize(ScreenPtr pScreen,
     pScreen->DeviceCursorInitialize = miPointerDeviceInitialize;
     pScreen->DeviceCursorCleanup = miPointerDeviceCleanup;
 
-    events = NULL;
+    mipointermove_events = NULL;
     return TRUE;
 }
 
@@ -160,8 +160,8 @@ miPointerCloseScreen(ScreenPtr pScreen)
 
     pScreen->CloseScreen = pScreenPriv->CloseScreen;
     free((pointer) pScreenPriv);
-    FreeEventList(events, GetMaximumEventsNum());
-    events = NULL;
+    FreeEventList(mipointermove_events, GetMaximumEventsNum());
+    mipointermove_events = NULL;
     return (*pScreen->CloseScreen) (pScreen);
 }
 
@@ -710,17 +710,17 @@ miPointerMove(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
     valuators[0] = x;
     valuators[1] = y;
 
-    if (!events) {
-        events = InitEventList(GetMaximumEventsNum());
+    if (!mipointermove_events) {
+        mipointermove_events = InitEventList(GetMaximumEventsNum());
 
-        if (!events) {
+        if (!mipointermove_events) {
             FatalError("Could not allocate event store.\n");
             return;
         }
     }
 
     valuator_mask_set_range(&mask, 0, 2, valuators);
-    nevents = GetPointerEvents(events, pDev, MotionNotify, 0,
+    nevents = GetPointerEvents(mipointermove_events, pDev, MotionNotify, 0,
                                POINTER_SCREEN | POINTER_ABSOLUTE |
                                POINTER_NORAW, &mask);
 
@@ -729,7 +729,7 @@ miPointerMove(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
     darwinEvents_lock();
 #endif
     for (i = 0; i < nevents; i++)
-        mieqEnqueue(pDev, &events[i]);
+        mieqEnqueue(pDev, &mipointermove_events[i]);
 #ifdef XQUARTZ
     darwinEvents_unlock();
 #endif
commit 88a2cccc37cac4e171f9bfc020017ddfa66ae417
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Dec 7 09:11:13 2012 +1000

    Xi: if the device is currently grabbed, flag the barrier event
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index a7ec0c4..f025dd1 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1655,6 +1655,9 @@ ProcessBarrierEvent(InternalEvent *e, DeviceIntPtr dev)
     if (dixLookupWindow(&pWin, be->window, serverClient, DixReadAccess) != Success)
         return;
 
+    if (grab)
+        be->flags |= XIBarrierDeviceIsGrabbed;
+
     rc = EventToXI2(e, &ev);
     if (rc != Success) {
         ErrorF("[Xi] event conversion from %s failed with code %d\n", __func__, rc);
commit 353aa515922e1095047161ec47a2722772218f20
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 6 15:09:27 2012 +1000

    Xi: deliver barrier events as grabbed events where necessary
    
    If the grab_window is the barrier window and the client owns the grab,
    deliver as normal grabbed event (respecting owner_events). Otherwise,
    deliver as usual.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index e606d9e..a7ec0c4 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1647,6 +1647,7 @@ ProcessBarrierEvent(InternalEvent *e, DeviceIntPtr dev)
     BarrierEvent *be = &e->barrier_event;
     xEvent *ev;
     int rc;
+    GrabPtr grab = dev->deviceGrab.grab;
 
     if (!IsMaster(dev))
         return;
@@ -1660,10 +1661,21 @@ ProcessBarrierEvent(InternalEvent *e, DeviceIntPtr dev)
         return;
     }
 
-    filter = GetEventFilter(dev, ev);
+    /* A client has a grab, deliver to this client if the grab_window is the
+       barrier window.
+
+       Otherwise, deliver normally to the client.
+     */
+    if (grab &&
+        CLIENT_ID(be->barrierid) == CLIENT_ID(grab->resource) &&
+        grab->window->drawable.id == be->window) {
+        DeliverGrabbedEvent(e, dev, FALSE);
+    } else {
+        filter = GetEventFilter(dev, ev);
 
-    DeliverEventsToWindow(dev, pWin, ev, 1,
-                          filter, NullGrab);
+        DeliverEventsToWindow(dev, pWin, ev, 1,
+                              filter, NullGrab);
+    }
     free(ev);
 }
 
commit 3b161401700a2d916da0f81f99b39e75fdbe78df
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 6 14:13:26 2012 +1000

    dix: ignore barrier events in FixUpEventFromWindow
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/dix/events.c b/dix/events.c
index 49b8bc5..c98a2de 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2436,6 +2436,8 @@ FixUpEventFromWindow(SpritePtr pSprite,
         case XI_DeviceChanged:
         case XI_HierarchyChanged:
         case XI_PropertyEvent:
+        case XI_BarrierHit:
+        case XI_BarrierLeave:
             return;
         default:
             break;
commit a1eeb6fbecf0bd9665a9158b27c273e83b3ab351
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 6 13:25:29 2012 +1000

    dix: handle barrier events properly when converting to core/XI 1.x
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index bb5c8d3..47dcf8b 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -161,6 +161,8 @@ EventToCore(InternalEvent *event, xEvent **core_out, int *count_out)
     case ET_TouchUpdate:
     case ET_TouchEnd:
     case ET_TouchOwnership:
+    case ET_BarrierHit:
+    case ET_BarrierLeave:
         ret = BadMatch;
         break;
     default:
@@ -217,6 +219,8 @@ EventToXI(InternalEvent *ev, xEvent **xi, int *count)
     case ET_TouchUpdate:
     case ET_TouchEnd:
     case ET_TouchOwnership:
+    case ET_BarrierHit:
+    case ET_BarrierLeave:
         *count = 0;
         *xi = NULL;
         return BadMatch;
commit 1b83775f6712a7e48c49a3411a87103e8e906e67
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 6 12:39:04 2012 +1000

    dix: skip delivery if it's not the right pointer barrier client
    
    Only deliver to the client that created the barrier, not to other clients.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/dix/events.c b/dix/events.c
index 3282ef8..49b8bc5 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -219,6 +219,9 @@ static void CheckVirtualMotion(DeviceIntPtr pDev, QdEventPtr qe,
 static void CheckPhysLimits(DeviceIntPtr pDev, CursorPtr cursor,
                             Bool generateEvents, Bool confineToScreen,
                             ScreenPtr pScreen);
+static Bool IsWrongPointerBarrierClient(ClientPtr client,
+                                        DeviceIntPtr dev,
+                                        xEvent *event);
 
 /** Key repeat hack. Do not use but in TryClientEvents */
 extern BOOL EventIsKeyRepeat(xEvent *event);
@@ -2076,6 +2079,9 @@ DeliverEventToInputClients(DeviceIntPtr dev, InputClients * inputclients,
         if (IsInterferingGrab(client, dev, events))
             continue;
 
+        if (IsWrongPointerBarrierClient(client, dev, events))
+            continue;
+
         mask = GetEventMask(dev, events, inputclients);
 
         if (XaceHook(XACE_RECEIVE_ACCESS, client, win, events, count))
@@ -6064,3 +6070,19 @@ IsInterferingGrab(ClientPtr client, DeviceIntPtr dev, xEvent *event)
 
     return FALSE;
 }
+
+/* PointerBarrier events are only delivered to the client that created that
+ * barrier */
+static Bool
+IsWrongPointerBarrierClient(ClientPtr client, DeviceIntPtr dev, xEvent *event)
+{
+    xXIBarrierEvent *ev = (xXIBarrierEvent*)event;
+
+    if (ev->type != GenericEvent || ev->extension != IReqCode)
+        return FALSE;
+
+    if (ev->evtype != XI_BarrierHit && ev->evtype != XI_BarrierLeave)
+        return FALSE;
+
+    return client->index != CLIENT_ID(ev->barrier);
+}
commit c50db6faba4ee1c27b735c6e9c98a4276ba3c7ff
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 6 12:58:55 2012 +1000

    Xi: fill in barrier root x/y after clamping to RandR outputs
    
    x/y for barrier events should contain the actual pointer position.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index 104280c..048af62 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -407,6 +407,8 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
         ev.window = c->window->drawable.id;
         c->last_timestamp = ms;
 
+        /* root x/y is filled in later */
+
         barrier_events->barrier_event = ev;
         barrier_events++;
         *nevents += 1;
@@ -436,6 +438,8 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
         ev.window = c->window->drawable.id;
         c->last_timestamp = ms;
 
+        /* root x/y is filled in later */
+
         barrier_events->barrier_event = ev;
         barrier_events++;
         *nevents += 1;
diff --git a/mi/mipointer.c b/mi/mipointer.c
index f4fbd29..7bc0983 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -573,6 +573,8 @@ miPointerSetPosition(DeviceIntPtr pDev, int mode, double *screenx,
     ScreenPtr newScreen;
     int x, y;
     Bool switch_screen = FALSE;
+    Bool should_constrain_barriers = FALSE;
+    int i;
 
     miPointerPtr pPointer;
 
@@ -589,7 +591,9 @@ miPointerSetPosition(DeviceIntPtr pDev, int mode, double *screenx,
     x -= pScreen->x;
     y -= pScreen->y;
 
-    if (mode == Relative) {
+    should_constrain_barriers = (mode == Relative);
+
+    if (should_constrain_barriers) {
         /* coordinates after clamped to a barrier */
         int constrained_x, constrained_y;
         int current_x, current_y; /* current position in per-screen coord */
@@ -637,6 +641,18 @@ miPointerSetPosition(DeviceIntPtr pDev, int mode, double *screenx,
     if (pPointer->x != x || pPointer->y != y || pPointer->pScreen != pScreen)
         miPointerMoveNoEvent(pDev, pScreen, x, y);
 
+    /* check if we generated any barrier events and if so, update root x/y
+     * to the fully constrained coords */
+    if (should_constrain_barriers) {
+        for (i = 0; i < *nevents; i++) {
+            if (events[i].any.type == ET_BarrierHit ||
+                events[i].any.type == ET_BarrierLeave) {
+                events[i].barrier_event.root_x = x;
+                events[i].barrier_event.root_y = y;
+            }
+        }
+    }
+
     /* Convert to desktop coordinates again */
     x += pScreen->x;
     y += pScreen->y;
commit 21a15f9a04ec0a6c8f654eef943561e98db2475d
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Dec 3 10:41:16 2012 +1000

    Pass the event list through to the pointer barrier code to return it
    
    Instead of having the pointer barrier code enqueue events separately from
    GetPointerEvents, pass the event list through and let it add to it.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index 27b21ee..104280c 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -335,7 +335,8 @@ void
 input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
                        int current_x, int current_y,
                        int dest_x, int dest_y,
-                       int *out_x, int *out_y)
+                       int *out_x, int *out_y,
+                       int *nevents, InternalEvent* events)
 {
     /* Clamped coordinates here refer to screen edge clamping. */
     BarrierScreenPtr cs = GetBarrierScreen(screen);
@@ -356,6 +357,10 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
         .dy = dest_y - current_y,
         .root = screen->root->drawable.id,
     };
+    InternalEvent *barrier_events = events;
+
+    if (nevents)
+        *nevents = 0;
 
     if (xorg_list_is_empty(&cs->barriers) || IsFloating(dev))
         goto out;
@@ -402,7 +407,9 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
         ev.window = c->window->drawable.id;
         c->last_timestamp = ms;
 
-        mieqEnqueue(dev, (InternalEvent *) &ev);
+        barrier_events->barrier_event = ev;
+        barrier_events++;
+        *nevents += 1;
     }
 
     xorg_list_for_each_entry(c, &cs->barriers, entry) {
@@ -429,7 +436,9 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
         ev.window = c->window->drawable.id;
         c->last_timestamp = ms;
 
-        mieqEnqueue(dev, (InternalEvent *) &ev);
+        barrier_events->barrier_event = ev;
+        barrier_events++;
+        *nevents += 1;
 
         /* If we've left the hit box, this is the
          * start of a new event ID. */
diff --git a/dix/getevents.c b/dix/getevents.c
index fa538d9..3d41e1e 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -916,10 +916,13 @@ scale_to_desktop(DeviceIntPtr dev, ValuatorMask *mask,
  * @param[in,out] devy y desktop-wide coordinate in device coordinate system
  * @param[in,out] screenx x coordinate in desktop coordinate system
  * @param[in,out] screeny y coordinate in desktop coordinate system
+ * @param[out] nevents Number of barrier events added to events
+ * @param[in,out] events List of events barrier events are added to
  */
 static ScreenPtr
 positionSprite(DeviceIntPtr dev, int mode, ValuatorMask *mask,
-               double *devx, double *devy, double *screenx, double *screeny)
+               double *devx, double *devy, double *screenx, double *screeny,
+               int *nevents, InternalEvent* events)
 {
     ScreenPtr scr = miPointerGetScreen(dev);
     double tmpx, tmpy;
@@ -933,7 +936,7 @@ positionSprite(DeviceIntPtr dev, int mode, ValuatorMask *mask,
     /* miPointerSetPosition takes care of crossing screens for us, as well as
      * clipping to the current screen. Coordinates returned are in desktop
      * coord system */
-    scr = miPointerSetPosition(dev, mode, screenx, screeny);
+    scr = miPointerSetPosition(dev, mode, screenx, screeny, nevents, events);
 
     /* If we were constrained, rescale x/y from the screen coordinates so
      * the device valuators reflect the correct position. For screen
@@ -1319,6 +1322,7 @@ fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type,
     int sx, sy;                         /* for POINTER_SCREEN */
     ValuatorMask mask;
     ScreenPtr scr;
+    int num_barrier_events = 0;
 
     switch (type) {
     case MotionNotify:
@@ -1395,7 +1399,10 @@ fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type,
     }
 
     scr = positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative,
-                         &mask, &devx, &devy, &screenx, &screeny);
+                         &mask, &devx, &devy, &screenx, &screeny,
+                         &num_barrier_events, events);
+    num_events += num_barrier_events;
+    events += num_barrier_events;
 
     /* screenx, screeny are in desktop coordinates,
        mask is in device coordinates per-screen (the event data)
@@ -1945,7 +1952,7 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid,
         scr = scale_to_desktop(dev, &mask, &devx, &devy, &screenx, &screeny);
     if (emulate_pointer)
         scr = positionSprite(dev, Absolute, &mask,
-                             &devx, &devy, &screenx, &screeny);
+                             &devx, &devy, &screenx, &screeny, NULL, NULL);
 
     /* see fill_pointer_events for coordinate systems */
     if (emulate_pointer)
diff --git a/include/input.h b/include/input.h
index a5d0462..23a20b5 100644
--- a/include/input.h
+++ b/include/input.h
@@ -681,6 +681,7 @@ extern _X_HIDDEN void update_desktop_dimensions(void);
 extern _X_HIDDEN void input_constrain_cursor(DeviceIntPtr pDev, ScreenPtr screen,
                                              int current_x, int current_y,
                                              int dest_x, int dest_y,
-                                             int *out_x, int *out_y);
+                                             int *out_x, int *out_y,
+                                             int *nevents, InternalEvent* events);
 
 #endif                          /* INPUT_H */
diff --git a/mi/mipointer.c b/mi/mipointer.c
index d170824..f4fbd29 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -565,7 +565,8 @@ miPointerMoveNoEvent(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
  */
 ScreenPtr
 miPointerSetPosition(DeviceIntPtr pDev, int mode, double *screenx,
-                     double *screeny)
+                     double *screeny,
+                     int *nevents, InternalEvent* events)
 {
     miPointerScreenPtr pScreenPriv;
     ScreenPtr pScreen;
@@ -598,7 +599,8 @@ miPointerSetPosition(DeviceIntPtr pDev, int mode, double *screenx,
 
         input_constrain_cursor(pDev, pScreen,
                                current_x, current_y, x, y,
-                               &constrained_x, &constrained_y);
+                               &constrained_x, &constrained_y,
+                               nevents, events);
 
         x = constrained_x;
         y = constrained_y;
diff --git a/mi/mipointer.h b/mi/mipointer.h
index 1500e21..f89dff3 100644
--- a/mi/mipointer.h
+++ b/mi/mipointer.h
@@ -115,7 +115,8 @@ miPointerGetPosition(DeviceIntPtr pDev, int *x, int *y);
 /* Moves the cursor to the specified position.  May clip the co-ordinates:
  * x and y are modified in-place. */
 extern _X_EXPORT ScreenPtr
-miPointerSetPosition(DeviceIntPtr pDev, int mode, double *x, double *y);
+miPointerSetPosition(DeviceIntPtr pDev, int mode, double *x, double *y,
+                     int *nevents, InternalEvent *events);
 
 extern _X_EXPORT void
 miPointerUpdateSprite(DeviceIntPtr pDev);
commit 707b4dc61f18960611409ef5ad8947be189f7296
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Tue Nov 27 15:31:52 2012 -0500

    barriers: Support line and ray barriers
    
    This allows clients to add barriers that extend to the edge of the
    screen. Clients are encouraged to use these instead of precise coordinates
    in these cases to help prevent pointer leaks.
    
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index a65d208..27b21ee 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -140,6 +140,19 @@ barrier_is_blocking_direction(const struct PointerBarrier * barrier,
     return (barrier->directions & direction) != direction;
 }
 
+static BOOL
+inside_segment(int v, int v1, int v2)
+{
+    if (v1 < 0 && v2 < 0) /* line */
+        return TRUE;
+    else if (v1 < 0)      /* ray */
+        return v <= v2;
+    else if (v2 < 0)      /* ray */
+        return v >= v1;
+    else                  /* line segment */
+        return v >= v1 && v <= v2;
+}
+
 #define T(v, a, b) (((float)v) - (a)) / ((b) - (a))
 #define F(t, a, b) ((t) * ((a) - (b)) + (a))
 
@@ -171,7 +184,7 @@ barrier_is_blocking(const struct PointerBarrier * barrier,
             return FALSE;
 
         y = F(t, y1, y2);
-        if (y < barrier->y1 || y > barrier->y2)
+        if (!inside_segment(y, barrier->y1, barrier->y2))
             return FALSE;
 
         *distance = sqrt((pow(y - y1, 2) + pow(barrier->x1 - x1, 2)));
@@ -188,7 +201,7 @@ barrier_is_blocking(const struct PointerBarrier * barrier,
             return FALSE;
 
         x = F(t, x1, x2);
-        if (x < barrier->x1 || x > barrier->x2)
+        if (!inside_segment(x, barrier->x1, barrier->x2))
             return FALSE;
 
         *distance = sqrt((pow(x - x1, 2) + pow(barrier->y1 - y1, 2)));
@@ -428,6 +441,18 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
     *out_y = y;
 }
 
+static void
+sort_min_max(INT16 *a, INT16 *b)
+{
+    INT16 A, B;
+    if (*a < 0 || *b < 0)
+        return;
+    A = *a;
+    B = *b;
+    *a = min(A, B);
+    *b = max(A, B);
+}
+
 static int
 CreatePointerBarrierClient(ClientPtr client,
                            xXFixesCreatePointerBarrierReq * stuff,
@@ -491,10 +516,12 @@ CreatePointerBarrierClient(ClientPtr client,
     ret->release_event_id = 0;
     ret->hit = FALSE;
     ret->seen = FALSE;
-    ret->barrier.x1 = min(stuff->x1, stuff->x2);
-    ret->barrier.x2 = max(stuff->x1, stuff->x2);
-    ret->barrier.y1 = min(stuff->y1, stuff->y2);
-    ret->barrier.y2 = max(stuff->y1, stuff->y2);
+    ret->barrier.x1 = stuff->x1;
+    ret->barrier.x2 = stuff->x2;
+    ret->barrier.y1 = stuff->y1;
+    ret->barrier.y2 = stuff->y2;
+    sort_min_max(&ret->barrier.x1, &ret->barrier.x2);
+    sort_min_max(&ret->barrier.y1, &ret->barrier.y2);
     ret->barrier.directions = stuff->directions & 0x0f;
     if (barrier_is_horizontal(&ret->barrier))
         ret->barrier.directions &= ~(BarrierPositiveX | BarrierNegativeX);
@@ -587,6 +614,13 @@ XICreatePointerBarrier(ClientPtr client,
     if (barrier_is_horizontal(&b) && barrier_is_vertical(&b))
         return BadValue;
 
+    /* no infinite barriers on the wrong axis */
+    if (barrier_is_horizontal(&b) && (b.y1 < 0 || b.y2 < 0))
+        return BadValue;
+
+    if (barrier_is_vertical(&b) && (b.x1 < 0 || b.x2 < 0))
+        return BadValue;
+
     if ((err = CreatePointerBarrierClient(client, stuff, &barrier)))
         return err;
 
diff --git a/Xi/xibarriers.h b/Xi/xibarriers.h
index f29bb6c..bdcb0b2 100644
--- a/Xi/xibarriers.h
+++ b/Xi/xibarriers.h
@@ -11,7 +11,7 @@
 extern _X_EXPORT RESTYPE PointerBarrierType;
 
 struct PointerBarrier {
-    CARD16 x1, x2, y1, y2;
+    INT16 x1, x2, y1, y2;
     CARD32 directions;
 };
 
diff --git a/test/fixes.c b/test/fixes.c
index 7807c73..4ac6750 100644
--- a/test/fixes.c
+++ b/test/fixes.c
@@ -265,6 +265,32 @@ fixes_pointer_barriers_test(void)
     x2 = x + 100;
     assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
 
+    /* ray vert barrier */
+    barrier.x1 = x;
+    barrier.x2 = x;
+    barrier.y1 = -1;
+    barrier.y2 = y + 100;
+
+    /* ray barrier simple case */
+    y1 = y;
+    y2 = y;
+    x1 = x + 50;
+    x2 = x - 50;
+    assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+    /* endpoint outside y range; should be blocked */
+    y1 = y - 1000;
+    y2 = y - 1000;
+    x1 = x + 50;
+    x2 = x - 50;
+    assert(barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
+
+    /* endpoint outside y range */
+    y1 = y + 150;
+    y2 = y + 150;
+    x1 = x + 50;
+    x2 = x - 50;
+    assert(!barrier_is_blocking(&barrier, x1, y1, x2, y2, &distance));
 }
 
 static void
commit 0a5a0d7c242add4d79721c1b90073b603a475534
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Tue Nov 27 14:29:52 2012 -0500

    barriers: Replace complex intersection test with simpler math
    
    Since barriers are axis-aligned, we can do the intersection test with
    simple interpolation rather than line-segment intersection. This also
    helps us out in the future when we want the barriers to extend to be
    rays and lines rather than just segments.
    
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index 2e7f2cc..a65d208 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -140,6 +140,9 @@ barrier_is_blocking_direction(const struct PointerBarrier * barrier,
     return (barrier->directions & direction) != direction;
 }
 
+#define T(v, a, b) (((float)v) - (a)) / ((b) - (a))
+#define F(t, a, b) ((t) * ((a) - (b)) + (a))
+
 /**
  * Test if the movement vector x1/y1 → x2/y2 is intersecting with the
  * barrier. A movement vector with the startpoint or endpoint adjacent to
@@ -157,67 +160,40 @@ BOOL
 barrier_is_blocking(const struct PointerBarrier * barrier,
                     int x1, int y1, int x2, int y2, double *distance)
 {
-    BOOL rc = FALSE;
-    float ua, ub, ud;
-    int dir = barrier_get_direction(x1, y1, x2, y2);
-
-    /* Algorithm below doesn't handle edge cases well, hence the extra
-     * checks. */
     if (barrier_is_vertical(barrier)) {
-        /* handle immediate barrier adjacency, moving away */
-        if (dir & BarrierPositiveX && x1 == barrier->x1)
+        float t, y;
+        t = T(barrier->x1, x1, x2);
+        if (t < 0 || t > 1)
             return FALSE;
-        if (dir & BarrierNegativeX && x1 == (barrier->x1 - 1))
+
+        /* Edge case: moving away from barrier. */
+        if (x2 > x1 && t == 0)
             return FALSE;
-        /* startpoint adjacent to barrier, moving towards -> block */
-        if (dir & BarrierPositiveX && x1 == (barrier->x1 - 1) && y1 >= barrier->y1 && y1 <= barrier->y2) {
-            *distance = 0;
-            return TRUE;
-        }
-        if (dir & BarrierNegativeX && x1 == barrier->x1 && y1 >= barrier->y1 && y1 <= barrier->y2) {
-            *distance = 0;
-            return TRUE;
-        }
+
+        y = F(t, y1, y2);
+        if (y < barrier->y1 || y > barrier->y2)
+            return FALSE;
+
+        *distance = sqrt((pow(y - y1, 2) + pow(barrier->x1 - x1, 2)));
+        return TRUE;
     }
     else {
-        /* handle immediate barrier adjacency, moving away */
-        if (dir & BarrierPositiveY && y1 == barrier->y1)
+        float t, x;
+        t = T(barrier->y1, y1, y2);
+        if (t < 0 || t > 1)
             return FALSE;
-        if (dir & BarrierNegativeY && y1 == (barrier->y1 - 1))
-            return FALSE;
-        /* startpoint adjacent to barrier, moving towards -> block */
-        if (dir & BarrierPositiveY && y1 == (barrier->y1 - 1) && x1 >= barrier->x1 && x1 <= barrier->x2) {
-            *distance = 0;
-            return TRUE;
-        }
-        if (dir & BarrierNegativeY && y1 == barrier->y1 && x1 >= barrier->x1 && x1 <= barrier->x2) {
-            *distance = 0;
-            return TRUE;
-        }
-    }
 
-    /* not an edge case, compute distance */
-    ua = 0;
-    ud = (barrier->y2 - barrier->y1) * (x2 - x1) - (barrier->x2 -
-                                                    barrier->x1) * (y2 - y1);
-    if (ud != 0) {
-        ua = ((barrier->x2 - barrier->x1) * (y1 - barrier->y1) -
-              (barrier->y2 - barrier->y1) * (x1 - barrier->x1)) / ud;
-        ub = ((x2 - x1) * (y1 - barrier->y1) -
-              (y2 - y1) * (x1 - barrier->x1)) / ud;
-        if (ua < 0 || ua > 1 || ub < 0 || ub > 1)
-            ua = 0;
-    }
+        /* Edge case: moving away from barrier. */
+        if (y2 > y1 && t == 0)
+            return FALSE;
 
-    if (ua > 0 && ua <= 1) {
-        double ix = barrier->x1 + ua * (barrier->x2 - barrier->x1);
-        double iy = barrier->y1 + ua * (barrier->y2 - barrier->y1);
+        x = F(t, x1, x2);
+        if (x < barrier->x1 || x > barrier->x2)
+            return FALSE;
 
-        *distance = sqrt(pow(x1 - ix, 2) + pow(y1 - iy, 2));
-        rc = TRUE;
+        *distance = sqrt((pow(x - x1, 2) + pow(barrier->y1 - y1, 2)));
+        return TRUE;
     }
-
-    return rc;
 }
 
 #define HIT_EDGE_EXTENTS 2
commit 6401317bdcf58b2717214ac65c8f47b0c384a7db
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Sun Dec 9 19:45:48 2012 -0500

    barriers: Send an XI_BarrierLeave event when a barrier is destroyed
    
    This ensures that we always complete an event sequence.
    
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index b62a18e..2e7f2cc 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -539,8 +539,52 @@ static int
 BarrierFreeBarrier(void *data, XID id)
 {
     struct PointerBarrierClient *c;
+    Time ms = GetTimeInMillis();
 
     c = container_of(data, struct PointerBarrierClient, barrier);
+
+    /* FIXME: this is really broken for multidevice */
+    if (c->hit) {
+        DeviceIntPtr dev = NULL;
+        ScreenPtr screen = c->screen;
+        BarrierEvent ev = {
+            .header = ET_Internal,
+            .type = ET_BarrierLeave,
+            .length = sizeof (BarrierEvent),
+            .time = ms,
+            /* .deviceid */
+            .sourceid = 0,
+            .barrierid = c->id,
+            .window = c->window->drawable.id,
+            .root = screen->root->drawable.id,
+            .dx = 0,
+            .dy = 0,
+            /* .root_x */
+            /* .root_y */
+            .dt = ms - c->last_timestamp,
+            .event_id = c->barrier_event_id,
+            .flags = XIBarrierPointerReleased,
+        };
+
+        for (dev = inputInfo.devices; dev; dev = dev->next) {
+            int root_x, root_y;
+
+            if (dev->type != MASTER_POINTER)
+                continue;
+
+            if (!barrier_blocks_device(c, dev))
+                continue;
+
+            ev.deviceid = dev->id;
+
+            GetSpritePosition(dev, &root_x, &root_y);
+            ev.root_x = root_x;
+            ev.root_y = root_y;
+
+            mieqEnqueue(dev, (InternalEvent *) &ev);
+        }
+    }
+
     xorg_list_del(&c->entry);
 
     free(c);
commit 207e8dee00dd26ff4363edb72058b48b8a76b824
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Sun Dec 9 19:44:13 2012 -0500

    barriers: Clean up code
    
    Rename a variable. This is to make the diff in the next commit cleaner.
    
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index 75ea4f7..b62a18e 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -538,12 +538,12 @@ CreatePointerBarrierClient(ClientPtr client,
 static int
 BarrierFreeBarrier(void *data, XID id)
 {
-    struct PointerBarrierClient *barrier;
+    struct PointerBarrierClient *c;
 
-    barrier = container_of(data, struct PointerBarrierClient, barrier);
-    xorg_list_del(&barrier->entry);
+    c = container_of(data, struct PointerBarrierClient, barrier);
+    xorg_list_del(&c->entry);
 
-    free(barrier);
+    free(c);
     return Success;
 }
 
commit 7fabecd8e3efe76caeb740d905a02ae4256e3246
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Wed Dec 5 19:58:05 2012 -0500

    barriers: Send a BarrierLeave event when we leave the hitbox
    
    Additionally, add flags when the pointer is released.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index 45e97cf..75ea4f7 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -417,6 +417,7 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
     }
 
     xorg_list_for_each_entry(c, &cs->barriers, entry) {
+        int flags = 0;
         c->seen = FALSE;
         if (!c->hit)
             continue;
@@ -425,6 +426,22 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
             continue;
 
         c->hit = FALSE;
+
+        ev.type = ET_BarrierLeave;
+
+        if (c->barrier_event_id == c->release_event_id)
+            flags |= XIBarrierPointerReleased;
+
+        ev.flags = flags;
+        ev.event_id = c->barrier_event_id;
+        ev.barrierid = c->id;
+
+        ev.dt = ms - c->last_timestamp;
+        ev.window = c->window->drawable.id;
+        c->last_timestamp = ms;
+
+        mieqEnqueue(dev, (InternalEvent *) &ev);
+
         /* If we've left the hit box, this is the
          * start of a new event ID. */
         c->barrier_event_id++;
commit dac9e13a6c874f3b99ba4cf9085ed0e63beb0871
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Mon Nov 26 20:37:56 2012 -0500

    barriers: Increment event ID on hit box leave
    
    We eventually want to send a new notify event on hitbox leave,
    which signifies the dawn of a new barrier event ID, so it's
    convenient if we can put the code here.
    
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index 95a62ae..45e97cf 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -418,8 +418,16 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
 
     xorg_list_for_each_entry(c, &cs->barriers, entry) {
         c->seen = FALSE;
-        if (c->hit && !barrier_inside_hit_box(&c->barrier, x, y))
-            c->hit = FALSE;
+        if (!c->hit)
+            continue;
+
+        if (barrier_inside_hit_box(&c->barrier, x, y))
+            continue;
+
+        c->hit = FALSE;
+        /* If we've left the hit box, this is the
+         * start of a new event ID. */
+        c->barrier_event_id++;
     }
 
  out:
@@ -486,7 +494,7 @@ CreatePointerBarrierClient(ClientPtr client,
     }
 
     ret->id = stuff->barrier;
-    ret->barrier_event_id = 0;
+    ret->barrier_event_id = 1;
     ret->release_event_id = 0;
     ret->hit = FALSE;
     ret->seen = FALSE;
commit e3a734d081ebda4460e6c1eb7dcdd0f7c10ba9b4
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Sat Nov 24 21:42:56 2012 -0500

    barriers: Add a couple pixels of elbow room for the hit detection
    
    Pointers (and the hands that drive them) aren't very precise, and the
    slightest amount of nudging to either side might be enough to reset
    the event ID, making clients think they have an entirely new hit. Allow
    for a slightly bigger "hit box" before these barriers get reset.
    
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index ac94927..95a62ae 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -79,7 +79,7 @@ struct PointerBarrierClient {
     int barrier_event_id;
     int release_event_id;
     Bool hit;
-    Bool last_hit;
+    Bool seen;
 };
 
 typedef struct _BarrierScreen {
@@ -220,6 +220,35 @@ barrier_is_blocking(const struct PointerBarrier * barrier,
     return rc;
 }
 
+#define HIT_EDGE_EXTENTS 2
+static BOOL
+barrier_inside_hit_box(struct PointerBarrier *barrier, int x, int y)
+{
+    int x1, x2, y1, y2;
+    int dir;
+
+    x1 = barrier->x1;
+    x2 = barrier->x2;
+    y1 = barrier->y1;
+    y2 = barrier->y2;
+    dir = ~(barrier->directions);
+
+    if (barrier_is_vertical(barrier)) {
+        if (dir & BarrierPositiveX)
+            x1 -= HIT_EDGE_EXTENTS;
+        if (dir & BarrierNegativeX)
+            x2 += HIT_EDGE_EXTENTS;
+    }
+    if (barrier_is_horizontal(barrier)) {
+        if (dir & BarrierPositiveY)
+            y1 -= HIT_EDGE_EXTENTS;
+        if (dir & BarrierNegativeY)
+            y2 += HIT_EDGE_EXTENTS;
+    }
+
+    return x >= x1 && x <= x2 && y >= y1 && y <= y2;
+}
+
 static BOOL
 barrier_blocks_device(struct PointerBarrierClient *client,
                       DeviceIntPtr dev)
@@ -267,7 +296,7 @@ barrier_find_nearest(BarrierScreenPtr cs, DeviceIntPtr dev,
         struct PointerBarrier *b = &c->barrier;
         double distance;
 
-        if (c->hit)
+        if (c->seen)
             continue;
 
         if (!barrier_is_blocking_direction(b, dir))
@@ -388,8 +417,9 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
     }
 
     xorg_list_for_each_entry(c, &cs->barriers, entry) {
-        c->last_hit = c->hit;
-        c->hit = FALSE;
+        c->seen = FALSE;
+        if (c->hit && !barrier_inside_hit_box(&c->barrier, x, y))
+            c->hit = FALSE;
     }
 
  out:
@@ -459,7 +489,7 @@ CreatePointerBarrierClient(ClientPtr client,
     ret->barrier_event_id = 0;
     ret->release_event_id = 0;
     ret->hit = FALSE;
-    ret->last_hit = FALSE;
+    ret->seen = FALSE;
     ret->barrier.x1 = min(stuff->x1, stuff->x2);
     ret->barrier.x2 = max(stuff->x1, stuff->x2);
     ret->barrier.y1 = min(stuff->y1, stuff->y2);
commit 3b2fbcfa6c75ab072926ab9659adf785b324ce28
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Thu Nov 8 01:17:40 2012 -0500

    barriers: Add support for edge cases when releasing barriers
    
    If we release a barrier, we want to ensure that we block all
    other barriers afterwards, rather than capping the limit to
    the two nearest barriers.
    
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index 8f12253..ac94927 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -267,6 +267,9 @@ barrier_find_nearest(BarrierScreenPtr cs, DeviceIntPtr dev,
         struct PointerBarrier *b = &c->barrier;
         double distance;
 
+        if (c->hit)
+            continue;
+
         if (!barrier_is_blocking_direction(b, dir))
             continue;
 
@@ -321,7 +324,6 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
     int x = dest_x,
         y = dest_y;
     int dir;
-    int i;
     struct PointerBarrier *nearest = NULL;
     PointerBarrierClientPtr c;
     Time ms = GetTimeInMillis();
@@ -349,8 +351,7 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
      */
     dir = barrier_get_direction(current_x, current_y, x, y);
 
-#define MAX_BARRIERS 2
-    for (i = 0; i < MAX_BARRIERS; i++) {
+    while (dir != 0) {
         c = barrier_find_nearest(cs, dev, dir, current_x, current_y, x, y);
         if (!c)
             break;
commit a1ee26e624e6a7030ecb37a608190cb8e3d1f65b
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 6 12:06:28 2012 +1000

    barriers: Don't allow releasing the pointer on other client's barriers
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index 86e811e..8f12253 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -591,6 +591,9 @@ ProcXIBarrierReleasePointer(ClientPtr client)
             return err;
         }
 
+        if (CLIENT_ID(barrier_id) != client->index)
+            return BadAccess;
+
         barrier = container_of(b, struct PointerBarrierClient, barrier);
         if (barrier->barrier_event_id == event_id)
             barrier->release_event_id = event_id;
commit 2884b249294e3e8fc749bbb81e2a897314fa0818
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 6 11:59:53 2012 +1000

    barriers: Don't allow destroying other client's barriers
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index f16094d..86e811e 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -534,6 +534,9 @@ XIDestroyPointerBarrier(ClientPtr client,
         return err;
     }
 
+    if (CLIENT_ID(stuff->barrier) != client->index)
+        return BadAccess;
+
     FreeResource(stuff->barrier, RT_NONE);
     return Success;
 }
commit e130a46ab45839f91b29ee75bf19a597dfe3da28
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Thu Nov 1 16:06:40 2012 -0400

    Add support for XI2.3: Pointer barrier events and releases.
    
    This adds support for clients that would like to get a notification
    every time a barrier is hit, and allows clients to temporarily release
    a barrier so that pointers can go through them, without having to
    destroy and recreate barriers.
    
    Based on work by Chris Halse Rogers <chris.halse.rogers at canonical.com>
    
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 2caf98c..e606d9e 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1639,6 +1639,34 @@ ProcessTouchEvent(InternalEvent *ev, DeviceIntPtr dev)
         UpdateDeviceState(dev, &ev->device_event);
 }
 
+static void
+ProcessBarrierEvent(InternalEvent *e, DeviceIntPtr dev)
+{
+    Mask filter;
+    WindowPtr pWin;
+    BarrierEvent *be = &e->barrier_event;
+    xEvent *ev;
+    int rc;
+
+    if (!IsMaster(dev))
+        return;
+
+    if (dixLookupWindow(&pWin, be->window, serverClient, DixReadAccess) != Success)
+        return;
+
+    rc = EventToXI2(e, &ev);
+    if (rc != Success) {
+        ErrorF("[Xi] event conversion from %s failed with code %d\n", __func__, rc);
+        return;
+    }
+
+    filter = GetEventFilter(dev, ev);
+
+    DeliverEventsToWindow(dev, pWin, ev, 1,
+                          filter, NullGrab);
+    free(ev);
+}
+
 /**
  * Process DeviceEvents and DeviceChangedEvents.
  */
@@ -1788,6 +1816,10 @@ ProcessOtherEvent(InternalEvent *ev, DeviceIntPtr device)
     case ET_TouchEnd:
         ProcessTouchEvent(ev, device);
         break;
+    case ET_BarrierHit:
+    case ET_BarrierLeave:
+        ProcessBarrierEvent(ev, device);
+        break;
     default:
         ProcessDeviceEvent(ev, device);
         break;
diff --git a/Xi/extinit.c b/Xi/extinit.c
index 1074b23..175d89b 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -252,7 +252,8 @@ static int (*ProcIVector[]) (ClientPtr) = {
         ProcXIChangeProperty,   /* 57 */
         ProcXIDeleteProperty,   /* 58 */
         ProcXIGetProperty,      /* 59 */
-        ProcXIGetSelectedEvents /* 60 */
+        ProcXIGetSelectedEvents, /* 60 */
+        ProcXIBarrierReleasePointer /* 61 */
 };
 
 /* For swapped clients */
@@ -317,7 +318,8 @@ static int (*SProcIVector[]) (ClientPtr) = {
         SProcXIChangeProperty,  /* 57 */
         SProcXIDeleteProperty,  /* 58 */
         SProcXIGetProperty,     /* 59 */
-        SProcXIGetSelectedEvents        /* 60 */
+        SProcXIGetSelectedEvents,       /* 60 */
+        SProcXIBarrierReleasePointer /* 61 */
 };
 
 /*****************************************************************
@@ -840,6 +842,33 @@ STouchOwnershipEvent(xXITouchOwnershipEvent * from, xXITouchOwnershipEvent * to)
     swapl(&to->child);
 }
 
+static void
+SBarrierEvent(xXIBarrierEvent * from,
+              xXIBarrierEvent * to) {
+    to->type = from->type;
+
+    cpswapl(from->length, to->length);
+    cpswapl(from->time, to->time);
+    cpswaps(from->deviceid, to->deviceid);
+    cpswaps(from->sourceid, to->sourceid);
+    cpswapl(from->event, to->event);
+    cpswapl(from->root, to->root);
+    cpswapl(from->root_x, to->root_x);
+    cpswapl(from->root_y, to->root_y);
+
+#define SWAP_FP3232(x, y)                       \
+    do {                                        \
+        cpswapl((x).integral, (y).integral);    \
+        cpswapl((x).frac, (y).frac);            \
+    } while(0)
+
+    SWAP_FP3232(from->dx, to->dx);
+    SWAP_FP3232(from->dy, to->dy);
+    cpswapl(from->dtime, to->dtime);
+    cpswapl(from->barrier, to->barrier);
+    cpswapl(from->eventid, to->eventid);
+}
+
 /** Event swapping function for XI2 events. */
 void
 XI2EventSwap(xGenericEvent *from, xGenericEvent *to)
@@ -886,6 +915,11 @@ XI2EventSwap(xGenericEvent *from, xGenericEvent *to)
     case XI_RawTouchEnd:
         SRawEvent((xXIRawEvent *) from, (xXIRawEvent *) to);
         break;
+    case XI_BarrierHit:
+    case XI_BarrierLeave:
+        SBarrierEvent((xXIBarrierEvent *) from,
+                      (xXIBarrierEvent *) to);
+        break;
     default:
         ErrorF("[Xi] Unknown event type to swap. This is a bug.\n");
         break;
diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index 0affde6..f16094d 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -56,6 +56,8 @@
 #include "xace.h"
 #include "list.h"
 #include "exglobals.h"
+#include "eventstr.h"
+#include "mi.h"
 
 RESTYPE PointerBarrierType;
 
@@ -66,11 +68,18 @@ static DevPrivateKeyRec BarrierScreenPrivateKeyRec;
 typedef struct PointerBarrierClient *PointerBarrierClientPtr;
 
 struct PointerBarrierClient {
+    XID id;
     ScreenPtr screen;
+    WindowPtr window;
     struct PointerBarrier barrier;
     struct xorg_list entry;
     int num_devices;
     int *device_ids; /* num_devices */
+    Time last_timestamp;
+    int barrier_event_id;
+    int release_event_id;
+    Bool hit;
+    Bool last_hit;
 };
 
 typedef struct _BarrierScreen {
@@ -315,6 +324,18 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
     int i;
     struct PointerBarrier *nearest = NULL;
     PointerBarrierClientPtr c;
+    Time ms = GetTimeInMillis();
+    BarrierEvent ev = {
+        .header = ET_Internal,
+        .type = 0,
+        .length = sizeof (BarrierEvent),
+        .time = ms,
+        .deviceid = dev->id,
+        .sourceid = dev->id,
+        .dx = dest_x - current_x,
+        .dy = dest_y - current_y,
+        .root = screen->root->drawable.id,
+    };
 
     if (xorg_list_is_empty(&cs->barriers) || IsFloating(dev))
         goto out;
@@ -336,6 +357,13 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
 
         nearest = &c->barrier;
 
+        c->seen = TRUE;
+        c->hit = TRUE;
+
+        if (c->barrier_event_id == c->release_event_id)
+            continue;
+
+        ev.type = ET_BarrierHit;
         barrier_clamp_to_barrier(nearest, dir, &x, &y);
 
         if (barrier_is_vertical(nearest)) {
@@ -346,6 +374,21 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
             dir &= ~(BarrierNegativeY | BarrierPositiveY);
             current_y = y;
         }
+
+        ev.flags = 0;
+        ev.event_id = c->barrier_event_id;
+        ev.barrierid = c->id;
+
+        ev.dt = ms - c->last_timestamp;
+        ev.window = c->window->drawable.id;
+        c->last_timestamp = ms;
+
+        mieqEnqueue(dev, (InternalEvent *) &ev);
+    }
+
+    xorg_list_for_each_entry(c, &cs->barriers, entry) {
+        c->last_hit = c->hit;
+        c->hit = FALSE;
     }
 
  out:
@@ -384,6 +427,7 @@ CreatePointerBarrierClient(ClientPtr client,
     cs = GetBarrierScreen(screen);
 
     ret->screen = screen;
+    ret->window = pWin;
     ret->num_devices = stuff->num_devices;
     if (ret->num_devices > 0)
         ret->device_ids = (int*)&ret[1];
@@ -410,6 +454,11 @@ CreatePointerBarrierClient(ClientPtr client,
         ret->device_ids[i] = device_id;
     }
 
+    ret->id = stuff->barrier;
+    ret->barrier_event_id = 0;
+    ret->release_event_id = 0;
+    ret->hit = FALSE;
+    ret->last_hit = FALSE;
     ret->barrier.x1 = min(stuff->x1, stuff->x2);
     ret->barrier.x2 = max(stuff->x1, stuff->x2);
     ret->barrier.y1 = min(stuff->y1, stuff->y2);
@@ -489,6 +538,64 @@ XIDestroyPointerBarrier(ClientPtr client,
     return Success;
 }
 
+int
+SProcXIBarrierReleasePointer(ClientPtr client)
+{
+    xXIBarrierReleasePointerInfo *info;
+    REQUEST(xXIBarrierReleasePointerReq);
+    int i;
+
+    info = (xXIBarrierReleasePointerInfo*) &stuff[1];
+
+    swaps(&stuff->length);
+    swapl(&stuff->num_barriers);
+    for (i = 0; i < stuff->num_barriers; i++, info++) {
+        swaps(&info->deviceid);
+        swapl(&info->barrier);
+        swapl(&info->eventid);
+    }
+
+    return (ProcXIBarrierReleasePointer(client));
+}
+
+int
+ProcXIBarrierReleasePointer(ClientPtr client)
+{
+    int i;
+    int err;
+    struct PointerBarrierClient *barrier;
+    struct PointerBarrier *b;
+    xXIBarrierReleasePointerInfo *info;
+
+    REQUEST(xXIBarrierReleasePointerReq);
+    REQUEST_AT_LEAST_SIZE(xXIBarrierReleasePointerReq);
+
+    info = (xXIBarrierReleasePointerInfo*) &stuff[1];
+    for (i = 0; i < stuff->num_barriers; i++, info++) {
+        CARD32 barrier_id, event_id;
+        _X_UNUSED CARD32 device_id;
+
+        barrier_id = info->barrier;
+        event_id = info->eventid;
+
+        /* FIXME: per-device releases */
+        device_id = info->deviceid;
+
+        err = dixLookupResourceByType((void **) &b, barrier_id,
+                                      PointerBarrierType, client, DixReadAccess);
+        if (err != Success) {
+            client->errorValue = barrier_id;
+            return err;
+        }
+
+        barrier = container_of(b, struct PointerBarrierClient, barrier);
+        if (barrier->barrier_event_id == event_id)
+            barrier->release_event_id = event_id;
+    }
+
+    return Success;
+}
+
 Bool
 XIBarrierInit(void)
 {
diff --git a/Xi/xibarriers.h b/Xi/xibarriers.h
index 8f2993f..f29bb6c 100644
--- a/Xi/xibarriers.h
+++ b/Xi/xibarriers.h
@@ -39,9 +39,7 @@ XIDestroyPointerBarrier(ClientPtr client,
 Bool
 XIBarrierInit(void);
 
-#endif /* _XIBARRIERS_H_ */
-
-
-
-
+int SProcXIBarrierReleasePointer(ClientPtr client);
+int ProcXIBarrierReleasePointer(ClientPtr client);
 
+#endif /* _XIBARRIERS_H_ */
diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index 2e422d7..bb5c8d3 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -57,6 +57,7 @@ static int eventToKeyButtonPointer(DeviceEvent *ev, xEvent **xi, int *count);
 static int eventToDeviceChanged(DeviceChangedEvent *ev, xEvent **dcce);
 static int eventToDeviceEvent(DeviceEvent *ev, xEvent **xi);
 static int eventToRawEvent(RawDeviceEvent *ev, xEvent **xi);
+static int eventToBarrierEvent(BarrierEvent *ev, xEvent **xi);
 static int eventToTouchOwnershipEvent(TouchOwnershipEvent *ev, xEvent **xi);
 
 /* Do not use, read comments below */
@@ -277,6 +278,9 @@ EventToXI2(InternalEvent *ev, xEvent **xi)
     case ET_RawTouchUpdate:
     case ET_RawTouchEnd:
         return eventToRawEvent(&ev->raw_event, xi);
+    case ET_BarrierHit:
+    case ET_BarrierLeave:
+        return eventToBarrierEvent(&ev->barrier_event, xi);
     default:
         break;
     }
@@ -782,6 +786,35 @@ eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
     return Success;
 }
 
+static int
+eventToBarrierEvent(BarrierEvent *ev, xEvent **xi)
+{
+    xXIBarrierEvent *barrier;
+    int len = sizeof(xXIBarrierEvent);
+
+    *xi = calloc(1, len);
+    barrier = (xXIBarrierEvent*) *xi;
+    barrier->type = GenericEvent;
+    barrier->extension = IReqCode;
+    barrier->evtype = GetXI2Type(ev->type);
+    barrier->length = bytes_to_int32(len - sizeof(xEvent));
+    barrier->deviceid = ev->deviceid;
+    barrier->sourceid = ev->sourceid;
+    barrier->time = ev->time;
+    barrier->event = ev->window;
+    barrier->root = ev->root;
+    barrier->dx = double_to_fp3232(ev->dx);
+    barrier->dy = double_to_fp3232(ev->dy);
+    barrier->dtime = ev->dt;
+    barrier->flags = ev->flags;
+    barrier->eventid = ev->event_id;
+    barrier->barrier = ev->barrierid;
+    barrier->root_x = double_to_fp1616(ev->root_x);
+    barrier->root_y = double_to_fp1616(ev->root_y);
+
+    return Success;
+}
+
 /**
  * Return the corresponding core type for the given event or 0 if no core
  * equivalent exists.
@@ -929,6 +962,12 @@ GetXI2Type(enum EventType type)
     case ET_TouchOwnership:
         xi2type = XI_TouchOwnership;
         break;
+    case ET_BarrierHit:
+        xi2type = XI_BarrierHit;
+        break;
+    case ET_BarrierLeave:
+        xi2type = XI_BarrierLeave;
+        break;
     default:
         break;
     }
diff --git a/include/events.h b/include/events.h
index 222bf32..c0ef45d 100644
--- a/include/events.h
+++ b/include/events.h
@@ -27,6 +27,7 @@
 typedef struct _DeviceEvent DeviceEvent;
 typedef struct _DeviceChangedEvent DeviceChangedEvent;
 typedef struct _TouchOwnershipEvent TouchOwnershipEvent;
+typedef struct _BarrierEvent BarrierEvent;
 
 #if XFreeXDGA
 typedef struct _DGAEvent DGAEvent;
diff --git a/include/eventstr.h b/include/eventstr.h
index eddba87..38fab4f 100644
--- a/include/eventstr.h
+++ b/include/eventstr.h
@@ -72,6 +72,8 @@ enum EventType {
     ET_RawTouchUpdate,
     ET_RawTouchEnd,
     ET_XQuartz,
+    ET_BarrierHit,
+    ET_BarrierLeave,
     ET_Internal = 0xFF          /* First byte */
 };
 
@@ -227,6 +229,25 @@ struct _RawDeviceEvent {
     uint32_t flags;       /**< Flags to be copied into the generated event */
 };
 
+struct _BarrierEvent {
+    unsigned char header; /**<  Always ET_Internal */
+    enum EventType type;  /**<  ET_BarrierHit, ET_BarrierLeave */
+    int length;           /**<  Length in bytes */
+    Time time;            /**<  Time in ms */
+    int deviceid;         /**< Device to post this event for */
+    int sourceid;         /**< The physical source device */
+    int barrierid;
+    Window window;
+    Window root;
+    double dx;
+    double dy;
+    double root_x;
+    double root_y;
+    int16_t dt;
+    int32_t event_id;
+    uint32_t flags;
+};
+
 #ifdef XQUARTZ
 #define XQUARTZ_EVENT_MAXARGS 5
 struct _XQuartzEvent {
@@ -253,6 +274,7 @@ union _InternalEvent {
     DeviceEvent device_event;
     DeviceChangedEvent changed_event;
     TouchOwnershipEvent touch_ownership_event;
+    BarrierEvent barrier_event;
 #if XFreeXDGA
     DGAEvent dga_event;
 #endif
diff --git a/include/inputstr.h b/include/inputstr.h
index bb0a779..17cee98 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -71,7 +71,7 @@ extern _X_EXPORT int CountBits(const uint8_t * mask, int len);
  * events to the protocol, the server will not support these events until
  * this number here is bumped.
  */
-#define XI2LASTEVENT    XI_RawTouchEnd
+#define XI2LASTEVENT    XI_BarrierLeave
 #define XI2MASKSIZE     ((XI2LASTEVENT >> 3) + 1)       /* no of bytes for masks */
 
 /**
diff --git a/mi/mieq.c b/mi/mieq.c
index b2c7769..22f8c91 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -407,6 +407,10 @@ ChangeDeviceID(DeviceIntPtr dev, InternalEvent *event)
     case ET_RawTouchUpdate:
         event->raw_event.deviceid = dev->id;
         break;
+    case ET_BarrierHit:
+    case ET_BarrierLeave:
+        event->barrier_event.deviceid = dev->id;
+        break;
     default:
         ErrorF("[mi] Unknown event type (%d), cannot change id.\n",
                event->any.type);
commit 85a37ddcc2ff49adaec4075532b60e7d015f901c
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Sun Dec 9 22:48:18 2012 -0500

    barriers: Reindent the constrainment hook
    
    This is to make future diffs much cleaner. Best viewed with -w.
    
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index 21ad6c7..0affde6 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -311,43 +311,44 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
     BarrierScreenPtr cs = GetBarrierScreen(screen);
     int x = dest_x,
         y = dest_y;
+    int dir;
+    int i;
+    struct PointerBarrier *nearest = NULL;
+    PointerBarrierClientPtr c;
+
+    if (xorg_list_is_empty(&cs->barriers) || IsFloating(dev))
+        goto out;
 
-    if (!xorg_list_is_empty(&cs->barriers) && !IsFloating(dev)) {
-        int dir;
-        int i;
-        struct PointerBarrier *nearest = NULL;
-        PointerBarrierClientPtr c;
-
-        /* How this works:
-         * Given the origin and the movement vector, get the nearest barrier
-         * to the origin that is blocking the movement.
-         * Clamp to that barrier.
-         * Then, check from the clamped intersection to the original
-         * destination, again finding the nearest barrier and clamping.
-         */
-        dir = barrier_get_direction(current_x, current_y, x, y);
+    /* How this works:
+     * Given the origin and the movement vector, get the nearest barrier
+     * to the origin that is blocking the movement.
+     * Clamp to that barrier.
+     * Then, check from the clamped intersection to the original
+     * destination, again finding the nearest barrier and clamping.
+     */
+    dir = barrier_get_direction(current_x, current_y, x, y);
 
 #define MAX_BARRIERS 2
-        for (i = 0; i < MAX_BARRIERS; i++) {
-            c = barrier_find_nearest(cs, dev, dir, current_x, current_y, x, y);
-            if (!c)
-                break;
+    for (i = 0; i < MAX_BARRIERS; i++) {
+        c = barrier_find_nearest(cs, dev, dir, current_x, current_y, x, y);
+        if (!c)
+            break;
 
-            nearest = &c->barrier;
+        nearest = &c->barrier;
 
-            barrier_clamp_to_barrier(nearest, dir, &x, &y);
+        barrier_clamp_to_barrier(nearest, dir, &x, &y);
 
-            if (barrier_is_vertical(nearest)) {
-                dir &= ~(BarrierNegativeX | BarrierPositiveX);
-                current_x = x;
-            }
-            else if (barrier_is_horizontal(nearest)) {
-                dir &= ~(BarrierNegativeY | BarrierPositiveY);
-                current_y = y;
-            }
+        if (barrier_is_vertical(nearest)) {
+            dir &= ~(BarrierNegativeX | BarrierPositiveX);
+            current_x = x;
+        }
+        else if (barrier_is_horizontal(nearest)) {
+            dir &= ~(BarrierNegativeY | BarrierPositiveY);
+            current_y = y;
         }
     }
 
+ out:
     *out_x = x;
     *out_y = y;
 }
commit 97da74c80e8b8eb03f7c1e34180cf5cd343bd608
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Sun Dec 9 22:19:14 2012 -0500

    barriers: Switch to finding the nearest barrier client
    
    When we add events, we eventually want to add more state to the
    PointerBarrierClient, so return one of these instead of the dummy
    public structure that's not very interesting.
    
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index 9c7affd..21ad6c7 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -237,7 +237,7 @@ barrier_blocks_device(struct PointerBarrierClient *client,
 }
 
 /**
- * Find the nearest barrier that is blocking movement from x1/y1 to x2/y2.
+ * Find the nearest barrier client that is blocking movement from x1/y1 to x2/y2.
  *
  * @param dir Only barriers blocking movement in direction dir are checked
  * @param x1 X start coordinate of movement vector
@@ -246,13 +246,12 @@ barrier_blocks_device(struct PointerBarrierClient *client,
  * @param y2 Y end coordinate of movement vector
  * @return The barrier nearest to the movement origin that blocks this movement.
  */
-static struct PointerBarrier *
+static struct PointerBarrierClient *
 barrier_find_nearest(BarrierScreenPtr cs, DeviceIntPtr dev,
                      int dir,
                      int x1, int y1, int x2, int y2)
 {
-    struct PointerBarrierClient *c;
-    struct PointerBarrier *nearest = NULL;
+    struct PointerBarrierClient *c, *nearest = NULL;
     double min_distance = INT_MAX;      /* can't get higher than that in X anyway */
 
     xorg_list_for_each_entry(c, &cs->barriers, entry) {
@@ -268,7 +267,7 @@ barrier_find_nearest(BarrierScreenPtr cs, DeviceIntPtr dev,
         if (barrier_is_blocking(b, x1, y1, x2, y2, &distance)) {
             if (min_distance > distance) {
                 min_distance = distance;
-                nearest = b;
+                nearest = c;
             }
         }
     }
@@ -317,6 +316,7 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
         int dir;
         int i;
         struct PointerBarrier *nearest = NULL;
+        PointerBarrierClientPtr c;
 
         /* How this works:
          * Given the origin and the movement vector, get the nearest barrier
@@ -329,10 +329,12 @@ input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
 
 #define MAX_BARRIERS 2
         for (i = 0; i < MAX_BARRIERS; i++) {
-            nearest = barrier_find_nearest(cs, dev, dir, current_x, current_y, x, y);
-            if (!nearest)
+            c = barrier_find_nearest(cs, dev, dir, current_x, current_y, x, y);
+            if (!c)
                 break;
 
+            nearest = &c->barrier;
+
             barrier_clamp_to_barrier(nearest, dir, &x, &y);
 
             if (barrier_is_vertical(nearest)) {
commit 7e16dd3628334a5991b6713d778a46c1ce3b8b78
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Sat Nov 24 19:39:47 2012 -0500

    barriers: Switch to an explicit hook for barrier constrainment
    
    Rather than riding on the ConstrainCursorHarder hook, which has
    several issues, move to an explicit hook, which will help us with
    some RANDR interaction issues.
    
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index 9e43196..9c7affd 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -74,16 +74,12 @@ struct PointerBarrierClient {
 };
 
 typedef struct _BarrierScreen {
-    CloseScreenProcPtr CloseScreen;
-    ConstrainCursorHarderProcPtr ConstrainCursorHarder;
     struct xorg_list barriers;
 } BarrierScreenRec, *BarrierScreenPtr;
 
 #define GetBarrierScreen(s) ((BarrierScreenPtr)dixLookupPrivate(&(s)->devPrivates, BarrierScreenPrivateKey))
 #define GetBarrierScreenIfSet(s) GetBarrierScreen(s)
 #define SetBarrierScreen(s,p) dixSetPrivate(&(s)->devPrivates, BarrierScreenPrivateKey, p)
-#define Wrap(as,s,elt,func)	(((as)->elt = (s)->elt), (s)->elt = func)
-#define Unwrap(as,s,elt,backup)	(((backup) = (s)->elt), (s)->elt = (as)->elt)
 
 static BOOL
 barrier_is_horizontal(const struct PointerBarrier *barrier)
@@ -306,22 +302,22 @@ barrier_clamp_to_barrier(struct PointerBarrier *barrier, int dir, int *x,
     }
 }
 
-static void
-BarrierConstrainCursorHarder(DeviceIntPtr dev, ScreenPtr screen, int mode,
-                             int *x, int *y)
+void
+input_constrain_cursor(DeviceIntPtr dev, ScreenPtr screen,
+                       int current_x, int current_y,
+                       int dest_x, int dest_y,
+                       int *out_x, int *out_y)
 {
+    /* Clamped coordinates here refer to screen edge clamping. */
     BarrierScreenPtr cs = GetBarrierScreen(screen);
+    int x = dest_x,
+        y = dest_y;
 
-    if (!xorg_list_is_empty(&cs->barriers) && !IsFloating(dev) &&
-        mode == Relative) {
-        int ox, oy;
+    if (!xorg_list_is_empty(&cs->barriers) && !IsFloating(dev)) {
         int dir;
         int i;
         struct PointerBarrier *nearest = NULL;
 
-        /* where are we coming from */
-        miPointerGetPosition(dev, &ox, &oy);
-
         /* How this works:
          * Given the origin and the movement vector, get the nearest barrier
          * to the origin that is blocking the movement.
@@ -329,32 +325,29 @@ BarrierConstrainCursorHarder(DeviceIntPtr dev, ScreenPtr screen, int mode,
          * Then, check from the clamped intersection to the original
          * destination, again finding the nearest barrier and clamping.
          */
-        dir = barrier_get_direction(ox, oy, *x, *y);
+        dir = barrier_get_direction(current_x, current_y, x, y);
 
 #define MAX_BARRIERS 2
         for (i = 0; i < MAX_BARRIERS; i++) {
-            nearest = barrier_find_nearest(cs, dev, dir, ox, oy, *x, *y);
+            nearest = barrier_find_nearest(cs, dev, dir, current_x, current_y, x, y);
             if (!nearest)
                 break;
 
-            barrier_clamp_to_barrier(nearest, dir, x, y);
+            barrier_clamp_to_barrier(nearest, dir, &x, &y);
 
             if (barrier_is_vertical(nearest)) {
                 dir &= ~(BarrierNegativeX | BarrierPositiveX);
-                ox = *x;
+                current_x = x;
             }
             else if (barrier_is_horizontal(nearest)) {
                 dir &= ~(BarrierNegativeY | BarrierPositiveY);
-                oy = *y;
+                current_y = y;
             }
         }
     }
 
-    if (cs->ConstrainCursorHarder) {
-        screen->ConstrainCursorHarder = cs->ConstrainCursorHarder;
-        screen->ConstrainCursorHarder(dev, screen, mode, x, y);
-        screen->ConstrainCursorHarder = BarrierConstrainCursorHarder;
-    }
+    *out_x = x;
+    *out_y = y;
 }
 
 static int
@@ -493,21 +486,6 @@ XIDestroyPointerBarrier(ClientPtr client,
     return Success;
 }
 
-static Bool
-BarrierCloseScreen(ScreenPtr pScreen)
-{
-    BarrierScreenPtr cs = GetBarrierScreen(pScreen);
-    Bool ret;
-    _X_UNUSED CloseScreenProcPtr close_proc;
-    _X_UNUSED ConstrainCursorHarderProcPtr constrain_proc;
-
-    Unwrap(cs, pScreen, CloseScreen, close_proc);
-    Unwrap(cs, pScreen, ConstrainCursorHarder, constrain_proc);
-    ret = (*pScreen->CloseScreen) (pScreen);
-    free(cs);
-    return ret;
-}
-
 Bool
 XIBarrierInit(void)
 {
@@ -524,8 +502,6 @@ XIBarrierInit(void)
         if (!cs)
             return FALSE;
         xorg_list_init(&cs->barriers);
-        Wrap(cs, pScreen, CloseScreen, BarrierCloseScreen);
-        Wrap(cs, pScreen, ConstrainCursorHarder, BarrierConstrainCursorHarder);
         SetBarrierScreen(pScreen, cs);
     }
 
diff --git a/include/input.h b/include/input.h
index 2387dbf..a5d0462 100644
--- a/include/input.h
+++ b/include/input.h
@@ -678,4 +678,9 @@ extern _X_EXPORT void input_option_set_value(InputOption *opt,
 extern _X_HIDDEN Bool point_on_screen(ScreenPtr pScreen, int x, int y);
 extern _X_HIDDEN void update_desktop_dimensions(void);
 
+extern _X_HIDDEN void input_constrain_cursor(DeviceIntPtr pDev, ScreenPtr screen,
+                                             int current_x, int current_y,
+                                             int dest_x, int dest_y,
+                                             int *out_x, int *out_y);
+
 #endif                          /* INPUT_H */
diff --git a/mi/mipointer.c b/mi/mipointer.c
index f345063..d170824 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -588,6 +588,22 @@ miPointerSetPosition(DeviceIntPtr pDev, int mode, double *screenx,
     x -= pScreen->x;
     y -= pScreen->y;
 
+    if (mode == Relative) {
+        /* coordinates after clamped to a barrier */
+        int constrained_x, constrained_y;
+        int current_x, current_y; /* current position in per-screen coord */
+
+        current_x = MIPOINTER(pDev)->x - pScreen->y;
+        current_y = MIPOINTER(pDev)->y - pScreen->x;
+
+        input_constrain_cursor(pDev, pScreen,
+                               current_x, current_y, x, y,
+                               &constrained_x, &constrained_y);
+
+        x = constrained_x;
+        y = constrained_y;
+    }
+
     if (switch_screen) {
         pScreenPriv = GetScreenPrivate(pScreen);
         if (!pPointer->confined) {
commit 2868a93945f043e1efd897d56543fe673e341faf
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Sun Dec 9 18:41:52 2012 -0500

    barriers: Don't loop over the server to destroy a barrier
    
    This is completely pointless as far as I can tell.
    
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
index ba9fd06..9e43196 100644
--- a/Xi/xibarriers.c
+++ b/Xi/xibarriers.c
@@ -437,22 +437,10 @@ CreatePointerBarrierClient(ClientPtr client,
 static int
 BarrierFreeBarrier(void *data, XID id)
 {
-    struct PointerBarrierClient *b = NULL, *barrier;
-    ScreenPtr screen;
-    BarrierScreenPtr cs;
+    struct PointerBarrierClient *barrier;
 
     barrier = container_of(data, struct PointerBarrierClient, barrier);
-
-    screen = barrier->screen;
-    cs = GetBarrierScreen(screen);
-
-    /* find and unlink from the screen private */
-    xorg_list_for_each_entry(b, &cs->barriers, entry) {
-        if (b == barrier) {
-            xorg_list_del(&b->entry);
-            break;
-        }
-    }
+    xorg_list_del(&barrier->entry);
 
     free(barrier);
     return Success;
commit 482e0cb35225dc3b0664f9429db19c61b0c98ef6
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Thu Nov 1 14:14:13 2012 -0400

    cursor: Move pointer barrier code over to XI
    
    In order to send events to specific windows associated with the barrier,
    we need to move the code that handles barriers to somewhere where it's
    easier to construct and send events. Rather than duplicating XSync with
    its XSyncSelectAlarm, re-use the existing XI infrastructure.
    
    For now, just move a bunch of code over, rename some things, and initialize
    the new structures, but still consider it a separate codebase. Pointer barrier
    requests are still handled by XFixes, so this is a weird intermediate state.
    It's unknown whether we'll add explicit requests to pointer barriers inside
    XI.
    
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/Makefile.am b/Xi/Makefile.am
index 69c7886..af85bd0 100644
--- a/Xi/Makefile.am
+++ b/Xi/Makefile.am
@@ -78,6 +78,8 @@ libXi_la_SOURCES =	\
 	ungrdevk.h \
 	xiallowev.c \
 	xiallowev.h \
+	xibarriers.c \
+	xibarriers.h \
 	xichangecursor.c \
 	xichangecursor.h \
 	xichangehierarchy.c \
diff --git a/Xi/extinit.c b/Xi/extinit.c
index 7e30755..1074b23 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -122,6 +122,7 @@ SOFTWARE.
 #include "xiqueryversion.h"
 #include "xisetclientpointer.h"
 #include "xiwarppointer.h"
+#include "xibarriers.h"
 
 /* Masks for XI events have to be aligned with core event (partially anyway).
  * If DeviceButtonMotionMask is != ButtonMotionMask, event delivery
@@ -1263,6 +1264,9 @@ XInputExtensionInit(void)
     if (!AddCallback(&ClientStateCallback, XIClientCallback, 0))
         FatalError("Failed to add callback to XI.\n");
 
+    if (!XIBarrierInit())
+        FatalError("Could not initialize barriers.\n");
+
     extEntry = AddExtension(INAME, IEVENTS, IERRORS, ProcIDispatch,
                             SProcIDispatch, IResetProc, StandardMinorOpcode);
     if (extEntry) {
diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c
new file mode 100644
index 0000000..ba9fd06
--- /dev/null
+++ b/Xi/xibarriers.c
@@ -0,0 +1,548 @@
+/*
+ * Copyright 2012 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.
+ *
+ * Copyright © 2002 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Keith Packard not be used in
+ * advertising or publicity pertaining to distribution of the software without
+ * specific, written prior permission.  Keith Packard makes no
+ * representations about the suitability of this software for any purpose.  It
+ * is provided "as is" without express or implied warranty.
+ *
+ * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "xibarriers.h"
+#include "scrnintstr.h"
+#include "cursorstr.h"
+#include "dixevents.h"
+#include "servermd.h"
+#include "mipointer.h"
+#include "inputstr.h"
+#include "windowstr.h"
+#include "xace.h"
+#include "list.h"
+#include "exglobals.h"
+
+RESTYPE PointerBarrierType;
+
+static DevPrivateKeyRec BarrierScreenPrivateKeyRec;
+
+#define BarrierScreenPrivateKey (&BarrierScreenPrivateKeyRec)
+
+typedef struct PointerBarrierClient *PointerBarrierClientPtr;
+
+struct PointerBarrierClient {
+    ScreenPtr screen;
+    struct PointerBarrier barrier;
+    struct xorg_list entry;
+    int num_devices;
+    int *device_ids; /* num_devices */
+};
+
+typedef struct _BarrierScreen {
+    CloseScreenProcPtr CloseScreen;
+    ConstrainCursorHarderProcPtr ConstrainCursorHarder;
+    struct xorg_list barriers;
+} BarrierScreenRec, *BarrierScreenPtr;
+
+#define GetBarrierScreen(s) ((BarrierScreenPtr)dixLookupPrivate(&(s)->devPrivates, BarrierScreenPrivateKey))
+#define GetBarrierScreenIfSet(s) GetBarrierScreen(s)
+#define SetBarrierScreen(s,p) dixSetPrivate(&(s)->devPrivates, BarrierScreenPrivateKey, p)
+#define Wrap(as,s,elt,func)	(((as)->elt = (s)->elt), (s)->elt = func)
+#define Unwrap(as,s,elt,backup)	(((backup) = (s)->elt), (s)->elt = (as)->elt)
+
+static BOOL
+barrier_is_horizontal(const struct PointerBarrier *barrier)
+{
+    return barrier->y1 == barrier->y2;
+}
+
+static BOOL
+barrier_is_vertical(const struct PointerBarrier *barrier)
+{
+    return barrier->x1 == barrier->x2;
+}
+
+/**
+ * @return The set of barrier movement directions the movement vector
+ * x1/y1 → x2/y2 represents.
+ */
+int
+barrier_get_direction(int x1, int y1, int x2, int y2)
+{
+    int direction = 0;
+
+    /* which way are we trying to go */
+    if (x2 > x1)
+        direction |= BarrierPositiveX;
+    if (x2 < x1)
+        direction |= BarrierNegativeX;
+    if (y2 > y1)
+        direction |= BarrierPositiveY;
+    if (y2 < y1)
+        direction |= BarrierNegativeY;
+
+    return direction;
+}
+
+/**
+ * Test if the barrier may block movement in the direction defined by
+ * x1/y1 → x2/y2. This function only tests whether the directions could be
+ * blocked, it does not test if the barrier actually blocks the movement.
+ *
+ * @return TRUE if the barrier blocks the direction of movement or FALSE
+ * otherwise.
+ */
+BOOL
+barrier_is_blocking_direction(const struct PointerBarrier * barrier,
+                              int direction)
+{
+    /* Barriers define which way is ok, not which way is blocking */
+    return (barrier->directions & direction) != direction;
+}
+
+/**
+ * Test if the movement vector x1/y1 → x2/y2 is intersecting with the
+ * barrier. A movement vector with the startpoint or endpoint adjacent to
+ * the barrier itself counts as intersecting.
+ *
+ * @param x1 X start coordinate of movement vector
+ * @param y1 Y start coordinate of movement vector
+ * @param x2 X end coordinate of movement vector
+ * @param y2 Y end coordinate of movement vector
+ * @param[out] distance The distance between the start point and the
+ * intersection with the barrier (if applicable).
+ * @return TRUE if the barrier intersects with the given vector
+ */
+BOOL
+barrier_is_blocking(const struct PointerBarrier * barrier,
+                    int x1, int y1, int x2, int y2, double *distance)
+{
+    BOOL rc = FALSE;
+    float ua, ub, ud;
+    int dir = barrier_get_direction(x1, y1, x2, y2);
+
+    /* Algorithm below doesn't handle edge cases well, hence the extra
+     * checks. */
+    if (barrier_is_vertical(barrier)) {
+        /* handle immediate barrier adjacency, moving away */
+        if (dir & BarrierPositiveX && x1 == barrier->x1)
+            return FALSE;
+        if (dir & BarrierNegativeX && x1 == (barrier->x1 - 1))
+            return FALSE;
+        /* startpoint adjacent to barrier, moving towards -> block */
+        if (dir & BarrierPositiveX && x1 == (barrier->x1 - 1) && y1 >= barrier->y1 && y1 <= barrier->y2) {
+            *distance = 0;
+            return TRUE;
+        }
+        if (dir & BarrierNegativeX && x1 == barrier->x1 && y1 >= barrier->y1 && y1 <= barrier->y2) {
+            *distance = 0;
+            return TRUE;
+        }
+    }
+    else {
+        /* handle immediate barrier adjacency, moving away */
+        if (dir & BarrierPositiveY && y1 == barrier->y1)
+            return FALSE;
+        if (dir & BarrierNegativeY && y1 == (barrier->y1 - 1))
+            return FALSE;
+        /* startpoint adjacent to barrier, moving towards -> block */
+        if (dir & BarrierPositiveY && y1 == (barrier->y1 - 1) && x1 >= barrier->x1 && x1 <= barrier->x2) {
+            *distance = 0;
+            return TRUE;
+        }
+        if (dir & BarrierNegativeY && y1 == barrier->y1 && x1 >= barrier->x1 && x1 <= barrier->x2) {
+            *distance = 0;
+            return TRUE;
+        }
+    }
+
+    /* not an edge case, compute distance */
+    ua = 0;
+    ud = (barrier->y2 - barrier->y1) * (x2 - x1) - (barrier->x2 -
+                                                    barrier->x1) * (y2 - y1);
+    if (ud != 0) {
+        ua = ((barrier->x2 - barrier->x1) * (y1 - barrier->y1) -
+              (barrier->y2 - barrier->y1) * (x1 - barrier->x1)) / ud;
+        ub = ((x2 - x1) * (y1 - barrier->y1) -
+              (y2 - y1) * (x1 - barrier->x1)) / ud;
+        if (ua < 0 || ua > 1 || ub < 0 || ub > 1)
+            ua = 0;
+    }
+
+    if (ua > 0 && ua <= 1) {
+        double ix = barrier->x1 + ua * (barrier->x2 - barrier->x1);
+        double iy = barrier->y1 + ua * (barrier->y2 - barrier->y1);
+
+        *distance = sqrt(pow(x1 - ix, 2) + pow(y1 - iy, 2));
+        rc = TRUE;
+    }
+
+    return rc;
+}
+
+static BOOL
+barrier_blocks_device(struct PointerBarrierClient *client,
+                      DeviceIntPtr dev)
+{
+    int i;
+    int master_id;
+
+    /* Clients with no devices are treated as
+     * if they specified XIAllDevices. */
+    if (client->num_devices == 0)
+        return TRUE;
+
+    master_id = GetMaster(dev, POINTER_OR_FLOAT)->id;
+
+    for (i = 0; i < client->num_devices; i++) {
+        int device_id = client->device_ids[i];
+        if (device_id == XIAllDevices ||
+            device_id == XIAllMasterDevices ||
+            device_id == master_id)
+            return TRUE;
+    }
+
+    return FALSE;
+}
+
+/**
+ * Find the nearest barrier that is blocking movement from x1/y1 to x2/y2.
+ *
+ * @param dir Only barriers blocking movement in direction dir are checked
+ * @param x1 X start coordinate of movement vector
+ * @param y1 Y start coordinate of movement vector
+ * @param x2 X end coordinate of movement vector
+ * @param y2 Y end coordinate of movement vector
+ * @return The barrier nearest to the movement origin that blocks this movement.
+ */
+static struct PointerBarrier *
+barrier_find_nearest(BarrierScreenPtr cs, DeviceIntPtr dev,
+                     int dir,
+                     int x1, int y1, int x2, int y2)
+{
+    struct PointerBarrierClient *c;
+    struct PointerBarrier *nearest = NULL;
+    double min_distance = INT_MAX;      /* can't get higher than that in X anyway */
+
+    xorg_list_for_each_entry(c, &cs->barriers, entry) {
+        struct PointerBarrier *b = &c->barrier;
+        double distance;
+
+        if (!barrier_is_blocking_direction(b, dir))
+            continue;
+
+        if (!barrier_blocks_device(c, dev))
+            continue;
+
+        if (barrier_is_blocking(b, x1, y1, x2, y2, &distance)) {
+            if (min_distance > distance) {
+                min_distance = distance;
+                nearest = b;
+            }
+        }
+    }
+
+    return nearest;
+}
+
+/**
+ * Clamp to the given barrier given the movement direction specified in dir.
+ *
+ * @param barrier The barrier to clamp to
+ * @param dir The movement direction
+ * @param[out] x The clamped x coordinate.
+ * @param[out] y The clamped x coordinate.
+ */
+void
+barrier_clamp_to_barrier(struct PointerBarrier *barrier, int dir, int *x,
+                         int *y)
+{
+    if (barrier_is_vertical(barrier)) {
+        if ((dir & BarrierNegativeX) & ~barrier->directions)
+            *x = barrier->x1;
+        if ((dir & BarrierPositiveX) & ~barrier->directions)
+            *x = barrier->x1 - 1;
+    }
+    if (barrier_is_horizontal(barrier)) {
+        if ((dir & BarrierNegativeY) & ~barrier->directions)
+            *y = barrier->y1;
+        if ((dir & BarrierPositiveY) & ~barrier->directions)
+            *y = barrier->y1 - 1;
+    }
+}
+
+static void
+BarrierConstrainCursorHarder(DeviceIntPtr dev, ScreenPtr screen, int mode,
+                             int *x, int *y)
+{
+    BarrierScreenPtr cs = GetBarrierScreen(screen);
+
+    if (!xorg_list_is_empty(&cs->barriers) && !IsFloating(dev) &&
+        mode == Relative) {
+        int ox, oy;
+        int dir;
+        int i;
+        struct PointerBarrier *nearest = NULL;
+
+        /* where are we coming from */
+        miPointerGetPosition(dev, &ox, &oy);
+
+        /* How this works:
+         * Given the origin and the movement vector, get the nearest barrier
+         * to the origin that is blocking the movement.
+         * Clamp to that barrier.
+         * Then, check from the clamped intersection to the original
+         * destination, again finding the nearest barrier and clamping.
+         */
+        dir = barrier_get_direction(ox, oy, *x, *y);
+
+#define MAX_BARRIERS 2
+        for (i = 0; i < MAX_BARRIERS; i++) {
+            nearest = barrier_find_nearest(cs, dev, dir, ox, oy, *x, *y);
+            if (!nearest)
+                break;
+
+            barrier_clamp_to_barrier(nearest, dir, x, y);
+
+            if (barrier_is_vertical(nearest)) {
+                dir &= ~(BarrierNegativeX | BarrierPositiveX);
+                ox = *x;
+            }
+            else if (barrier_is_horizontal(nearest)) {
+                dir &= ~(BarrierNegativeY | BarrierPositiveY);
+                oy = *y;
+            }
+        }
+    }
+
+    if (cs->ConstrainCursorHarder) {
+        screen->ConstrainCursorHarder = cs->ConstrainCursorHarder;
+        screen->ConstrainCursorHarder(dev, screen, mode, x, y);
+        screen->ConstrainCursorHarder = BarrierConstrainCursorHarder;
+    }
+}
+
+static int
+CreatePointerBarrierClient(ClientPtr client,
+                           xXFixesCreatePointerBarrierReq * stuff,
+                           PointerBarrierClientPtr *client_out)
+{
+    WindowPtr pWin;
+    ScreenPtr screen;
+    BarrierScreenPtr cs;
+    int err;
+    int size;
+    int i;
+    struct PointerBarrierClient *ret;
+    CARD16 *in_devices;
+
+    size = sizeof(*ret) + sizeof(DeviceIntPtr) * stuff->num_devices;
+    ret = malloc(size);
+
+    if (!ret) {
+        return BadAlloc;
+    }
+
+    err = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess);
+    if (err != Success) {
+        client->errorValue = stuff->window;
+        goto error;
+    }
+
+    screen = pWin->drawable.pScreen;
+    cs = GetBarrierScreen(screen);
+
+    ret->screen = screen;
+    ret->num_devices = stuff->num_devices;
+    if (ret->num_devices > 0)
+        ret->device_ids = (int*)&ret[1];
+    else
+        ret->device_ids = NULL;
+
+    in_devices = (CARD16 *) &stuff[1];
+    for (i = 0; i < stuff->num_devices; i++) {
+        int device_id = in_devices[i];
+        DeviceIntPtr device;
+
+        if ((err = dixLookupDevice (&device, device_id,
+                                    client, DixReadAccess))) {
+            client->errorValue = device_id;
+            goto error;
+        }
+
+        if (!IsMaster (device)) {
+            client->errorValue = device_id;
+            err = BadDevice;
+            goto error;
+        }
+
+        ret->device_ids[i] = device_id;
+    }
+
+    ret->barrier.x1 = min(stuff->x1, stuff->x2);
+    ret->barrier.x2 = max(stuff->x1, stuff->x2);
+    ret->barrier.y1 = min(stuff->y1, stuff->y2);
+    ret->barrier.y2 = max(stuff->y1, stuff->y2);
+    ret->barrier.directions = stuff->directions & 0x0f;
+    if (barrier_is_horizontal(&ret->barrier))
+        ret->barrier.directions &= ~(BarrierPositiveX | BarrierNegativeX);
+    if (barrier_is_vertical(&ret->barrier))
+        ret->barrier.directions &= ~(BarrierPositiveY | BarrierNegativeY);
+    xorg_list_add(&ret->entry, &cs->barriers);
+
+    *client_out = ret;
+    return Success;
+
+ error:
+    *client_out = NULL;
+    free(ret);
+    return err;
+}
+
+static int
+BarrierFreeBarrier(void *data, XID id)
+{
+    struct PointerBarrierClient *b = NULL, *barrier;
+    ScreenPtr screen;
+    BarrierScreenPtr cs;
+
+    barrier = container_of(data, struct PointerBarrierClient, barrier);
+
+    screen = barrier->screen;
+    cs = GetBarrierScreen(screen);
+
+    /* find and unlink from the screen private */
+    xorg_list_for_each_entry(b, &cs->barriers, entry) {
+        if (b == barrier) {
+            xorg_list_del(&b->entry);
+            break;
+        }
+    }
+
+    free(barrier);
+    return Success;
+}
+
+int
+XICreatePointerBarrier(ClientPtr client,
+                       xXFixesCreatePointerBarrierReq * stuff)
+{
+    int err;
+    struct PointerBarrierClient *barrier;
+    struct PointerBarrier b;
+
+    b.x1 = stuff->x1;
+    b.x2 = stuff->x2;
+    b.y1 = stuff->y1;
+    b.y2 = stuff->y2;
+
+    if (!barrier_is_horizontal(&b) && !barrier_is_vertical(&b))
+        return BadValue;
+
+    /* no 0-sized barriers */
+    if (barrier_is_horizontal(&b) && barrier_is_vertical(&b))
+        return BadValue;
+
+    if ((err = CreatePointerBarrierClient(client, stuff, &barrier)))
+        return err;
+
+    if (!AddResource(stuff->barrier, PointerBarrierType, &barrier->barrier))
+        return BadAlloc;
+
+    return Success;
+}
+
+int
+XIDestroyPointerBarrier(ClientPtr client,
+                        xXFixesDestroyPointerBarrierReq * stuff)
+{
+    int err;
+    void *barrier;
+
+    err = dixLookupResourceByType((void **) &barrier, stuff->barrier,
+                                  PointerBarrierType, client, DixDestroyAccess);
+    if (err != Success) {
+        client->errorValue = stuff->barrier;
+        return err;
+    }
+
+    FreeResource(stuff->barrier, RT_NONE);
+    return Success;
+}
+
+static Bool
+BarrierCloseScreen(ScreenPtr pScreen)
+{
+    BarrierScreenPtr cs = GetBarrierScreen(pScreen);
+    Bool ret;
+    _X_UNUSED CloseScreenProcPtr close_proc;
+    _X_UNUSED ConstrainCursorHarderProcPtr constrain_proc;
+
+    Unwrap(cs, pScreen, CloseScreen, close_proc);
+    Unwrap(cs, pScreen, ConstrainCursorHarder, constrain_proc);
+    ret = (*pScreen->CloseScreen) (pScreen);
+    free(cs);
+    return ret;
+}
+
+Bool
+XIBarrierInit(void)
+{
+    int i;
+
+    if (!dixRegisterPrivateKey(&BarrierScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+        return FALSE;
+
+    for (i = 0; i < screenInfo.numScreens; i++) {
+        ScreenPtr pScreen = screenInfo.screens[i];
+        BarrierScreenPtr cs;
+
+        cs = (BarrierScreenPtr) calloc(1, sizeof(BarrierScreenRec));
+        if (!cs)
+            return FALSE;
+        xorg_list_init(&cs->barriers);
+        Wrap(cs, pScreen, CloseScreen, BarrierCloseScreen);
+        Wrap(cs, pScreen, ConstrainCursorHarder, BarrierConstrainCursorHarder);
+        SetBarrierScreen(pScreen, cs);
+    }
+
+    PointerBarrierType = CreateNewResourceType(BarrierFreeBarrier,
+                                               "XIPointerBarrier");
+
+    return PointerBarrierType;
+}
diff --git a/Xi/xibarriers.h b/Xi/xibarriers.h
new file mode 100644
index 0000000..8f2993f
--- /dev/null
+++ b/Xi/xibarriers.h
@@ -0,0 +1,47 @@
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifndef _XIBARRIERS_H_
+#define _XIBARRIERS_H_
+
+#include "resource.h"
+
+extern _X_EXPORT RESTYPE PointerBarrierType;
+
+struct PointerBarrier {
+    CARD16 x1, x2, y1, y2;
+    CARD32 directions;
+};
+
+int
+barrier_get_direction(int, int, int, int);
+BOOL
+barrier_is_blocking(const struct PointerBarrier *, int, int, int, int,
+                        double *);
+BOOL
+barrier_is_blocking_direction(const struct PointerBarrier *, int);
+void
+barrier_clamp_to_barrier(struct PointerBarrier *barrier, int dir, int *x,
+                             int *y);
+
+#include <xfixesint.h>
+
+int
+XICreatePointerBarrier(ClientPtr client,
+                       xXFixesCreatePointerBarrierReq * stuff);
+
+int
+XIDestroyPointerBarrier(ClientPtr client,
+                        xXFixesDestroyPointerBarrierReq * stuff);
+
+Bool
+XIBarrierInit(void);
+
+#endif /* _XIBARRIERS_H_ */
+
+
+
+
+
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index ffee4d6..568e717 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -56,12 +56,11 @@
 #include "windowstr.h"
 #include "xace.h"
 #include "list.h"
-#include "exglobals.h"
+#include "xibarriers.h"
 
 static RESTYPE CursorClientType;
 static RESTYPE CursorHideCountType;
 static RESTYPE CursorWindowType;
-RESTYPE PointerBarrierType;
 static CursorPtr CursorCurrent[MAXDEVICES];
 
 static DevPrivateKeyRec CursorScreenPrivateKeyRec;
@@ -113,16 +112,6 @@ typedef struct _CursorHideCountRec {
     XID resource;
 } CursorHideCountRec;
 
-typedef struct PointerBarrierClient *PointerBarrierClientPtr;
-
-struct PointerBarrierClient {
-    ScreenPtr screen;
-    struct PointerBarrier barrier;
-    struct xorg_list entry;
-    int num_devices;
-    int *device_ids; /* num_devices */
-};
-
 /*
  * Wrap DisplayCursor to catch cursor change events
  */
@@ -130,9 +119,7 @@ struct PointerBarrierClient {
 typedef struct _CursorScreen {
     DisplayCursorProcPtr DisplayCursor;
     CloseScreenProcPtr CloseScreen;
-    ConstrainCursorHarderProcPtr ConstrainCursorHarder;
     CursorHideCountPtr pCursorHideCounts;
-    struct xorg_list barriers;
 } CursorScreenRec, *CursorScreenPtr;
 
 #define GetCursorScreen(s) ((CursorScreenPtr)dixLookupPrivate(&(s)->devPrivates, CursorScreenPrivateKey))
@@ -199,11 +186,9 @@ CursorCloseScreen(ScreenPtr pScreen)
     Bool ret;
     _X_UNUSED CloseScreenProcPtr close_proc;
     _X_UNUSED DisplayCursorProcPtr display_proc;
-    _X_UNUSED ConstrainCursorHarderProcPtr constrain_proc;
 
     Unwrap(cs, pScreen, CloseScreen, close_proc);
     Unwrap(cs, pScreen, DisplayCursor, display_proc);
-    Unwrap(cs, pScreen, ConstrainCursorHarder, constrain_proc);
     deleteCursorHideCountsForScreen(pScreen);
     ret = (*pScreen->CloseScreen) (pScreen);
     free(cs);
@@ -1013,384 +998,15 @@ CursorFreeWindow(pointer data, XID id)
     return 1;
 }
 
-static BOOL
-barrier_is_horizontal(const struct PointerBarrier *barrier)
-{
-    return barrier->y1 == barrier->y2;
-}
-
-static BOOL
-barrier_is_vertical(const struct PointerBarrier *barrier)
-{
-    return barrier->x1 == barrier->x2;
-}
-
-/**
- * @return The set of barrier movement directions the movement vector
- * x1/y1 → x2/y2 represents.
- */
-int
-barrier_get_direction(int x1, int y1, int x2, int y2)
-{
-    int direction = 0;
-
-    /* which way are we trying to go */
-    if (x2 > x1)
-        direction |= BarrierPositiveX;
-    if (x2 < x1)
-        direction |= BarrierNegativeX;
-    if (y2 > y1)
-        direction |= BarrierPositiveY;
-    if (y2 < y1)
-        direction |= BarrierNegativeY;
-
-    return direction;
-}
-
-/**
- * Test if the barrier may block movement in the direction defined by
- * x1/y1 → x2/y2. This function only tests whether the directions could be
- * blocked, it does not test if the barrier actually blocks the movement.
- *
- * @return TRUE if the barrier blocks the direction of movement or FALSE
- * otherwise.
- */
-BOOL
-barrier_is_blocking_direction(const struct PointerBarrier * barrier,
-                              int direction)
-{
-    /* Barriers define which way is ok, not which way is blocking */
-    return (barrier->directions & direction) != direction;
-}
-
-/**
- * Test if the movement vector x1/y1 → x2/y2 is intersecting with the
- * barrier. A movement vector with the startpoint or endpoint adjacent to
- * the barrier itself counts as intersecting.
- *
- * @param x1 X start coordinate of movement vector
- * @param y1 Y start coordinate of movement vector
- * @param x2 X end coordinate of movement vector
- * @param y2 Y end coordinate of movement vector
- * @param[out] distance The distance between the start point and the
- * intersection with the barrier (if applicable).
- * @return TRUE if the barrier intersects with the given vector
- */
-BOOL
-barrier_is_blocking(const struct PointerBarrier * barrier,
-                    int x1, int y1, int x2, int y2, double *distance)
-{
-    BOOL rc = FALSE;
-    float ua, ub, ud;
-    int dir = barrier_get_direction(x1, y1, x2, y2);
-
-    /* Algorithm below doesn't handle edge cases well, hence the extra
-     * checks. */
-    if (barrier_is_vertical(barrier)) {
-        /* handle immediate barrier adjacency, moving away */
-        if (dir & BarrierPositiveX && x1 == barrier->x1)
-            return FALSE;
-        if (dir & BarrierNegativeX && x1 == (barrier->x1 - 1))
-            return FALSE;
-        /* startpoint adjacent to barrier, moving towards -> block */
-        if (dir & BarrierPositiveX && x1 == (barrier->x1 - 1) && y1 >= barrier->y1 && y1 <= barrier->y2) {
-            *distance = 0;
-            return TRUE;
-        }
-        if (dir & BarrierNegativeX && x1 == barrier->x1 && y1 >= barrier->y1 && y1 <= barrier->y2) {
-            *distance = 0;
-            return TRUE;
-        }
-    }
-    else {
-        /* handle immediate barrier adjacency, moving away */
-        if (dir & BarrierPositiveY && y1 == barrier->y1)
-            return FALSE;
-        if (dir & BarrierNegativeY && y1 == (barrier->y1 - 1))
-            return FALSE;
-        /* startpoint adjacent to barrier, moving towards -> block */
-        if (dir & BarrierPositiveY && y1 == (barrier->y1 - 1) && x1 >= barrier->x1 && x1 <= barrier->x2) {
-            *distance = 0;
-            return TRUE;
-        }
-        if (dir & BarrierNegativeY && y1 == barrier->y1 && x1 >= barrier->x1 && x1 <= barrier->x2) {
-            *distance = 0;
-            return TRUE;
-        }
-    }
-
-    /* not an edge case, compute distance */
-    ua = 0;
-    ud = (barrier->y2 - barrier->y1) * (x2 - x1) - (barrier->x2 -
-                                                    barrier->x1) * (y2 - y1);
-    if (ud != 0) {
-        ua = ((barrier->x2 - barrier->x1) * (y1 - barrier->y1) -
-              (barrier->y2 - barrier->y1) * (x1 - barrier->x1)) / ud;
-        ub = ((x2 - x1) * (y1 - barrier->y1) -
-              (y2 - y1) * (x1 - barrier->x1)) / ud;
-        if (ua < 0 || ua > 1 || ub < 0 || ub > 1)
-            ua = 0;
-    }
-
-    if (ua > 0 && ua <= 1) {
-        double ix = barrier->x1 + ua * (barrier->x2 - barrier->x1);
-        double iy = barrier->y1 + ua * (barrier->y2 - barrier->y1);
-
-        *distance = sqrt(pow(x1 - ix, 2) + pow(y1 - iy, 2));
-        rc = TRUE;
-    }
-
-    return rc;
-}
-
-static BOOL
-barrier_blocks_device(struct PointerBarrierClient *client,
-                      DeviceIntPtr dev)
-{
-    int i;
-    int master_id;
-
-    /* Clients with no devices are treated as
-     * if they specified XIAllDevices. */
-    if (client->num_devices == 0)
-        return TRUE;
-
-    master_id = GetMaster(dev, POINTER_OR_FLOAT)->id;
-
-    for (i = 0; i < client->num_devices; i++) {
-        int device_id = client->device_ids[i];
-        if (device_id == XIAllDevices ||
-            device_id == XIAllMasterDevices ||
-            device_id == master_id)
-            return TRUE;
-    }
-
-    return FALSE;
-}
-
-/**
- * Find the nearest barrier that is blocking movement from x1/y1 to x2/y2.
- *
- * @param dir Only barriers blocking movement in direction dir are checked
- * @param x1 X start coordinate of movement vector
- * @param y1 Y start coordinate of movement vector
- * @param x2 X end coordinate of movement vector
- * @param y2 Y end coordinate of movement vector
- * @return The barrier nearest to the movement origin that blocks this movement.
- */
-static struct PointerBarrier *
-barrier_find_nearest(CursorScreenPtr cs, DeviceIntPtr dev,
-                     int dir,
-                     int x1, int y1, int x2, int y2)
-{
-    struct PointerBarrierClient *c;
-    struct PointerBarrier *nearest = NULL;
-    double min_distance = INT_MAX;      /* can't get higher than that in X anyway */
-
-    xorg_list_for_each_entry(c, &cs->barriers, entry) {
-        struct PointerBarrier *b = &c->barrier;
-        double distance;
-
-        if (!barrier_is_blocking_direction(b, dir))
-            continue;
-
-        if (!barrier_blocks_device(c, dev))
-            continue;
-
-        if (barrier_is_blocking(b, x1, y1, x2, y2, &distance)) {
-            if (min_distance > distance) {
-                min_distance = distance;
-                nearest = b;
-            }
-        }
-    }
-
-    return nearest;
-}
-
-/**
- * Clamp to the given barrier given the movement direction specified in dir.
- *
- * @param barrier The barrier to clamp to
- * @param dir The movement direction
- * @param[out] x The clamped x coordinate.
- * @param[out] y The clamped x coordinate.
- */
-void
-barrier_clamp_to_barrier(struct PointerBarrier *barrier, int dir, int *x,
-                         int *y)
-{
-    if (barrier_is_vertical(barrier)) {
-        if ((dir & BarrierNegativeX) & ~barrier->directions)
-            *x = barrier->x1;
-        if ((dir & BarrierPositiveX) & ~barrier->directions)
-            *x = barrier->x1 - 1;
-    }
-    if (barrier_is_horizontal(barrier)) {
-        if ((dir & BarrierNegativeY) & ~barrier->directions)
-            *y = barrier->y1;
-        if ((dir & BarrierPositiveY) & ~barrier->directions)
-            *y = barrier->y1 - 1;
-    }
-}
-
-static void
-CursorConstrainCursorHarder(DeviceIntPtr dev, ScreenPtr screen, int mode,
-                            int *x, int *y)
-{
-    CursorScreenPtr cs = GetCursorScreen(screen);
-
-    if (!xorg_list_is_empty(&cs->barriers) && !IsFloating(dev) &&
-        mode == Relative) {
-        int ox, oy;
-        int dir;
-        int i;
-        struct PointerBarrier *nearest = NULL;
-
-        /* where are we coming from */
-        miPointerGetPosition(dev, &ox, &oy);
-
-        /* How this works:
-         * Given the origin and the movement vector, get the nearest barrier
-         * to the origin that is blocking the movement.
-         * Clamp to that barrier.
-         * Then, check from the clamped intersection to the original
-         * destination, again finding the nearest barrier and clamping.
-         */
-        dir = barrier_get_direction(ox, oy, *x, *y);
-
-#define MAX_BARRIERS 2
-        for (i = 0; i < MAX_BARRIERS; i++) {
-            nearest = barrier_find_nearest(cs, dev, dir, ox, oy, *x, *y);
-            if (!nearest)
-                break;
-
-            barrier_clamp_to_barrier(nearest, dir, x, y);
-
-            if (barrier_is_vertical(nearest)) {
-                dir &= ~(BarrierNegativeX | BarrierPositiveX);
-                ox = *x;
-            }
-            else if (barrier_is_horizontal(nearest)) {
-                dir &= ~(BarrierNegativeY | BarrierPositiveY);
-                oy = *y;
-            }
-        }
-    }
-
-    if (cs->ConstrainCursorHarder) {
-        screen->ConstrainCursorHarder = cs->ConstrainCursorHarder;
-        screen->ConstrainCursorHarder(dev, screen, mode, x, y);
-        screen->ConstrainCursorHarder = CursorConstrainCursorHarder;
-    }
-}
-
-static int
-CreatePointerBarrierClient(ScreenPtr screen, ClientPtr client,
-                           xXFixesCreatePointerBarrierReq * stuff,
-                           PointerBarrierClientPtr *client_out)
-{
-    CursorScreenPtr cs = GetCursorScreen(screen);
-    int err;
-    int size;
-    int i;
-    CARD16 *in_devices;
-    struct PointerBarrierClient *ret;
-
-    size = sizeof(*ret) + sizeof(int) * stuff->num_devices;
-    ret = malloc(size);
-
-    *client_out = NULL;
-
-    if (!ret) {
-        return BadAlloc;
-    }
-
-    ret->screen = screen;
-    ret->num_devices = stuff->num_devices;
-    if (ret->num_devices > 0)
-        ret->device_ids = (int*)&ret[1];
-    else
-        ret->device_ids = NULL;
-
-    in_devices = (CARD16 *) &stuff[1];
-    for (i = 0; i < stuff->num_devices; i++) {
-        int device_id = in_devices[i];
-        DeviceIntPtr device;
-
-        if ((err = dixLookupDevice (&device, device_id,
-                                    client, DixReadAccess))) {
-            client->errorValue = device_id;
-            goto error;
-        }
-
-        if (!IsMaster (device)) {
-            client->errorValue = device_id;
-            err = BadDevice;
-            goto error;
-        }
-
-        ret->device_ids[i] = device_id;
-    }
-
-    ret->barrier.x1 = min(stuff->x1, stuff->x2);
-    ret->barrier.x2 = max(stuff->x1, stuff->x2);
-    ret->barrier.y1 = min(stuff->y1, stuff->y2);
-    ret->barrier.y2 = max(stuff->y1, stuff->y2);
-    ret->barrier.directions = stuff->directions & 0x0f;
-    if (barrier_is_horizontal(&ret->barrier))
-        ret->barrier.directions &= ~(BarrierPositiveX | BarrierNegativeX);
-    if (barrier_is_vertical(&ret->barrier))
-        ret->barrier.directions &= ~(BarrierPositiveY | BarrierNegativeY);
-    xorg_list_add(&ret->entry, &cs->barriers);
-
-    *client_out = ret;
-    return Success;
-
- error:
-    free(ret);
-    return err;
-}
-
 int
 ProcXFixesCreatePointerBarrier(ClientPtr client)
 {
-    int err;
-    WindowPtr pWin;
-    struct PointerBarrierClient *barrier;
-    struct PointerBarrier b;
-
     REQUEST(xXFixesCreatePointerBarrierReq);
 
     REQUEST_FIXED_SIZE(xXFixesCreatePointerBarrierReq, pad_to_int32(stuff->num_devices));
     LEGAL_NEW_RESOURCE(stuff->barrier, client);
 
-    err = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess);
-    if (err != Success) {
-        client->errorValue = stuff->window;
-        return err;
-    }
-
-    b.x1 = stuff->x1;
-    b.x2 = stuff->x2;
-    b.y1 = stuff->y1;
-    b.y2 = stuff->y2;
-
-    if (!barrier_is_horizontal(&b) && !barrier_is_vertical(&b))
-        return BadValue;
-
-    /* no 0-sized barriers */
-    if (barrier_is_horizontal(&b) && barrier_is_vertical(&b))
-        return BadValue;
-
-    if ((err = CreatePointerBarrierClient(pWin->drawable.pScreen,
-                                          client, stuff, &barrier)))
-        return err;
-
-    if (!AddResource(stuff->barrier, PointerBarrierType, &barrier->barrier))
-        return BadAlloc;
-
-    return Success;
+    return XICreatePointerBarrier(client, stuff);
 }
 
 int
@@ -1418,49 +1034,14 @@ SProcXFixesCreatePointerBarrier(ClientPtr client)
     return ProcXFixesVector[stuff->xfixesReqType] (client);
 }
 
-static int
-CursorFreeBarrier(void *data, XID id)
-{
-    struct PointerBarrierClient *b = NULL, *barrier;
-    ScreenPtr screen;
-    CursorScreenPtr cs;
-
-    barrier = container_of(data, struct PointerBarrierClient, barrier);
-
-    screen = barrier->screen;
-    cs = GetCursorScreen(screen);
-
-    /* find and unlink from the screen private */
-    xorg_list_for_each_entry(b, &cs->barriers, entry) {
-        if (b == barrier) {
-            xorg_list_del(&b->entry);
-            break;
-        }
-    }
-
-    free(barrier);
-    return Success;
-}
-
 int
 ProcXFixesDestroyPointerBarrier(ClientPtr client)
 {
-    int err;
-    void *barrier;
-
     REQUEST(xXFixesDestroyPointerBarrierReq);
 
     REQUEST_SIZE_MATCH(xXFixesDestroyPointerBarrierReq);
 
-    err = dixLookupResourceByType((void **) &barrier, stuff->barrier,
-                                  PointerBarrierType, client, DixDestroyAccess);
-    if (err != Success) {
-        client->errorValue = stuff->barrier;
-        return err;
-    }
-
-    FreeResource(stuff->barrier, RT_NONE);
-    return Success;
+    return XIDestroyPointerBarrier(client, stuff);
 }
 
 int
@@ -1492,10 +1073,8 @@ XFixesCursorInit(void)
         cs = (CursorScreenPtr) calloc(1, sizeof(CursorScreenRec));
         if (!cs)
             return FALSE;
-        xorg_list_init(&cs->barriers);
         Wrap(cs, pScreen, CloseScreen, CursorCloseScreen);
         Wrap(cs, pScreen, DisplayCursor, CursorDisplayCursor);
-        Wrap(cs, pScreen, ConstrainCursorHarder, CursorConstrainCursorHarder);
         cs->pCursorHideCounts = NULL;
         SetCursorScreen(pScreen, cs);
     }
@@ -1505,9 +1084,6 @@ XFixesCursorInit(void)
                                                 "XFixesCursorHideCount");
     CursorWindowType = CreateNewResourceType(CursorFreeWindow,
                                              "XFixesCursorWindow");
-    PointerBarrierType = CreateNewResourceType(CursorFreeBarrier,
-                                               "XFixesPointerBarrier");
 
-    return CursorClientType && CursorHideCountType && CursorWindowType &&
-        PointerBarrierType;
+    return CursorClientType && CursorHideCountType && CursorWindowType;
 }
diff --git a/xfixes/xfixes.h b/xfixes/xfixes.h
index 19af09f..9882871 100644
--- a/xfixes/xfixes.h
+++ b/xfixes/xfixes.h
@@ -30,7 +30,6 @@
 #include "resource.h"
 
 extern _X_EXPORT RESTYPE RegionResType;
-extern _X_EXPORT RESTYPE PointerBarrierType;
 extern _X_EXPORT int XFixesErrorBase;
 
 #define VERIFY_REGION(pRegion, rid, client, mode)			\
@@ -52,20 +51,6 @@ extern _X_EXPORT int XFixesErrorBase;
 extern _X_EXPORT RegionPtr
  XFixesRegionCopy(RegionPtr pRegion);
 
-struct PointerBarrier {
-    CARD16 x1, x2, y1, y2;
-    CARD32 directions;
-};
-
-extern int
- barrier_get_direction(int, int, int, int);
-extern BOOL
-barrier_is_blocking(const struct PointerBarrier *, int, int, int, int,
-                    double *);
-extern BOOL barrier_is_blocking_direction(const struct PointerBarrier *, int);
-extern void
-
-barrier_clamp_to_barrier(struct PointerBarrier *barrier, int dir, int *x,
-                         int *y);
+#include "xibarriers.h"
 
 #endif                          /* _XFIXES_H_ */
commit b34cffd27b9ef46e1dd477219cbb90e36d5609e3
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Dec 3 11:39:08 2012 +1000

    include: fix comment
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/include/eventstr.h b/include/eventstr.h
index dd6fbef..eddba87 100644
--- a/include/eventstr.h
+++ b/include/eventstr.h
@@ -130,7 +130,7 @@ struct _DeviceEvent {
  */
 struct _TouchOwnershipEvent {
     unsigned char header; /**< Always ET_Internal */
-    enum EventType type;  /**< One of EventType */
+    enum EventType type;  /**< ET_TouchOwnership */
     int length;           /**< Length in bytes */
     Time time;            /**< Time in ms */
     int deviceid;         /**< Device to post this event for */
commit ea1d76d1b68c7cbcedcaa1f967c5027e0cc1c7a2
Author: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>
Date:   Mon Nov 5 23:50:58 2012 -0600

    Fix formatting of address operators
    
    The formatter confused address operators preceded by casts with
    bitwise-and expressions, placing spaces on either side of both.
    That syntax isn't used by ordinary address operators, however,
    so fix them for consistency.
    
    Signed-off-by: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xext/saver.c b/Xext/saver.c
index f73e2a2..8de043f 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -837,7 +837,7 @@ ScreenSaverSetAttributes(ClientPtr client)
     if ((visual != ancwopt->visual) || (depth != pParent->drawable.depth)) {
         fOK = FALSE;
         for (idepth = 0; idepth < pScreen->numDepths; idepth++) {
-            pDepth = (DepthPtr) & pScreen->allowedDepths[idepth];
+            pDepth = (DepthPtr) &pScreen->allowedDepths[idepth];
             if ((depth == pDepth->depth) || (depth == 0)) {
                 for (ivisual = 0; ivisual < pDepth->numVids; ivisual++) {
                     if (visual == pDepth->vids[ivisual]) {
diff --git a/Xi/extinit.c b/Xi/extinit.c
index 7e30755..06b8027 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -646,7 +646,7 @@ SDeviceChangedEvent(xXIDeviceChangedEvent * from, xXIDeviceChangedEvent * to)
     *to = *from;
     memcpy(&to[1], &from[1], from->length * 4);
 
-    any = (xXIAnyInfo *) & to[1];
+    any = (xXIAnyInfo *) &to[1];
     for (i = 0; i < to->num_classes; i++) {
         int length = any->length;
 
@@ -654,7 +654,7 @@ SDeviceChangedEvent(xXIDeviceChangedEvent * from, xXIDeviceChangedEvent * to)
         case KeyClass:
         {
             xXIKeyInfo *ki = (xXIKeyInfo *) any;
-            uint32_t *key = (uint32_t *) & ki[1];
+            uint32_t *key = (uint32_t *) &ki[1];
 
             for (j = 0; j < ki->num_keycodes; j++, key++)
                 swapl(key);
@@ -765,7 +765,7 @@ SDeviceHierarchyEvent(xXIHierarchyEvent * from, xXIHierarchyEvent * to)
     swapl(&to->flags);
     swaps(&to->num_info);
 
-    info = (xXIHierarchyInfo *) & to[1];
+    info = (xXIHierarchyInfo *) &to[1];
     for (i = 0; i < from->num_info; i++) {
         swaps(&info->deviceid);
         swaps(&info->attachment);
diff --git a/Xi/gtmotion.c b/Xi/gtmotion.c
index 4642b19..cde5351 100644
--- a/Xi/gtmotion.c
+++ b/Xi/gtmotion.c
@@ -131,7 +131,7 @@ ProcXGetDeviceMotionEvents(ClientPtr client)
     num_events = v->numMotionEvents;
     if (num_events) {
         size = sizeof(Time) + (axes * sizeof(INT32));
-        rep.nEvents = GetMotionHistory(dev, (xTimecoord **) & coords,   /* XXX */
+        rep.nEvents = GetMotionHistory(dev, (xTimecoord **) &coords,   /* XXX */
                                        start.milliseconds, stop.milliseconds,
                                        (ScreenPtr) NULL, FALSE);
     }
diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
index 89f16d8..15cbac3 100644
--- a/Xi/xichangehierarchy.c
+++ b/Xi/xichangehierarchy.c
@@ -79,7 +79,7 @@ XISendDeviceHierarchyEvent(int flags[MAXDEVICES])
     ev->flags = 0;
     ev->num_info = inputInfo.numDevices;
 
-    info = (xXIHierarchyInfo *) & ev[1];
+    info = (xXIHierarchyInfo *) &ev[1];
     for (dev = inputInfo.devices; dev; dev = dev->next) {
         info->deviceid = dev->id;
         info->enabled = dev->enabled;
diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
index 85c1dd8..4e544f0 100644
--- a/Xi/xiquerydevice.c
+++ b/Xi/xiquerydevice.c
@@ -304,7 +304,7 @@ ListKeyInfo(DeviceIntPtr dev, xXIKeyInfo * info)
     info->length = sizeof(xXIKeyInfo) / 4 + info->num_keycodes;
     info->sourceid = dev->key->sourceid;
 
-    kc = (uint32_t *) & info[1];
+    kc = (uint32_t *) &info[1];
     for (i = xkb->min_key_code; i <= xkb->max_key_code; i++, kc++)
         *kc = i;
 
@@ -321,7 +321,7 @@ SwapKeyInfo(DeviceIntPtr dev, xXIKeyInfo * info)
     swaps(&info->length);
     swaps(&info->sourceid);
 
-    for (i = 0, key = (uint32_t *) & info[1]; i < info->num_keycodes;
+    for (i = 0, key = (uint32_t *) &info[1]; i < info->num_keycodes;
          i++, key++)
         swapl(key);
 
diff --git a/dix/colormap.c b/dix/colormap.c
index a43e279..39fddc9 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -658,15 +658,15 @@ FreeCell(ColormapPtr pmap, Pixel i, int channel)
     default:         /* so compiler can see that everything gets initialized */
     case PSEUDOMAP:
     case REDMAP:
-        pent = (EntryPtr) & pmap->red[i];
+        pent = (EntryPtr) &pmap->red[i];
         pCount = &pmap->freeRed;
         break;
     case GREENMAP:
-        pent = (EntryPtr) & pmap->green[i];
+        pent = (EntryPtr) &pmap->green[i];
         pCount = &pmap->freeGreen;
         break;
     case BLUEMAP:
-        pent = (EntryPtr) & pmap->blue[i];
+        pent = (EntryPtr) &pmap->blue[i];
         pCount = &pmap->freeBlue;
         break;
     }
@@ -1400,7 +1400,7 @@ QueryColors(ColormapPtr pmap, int count, Pixel * ppixIn, xrgb * prgbList,
                 errVal = BadValue;
             }
             else {
-                pent = (EntryPtr) & pmap->red[pixel];
+                pent = (EntryPtr) &pmap->red[pixel];
                 if (pent->fShared) {
                     prgb->red = pent->co.shco.red->color;
                     prgb->green = pent->co.shco.green->color;
diff --git a/dix/devices.c b/dix/devices.c
index 613323f..3c7d480 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -283,7 +283,7 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart)
     dev->coreEvents = TRUE;
 
     /* sprite defaults */
-    dev->spriteInfo = (SpriteInfoPtr) & dev[1];
+    dev->spriteInfo = (SpriteInfoPtr) &dev[1];
 
     /*  security creation/labeling check
      */
@@ -944,7 +944,7 @@ CloseDevice(DeviceIntPtr dev)
 
     free(dev->name);
 
-    classes = (ClassesPtr) & dev->key;
+    classes = (ClassesPtr) &dev->key;
     FreeAllDeviceClasses(classes);
 
     if (IsMaster(dev)) {
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 99ba277..8d61735 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -2454,7 +2454,7 @@ ProcListInstalledColormaps(ClientPtr client)
     preply->type = X_Reply;
     preply->sequenceNumber = client->sequence;
     nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps)
-        (pWin->drawable.pScreen, (Colormap *) & preply[1]);
+        (pWin->drawable.pScreen, (Colormap *) &preply[1]);
     preply->nColormaps = nummaps;
     preply->length = nummaps;
     WriteReplyToClient(client, sizeof(xListInstalledColormapsReply), preply);
diff --git a/dix/eventconvert.c b/dix/eventconvert.c
index 2e422d7..218c954 100644
--- a/dix/eventconvert.c
+++ b/dix/eventconvert.c
@@ -451,7 +451,7 @@ appendKeyInfo(DeviceChangedEvent *dce, xXIKeyInfo * info)
     info->length = sizeof(xXIKeyInfo) / 4 + info->num_keycodes;
     info->sourceid = dce->sourceid;
 
-    kc = (uint32_t *) & info[1];
+    kc = (uint32_t *) &info[1];
     for (i = 0; i < info->num_keycodes; i++)
         *kc++ = i + dce->keys.min_keycode;
 
diff --git a/dix/window.c b/dix/window.c
index 99b3e0a..a5b28a6 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -680,7 +680,7 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
     if ((visual != ancwopt->visual) || (depth != pParent->drawable.depth)) {
         fOK = FALSE;
         for (idepth = 0; idepth < pScreen->numDepths; idepth++) {
-            pDepth = (DepthPtr) & pScreen->allowedDepths[idepth];
+            pDepth = (DepthPtr) &pScreen->allowedDepths[idepth];
             if ((depth == pDepth->depth) || (depth == 0)) {
                 for (ivisual = 0; ivisual < pDepth->numVids; ivisual++) {
                     if (visual == pDepth->vids[ivisual]) {
diff --git a/exa/exa.c b/exa/exa.c
index d12344f..f8e499c 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -620,8 +620,8 @@ exaCreateGC(GCPtr pGC)
 
     swap(pExaScr, pScreen, CreateGC);
     if ((ret = (*pScreen->CreateGC) (pGC))) {
-        wrap(pExaGC, pGC, funcs, (GCFuncs *) & exaGCFuncs);
-        wrap(pExaGC, pGC, ops, (GCOps *) & exaOps);
+        wrap(pExaGC, pGC, funcs, (GCFuncs *) &exaGCFuncs);
+        wrap(pExaGC, pGC, ops, (GCOps *) &exaOps);
     }
     swap(pExaScr, pScreen, CreateGC);
 
diff --git a/fb/fbgc.c b/fb/fbgc.c
index e6f8279..f4d7f3a 100644
--- a/fb/fbgc.c
+++ b/fb/fbgc.c
@@ -64,8 +64,8 @@ const GCOps fbGCOps = {
 Bool
 fbCreateGC(GCPtr pGC)
 {
-    pGC->ops = (GCOps *) & fbGCOps;
-    pGC->funcs = (GCFuncs *) & fbGCFuncs;
+    pGC->ops = (GCOps *) &fbGCOps;
+    pGC->funcs = (GCFuncs *) &fbGCFuncs;
 
     /* fb wants to translate before scan conversion */
     pGC->miTranslate = 1;
diff --git a/glx/glapi.c b/glx/glapi.c
index 02e06ac..ad7329e 100644
--- a/glx/glapi.c
+++ b/glx/glapi.c
@@ -490,7 +490,7 @@ init_glapi_relocs(void)
     char run_time_patch[] = {
         0x65, 0xa1, 0, 0, 0, 0  /* movl %gs:0,%eax */
     };
-    GLuint *offset = (GLuint *) & run_time_patch[2];    /* 32-bits for x86/32 */
+    GLuint *offset = (GLuint *) &run_time_patch[2];    /* 32-bits for x86/32 */
     const GLubyte *const get_disp = (const GLubyte *) run_time_patch;
     GLubyte *curr_func = (GLubyte *) gl_dispatch_functions_start;
 
diff --git a/glx/glxdri.c b/glx/glxdri.c
index a5d87ec..da46468 100644
--- a/glx/glxdri.c
+++ b/glx/glxdri.c
@@ -1069,7 +1069,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
 
     /* Map the framebuffer region. */
     status = drmMap(fd, hFB, framebuffer.size,
-                    (drmAddressPtr) & framebuffer.base);
+                    (drmAddressPtr) &framebuffer.base);
     if (status != 0) {
         LogMessage(X_ERROR, "AIGLX error: drmMap of framebuffer failed (%s)\n",
                    strerror(-status));
diff --git a/glx/indirect_program.c b/glx/indirect_program.c
index 3b50ecd..0114d73 100644
--- a/glx/indirect_program.c
+++ b/glx/indirect_program.c
@@ -109,7 +109,7 @@ DoGetProgramString(struct __GLXclientStateRec *cl, GLbyte * pc,
         }
         else {
             __GLX_BEGIN_REPLY(compsize);
-            ((xGLXGetTexImageReply *) & __glXReply)->width = compsize;
+            ((xGLXGetTexImageReply *) &__glXReply)->width = compsize;
             __GLX_SEND_HEADER();
             __GLX_SEND_VOID_ARRAY(compsize);
         }
diff --git a/glx/indirect_texture_compression.c b/glx/indirect_texture_compression.c
index 49d6db5..5c2d06b 100644
--- a/glx/indirect_texture_compression.c
+++ b/glx/indirect_texture_compression.c
@@ -72,7 +72,7 @@ __glXDisp_GetCompressedTexImageARB(struct __GLXclientStateRec *cl, GLbyte * pc)
         }
         else {
             __GLX_BEGIN_REPLY(compsize);
-            ((xGLXGetTexImageReply *) & __glXReply)->width = compsize;
+            ((xGLXGetTexImageReply *) &__glXReply)->width = compsize;
             __GLX_SEND_HEADER();
             __GLX_SEND_VOID_ARRAY(compsize);
         }
@@ -118,7 +118,7 @@ __glXDispSwap_GetCompressedTexImageARB(struct __GLXclientStateRec *cl,
         }
         else {
             __GLX_BEGIN_REPLY(compsize);
-            ((xGLXGetTexImageReply *) & __glXReply)->width = compsize;
+            ((xGLXGetTexImageReply *) &__glXReply)->width = compsize;
             __GLX_SEND_HEADER();
             __GLX_SEND_VOID_ARRAY(compsize);
         }
diff --git a/glx/renderpixswap.c b/glx/renderpixswap.c
index 0655b74..24423cd 100644
--- a/glx/renderpixswap.c
+++ b/glx/renderpixswap.c
@@ -51,17 +51,17 @@ __glXDispSwap_SeparableFilter2D(GLbyte * pc)
 
     hdrlen = __GLX_PAD(__GLX_CONV_FILT_CMD_HDR_SIZE);
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->rowLength);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipRows);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipPixels);
-    __GLX_SWAP_INT((GLbyte *) & hdr->alignment);
+    __GLX_SWAP_INT((GLbyte *) &hdr->rowLength);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipRows);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipPixels);
+    __GLX_SWAP_INT((GLbyte *) &hdr->alignment);
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->target);
-    __GLX_SWAP_INT((GLbyte *) & hdr->internalformat);
-    __GLX_SWAP_INT((GLbyte *) & hdr->width);
-    __GLX_SWAP_INT((GLbyte *) & hdr->height);
-    __GLX_SWAP_INT((GLbyte *) & hdr->format);
-    __GLX_SWAP_INT((GLbyte *) & hdr->type);
+    __GLX_SWAP_INT((GLbyte *) &hdr->target);
+    __GLX_SWAP_INT((GLbyte *) &hdr->internalformat);
+    __GLX_SWAP_INT((GLbyte *) &hdr->width);
+    __GLX_SWAP_INT((GLbyte *) &hdr->height);
+    __GLX_SWAP_INT((GLbyte *) &hdr->format);
+    __GLX_SWAP_INT((GLbyte *) &hdr->type);
 
     /*
      ** Just invert swapBytes flag; the GL will figure out if it needs to swap
diff --git a/glx/singlepix.c b/glx/singlepix.c
index 55cd443..fb6868d 100644
--- a/glx/singlepix.c
+++ b/glx/singlepix.c
@@ -150,9 +150,9 @@ __glXDisp_GetTexImage(__GLXclientState * cl, GLbyte * pc)
     }
     else {
         __GLX_BEGIN_REPLY(compsize);
-        ((xGLXGetTexImageReply *) & __glXReply)->width = width;
-        ((xGLXGetTexImageReply *) & __glXReply)->height = height;
-        ((xGLXGetTexImageReply *) & __glXReply)->depth = depth;
+        ((xGLXGetTexImageReply *) &__glXReply)->width = width;
+        ((xGLXGetTexImageReply *) &__glXReply)->height = height;
+        ((xGLXGetTexImageReply *) &__glXReply)->depth = depth;
         __GLX_SEND_HEADER();
         __GLX_SEND_VOID_ARRAY(compsize);
     }
@@ -252,8 +252,8 @@ GetSeparableFilter(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
     }
     else {
         __GLX_BEGIN_REPLY(compsize + compsize2);
-        ((xGLXGetSeparableFilterReply *) & __glXReply)->width = width;
-        ((xGLXGetSeparableFilterReply *) & __glXReply)->height = height;
+        ((xGLXGetSeparableFilterReply *) &__glXReply)->width = width;
+        ((xGLXGetSeparableFilterReply *) &__glXReply)->height = height;
         __GLX_SEND_HEADER();
         __GLX_SEND_VOID_ARRAY(compsize + compsize2);
     }
@@ -330,8 +330,8 @@ GetConvolutionFilter(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
     }
     else {
         __GLX_BEGIN_REPLY(compsize);
-        ((xGLXGetConvolutionFilterReply *) & __glXReply)->width = width;
-        ((xGLXGetConvolutionFilterReply *) & __glXReply)->height = height;
+        ((xGLXGetConvolutionFilterReply *) &__glXReply)->width = width;
+        ((xGLXGetConvolutionFilterReply *) &__glXReply)->height = height;
         __GLX_SEND_HEADER();
         __GLX_SEND_VOID_ARRAY(compsize);
     }
@@ -399,7 +399,7 @@ GetHistogram(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
     }
     else {
         __GLX_BEGIN_REPLY(compsize);
-        ((xGLXGetHistogramReply *) & __glXReply)->width = width;
+        ((xGLXGetHistogramReply *) &__glXReply)->width = width;
         __GLX_SEND_HEADER();
         __GLX_SEND_VOID_ARRAY(compsize);
     }
@@ -528,7 +528,7 @@ GetColorTable(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
     }
     else {
         __GLX_BEGIN_REPLY(compsize);
-        ((xGLXGetColorTableReply *) & __glXReply)->width = width;
+        ((xGLXGetColorTableReply *) &__glXReply)->width = width;
         __GLX_SEND_HEADER();
         __GLX_SEND_VOID_ARRAY(compsize);
     }
diff --git a/glx/singlepixswap.c b/glx/singlepixswap.c
index b6d6283..c777cea 100644
--- a/glx/singlepixswap.c
+++ b/glx/singlepixswap.c
@@ -176,9 +176,9 @@ __glXDispSwap_GetTexImage(__GLXclientState * cl, GLbyte * pc)
         __GLX_SWAP_INT(&width);
         __GLX_SWAP_INT(&height);
         __GLX_SWAP_INT(&depth);
-        ((xGLXGetTexImageReply *) & __glXReply)->width = width;
-        ((xGLXGetTexImageReply *) & __glXReply)->height = height;
-        ((xGLXGetTexImageReply *) & __glXReply)->depth = depth;
+        ((xGLXGetTexImageReply *) &__glXReply)->width = width;
+        ((xGLXGetTexImageReply *) &__glXReply)->height = height;
+        ((xGLXGetTexImageReply *) &__glXReply)->depth = depth;
         __GLX_SEND_HEADER();
         __GLX_SEND_VOID_ARRAY(compsize);
     }
@@ -290,8 +290,8 @@ GetSeparableFilter(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
         __GLX_SWAP_REPLY_HEADER();
         __GLX_SWAP_INT(&width);
         __GLX_SWAP_INT(&height);
-        ((xGLXGetSeparableFilterReply *) & __glXReply)->width = width;
-        ((xGLXGetSeparableFilterReply *) & __glXReply)->height = height;
+        ((xGLXGetSeparableFilterReply *) &__glXReply)->width = width;
+        ((xGLXGetSeparableFilterReply *) &__glXReply)->height = height;
         __GLX_SEND_VOID_ARRAY(compsize + compsize2);
     }
 
@@ -376,8 +376,8 @@ GetConvolutionFilter(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
         __GLX_SWAP_REPLY_HEADER();
         __GLX_SWAP_INT(&width);
         __GLX_SWAP_INT(&height);
-        ((xGLXGetConvolutionFilterReply *) & __glXReply)->width = width;
-        ((xGLXGetConvolutionFilterReply *) & __glXReply)->height = height;
+        ((xGLXGetConvolutionFilterReply *) &__glXReply)->width = width;
+        ((xGLXGetConvolutionFilterReply *) &__glXReply)->height = height;
         __GLX_SEND_VOID_ARRAY(compsize);
     }
 
@@ -452,7 +452,7 @@ GetHistogram(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
         __GLX_BEGIN_REPLY(compsize);
         __GLX_SWAP_REPLY_HEADER();
         __GLX_SWAP_INT(&width);
-        ((xGLXGetHistogramReply *) & __glXReply)->width = width;
+        ((xGLXGetHistogramReply *) &__glXReply)->width = width;
         __GLX_SEND_VOID_ARRAY(compsize);
     }
 
@@ -594,7 +594,7 @@ GetColorTable(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
         __GLX_BEGIN_REPLY(compsize);
         __GLX_SWAP_REPLY_HEADER();
         __GLX_SWAP_INT(&width);
-        ((xGLXGetColorTableReply *) & __glXReply)->width = width;
+        ((xGLXGetColorTableReply *) &__glXReply)->width = width;
         __GLX_SEND_VOID_ARRAY(compsize);
     }
 
diff --git a/glx/xfont.c b/glx/xfont.c
index 037ed9e..b203866 100644
--- a/glx/xfont.c
+++ b/glx/xfont.c
@@ -168,7 +168,7 @@ __glXDisp_UseXFont(__GLXclientState * cl, GLbyte * pc)
     }
 
     CALL_GetIntegerv(GET_DISPATCH(),
-                     (GL_LIST_INDEX, (GLint *) & currentListIndex));
+                     (GL_LIST_INDEX, (GLint *) &currentListIndex));
     if (currentListIndex != 0) {
         /*
          ** A display list is currently being made.  It is an error
diff --git a/hw/dmx/config/Canvas.c b/hw/dmx/config/Canvas.c
index 34a47a2..f0586e5 100644
--- a/hw/dmx/config/Canvas.c
+++ b/hw/dmx/config/Canvas.c
@@ -76,7 +76,7 @@ CanvasExpose(Widget w, XEvent * event, Region region)
 
     if (!XtIsRealized(w))
         return;
-    XtCallCallbacks(w, XtNcanvasExposeCallback, (XtPointer) & data);
+    XtCallCallbacks(w, XtNcanvasExposeCallback, (XtPointer) &data);
 }
 
 static void
@@ -162,4 +162,4 @@ CanvasClassRec canvasClassRec = {
      }
 };
 
-WidgetClass canvasWidgetClass = (WidgetClass) & canvasClassRec;
+WidgetClass canvasWidgetClass = (WidgetClass) &canvasClassRec;
diff --git a/hw/dmx/dmx_glxvisuals.c b/hw/dmx/dmx_glxvisuals.c
index 9fcc0e5..f903b74 100644
--- a/hw/dmx/dmx_glxvisuals.c
+++ b/hw/dmx/dmx_glxvisuals.c
@@ -61,7 +61,7 @@ GetGLXVisualConfigs(Display * dpy, int screen, int *nconfigs)
     req->reqType = majorOpcode;
     req->glxCode = X_GLXGetVisualConfigs;
     req->screen = screen;
-    if (!_XReply(dpy, (xReply *) & reply, 0, False)) {
+    if (!_XReply(dpy, (xReply *) &reply, 0, False)) {
         /* Something is busted. Punt. */
         UnlockDisplay(dpy);
         SyncHandle();
@@ -252,7 +252,7 @@ GetGLXFBConfigs(Display * dpy, int glxMajorOpcode, int *nconfigs)
 
     *nconfigs = 0;
 
-    if (!_XReply(dpy, (xReply *) & reply, 0, False)) {
+    if (!_XReply(dpy, (xReply *) &reply, 0, False)) {
         /* Something is busted. Punt. */
         UnlockDisplay(dpy);
         SyncHandle();
diff --git a/hw/dmx/dmxwindow.c b/hw/dmx/dmxwindow.c
index 855e56b..9b8a384 100644
--- a/hw/dmx/dmxwindow.c
+++ b/hw/dmx/dmxwindow.c
@@ -786,7 +786,7 @@ dmxWindowExposures(WindowPtr pWindow, RegionPtr prgn, RegionPtr other_exposed)
     if (pWinPriv->window) {
         while (XCheckIfEvent(dmxScreen->beDisplay, &ev,
                              dmxWindowExposurePredicate,
-                             (XPointer) & pWinPriv->window)) {
+                             (XPointer) &pWinPriv->window)) {
             /* Handle expose events -- this should not be necessary
                since the base window in which the root window was
                created is guaranteed to be on top (override_redirect),
diff --git a/hw/dmx/examples/xinput.c b/hw/dmx/examples/xinput.c
index db66010..6eddc6a 100644
--- a/hw/dmx/examples/xinput.c
+++ b/hw/dmx/examples/xinput.c
@@ -303,8 +303,8 @@ main(int argc, char **argv)
 
             XNextEvent(display, &event);
             for (i = 0; i < cnt; i++) {
-                XDeviceMotionEvent *e = (XDeviceMotionEvent *) & event;
-                XDeviceButtonEvent *b = (XDeviceButtonEvent *) & event;
+                XDeviceMotionEvent *e = (XDeviceMotionEvent *) &event;
+                XDeviceButtonEvent *b = (XDeviceButtonEvent *) &event;
 
                 if (event.type == event_type[i]) {
                     printf("%s id=%lu (%d @ %d,%d; s=0x%04x, d=%d, t=%lu)"
diff --git a/hw/dmx/glxProxy/glxcmds.c b/hw/dmx/glxProxy/glxcmds.c
index 91011d1..4538274 100644
--- a/hw/dmx/glxProxy/glxcmds.c
+++ b/hw/dmx/glxProxy/glxcmds.c
@@ -1276,7 +1276,7 @@ MakeCurrent(__GLXclientState * cl,
             be_req->context =
                 (unsigned int) (glxc ? glxc->real_ids[s - from_screen] : 0);
             be_req->oldContextTag = GetCurrentBackEndTag(cl, tag, s);
-            if (!_XReply(dpy, (xReply *) & be_reply, 0, False)) {
+            if (!_XReply(dpy, (xReply *) &be_reply, 0, False)) {
 
                 /* The make current failed */
                 UnlockDisplay(dpy);
@@ -1331,7 +1331,7 @@ MakeCurrent(__GLXclientState * cl,
                 be_new_req->context =
                     (unsigned int) (glxc ? glxc->real_ids[s - from_screen] : 0);
                 be_new_req->oldContextTag = GetCurrentBackEndTag(cl, tag, s);
-                if (!_XReply(dpy, (xReply *) & be_new_reply, 0, False)) {
+                if (!_XReply(dpy, (xReply *) &be_new_reply, 0, False)) {
 
                     /* The make current failed */
                     UnlockDisplay(dpy);
@@ -1362,7 +1362,7 @@ MakeCurrent(__GLXclientState * cl,
                 ext_req->context =
                     (unsigned int) (glxc ? glxc->real_ids[s - from_screen] : 0);
                 ext_req->oldContextTag = GetCurrentBackEndTag(cl, tag, s);
-                if (!_XReply(dpy, (xReply *) & ext_reply, 0, False)) {
+                if (!_XReply(dpy, (xReply *) &ext_reply, 0, False)) {
 
                     /* The make current failed */
                     UnlockDisplay(dpy);
@@ -2177,7 +2177,7 @@ __glXDoSwapBuffers(__GLXclientState * cl, XID drawId, GLXContextTag tag)
             finishReq->glxCode = X_GLsop_Finish;
             finishReq->contextTag =
                 (tag ? GetCurrentBackEndTag(cl, tag, s) : 0);
-            (void) _XReply(dpy, (xReply *) & reply, 0, False);
+            (void) _XReply(dpy, (xReply *) &reply, 0, False);
             UnlockDisplay(dpy);
             SyncHandle();
         }
@@ -2605,7 +2605,7 @@ __glXQueryExtensionsString(__GLXclientState * cl, GLbyte * pc)
     be_req->reqType = dmxScreen->glxMajorOpcode;
     be_req->glxCode = X_GLXQueryServerString;
     be_req->screen = DefaultScreen(dpy);
-    _XReply(dpy, (xReply *) & be_reply, 0, False);
+    _XReply(dpy, (xReply *) &be_reply, 0, False);
     len = (int) be_reply.length;
     numbytes = (int) be_reply.n;
     slop = numbytes * __GLX_SIZE_INT8 & 3;
@@ -2690,7 +2690,7 @@ __glXQueryServerString(__GLXclientState * cl, GLbyte * pc)
     be_req->glxCode = X_GLXQueryServerString;
     be_req->screen = DefaultScreen(dpy);
     be_req->name = name;
-    _XReply(dpy, (xReply *) & be_reply, 0, False);
+    _XReply(dpy, (xReply *) &be_reply, 0, False);
     len = (int) be_reply.length;
     numbytes = (int) be_reply.n;
     slop = numbytes * __GLX_SIZE_INT8 & 3;
@@ -3045,7 +3045,7 @@ __glXGetFBConfigsSGIX(__GLXclientState * cl, GLbyte * pc)
     new_req.length = req->length;
     new_req.screen = req->screen;
 
-    return (__glXGetFBConfigs(cl, (GLbyte *) & new_req));
+    return (__glXGetFBConfigs(cl, (GLbyte *) &new_req));
 }
 
 int
@@ -3591,7 +3591,7 @@ __glXGetDrawableAttributes(__GLXclientState * cl, GLbyte * pc)
     be_req->glxCode = X_GLXGetDrawableAttributes;
     be_req->drawable = be_drawable;
     be_req->length = req->length;
-    if (!_XReply(dpy, (xReply *) & reply, 0, False)) {
+    if (!_XReply(dpy, (xReply *) &reply, 0, False)) {
         UnlockDisplay(dpy);
         SyncHandle();
         return (BE_TO_CLIENT_ERROR(dmxLastErrorEvent.error_code));
diff --git a/hw/dmx/glxProxy/glxcmdsswap.c b/hw/dmx/glxProxy/glxcmdsswap.c
index ac79cda..ab3e7ed 100644
--- a/hw/dmx/glxProxy/glxcmdsswap.c
+++ b/hw/dmx/glxProxy/glxcmdsswap.c
@@ -1051,7 +1051,7 @@ __glXSwapGetFBConfigsSGIX(__GLXclientState * cl, GLbyte * pc)
     new_req.length = req->length;
     new_req.screen = req->screen;
 
-    return (__glXSwapGetFBConfigs(cl, (GLbyte *) & new_req));
+    return (__glXSwapGetFBConfigs(cl, (GLbyte *) &new_req));
 }
 
 int
diff --git a/hw/dmx/glxProxy/glxscreens.c b/hw/dmx/glxProxy/glxscreens.c
index f725bd1..2a19092 100644
--- a/hw/dmx/glxProxy/glxscreens.c
+++ b/hw/dmx/glxProxy/glxscreens.c
@@ -88,7 +88,7 @@ CalcServerVersionAndExtensions(void)
         req->glxCode = X_GLXQueryVersion;
         req->majorVersion = GLX_SERVER_MAJOR_VERSION;
         req->minorVersion = GLX_SERVER_MINOR_VERSION;
-        _XReply(dpy, (xReply *) & reply, 0, False);
+        _XReply(dpy, (xReply *) &reply, 0, False);
         UnlockDisplay(dpy);
         SyncHandle();
 
@@ -147,7 +147,7 @@ CalcServerVersionAndExtensions(void)
         req->glxCode = X_GLXQueryServerString;
         req->screen = DefaultScreen(dpy);
         req->name = GLX_EXTENSIONS;
-        _XReply(dpy, (xReply *) & reply, 0, False);
+        _XReply(dpy, (xReply *) &reply, 0, False);
 
         length = (int) reply.length;
         numbytes = (int) reply.n;
diff --git a/hw/dmx/glxProxy/glxsingle.c b/hw/dmx/glxProxy/glxsingle.c
index 8784200..e60cfeb 100644
--- a/hw/dmx/glxProxy/glxsingle.c
+++ b/hw/dmx/glxProxy/glxsingle.c
@@ -249,7 +249,7 @@ __glXForwardPipe0WithReply(__GLXclientState * cl, GLbyte * pc)
     /*
      * get the reply from the back-end server
      */
-    _XReply(dpy, (xReply *) & be_reply, 0, False);
+    _XReply(dpy, (xReply *) &be_reply, 0, False);
     be_buf_size = be_reply.length << 2;
     if (be_buf_size > 0) {
         be_buf = (char *) malloc(be_buf_size);
@@ -348,7 +348,7 @@ __glXForwardAllWithReply(__GLXclientState * cl, GLbyte * pc)
         /*
          * get the reply from the back-end server
          */
-        _XReply(dpy, (xReply *) & be_reply, 0, False);
+        _XReply(dpy, (xReply *) &be_reply, 0, False);
         be_buf_size = be_reply.length << 2;
         if (be_buf_size > 0) {
             be_buf = (char *) malloc(be_buf_size);
@@ -919,7 +919,7 @@ __glXDisp_ReadPixels(__GLXclientState * cl, GLbyte * pc)
                 *(GLboolean *) (be_pc + 24) = swapBytes;
                 *(GLboolean *) (be_pc + 25) = lsbFirst;
 
-                _XReply(dpy, (xReply *) & be_reply, 0, False);
+                _XReply(dpy, (xReply *) &be_reply, 0, False);
 
                 if (be_reply.length > 0) {
                     char *be_buf;
diff --git a/hw/dmx/glxProxy/glxvendor.c b/hw/dmx/glxProxy/glxvendor.c
index e5c8da1..5777c6a 100644
--- a/hw/dmx/glxProxy/glxvendor.c
+++ b/hw/dmx/glxProxy/glxvendor.c
@@ -237,7 +237,7 @@ __glXVForwardPipe0WithReply(__GLXclientState * cl, GLbyte * pc)
     /*
      * get the reply from the back-end server
      */
-    _XReply(dpy, (xReply *) & be_reply, 0, False);
+    _XReply(dpy, (xReply *) &be_reply, 0, False);
     be_buf_size = be_reply.length << 2;
     if (be_buf_size > 0) {
         be_buf = (char *) malloc(be_buf_size);
@@ -331,7 +331,7 @@ __glXVForwardAllWithReply(__GLXclientState * cl, GLbyte * pc)
         /*
          * get the reply from the back-end server
          */
-        _XReply(dpy, (xReply *) & be_reply, 0, False);
+        _XReply(dpy, (xReply *) &be_reply, 0, False);
         be_buf_size = be_reply.length << 2;
         if (be_buf_size > 0) {
             be_buf = (char *) malloc(be_buf_size);
diff --git a/hw/dmx/glxProxy/renderpixswap.c b/hw/dmx/glxProxy/renderpixswap.c
index 3458e61..32df0d5 100644
--- a/hw/dmx/glxProxy/renderpixswap.c
+++ b/hw/dmx/glxProxy/renderpixswap.c
@@ -39,10 +39,10 @@ __glXDispSwap_PolygonStipple(GLbyte * pc)
 
     __GLX_DECLARE_SWAP_VARIABLES;
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->rowLength);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipRows);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipPixels);
-    __GLX_SWAP_INT((GLbyte *) & hdr->alignment);
+    __GLX_SWAP_INT((GLbyte *) &hdr->rowLength);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipRows);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipPixels);
+    __GLX_SWAP_INT((GLbyte *) &hdr->alignment);
 
     hdr->swapBytes = !hdr->swapBytes;
 }
@@ -54,17 +54,17 @@ __glXDispSwap_Bitmap(GLbyte * pc)
 
     __GLX_DECLARE_SWAP_VARIABLES;
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->rowLength);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipRows);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipPixels);
-    __GLX_SWAP_INT((GLbyte *) & hdr->alignment);
+    __GLX_SWAP_INT((GLbyte *) &hdr->rowLength);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipRows);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipPixels);
+    __GLX_SWAP_INT((GLbyte *) &hdr->alignment);
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->width);
-    __GLX_SWAP_INT((GLbyte *) & hdr->height);
-    __GLX_SWAP_FLOAT((GLbyte *) & hdr->xorig);
-    __GLX_SWAP_FLOAT((GLbyte *) & hdr->yorig);
-    __GLX_SWAP_FLOAT((GLbyte *) & hdr->xmove);
-    __GLX_SWAP_FLOAT((GLbyte *) & hdr->ymove);
+    __GLX_SWAP_INT((GLbyte *) &hdr->width);
+    __GLX_SWAP_INT((GLbyte *) &hdr->height);
+    __GLX_SWAP_FLOAT((GLbyte *) &hdr->xorig);
+    __GLX_SWAP_FLOAT((GLbyte *) &hdr->yorig);
+    __GLX_SWAP_FLOAT((GLbyte *) &hdr->xmove);
+    __GLX_SWAP_FLOAT((GLbyte *) &hdr->ymove);
 
     hdr->swapBytes = !hdr->swapBytes;
 
@@ -77,19 +77,19 @@ __glXDispSwap_TexImage1D(GLbyte * pc)
 
     __GLX_DECLARE_SWAP_VARIABLES;
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->rowLength);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipRows);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipPixels);
-    __GLX_SWAP_INT((GLbyte *) & hdr->alignment);
+    __GLX_SWAP_INT((GLbyte *) &hdr->rowLength);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipRows);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipPixels);
+    __GLX_SWAP_INT((GLbyte *) &hdr->alignment);
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->target);
-    __GLX_SWAP_INT((GLbyte *) & hdr->level);
-    __GLX_SWAP_INT((GLbyte *) & hdr->components);
-    __GLX_SWAP_INT((GLbyte *) & hdr->width);
-    __GLX_SWAP_INT((GLbyte *) & hdr->height);
-    __GLX_SWAP_INT((GLbyte *) & hdr->border);
-    __GLX_SWAP_INT((GLbyte *) & hdr->format);
-    __GLX_SWAP_INT((GLbyte *) & hdr->type);
+    __GLX_SWAP_INT((GLbyte *) &hdr->target);
+    __GLX_SWAP_INT((GLbyte *) &hdr->level);
+    __GLX_SWAP_INT((GLbyte *) &hdr->components);
+    __GLX_SWAP_INT((GLbyte *) &hdr->width);
+    __GLX_SWAP_INT((GLbyte *) &hdr->height);
+    __GLX_SWAP_INT((GLbyte *) &hdr->border);
+    __GLX_SWAP_INT((GLbyte *) &hdr->format);
+    __GLX_SWAP_INT((GLbyte *) &hdr->type);
 
     /*
      ** Just invert swapBytes flag; the GL will figure out if it needs to swap
@@ -105,19 +105,19 @@ __glXDispSwap_TexImage2D(GLbyte * pc)
 
     __GLX_DECLARE_SWAP_VARIABLES;
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->rowLength);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipRows);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipPixels);
-    __GLX_SWAP_INT((GLbyte *) & hdr->alignment);
+    __GLX_SWAP_INT((GLbyte *) &hdr->rowLength);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipRows);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipPixels);
+    __GLX_SWAP_INT((GLbyte *) &hdr->alignment);
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->target);
-    __GLX_SWAP_INT((GLbyte *) & hdr->level);
-    __GLX_SWAP_INT((GLbyte *) & hdr->components);
-    __GLX_SWAP_INT((GLbyte *) & hdr->width);
-    __GLX_SWAP_INT((GLbyte *) & hdr->height);
-    __GLX_SWAP_INT((GLbyte *) & hdr->border);
-    __GLX_SWAP_INT((GLbyte *) & hdr->format);
-    __GLX_SWAP_INT((GLbyte *) & hdr->type);
+    __GLX_SWAP_INT((GLbyte *) &hdr->target);
+    __GLX_SWAP_INT((GLbyte *) &hdr->level);
+    __GLX_SWAP_INT((GLbyte *) &hdr->components);
+    __GLX_SWAP_INT((GLbyte *) &hdr->width);
+    __GLX_SWAP_INT((GLbyte *) &hdr->height);
+    __GLX_SWAP_INT((GLbyte *) &hdr->border);
+    __GLX_SWAP_INT((GLbyte *) &hdr->format);
+    __GLX_SWAP_INT((GLbyte *) &hdr->type);
 
     /*
      ** Just invert swapBytes flag; the GL will figure out if it needs to swap
@@ -133,25 +133,25 @@ __glXDispSwap_TexImage3D(GLbyte * pc)
 
     __GLX_DECLARE_SWAP_VARIABLES;
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->rowLength);
-    __GLX_SWAP_INT((GLbyte *) & hdr->imageHeight);
-    __GLX_SWAP_INT((GLbyte *) & hdr->imageDepth);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipRows);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipImages);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipVolumes);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipPixels);
-    __GLX_SWAP_INT((GLbyte *) & hdr->alignment);
-
-    __GLX_SWAP_INT((GLbyte *) & hdr->target);
-    __GLX_SWAP_INT((GLbyte *) & hdr->level);
-    __GLX_SWAP_INT((GLbyte *) & hdr->internalformat);
-    __GLX_SWAP_INT((GLbyte *) & hdr->width);
-    __GLX_SWAP_INT((GLbyte *) & hdr->height);
-    __GLX_SWAP_INT((GLbyte *) & hdr->depth);
-    __GLX_SWAP_INT((GLbyte *) & hdr->size4d);
-    __GLX_SWAP_INT((GLbyte *) & hdr->border);
-    __GLX_SWAP_INT((GLbyte *) & hdr->format);
-    __GLX_SWAP_INT((GLbyte *) & hdr->type);
+    __GLX_SWAP_INT((GLbyte *) &hdr->rowLength);
+    __GLX_SWAP_INT((GLbyte *) &hdr->imageHeight);
+    __GLX_SWAP_INT((GLbyte *) &hdr->imageDepth);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipRows);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipImages);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipVolumes);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipPixels);
+    __GLX_SWAP_INT((GLbyte *) &hdr->alignment);
+
+    __GLX_SWAP_INT((GLbyte *) &hdr->target);
+    __GLX_SWAP_INT((GLbyte *) &hdr->level);
+    __GLX_SWAP_INT((GLbyte *) &hdr->internalformat);
+    __GLX_SWAP_INT((GLbyte *) &hdr->width);
+    __GLX_SWAP_INT((GLbyte *) &hdr->height);
+    __GLX_SWAP_INT((GLbyte *) &hdr->depth);
+    __GLX_SWAP_INT((GLbyte *) &hdr->size4d);
+    __GLX_SWAP_INT((GLbyte *) &hdr->border);
+    __GLX_SWAP_INT((GLbyte *) &hdr->format);
+    __GLX_SWAP_INT((GLbyte *) &hdr->type);
 
     /*
      ** Just invert swapBytes flag; the GL will figure out if it needs to swap
@@ -167,15 +167,15 @@ __glXDispSwap_DrawPixels(GLbyte * pc)
 
     __GLX_DECLARE_SWAP_VARIABLES;
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->rowLength);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipRows);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipPixels);
-    __GLX_SWAP_INT((GLbyte *) & hdr->alignment);
+    __GLX_SWAP_INT((GLbyte *) &hdr->rowLength);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipRows);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipPixels);
+    __GLX_SWAP_INT((GLbyte *) &hdr->alignment);
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->width);
-    __GLX_SWAP_INT((GLbyte *) & hdr->height);
-    __GLX_SWAP_INT((GLbyte *) & hdr->format);
-    __GLX_SWAP_INT((GLbyte *) & hdr->type);
+    __GLX_SWAP_INT((GLbyte *) &hdr->width);
+    __GLX_SWAP_INT((GLbyte *) &hdr->height);
+    __GLX_SWAP_INT((GLbyte *) &hdr->format);
+    __GLX_SWAP_INT((GLbyte *) &hdr->type);
 
     /*
      ** Just invert swapBytes flag; the GL will figure out if it needs to swap
@@ -191,17 +191,17 @@ __glXDispSwap_TexSubImage1D(GLbyte * pc)
 
     __GLX_DECLARE_SWAP_VARIABLES;
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->rowLength);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipRows);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipPixels);
-    __GLX_SWAP_INT((GLbyte *) & hdr->alignment);
+    __GLX_SWAP_INT((GLbyte *) &hdr->rowLength);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipRows);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipPixels);
+    __GLX_SWAP_INT((GLbyte *) &hdr->alignment);
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->target);
-    __GLX_SWAP_INT((GLbyte *) & hdr->level);
-    __GLX_SWAP_INT((GLbyte *) & hdr->xoffset);
-    __GLX_SWAP_INT((GLbyte *) & hdr->width);
-    __GLX_SWAP_INT((GLbyte *) & hdr->format);
-    __GLX_SWAP_INT((GLbyte *) & hdr->type);
+    __GLX_SWAP_INT((GLbyte *) &hdr->target);
+    __GLX_SWAP_INT((GLbyte *) &hdr->level);
+    __GLX_SWAP_INT((GLbyte *) &hdr->xoffset);
+    __GLX_SWAP_INT((GLbyte *) &hdr->width);
+    __GLX_SWAP_INT((GLbyte *) &hdr->format);
+    __GLX_SWAP_INT((GLbyte *) &hdr->type);
 
     /*
      ** Just invert swapBytes flag; the GL will figure out if it needs to swap
@@ -217,19 +217,19 @@ __glXDispSwap_TexSubImage2D(GLbyte * pc)
 
     __GLX_DECLARE_SWAP_VARIABLES;
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->rowLength);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipRows);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipPixels);
-    __GLX_SWAP_INT((GLbyte *) & hdr->alignment);
+    __GLX_SWAP_INT((GLbyte *) &hdr->rowLength);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipRows);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipPixels);
+    __GLX_SWAP_INT((GLbyte *) &hdr->alignment);
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->target);
-    __GLX_SWAP_INT((GLbyte *) & hdr->level);
-    __GLX_SWAP_INT((GLbyte *) & hdr->xoffset);
-    __GLX_SWAP_INT((GLbyte *) & hdr->yoffset);
-    __GLX_SWAP_INT((GLbyte *) & hdr->width);
-    __GLX_SWAP_INT((GLbyte *) & hdr->height);
-    __GLX_SWAP_INT((GLbyte *) & hdr->format);
-    __GLX_SWAP_INT((GLbyte *) & hdr->type);
+    __GLX_SWAP_INT((GLbyte *) &hdr->target);
+    __GLX_SWAP_INT((GLbyte *) &hdr->level);
+    __GLX_SWAP_INT((GLbyte *) &hdr->xoffset);
+    __GLX_SWAP_INT((GLbyte *) &hdr->yoffset);
+    __GLX_SWAP_INT((GLbyte *) &hdr->width);
+    __GLX_SWAP_INT((GLbyte *) &hdr->height);
+    __GLX_SWAP_INT((GLbyte *) &hdr->format);
+    __GLX_SWAP_INT((GLbyte *) &hdr->type);
 
     /*
      ** Just invert swapBytes flag; the GL will figure out if it needs to swap
@@ -246,26 +246,26 @@ __glXDispSwap_TexSubImage3D(GLbyte * pc)
 
     __GLX_DECLARE_SWAP_VARIABLES;
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->rowLength);
-    __GLX_SWAP_INT((GLbyte *) & hdr->imageHeight);
-    __GLX_SWAP_INT((GLbyte *) & hdr->imageDepth);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipRows);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipImages);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipVolumes);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipPixels);
-    __GLX_SWAP_INT((GLbyte *) & hdr->alignment);
-
-    __GLX_SWAP_INT((GLbyte *) & hdr->target);
-    __GLX_SWAP_INT((GLbyte *) & hdr->level);
-    __GLX_SWAP_INT((GLbyte *) & hdr->xoffset);
-    __GLX_SWAP_INT((GLbyte *) & hdr->yoffset);
-    __GLX_SWAP_INT((GLbyte *) & hdr->zoffset);
-    __GLX_SWAP_INT((GLbyte *) & hdr->width);
-    __GLX_SWAP_INT((GLbyte *) & hdr->height);
-    __GLX_SWAP_INT((GLbyte *) & hdr->depth);
-    __GLX_SWAP_INT((GLbyte *) & hdr->size4d);
-    __GLX_SWAP_INT((GLbyte *) & hdr->format);
-    __GLX_SWAP_INT((GLbyte *) & hdr->type);
+    __GLX_SWAP_INT((GLbyte *) &hdr->rowLength);
+    __GLX_SWAP_INT((GLbyte *) &hdr->imageHeight);
+    __GLX_SWAP_INT((GLbyte *) &hdr->imageDepth);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipRows);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipImages);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipVolumes);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipPixels);
+    __GLX_SWAP_INT((GLbyte *) &hdr->alignment);
+
+    __GLX_SWAP_INT((GLbyte *) &hdr->target);
+    __GLX_SWAP_INT((GLbyte *) &hdr->level);
+    __GLX_SWAP_INT((GLbyte *) &hdr->xoffset);
+    __GLX_SWAP_INT((GLbyte *) &hdr->yoffset);
+    __GLX_SWAP_INT((GLbyte *) &hdr->zoffset);
+    __GLX_SWAP_INT((GLbyte *) &hdr->width);
+    __GLX_SWAP_INT((GLbyte *) &hdr->height);
+    __GLX_SWAP_INT((GLbyte *) &hdr->depth);
+    __GLX_SWAP_INT((GLbyte *) &hdr->size4d);
+    __GLX_SWAP_INT((GLbyte *) &hdr->format);
+    __GLX_SWAP_INT((GLbyte *) &hdr->type);
 
     /*
      ** Just invert swapBytes flag; the GL will figure out if it needs to swap
@@ -281,16 +281,16 @@ __glXDispSwap_ColorTable(GLbyte * pc)
 
     __GLX_DECLARE_SWAP_VARIABLES;
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->rowLength);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipRows);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipPixels);
-    __GLX_SWAP_INT((GLbyte *) & hdr->alignment);
+    __GLX_SWAP_INT((GLbyte *) &hdr->rowLength);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipRows);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipPixels);
+    __GLX_SWAP_INT((GLbyte *) &hdr->alignment);
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->target);
-    __GLX_SWAP_INT((GLbyte *) & hdr->internalformat);
-    __GLX_SWAP_INT((GLbyte *) & hdr->width);
-    __GLX_SWAP_INT((GLbyte *) & hdr->format);
-    __GLX_SWAP_INT((GLbyte *) & hdr->type);
+    __GLX_SWAP_INT((GLbyte *) &hdr->target);
+    __GLX_SWAP_INT((GLbyte *) &hdr->internalformat);
+    __GLX_SWAP_INT((GLbyte *) &hdr->width);
+    __GLX_SWAP_INT((GLbyte *) &hdr->format);
+    __GLX_SWAP_INT((GLbyte *) &hdr->type);
 
     /*
      ** Just invert swapBytes flag; the GL will figure out if it needs to swap
@@ -306,16 +306,16 @@ __glXDispSwap_ColorSubTable(GLbyte * pc)
         (__GLXdispatchColorSubTableHeader *) pc;
     __GLX_DECLARE_SWAP_VARIABLES;
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->rowLength);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipRows);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipPixels);
-    __GLX_SWAP_INT((GLbyte *) & hdr->alignment);
+    __GLX_SWAP_INT((GLbyte *) &hdr->rowLength);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipRows);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipPixels);
+    __GLX_SWAP_INT((GLbyte *) &hdr->alignment);
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->target);
-    __GLX_SWAP_INT((GLbyte *) & hdr->start);
-    __GLX_SWAP_INT((GLbyte *) & hdr->count);
-    __GLX_SWAP_INT((GLbyte *) & hdr->format);
-    __GLX_SWAP_INT((GLbyte *) & hdr->type);
+    __GLX_SWAP_INT((GLbyte *) &hdr->target);
+    __GLX_SWAP_INT((GLbyte *) &hdr->start);
+    __GLX_SWAP_INT((GLbyte *) &hdr->count);
+    __GLX_SWAP_INT((GLbyte *) &hdr->format);
+    __GLX_SWAP_INT((GLbyte *) &hdr->type);
 
     /*
      ** Just invert swapBytes flag; the GL will figure out if it needs to swap
@@ -331,16 +331,16 @@ __glXDispSwap_ConvolutionFilter1D(GLbyte * pc)
         (__GLXdispatchConvolutionFilterHeader *) pc;
     __GLX_DECLARE_SWAP_VARIABLES;
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->rowLength);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipRows);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipPixels);
-    __GLX_SWAP_INT((GLbyte *) & hdr->alignment);
+    __GLX_SWAP_INT((GLbyte *) &hdr->rowLength);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipRows);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipPixels);
+    __GLX_SWAP_INT((GLbyte *) &hdr->alignment);
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->target);
-    __GLX_SWAP_INT((GLbyte *) & hdr->internalformat);
-    __GLX_SWAP_INT((GLbyte *) & hdr->width);
-    __GLX_SWAP_INT((GLbyte *) & hdr->format);
-    __GLX_SWAP_INT((GLbyte *) & hdr->type);
+    __GLX_SWAP_INT((GLbyte *) &hdr->target);
+    __GLX_SWAP_INT((GLbyte *) &hdr->internalformat);
+    __GLX_SWAP_INT((GLbyte *) &hdr->width);
+    __GLX_SWAP_INT((GLbyte *) &hdr->format);
+    __GLX_SWAP_INT((GLbyte *) &hdr->type);
 
     /*
      ** Just invert swapBytes flag; the GL will figure out if it needs to swap
@@ -356,17 +356,17 @@ __glXDispSwap_ConvolutionFilter2D(GLbyte * pc)
         (__GLXdispatchConvolutionFilterHeader *) pc;
     __GLX_DECLARE_SWAP_VARIABLES;
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->rowLength);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipRows);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipPixels);
-    __GLX_SWAP_INT((GLbyte *) & hdr->alignment);
+    __GLX_SWAP_INT((GLbyte *) &hdr->rowLength);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipRows);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipPixels);
+    __GLX_SWAP_INT((GLbyte *) &hdr->alignment);
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->target);
-    __GLX_SWAP_INT((GLbyte *) & hdr->internalformat);
-    __GLX_SWAP_INT((GLbyte *) & hdr->width);
-    __GLX_SWAP_INT((GLbyte *) & hdr->height);
-    __GLX_SWAP_INT((GLbyte *) & hdr->format);
-    __GLX_SWAP_INT((GLbyte *) & hdr->type);
+    __GLX_SWAP_INT((GLbyte *) &hdr->target);
+    __GLX_SWAP_INT((GLbyte *) &hdr->internalformat);
+    __GLX_SWAP_INT((GLbyte *) &hdr->width);
+    __GLX_SWAP_INT((GLbyte *) &hdr->height);
+    __GLX_SWAP_INT((GLbyte *) &hdr->format);
+    __GLX_SWAP_INT((GLbyte *) &hdr->type);
 
     /*
      ** Just invert swapBytes flag; the GL will figure out if it needs to swap
@@ -386,17 +386,17 @@ __glXDispSwap_SeparableFilter2D(GLbyte * pc)
 
     hdrlen = __GLX_PAD(__GLX_CONV_FILT_CMD_HDR_SIZE);
 
-    __GLX_SWAP_INT((GLbyte *) & hdr->rowLength);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipRows);
-    __GLX_SWAP_INT((GLbyte *) & hdr->skipPixels);
-    __GLX_SWAP_INT((GLbyte *) & hdr->alignment);
-
-    __GLX_SWAP_INT((GLbyte *) & hdr->target);
-    __GLX_SWAP_INT((GLbyte *) & hdr->internalformat);
-    __GLX_SWAP_INT((GLbyte *) & hdr->width);
-    __GLX_SWAP_INT((GLbyte *) & hdr->height);
-    __GLX_SWAP_INT((GLbyte *) & hdr->format);
-    __GLX_SWAP_INT((GLbyte *) & hdr->type);
+    __GLX_SWAP_INT((GLbyte *) &hdr->rowLength);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipRows);
+    __GLX_SWAP_INT((GLbyte *) &hdr->skipPixels);
+    __GLX_SWAP_INT((GLbyte *) &hdr->alignment);
+
+    __GLX_SWAP_INT((GLbyte *) &hdr->target);
+    __GLX_SWAP_INT((GLbyte *) &hdr->internalformat);
+    __GLX_SWAP_INT((GLbyte *) &hdr->width);
+    __GLX_SWAP_INT((GLbyte *) &hdr->height);
+    __GLX_SWAP_INT((GLbyte *) &hdr->format);
+    __GLX_SWAP_INT((GLbyte *) &hdr->type);
 
     /*
      ** Just invert swapBytes flag; the GL will figure out if it needs to swap
diff --git a/hw/kdrive/ephyr/XF86dri.c b/hw/kdrive/ephyr/XF86dri.c
index 74bf676..9d742f3 100644
--- a/hw/kdrive/ephyr/XF86dri.c
+++ b/hw/kdrive/ephyr/XF86dri.c
@@ -151,7 +151,7 @@ XF86DRIQueryVersion(Display * dpy, int *majorVersion, int *minorVersion,
     GetReq(XF86DRIQueryVersion, req);
     req->reqType = info->codes->major_opcode;
     req->driReqType = X_XF86DRIQueryVersion;
-    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
+    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
         UnlockDisplay(dpy);
         SyncHandle();
         TRACE("QueryVersion... return False");
@@ -181,7 +181,7 @@ XF86DRIQueryDirectRenderingCapable(Display * dpy, int screen, Bool *isCapable)
     req->reqType = info->codes->major_opcode;
     req->driReqType = X_XF86DRIQueryDirectRenderingCapable;
     req->screen = screen;
-    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
+    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
         UnlockDisplay(dpy);
         SyncHandle();
         TRACE("QueryDirectRenderingCapable... return False");
@@ -210,7 +210,7 @@ XF86DRIOpenConnection(Display * dpy, int screen,
     req->reqType = info->codes->major_opcode;
     req->driReqType = X_XF86DRIOpenConnection;
     req->screen = screen;
-    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
+    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
         UnlockDisplay(dpy);
         SyncHandle();
         TRACE("OpenConnection... return False");
@@ -260,7 +260,7 @@ XF86DRIAuthConnection(Display * dpy, int screen, drm_magic_t magic)
     req->screen = screen;
     req->magic = magic;
     rep.authenticated = 0;
-    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse) || !rep.authenticated) {
+    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse) || !rep.authenticated) {
         UnlockDisplay(dpy);
         SyncHandle();
         TRACE("AuthConnection... return False");
@@ -311,7 +311,7 @@ XF86DRIGetClientDriverName(Display * dpy, int screen,
     req->reqType = info->codes->major_opcode;
     req->driReqType = X_XF86DRIGetClientDriverName;
     req->screen = screen;
-    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
+    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
         UnlockDisplay(dpy);
         SyncHandle();
         TRACE("GetClientDriverName... return False");
@@ -362,7 +362,7 @@ XF86DRICreateContextWithConfig(Display * dpy, int screen, int configID,
     req->screen = screen;
     *context = XAllocID(dpy);
     req->context = *context;
-    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
+    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
         UnlockDisplay(dpy);
         SyncHandle();
         TRACE("CreateContext... return False");
@@ -421,7 +421,7 @@ XF86DRICreateDrawable(Display * dpy, int screen,
     req->driReqType = X_XF86DRICreateDrawable;
     req->screen = screen;
     req->drawable = drawable;
-    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
+    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
         UnlockDisplay(dpy);
         SyncHandle();
         TRACE("CreateDrawable... return False");
@@ -503,7 +503,7 @@ XF86DRIGetDrawableInfo(Display * dpy, int screen, Drawable drawable,
     req->screen = screen;
     req->drawable = drawable;
 
-    if (!_XReply(dpy, (xReply *) & rep, 1, xFalse)) {
+    if (!_XReply(dpy, (xReply *) &rep, 1, xFalse)) {
         UnlockDisplay(dpy);
         SyncHandle();
         TRACE("GetDrawableInfo... return False");
@@ -585,7 +585,7 @@ XF86DRIGetDeviceInfo(Display * dpy, int screen, drm_handle_t * hFrameBuffer,
     req->reqType = info->codes->major_opcode;
     req->driReqType = X_XF86DRIGetDeviceInfo;
     req->screen = screen;
-    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
+    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
         UnlockDisplay(dpy);
         SyncHandle();
         TRACE("GetDeviceInfo... return False");
diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index 1a98a2d..144c6e1 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -754,7 +754,7 @@ ProcXF86DRICreateContext(register ClientPtr client)
     if (!ephyrDRICreateContext(stuff->screen,
                                stuff->visual,
                                &context_id,
-                               (drm_context_t *) & rep.hHWContext)) {
+                               (drm_context_t *) &rep.hHWContext)) {
         return BadValue;
     }
 
@@ -964,7 +964,7 @@ ProcXF86DRICreateDrawable(ClientPtr client)
 
     if (!ephyrDRICreateDrawable(stuff->screen,
                                 remote_win,
-                                (drm_drawable_t *) & rep.hHWDrawable)) {
+                                (drm_drawable_t *) &rep.hHWDrawable)) {
         EPHYR_LOG_ERROR("failed to create dri drawable\n");
         return BadValue;
     }
diff --git a/hw/kdrive/ephyr/ephyrhostglx.c b/hw/kdrive/ephyr/ephyrhostglx.c
index 392489a..5c6c40f 100644
--- a/hw/kdrive/ephyr/ephyrhostglx.c
+++ b/hw/kdrive/ephyr/ephyrhostglx.c
@@ -121,7 +121,7 @@ ephyrHostGLXQueryVersion(int *a_major, int *a_minor)
     req->glxCode = X_GLXQueryVersion;
     req->majorVersion = 2;
     req->minorVersion = 1;
-    _XReply(dpy, (xReply *) & reply, 0, False);
+    _XReply(dpy, (xReply *) &reply, 0, False);
     UnlockDisplay(dpy);
     SyncHandle();
 
@@ -207,7 +207,7 @@ ephyrHostGLXGetStringFromServer(int a_screen_number,
     req->for_whom = default_screen;
     req->name = a_string_name;
 
-    _XReply(dpy, (xReply *) & reply, 0, False);
+    _XReply(dpy, (xReply *) &reply, 0, False);
 
     length = reply.length * 4;
     if (!length) {
@@ -303,7 +303,7 @@ ephyrHostGLXGetVisualConfigsInternal(enum VisualConfRequestType a_type,
         break;
     }
 
-    if (!_XReply(dpy, (xReply *) & reply, 0, False)) {
+    if (!_XReply(dpy, (xReply *) &reply, 0, False)) {
         EPHYR_LOG_ERROR("unknown error\n");
         UnlockDisplay(dpy);
         goto out;
@@ -615,7 +615,7 @@ ephyrHostGLXMakeCurrent(int a_drawable, int a_readable,
     }
 
     memset(&reply, 0, sizeof(reply));
-    if (!_XReply(dpy, (xReply *) & reply, 0, False)) {
+    if (!_XReply(dpy, (xReply *) &reply, 0, False)) {
         EPHYR_LOG_ERROR("failed to get reply from host\n");
         UnlockDisplay(dpy);
         SyncHandle();
@@ -735,7 +735,7 @@ ephyrHostIsContextDirect(int a_ctxt_id, int *a_is_direct)
     req->reqType = major_opcode;
     req->glxCode = X_GLXIsDirect;
     req->context = remote_glx_ctxt_id;
-    if (!_XReply(dpy, (xReply *) & reply, 0, False)) {
+    if (!_XReply(dpy, (xReply *) &reply, 0, False)) {
         EPHYR_LOG_ERROR("fail in reading reply from host\n");
         UnlockDisplay(dpy);
         SyncHandle();
diff --git a/hw/kdrive/ephyr/ephyrhostproxy.c b/hw/kdrive/ephyr/ephyrhostproxy.c
index 410e6b6..a4f25c1 100644
--- a/hw/kdrive/ephyr/ephyrhostproxy.c
+++ b/hw/kdrive/ephyr/ephyrhostproxy.c
@@ -73,7 +73,7 @@ ephyrHostProxyDoForward(pointer a_request_buffer,
     GetXReq(forward_req);
     memmove(forward_req, in_req, 4);
 
-    if (!_XReply(dpy, (xReply *) & reply, 0, FALSE)) {
+    if (!_XReply(dpy, (xReply *) &reply, 0, FALSE)) {
         EPHYR_LOG_ERROR("failed to get reply\n");
         goto out;
     }
diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index 05a821b..362aa05 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -304,7 +304,7 @@ ephyrHostXVAdaptorArrayAt(const EphyrHostXVAdaptorArray * a_this, int a_index)
 
     if (a_index >= a_this->nb_adaptors)
         return NULL;
-    return (EphyrHostXVAdaptor *) & a_this->adaptors[a_index];
+    return (EphyrHostXVAdaptor *) &a_this->adaptors[a_index];
 }
 
 char
@@ -668,7 +668,7 @@ ephyrHostXVQueryImageAttributes(int a_port_id,
     /*
      * read the reply
      */
-    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
+    if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) {
         EPHYR_LOG_ERROR("QeryImageAttribute req failed\n");
         goto out;
     }
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index 67eadd1..55dbd2e 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -495,7 +495,7 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this)
         port_priv_offset = a_this->adaptors[i].nPorts;
         for (j = 0; j < a_this->adaptors[i].nPorts; j++) {
             EphyrPortPriv *port_privs_base =
-                (EphyrPortPriv *) & a_this->adaptors[i].
+                (EphyrPortPriv *) &a_this->adaptors[i].
                 pPortPrivates[port_priv_offset];
             EphyrPortPriv *port_priv = &port_privs_base[j];
 
diff --git a/hw/xfree86/common/xf86cmap.c b/hw/xfree86/common/xf86cmap.c
index 25f84e5..85f35f8 100644
--- a/hw/xfree86/common/xf86cmap.c
+++ b/hw/xfree86/common/xf86cmap.c
@@ -608,7 +608,7 @@ CMapRefreshColors(ColormapPtr pmap, int defs, int *indices)
     case GrayScale:
         for (i = 0; i < defs; i++) {
             index = indices[i];
-            entry = (EntryPtr) & pmap->red[index];
+            entry = (EntryPtr) &pmap->red[index];
 
             if (entry->fShared) {
                 colors[index].red =
diff --git a/hw/xfree86/dri/xf86dri.c b/hw/xfree86/dri/xf86dri.c
index 0b2e8fa..086e833 100644
--- a/hw/xfree86/dri/xf86dri.c
+++ b/hw/xfree86/dri/xf86dri.c
@@ -280,7 +280,7 @@ ProcXF86DRICreateContext(register ClientPtr client)
 
     if (!DRICreateContext(pScreen,
                           NULL,
-                          stuff->context, (drm_context_t *) & rep.hHWContext)) {
+                          stuff->context, (drm_context_t *) &rep.hHWContext)) {
         return BadValue;
     }
 
@@ -329,7 +329,7 @@ ProcXF86DRICreateDrawable(ClientPtr client)
         return rc;
 
     if (!DRICreateDrawable(screenInfo.screens[stuff->screen], client,
-                           pDrawable, (drm_drawable_t *) & rep.hHWDrawable)) {
+                           pDrawable, (drm_drawable_t *) &rep.hHWDrawable)) {
         return BadValue;
     }
 
diff --git a/hw/xfree86/i2c/fi1236.c b/hw/xfree86/i2c/fi1236.c
index 282fe7e..2eb27ba 100644
--- a/hw/xfree86/i2c/fi1236.c
+++ b/hw/xfree86/i2c/fi1236.c
@@ -91,7 +91,7 @@ MT2032_getid(FI1236Ptr f)
     CARD8 in;
 
     in = 0x11;
-    I2C_WriteRead(&(f->d), (I2CByte *) & in, 1, out, 4);
+    I2C_WriteRead(&(f->d), (I2CByte *) &in, 1, out, 4);
     xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
                "MT2032: Company code 0x%02x%02x, part code 0x%02x, revision code 0x%02x\n",
                out[0], out[1], out[2], out[3]);
@@ -432,7 +432,7 @@ MT2032_get_afc_hint(FI1236Ptr f)
     CARD8 AFC;
 
     in = 0x0e;
-    I2C_WriteRead(&(f->d), (I2CByte *) & in, 1, out, 2);
+    I2C_WriteRead(&(f->d), (I2CByte *) &in, 1, out, 2);
     AFC = (out[0] >> 4) & 0x7;
 #if 0
     xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO, "AFC=%d TAD1=%d TAD2=%d\n",
@@ -467,7 +467,7 @@ MT2032_dump_status(FI1236Ptr f)
     CARD8 TAD2, TAD1;
 
     in = 0x0e;
-    I2C_WriteRead(&(f->d), (I2CByte *) & in, 1, out, 2);
+    I2C_WriteRead(&(f->d), (I2CByte *) &in, 1, out, 2);
     XOK = out[0] & 1;
     LO1LK = (out[0] >> 2) & 1;
     LO2LK = (out[0] >> 1) & 1;
@@ -589,12 +589,12 @@ FI1236_tune(FI1236Ptr f, CARD32 frequency)
 
     if ((f->type == TUNER_TYPE_FM1216ME) || (f->type == TUNER_TYPE_FI1236W)) {
         f->tuner_data.aux = 0x20;
-        I2C_WriteRead(&(f->d), (I2CByte *) & (f->tuner_data), 5, NULL, 0);
+        I2C_WriteRead(&(f->d), (I2CByte *) &(f->tuner_data), 5, NULL, 0);
         I2C_WriteRead(&(f->d), NULL, 0, &data, 1);
         xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO, "Tuner status %x\n", data);
     }
     else
-        I2C_WriteRead(&(f->d), (I2CByte *) & (f->tuner_data), 4, NULL, 0);
+        I2C_WriteRead(&(f->d), (I2CByte *) &(f->tuner_data), 4, NULL, 0);
 }
 
 void
diff --git a/hw/xfree86/i2c/tda9850.c b/hw/xfree86/i2c/tda9850.c
index c2ce697..d258bda 100644
--- a/hw/xfree86/i2c/tda9850.c
+++ b/hw/xfree86/i2c/tda9850.c
@@ -131,6 +131,6 @@ tda9850_getstatus(TDA9850Ptr t)
 {
     CARD16 status;
 
-    I2C_WriteRead(&(t->d), NULL, 0, (I2CByte *) & status, 2);
+    I2C_WriteRead(&(t->d), NULL, 0, (I2CByte *) &status, 2);
     return status;
 }
diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c
index 78ff74f..04c17b7 100644
--- a/hw/xwin/InitOutput.c
+++ b/hw/xwin/InitOutput.c
@@ -1042,7 +1042,7 @@ winCheckDisplayNumber(void)
                       NULL,
                       GetLastError(),
                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                      (LPTSTR) & lpMsgBuf, 0, NULL);
+                      (LPTSTR) &lpMsgBuf, 0, NULL);
         ErrorF("winCheckDisplayNumber - CreateMutex failed: %s\n",
                (LPSTR) lpMsgBuf);
         LocalFree(lpMsgBuf);
diff --git a/hw/xwin/glx/indirect.c b/hw/xwin/glx/indirect.c
index 22c5abc..00cef36 100644
--- a/hw/xwin/glx/indirect.c
+++ b/hw/xwin/glx/indirect.c
@@ -224,7 +224,7 @@ glxWinErrorMessage(void)
     if (!FormatMessage
         (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
          FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, last_error, 0,
-         (LPTSTR) & errorbuffer, sizeof(errorbuffer), NULL)) {
+         (LPTSTR) &errorbuffer, sizeof(errorbuffer), NULL)) {
         snprintf(errorbuffer, sizeof(errorbuffer), "Unknown error");
     }
 
@@ -1370,7 +1370,7 @@ glxWinDeferredCreateContext(__GLXWinContext * gc, __GLXWinDrawable * draw)
             }
 
             draw->hDIB =
-                CreateDIBSection(draw->dibDC, (BITMAPINFO *) & bmpHeader,
+                CreateDIBSection(draw->dibDC, (BITMAPINFO *) &bmpHeader,
                                  DIB_RGB_COLORS, &pBits, 0, 0);
             if (draw->dibDC == NULL) {
                 ErrorF("CreateDIBSection error: %s\n", glxWinErrorMessage());
diff --git a/hw/xwin/winclipboardxevents.c b/hw/xwin/winclipboardxevents.c
index 5cae98c..226c3f0 100644
--- a/hw/xwin/winclipboardxevents.c
+++ b/hw/xwin/winclipboardxevents.c
@@ -157,7 +157,7 @@ winClipboardFlushXEvents(HWND hwnd,
                  */
                 iReturn = XSendEvent(pDisplay,
                                      eventSelection.requestor,
-                                     False, 0L, (XEvent *) & eventSelection);
+                                     False, 0L, (XEvent *) &eventSelection);
                 if (iReturn == BadValue || iReturn == BadWindow) {
                     ErrorF("winClipboardFlushXEvents - SelectionRequest - "
                            "XSendEvent () failed\n");
@@ -341,7 +341,7 @@ winClipboardFlushXEvents(HWND hwnd,
             /* Notify the requesting window that the operation has completed */
             iReturn = XSendEvent(pDisplay,
                                  eventSelection.requestor,
-                                 False, 0L, (XEvent *) & eventSelection);
+                                 False, 0L, (XEvent *) &eventSelection);
             if (iReturn == BadValue || iReturn == BadWindow) {
                 ErrorF("winClipboardFlushXEvents - SelectionRequest - "
                        "XSendEvent () failed\n");
@@ -380,7 +380,7 @@ winClipboardFlushXEvents(HWND hwnd,
                 /* Notify the requesting window that the operation is complete */
                 iReturn = XSendEvent(pDisplay,
                                      eventSelection.requestor,
-                                     False, 0L, (XEvent *) & eventSelection);
+                                     False, 0L, (XEvent *) &eventSelection);
                 if (iReturn == BadValue || iReturn == BadWindow) {
                     /*
                      * Should not be a problem if XSendEvent fails because
diff --git a/hw/xwin/wincursor.c b/hw/xwin/wincursor.c
index b5ea0db..2962d06 100644
--- a/hw/xwin/wincursor.c
+++ b/hw/xwin/wincursor.c
@@ -104,7 +104,7 @@ winPointerWarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
 
         /* Translate the client area coords to screen coords */
         MapWindowPoints(pScreenPriv->hwndScreen,
-                        HWND_DESKTOP, (LPPOINT) & rcClient, 2);
+                        HWND_DESKTOP, (LPPOINT) &rcClient, 2);
 
         /* 
          * Update the Windows cursor position so that we don't
@@ -275,7 +275,7 @@ winLoadCursor(ScreenPtr pScreen, CursorPtr pCursor, int screen)
     if (!lpBits) {
         /* Bicolor, use a palettized DIB */
         WIN_DEBUG_MSG("winLoadCursor: Trying two color cursor\n");
-        pbmi = (BITMAPINFO *) & bi;
+        pbmi = (BITMAPINFO *) &bi;
         memset(pbmi, 0, sizeof(BITMAPINFOHEADER));
         pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
         pbmi->bmiHeader.biWidth = pScreenPriv->cursor.sm_cx;
@@ -358,7 +358,7 @@ winLoadCursor(ScreenPtr pScreen, CursorPtr pCursor, int screen)
                 CreateCompatibleBitmap(hDC, pScreenPriv->cursor.sm_cx,
                                        pScreenPriv->cursor.sm_cy);
             SetDIBits(hDC, hXor, 0, pScreenPriv->cursor.sm_cy, lpBits,
-                      (BITMAPINFO *) & bi, DIB_RGB_COLORS);
+                      (BITMAPINFO *) &bi, DIB_RGB_COLORS);
             ReleaseDC(NULL, hDC);
         }
         free(lpBits);
diff --git a/hw/xwin/winengine.c b/hw/xwin/winengine.c
index b2007d7..1f55ada 100644
--- a/hw/xwin/winengine.c
+++ b/hw/xwin/winengine.c
@@ -108,7 +108,7 @@ winDetectSupportedEngines(void)
         /* Try to query for DirectDraw4 interface */
         ddrval = IDirectDraw_QueryInterface(lpdd,
                                             &IID_IDirectDraw4,
-                                            (LPVOID *) & lpdd4);
+                                            (LPVOID *) &lpdd4);
         if (SUCCEEDED(ddrval)) {
             /* We have DirectDraw4 */
             winErrorFVerb(2,
diff --git a/hw/xwin/wingc.c b/hw/xwin/wingc.c
index 7ac305d..814d531 100644
--- a/hw/xwin/wingc.c
+++ b/hw/xwin/wingc.c
@@ -130,8 +130,8 @@ winCreateGCNativeGDI(GCPtr pGC)
     ErrorF("winCreateGCNativeGDI - depth: %d\n", pGC->depth);
 #endif
 
-    pGC->ops = (GCOps *) & winGCOps;
-    pGC->funcs = (GCFuncs *) & winGCFuncs;
+    pGC->ops = (GCOps *) &winGCOps;
+    pGC->funcs = (GCFuncs *) &winGCFuncs;
 
     /* We want all coordinates passed to spans functions to be screen relative */
     pGC->miTranslate = TRUE;
diff --git a/hw/xwin/winmsg.c b/hw/xwin/winmsg.c
index 57c1d18..56e7a09 100644
--- a/hw/xwin/winmsg.c
+++ b/hw/xwin/winmsg.c
@@ -137,7 +137,7 @@ winW32ErrorEx(int verb, const char *msg, DWORD errorcode)
                        NULL,
                        errorcode,
                        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                       (LPTSTR) & buffer, 0, NULL)) {
+                       (LPTSTR) &buffer, 0, NULL)) {
         winErrorFVerb(verb, "Unknown error in FormatMessage!\n");
     }
     else {
diff --git a/hw/xwin/winmultiwindowicons.c b/hw/xwin/winmultiwindowicons.c
index b8357e7..0322d98 100644
--- a/hw/xwin/winmultiwindowicons.c
+++ b/hw/xwin/winmultiwindowicons.c
@@ -253,7 +253,7 @@ NetWMToWinIconAlpha(uint32_t * icon)
     ii.fIcon = TRUE;
     ii.xHotspot = 0;            /* ignored */
     ii.yHotspot = 0;            /* ignored */
-    ii.hbmColor = CreateDIBSection(hdc, (BITMAPINFO *) & bmh,
+    ii.hbmColor = CreateDIBSection(hdc, (BITMAPINFO *) &bmh,
                                    DIB_RGB_COLORS, (void **) &DIB_pixels, NULL,
                                    0);
     ReleaseDC(NULL, hdc);
diff --git a/hw/xwin/winmultiwindowshape.c b/hw/xwin/winmultiwindowshape.c
index d5200cd..cb0f389 100644
--- a/hw/xwin/winmultiwindowshape.c
+++ b/hw/xwin/winmultiwindowshape.c
@@ -137,7 +137,7 @@ winReshapeMultiWindow(WindowPtr pWin)
 
         /* Translate client rectangle coords to screen coords */
         /* NOTE: Only transforms top and left members */
-        ClientToScreen(pWinPriv->hWnd, (LPPOINT) & rcClient);
+        ClientToScreen(pWinPriv->hWnd, (LPPOINT) &rcClient);
 
         /* Get window rectangle */
         if (!GetWindowRect(pWinPriv->hWnd, &rcWindow)) {
diff --git a/hw/xwin/winmultiwindowwndproc.c b/hw/xwin/winmultiwindowwndproc.c
index 4180a3a..c2292c6 100644
--- a/hw/xwin/winmultiwindowwndproc.c
+++ b/hw/xwin/winmultiwindowwndproc.c
@@ -498,7 +498,7 @@ winTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                           NULL,
                           GetLastError(),
                           MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                          (LPTSTR) & lpMsgBuf, 0, NULL);
+                          (LPTSTR) &lpMsgBuf, 0, NULL);
 
             ErrorF("winTopLevelWindowProc - BitBlt failed: %s\n",
                    (LPSTR) lpMsgBuf);
diff --git a/hw/xwin/winpfbdd.c b/hw/xwin/winpfbdd.c
index 0fd0efe..ee6ea72 100644
--- a/hw/xwin/winpfbdd.c
+++ b/hw/xwin/winpfbdd.c
@@ -78,7 +78,7 @@ winAllocateFBPrimaryDD(ScreenPtr pScreen)
     /* Get client area location in screen coords */
     GetClientRect(pScreenPriv->hwndScreen, &rcClient);
     MapWindowPoints(pScreenPriv->hwndScreen,
-                    HWND_DESKTOP, (LPPOINT) & rcClient, 2);
+                    HWND_DESKTOP, (LPPOINT) &rcClient, 2);
 
     /* Create a DirectDraw object, store the address at lpdd */
     ddrval = (*g_fpDirectDrawCreate) (NULL, &pScreenPriv->pdd, NULL);
@@ -88,7 +88,7 @@ winAllocateFBPrimaryDD(ScreenPtr pScreen)
     /* Get a DirectDraw2 interface pointer */
     ddrval = IDirectDraw_QueryInterface(pScreenPriv->pdd,
                                         &IID_IDirectDraw2,
-                                        (LPVOID *) & pScreenPriv->pdd2);
+                                        (LPVOID *) &pScreenPriv->pdd2);
     if (FAILED(ddrval)) {
         ErrorF("winAllocateFBShadowDD - Failed DD2 query: %08x\n",
                (unsigned int) ddrval);
@@ -465,7 +465,7 @@ winActivateAppPrimaryDD(ScreenPtr pScreen)
     /* Get client area in screen coords */
     GetClientRect(pScreenPriv->hwndScreen, &rcClient);
     MapWindowPoints(pScreenPriv->hwndScreen,
-                    HWND_DESKTOP, (LPPOINT) & rcClient, 2);
+                    HWND_DESKTOP, (LPPOINT) &rcClient, 2);
 
     /* Setup a source rectangle */
     rcSrc.left = 0;
@@ -530,7 +530,7 @@ winHotKeyAltTabPrimaryDD(ScreenPtr pScreen)
     /* Get client area in screen coords */
     GetClientRect(pScreenPriv->hwndScreen, &rcClient);
     MapWindowPoints(pScreenPriv->hwndScreen,
-                    HWND_DESKTOP, (LPPOINT) & rcClient, 2);
+                    HWND_DESKTOP, (LPPOINT) &rcClient, 2);
 
     /* Did we loose the primary surface? */
     ddrval = IDirectDrawSurface2_IsLost(pScreenPriv->pddsPrimary);
diff --git a/hw/xwin/winpixmap.c b/hw/xwin/winpixmap.c
index cb8ba91..d8a12d5 100644
--- a/hw/xwin/winpixmap.c
+++ b/hw/xwin/winpixmap.c
@@ -109,7 +109,7 @@ winCreatePixmapNativeGDI(ScreenPtr pScreen,
     /* Create a DIB for the pixmap */
     pPixmapPriv->hBitmap = winCreateDIBNativeGDI(iWidth, iHeight, iDepth,
                                                  &pPixmapPriv->pbBits,
-                                                 (BITMAPINFO **) & pPixmapPriv->
+                                                 (BITMAPINFO **) &pPixmapPriv->
                                                  pbmih);
 
 #if CYGDEBUG
diff --git a/hw/xwin/winscrinit.c b/hw/xwin/winscrinit.c
index 639a99c..e776bdb 100644
--- a/hw/xwin/winscrinit.c
+++ b/hw/xwin/winscrinit.c
@@ -550,7 +550,7 @@ winFinishScreenInitFB(int i, ScreenPtr pScreen, int argc, char **argv)
                        &pScreenPriv->ptWMProc,
                        &pScreenPriv->ptXMsgProc,
                        &pScreenPriv->pmServerStarted,
-                       pScreenInfo->dwScreen, (HWND) & pScreenPriv->hwndScreen,
+                       pScreenInfo->dwScreen, (HWND) &pScreenPriv->hwndScreen,
 #ifdef XWIN_MULTIWINDOWEXTWM
                        pScreenInfo->fInternalWM ||
 #endif
diff --git a/hw/xwin/winsetsp.c b/hw/xwin/winsetsp.c
index 8f75991..f102f9f 100644
--- a/hw/xwin/winsetsp.c
+++ b/hw/xwin/winsetsp.c
@@ -107,7 +107,7 @@ winSetSpansNativeGDI(DrawablePtr pDrawable,
                           0, 0,
                           *piWidths, 1,
                           pSrcs,
-                          (BITMAPINFO *) & bmi,
+                          (BITMAPINFO *) &bmi,
                           DIB_RGB_COLORS, g_copyROP[pGC->alu]);
 
             pSrcs += PixmapBytePad(*piWidths, pDrawable->depth);
@@ -150,7 +150,7 @@ winSetSpansNativeGDI(DrawablePtr pDrawable,
                           0, 0,
                           *piWidths, 1,
                           pSrcs,
-                          (BITMAPINFO *) & bmi,
+                          (BITMAPINFO *) &bmi,
                           DIB_RGB_COLORS, g_copyROP[pGC->alu]);
 
             pSrcs += PixmapBytePad(*piWidths, pDrawable->depth);
diff --git a/hw/xwin/winshaddd.c b/hw/xwin/winshaddd.c
index aad3a02..2e70608 100644
--- a/hw/xwin/winshaddd.c
+++ b/hw/xwin/winshaddd.c
@@ -232,7 +232,7 @@ winAllocateFBShadowDD(ScreenPtr pScreen)
     /* Get a DirectDraw2 interface pointer */
     ddrval = IDirectDraw_QueryInterface(pScreenPriv->pdd,
                                         &IID_IDirectDraw2,
-                                        (LPVOID *) & pScreenPriv->pdd2);
+                                        (LPVOID *) &pScreenPriv->pdd2);
     if (FAILED(ddrval)) {
         ErrorF("winAllocateFBShadowDD - Failed DD2 query: %08x\n",
                (unsigned int) ddrval);
@@ -507,7 +507,7 @@ winShadowUpdateDD(ScreenPtr pScreen, shadowBufPtr pBuf)
     ptOrigin.x = pScreenInfo->dwXOffset;
     ptOrigin.y = pScreenInfo->dwYOffset;
     MapWindowPoints(pScreenPriv->hwndScreen,
-                    HWND_DESKTOP, (LPPOINT) & ptOrigin, 1);
+                    HWND_DESKTOP, (LPPOINT) &ptOrigin, 1);
 
     /* Unlock the shadow surface, so we can blit */
     ddrval = IDirectDrawSurface2_Unlock(pScreenPriv->pddsShadow, NULL);
@@ -853,7 +853,7 @@ winBltExposedRegionsShadowDD(ScreenPtr pScreen)
     ptOrigin.y = pScreenInfo->dwYOffset;
 
     MapWindowPoints(pScreenPriv->hwndScreen,
-                    HWND_DESKTOP, (LPPOINT) & ptOrigin, 1);
+                    HWND_DESKTOP, (LPPOINT) &ptOrigin, 1);
     rcDest.left = ptOrigin.x;
     rcDest.right = ptOrigin.x + pScreenInfo->dwWidth;
     rcDest.top = ptOrigin.y;
@@ -996,7 +996,7 @@ winRedrawScreenShadowDD(ScreenPtr pScreen)
     ptOrigin.x = pScreenInfo->dwXOffset;
     ptOrigin.y = pScreenInfo->dwYOffset;
     MapWindowPoints(pScreenPriv->hwndScreen,
-                    HWND_DESKTOP, (LPPOINT) & ptOrigin, 1);
+                    HWND_DESKTOP, (LPPOINT) &ptOrigin, 1);
     rcDest.left = ptOrigin.x;
     rcDest.right = ptOrigin.x + pScreenInfo->dwWidth;
     rcDest.top = ptOrigin.y;
diff --git a/hw/xwin/winshadddnl.c b/hw/xwin/winshadddnl.c
index 7668bd1..01097f2 100644
--- a/hw/xwin/winshadddnl.c
+++ b/hw/xwin/winshadddnl.c
@@ -249,7 +249,7 @@ winAllocateFBShadowDDNL(ScreenPtr pScreen)
 
     /* Create a DirectDraw object, store the address at lpdd */
     ddrval = (*g_fpDirectDrawCreate) (NULL,
-                                      (LPDIRECTDRAW *) & pScreenPriv->pdd,
+                                      (LPDIRECTDRAW *) &pScreenPriv->pdd,
                                       NULL);
     if (FAILED(ddrval)) {
         ErrorF("winAllocateFBShadowDDNL - Could not start "
@@ -264,7 +264,7 @@ winAllocateFBShadowDDNL(ScreenPtr pScreen)
     /* Get a DirectDraw4 interface pointer */
     ddrval = IDirectDraw_QueryInterface(pScreenPriv->pdd,
                                         &IID_IDirectDraw4,
-                                        (LPVOID *) & pScreenPriv->pdd4);
+                                        (LPVOID *) &pScreenPriv->pdd4);
     if (FAILED(ddrval)) {
         ErrorF("winAllocateFBShadowDDNL - Failed DD4 query: %08x\n",
                (unsigned int) ddrval);
@@ -541,7 +541,7 @@ winShadowUpdateDDNL(ScreenPtr pScreen, shadowBufPtr pBuf)
     ptOrigin.x = pScreenInfo->dwXOffset;
     ptOrigin.y = pScreenInfo->dwYOffset;
     MapWindowPoints(pScreenPriv->hwndScreen,
-                    HWND_DESKTOP, (LPPOINT) & ptOrigin, 1);
+                    HWND_DESKTOP, (LPPOINT) &ptOrigin, 1);
 
     /*
      * Handle small regions with multiple blits,
@@ -880,7 +880,7 @@ winBltExposedRegionsShadowDDNL(ScreenPtr pScreen)
     ptOrigin.y = pScreenInfo->dwYOffset;
 
     MapWindowPoints(pScreenPriv->hwndScreen,
-                    HWND_DESKTOP, (LPPOINT) & ptOrigin, 1);
+                    HWND_DESKTOP, (LPPOINT) &ptOrigin, 1);
     rcDest.left = ptOrigin.x;
     rcDest.right = ptOrigin.x + pScreenInfo->dwWidth;
     rcDest.top = ptOrigin.y;
@@ -990,7 +990,7 @@ winRedrawScreenShadowDDNL(ScreenPtr pScreen)
     ptOrigin.x = pScreenInfo->dwXOffset;
     ptOrigin.y = pScreenInfo->dwYOffset;
     MapWindowPoints(pScreenPriv->hwndScreen,
-                    HWND_DESKTOP, (LPPOINT) & ptOrigin, 1);
+                    HWND_DESKTOP, (LPPOINT) &ptOrigin, 1);
     rcDest.left = ptOrigin.x;
     rcDest.right = ptOrigin.x + pScreenInfo->dwWidth;
     rcDest.top = ptOrigin.y;
diff --git a/hw/xwin/winshadgdi.c b/hw/xwin/winshadgdi.c
index 912f7e4..ebc2339 100644
--- a/hw/xwin/winshadgdi.c
+++ b/hw/xwin/winshadgdi.c
@@ -337,7 +337,7 @@ winAllocateFBShadowGDI(ScreenPtr pScreen)
     pScreenPriv->hbmpShadow = CreateDIBSection(pScreenPriv->hdcScreen,
                                                (BITMAPINFO *) pScreenPriv->
                                                pbmih, DIB_RGB_COLORS,
-                                               (VOID **) & pScreenInfo->pfb,
+                                               (VOID **) &pScreenInfo->pfb,
                                                NULL, 0);
     if (pScreenPriv->hbmpShadow == NULL || pScreenInfo->pfb == NULL) {
         winW32Error(2, "winAllocateFBShadowGDI - CreateDIBSection failed:");
diff --git a/hw/xwin/winwin32rootless.c b/hw/xwin/winwin32rootless.c
index 9743092..210fea3 100644
--- a/hw/xwin/winwin32rootless.c
+++ b/hw/xwin/winwin32rootless.c
@@ -634,7 +634,7 @@ winMWExtWMReshapeFrame(RootlessFrameID wid, RegionPtr pShape)
     /* Create region for non-client area */
     GetWindowRect(pRLWinPriv->hWnd, &rcWindow);
     GetClientRect(pRLWinPriv->hWnd, &rcClient);
-    MapWindowPoints(pRLWinPriv->hWnd, HWND_DESKTOP, (LPPOINT) & rcClient, 2);
+    MapWindowPoints(pRLWinPriv->hWnd, HWND_DESKTOP, (LPPOINT) &rcClient, 2);
     OffsetRgn(hRgn, rcClient.left - rcWindow.left, rcClient.top - rcWindow.top);
     OffsetRect(&rcClient, -rcWindow.left, -rcWindow.top);
     OffsetRect(&rcWindow, -rcWindow.left, -rcWindow.top);
@@ -725,7 +725,7 @@ winMWExtWMStartDrawing(RootlessFrameID wid, char **pixelData, int *bytesPerRow)
             hbmpNew = CreateDIBSection(pRLWinPriv->hdcScreen,
                                        (BITMAPINFO *) pRLWinPriv->pbmihShadow,
                                        DIB_RGB_COLORS,
-                                       (VOID **) & pRLWinPriv->pfb, NULL, 0);
+                                       (VOID **) &pRLWinPriv->pfb, NULL, 0);
             if (hbmpNew == NULL || pRLWinPriv->pfb == NULL) {
                 ErrorF("winMWExtWMStartDrawing - CreateDIBSection failed\n");
                 //return FALSE;
@@ -883,7 +883,7 @@ winMWExtWMUpdateRegion(RootlessFrameID wid, RegionPtr pDamage)
                       NULL,
                       GetLastError(),
                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                      (LPTSTR) & lpMsgBuf, 0, NULL);
+                      (LPTSTR) &lpMsgBuf, 0, NULL);
 
         ErrorF("winMWExtWMUpdateRegion - UpdateLayeredWindow failed: %s\n",
                (LPSTR) lpMsgBuf);
diff --git a/hw/xwin/winwin32rootlesswndproc.c b/hw/xwin/winwin32rootlesswndproc.c
index 436f9ed..13df186 100644
--- a/hw/xwin/winwin32rootlesswndproc.c
+++ b/hw/xwin/winwin32rootlesswndproc.c
@@ -780,7 +780,7 @@ winMWExtWMWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                           NULL,
                           GetLastError(),
                           MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                          (LPTSTR) & lpMsgBuf, 0, NULL);
+                          (LPTSTR) &lpMsgBuf, 0, NULL);
 
             ErrorF("winMWExtWMWindowProc - BitBlt failed: %s\n",
                    (LPSTR) lpMsgBuf);
@@ -1058,7 +1058,7 @@ winMWExtWMWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
             if (!pRLWinPriv->fMovingOrSizing
                 /*&& (pWinPos->flags & SWP_SHOWWINDOW) */ ) {
                 GetClientRect(hwnd, &rcClient);
-                MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT) & rcClient, 2);
+                MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT) &rcClient, 2);
 
                 if (!(pWinPos->flags & SWP_NOMOVE)
                     && !(pWinPos->flags & SWP_NOSIZE)) {
@@ -1263,7 +1263,7 @@ winMWExtWMWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
         GetClientRect(hwnd, &rcClient);
 
-        MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT) & rcClient, 2);
+        MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT) &rcClient, 2);
 
         if (winIsInternalWMRunning(pScreenInfo))
             winAdjustXWindow(pWin, hwnd);
diff --git a/os/access.c b/os/access.c
index 104b6a7..88a44d9 100644
--- a/os/access.c
+++ b/os/access.c
@@ -471,7 +471,7 @@ in6_fillscopeid(struct sockaddr_in6 *sin6)
 #if defined(__KAME__)
     if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
         sin6->sin6_scope_id =
-            ntohs(*(u_int16_t *) & sin6->sin6_addr.s6_addr[2]);
+            ntohs(*(u_int16_t *) &sin6->sin6_addr.s6_addr[2]);
         sin6->sin6_addr.s6_addr[2] = sin6->sin6_addr.s6_addr[3] = 0;
     }
 #endif
diff --git a/os/utils.c b/os/utils.c
index 6f75c17..e396ba4 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -1639,7 +1639,7 @@ System(const char *cmdline)
                            NULL,
                            GetLastError(),
                            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                           (LPTSTR) & buffer, 0, NULL)) {
+                           (LPTSTR) &buffer, 0, NULL)) {
             ErrorF("[xkb] Starting '%s' failed!\n", cmdline);
         }
         else {
diff --git a/os/xdmcp.c b/os/xdmcp.c
index 87f04b4..0538ac5 100644
--- a/os/xdmcp.c
+++ b/os/xdmcp.c
@@ -751,7 +751,7 @@ receive_packet(int socketfd)
     XdmcpHeader header;
 
     /* read message off socket */
-    if (!XdmcpFill(socketfd, &buffer, (XdmcpNetaddr) & from, &fromlen))
+    if (!XdmcpFill(socketfd, &buffer, (XdmcpNetaddr) &from, &fromlen))
         return;
 
     /* reset retransmission backoff */
@@ -1059,7 +1059,7 @@ send_query_msg(void)
 
         for (i = 0; i < NumBroadcastAddresses; i++)
             XdmcpFlush(xdmcpSocket, &buffer,
-                       (XdmcpNetaddr) & BroadcastAddresses[i],
+                       (XdmcpNetaddr) &BroadcastAddresses[i],
                        sizeof(struct sockaddr_in));
     }
 #if defined(IPv6) && defined(AF_INET6)
@@ -1098,7 +1098,7 @@ send_query_msg(void)
         if (SOCKADDR_FAMILY(ManagerAddress) == AF_INET6)
             socketfd = xdmcpSocket6;
 #endif
-        XdmcpFlush(socketfd, &buffer, (XdmcpNetaddr) & ManagerAddress,
+        XdmcpFlush(socketfd, &buffer, (XdmcpNetaddr) &ManagerAddress,
                    ManagerAddressLen);
     }
 }
@@ -1223,7 +1223,7 @@ send_request_msg(void)
         socketfd = xdmcpSocket6;
 #endif
     if (XdmcpFlush(socketfd, &buffer,
-                   (XdmcpNetaddr) & req_sockaddr, req_socklen))
+                   (XdmcpNetaddr) &req_sockaddr, req_socklen))
         state = XDM_AWAIT_REQUEST_RESPONSE;
 }
 
@@ -1316,7 +1316,7 @@ send_manage_msg(void)
     if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6)
         socketfd = xdmcpSocket6;
 #endif
-    XdmcpFlush(socketfd, &buffer, (XdmcpNetaddr) & req_sockaddr, req_socklen);
+    XdmcpFlush(socketfd, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen);
 }
 
 static void
@@ -1373,7 +1373,7 @@ send_keepalive_msg(void)
     if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6)
         socketfd = xdmcpSocket6;
 #endif
-    XdmcpFlush(socketfd, &buffer, (XdmcpNetaddr) & req_sockaddr, req_socklen);
+    XdmcpFlush(socketfd, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen);
 }
 
 static void
diff --git a/test/input.c b/test/input.c
index 191c817..be988a4 100644
--- a/test/input.c
+++ b/test/input.c
@@ -406,7 +406,7 @@ _dix_test_xi_convert(DeviceEvent *ev, int expected_rc, int expected_count)
         assert(kbp->same_screen == FALSE);
 
         while (--count > 0) {
-            deviceValuator *v = (deviceValuator *) & xi[count];
+            deviceValuator *v = (deviceValuator *) &xi[count];
 
             assert(v->type == DeviceValuator);
             assert(v->num_valuators <= 6);
diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c
index bb3177c..5db691c 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -694,7 +694,7 @@ test_values_XIDeviceChangedEvent(DeviceChangedEvent *in,
             assert(k->num_keycodes == in->keys.max_keycode -
                    in->keys.min_keycode + 1);
 
-            kc = (uint32_t *) & k[1];
+            kc = (uint32_t *) &k[1];
             for (j = 0; j < k->num_keycodes; j++) {
                 if (swap) {
                     swapl(&kc[j]);
diff --git a/test/xi2/protocol-xiquerydevice.c b/test/xi2/protocol-xiquerydevice.c
index 9d13bbb..c066daa 100644
--- a/test/xi2/protocol-xiquerydevice.c
+++ b/test/xi2/protocol-xiquerydevice.c
@@ -171,7 +171,7 @@ reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void *closure)
                        (xkb->max_key_code - xkb->min_key_code + 1));
                 assert(any->length == (2 + ki->num_keycodes));
 
-                kc = (uint32_t *) & ki[1];
+                kc = (uint32_t *) &ki[1];
                 for (k = 0; k < ki->num_keycodes; k++, kc++) {
                     if (client->swapped)
                         swapl(kc);
diff --git a/test/xi2/protocol-xiselectevents.c b/test/xi2/protocol-xiselectevents.c
index 8f6b947..183746f 100644
--- a/test/xi2/protocol-xiselectevents.c
+++ b/test/xi2/protocol-xiselectevents.c
@@ -98,7 +98,7 @@ request_XISelectEvent(xXISelectEventsReq * req, int error)
     xXIEventMask *mask, *next;
 
     req->length = (sz_xXISelectEventsReq / 4);
-    mask = (xXIEventMask *) & req[1];
+    mask = (xXIEventMask *) &req[1];
     for (i = 0; i < req->num_masks; i++) {
         req->length += sizeof(xXIEventMask) / 4 + mask->mask_len;
         mask = (xXIEventMask *) ((char *) &mask[1] + mask->mask_len * 4);
@@ -111,7 +111,7 @@ request_XISelectEvent(xXISelectEventsReq * req, int error)
 
     client.swapped = TRUE;
 
-    mask = (xXIEventMask *) & req[1];
+    mask = (xXIEventMask *) &req[1];
     for (i = 0; i < req->num_masks; i++) {
         next = (xXIEventMask *) ((char *) &mask[1] + mask->mask_len * 4);
         swaps(&mask->deviceid);
@@ -156,7 +156,7 @@ request_XISelectEvents_masks(xXISelectEventsReq * req)
     int nmasks = (XI2LASTEVENT + 7) / 8;
     unsigned char *bits;
 
-    mask = (xXIEventMask *) & req[1];
+    mask = (xXIEventMask *) &req[1];
     req->win = ROOT_WINDOW_ID;
 
     /* if a clients submits more than 100 masks, consider it insane and untested */
@@ -312,7 +312,7 @@ test_XISelectEvents(void)
     req->num_masks = 1;
 
     printf("Triggering bogus mask length error\n");
-    mask = (xXIEventMask *) & req[1];
+    mask = (xXIEventMask *) &req[1];
     mask->deviceid = 0;
     mask->mask_len = 0xFFFF;
     request_XISelectEvent(req, BadLength);
@@ -320,7 +320,7 @@ test_XISelectEvents(void)
     /* testing various device ids */
     printf("Testing existing device ids.\n");
     for (i = 0; i < 6; i++) {
-        mask = (xXIEventMask *) & req[1];
+        mask = (xXIEventMask *) &req[1];
         mask->deviceid = i;
         mask->mask_len = 1;
         req->win = ROOT_WINDOW_ID;
@@ -332,7 +332,7 @@ test_XISelectEvents(void)
     for (i = 6; i <= 0xFFFF; i++) {
         req->win = ROOT_WINDOW_ID;
         req->num_masks = 1;
-        mask = (xXIEventMask *) & req[1];
+        mask = (xXIEventMask *) &req[1];
         mask->deviceid = i;
         mask->mask_len = 1;
         request_XISelectEvent(req, BadDevice);
diff --git a/xkb/xkb.c b/xkb/xkb.c
index c67896f..7e51e40 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -1650,8 +1650,8 @@ CheckKeyTypes(ClientPtr client,
             xkbKTSetMapEntryWireDesc *mapWire;
             xkbModsWireDesc *preWire;
 
-            mapWire = (xkbKTSetMapEntryWireDesc *) & wire[1];
-            preWire = (xkbModsWireDesc *) & mapWire[wire->nMapEntries];
+            mapWire = (xkbKTSetMapEntryWireDesc *) &wire[1];
+            preWire = (xkbModsWireDesc *) &mapWire[wire->nMapEntries];
             for (n = 0; n < wire->nMapEntries; n++) {
                 if (client->swapped) {
                     swaps(&mapWire[n].virtualMods);
@@ -1761,8 +1761,8 @@ CheckKeySyms(ClientPtr client,
             *errorRtrn = _XkbErrCode3(0x17, i + req->firstKeySym, wire->nSyms);
             return 0;
         }
-        pSyms = (KeySym *) & wire[1];
-        wire = (xkbSymMapWireDesc *) & pSyms[wire->nSyms];
+        pSyms = (KeySym *) &wire[1];
+        wire = (xkbSymMapWireDesc *) &pSyms[wire->nSyms];
     }
 
     map = &xkb->map->key_sym_map[i];
@@ -2039,7 +2039,7 @@ SetKeyTypes(XkbDescPtr xkb,
             unsigned tmp;
 
             mapWire = (xkbKTSetMapEntryWireDesc *) map;
-            preWire = (xkbModsWireDesc *) & mapWire[wire->nMapEntries];
+            preWire = (xkbModsWireDesc *) &mapWire[wire->nMapEntries];
             for (n = 0; n < wire->nMapEntries; n++) {
                 pOld->map[n].active = 1;
                 pOld->map[n].mods.mask = mapWire[n].realMods;
@@ -2098,7 +2098,7 @@ SetKeySyms(ClientPtr client,
 
     oldMap = &xkb->map->key_sym_map[req->firstKeySym];
     for (i = 0; i < req->nKeySyms; i++, oldMap++) {
-        pSyms = (KeySym *) & wire[1];
+        pSyms = (KeySym *) &wire[1];
         if (wire->nSyms > 0) {
             newSyms = XkbResizeKeySyms(xkb, i + req->firstKeySym, wire->nSyms);
             for (s = 0; s < wire->nSyms; s++) {
@@ -2116,7 +2116,7 @@ SetKeySyms(ClientPtr client,
         oldMap->kt_index[3] = wire->ktIndex[3];
         oldMap->group_info = wire->groupInfo;
         oldMap->width = wire->width;
-        wire = (xkbSymMapWireDesc *) & pSyms[wire->nSyms];
+        wire = (xkbSymMapWireDesc *) &pSyms[wire->nSyms];
     }
     first = req->firstKeySym;
     last = first + req->nKeySyms - 1;
@@ -2408,7 +2408,7 @@ _XkbSetMapChecks(ClientPtr client, DeviceIntPtr dev, xkbSetMapReq * req,
     }
 
     if ((req->present & XkbKeyTypesMask) &&
-        (!CheckKeyTypes(client, xkb, req, (xkbKeyTypeWireDesc **) & values,
+        (!CheckKeyTypes(client, xkb, req, (xkbKeyTypeWireDesc **) &values,
                         &nTypes, mapWidths))) {
         client->errorValue = nTypes;
         return BadValue;
@@ -2433,7 +2433,7 @@ _XkbSetMapChecks(ClientPtr client, DeviceIntPtr dev, xkbSetMapReq * req,
 
     if ((req->present & XkbKeySymsMask) &&
         (!CheckKeySyms(client, xkb, req, nTypes, mapWidths, symsPerKey,
-                       (xkbSymMapWireDesc **) & values, &error))) {
+                       (xkbSymMapWireDesc **) &values, &error))) {
         client->errorValue = error;
         return BadValue;
     }
@@ -2447,7 +2447,7 @@ _XkbSetMapChecks(ClientPtr client, DeviceIntPtr dev, xkbSetMapReq * req,
 
     if ((req->present & XkbKeyBehaviorsMask) &&
         (!CheckKeyBehaviors
-         (xkb, req, (xkbBehaviorWireDesc **) & values, &error))) {
+         (xkb, req, (xkbBehaviorWireDesc **) &values, &error))) {
         client->errorValue = error;
         return BadValue;
     }
@@ -2469,7 +2469,7 @@ _XkbSetMapChecks(ClientPtr client, DeviceIntPtr dev, xkbSetMapReq * req,
     }
     if ((req->present & XkbVirtualModMapMask) &&
         (!CheckVirtualModMap
-         (xkb, req, (xkbVModMapWireDesc **) & values, &error))) {
+         (xkb, req, (xkbVModMapWireDesc **) &values, &error))) {
         client->errorValue = error;
         return BadValue;
     }
@@ -5097,7 +5097,7 @@ _CheckSetOverlay(char **wire_inout,
     }
     CHK_ATOM_ONLY(olWire->name);
     ol = XkbAddGeomOverlay(section, olWire->name, olWire->nRows);
-    rWire = (xkbOverlayRowWireDesc *) & olWire[1];
+    rWire = (xkbOverlayRowWireDesc *) &olWire[1];
     for (r = 0; r < olWire->nRows; r++) {
         register int k;
         xkbOverlayKeyWireDesc *kWire;
@@ -5109,7 +5109,7 @@ _CheckSetOverlay(char **wire_inout,
             return BadMatch;
         }
         row = XkbAddGeomOverlayRow(ol, rWire->rowUnder, rWire->nKeys);
-        kWire = (xkbOverlayKeyWireDesc *) & rWire[1];
+        kWire = (xkbOverlayKeyWireDesc *) &rWire[1];
         for (k = 0; k < rWire->nKeys; k++, kWire++) {
             if (XkbAddGeomOverlayKey(ol, row,
                                      (char *) kWire->over,
@@ -5163,7 +5163,7 @@ _CheckSetSections(XkbGeometryPtr geom,
         section->width = sWire->width;
         section->height = sWire->height;
         section->angle = sWire->angle;
-        rWire = (xkbRowWireDesc *) & sWire[1];
+        rWire = (xkbRowWireDesc *) &sWire[1];
         for (r = 0; r < sWire->nRows; r++) {
             register int k;
             XkbRowPtr row;
@@ -5179,7 +5179,7 @@ _CheckSetSections(XkbGeometryPtr geom,
             row->top = rWire->top;
             row->left = rWire->left;
             row->vertical = rWire->vertical;
-            kWire = (xkbKeyWireDesc *) & rWire[1];
+            kWire = (xkbKeyWireDesc *) &rWire[1];
             for (k = 0; k < rWire->nKeys; k++) {
                 XkbKeyPtr key;
 
@@ -5201,7 +5201,7 @@ _CheckSetSections(XkbGeometryPtr geom,
                     return BadMatch;
                 }
             }
-            rWire = (xkbRowWireDesc *) & kWire[rWire->nKeys];
+            rWire = (xkbRowWireDesc *) &kWire[rWire->nKeys];
         }
         wire = (char *) rWire;
         if (sWire->nDoodads > 0) {
@@ -5265,7 +5265,7 @@ _CheckSetShapes(XkbGeometryPtr geom,
                 if (!ol)
                     return BadAlloc;
                 ol->corner_radius = olWire->cornerRadius;
-                ptWire = (xkbPointWireDesc *) & olWire[1];
+                ptWire = (xkbPointWireDesc *) &olWire[1];
                 for (p = 0, pt = ol->points; p < olWire->nPoints; p++, pt++) {
                     pt->x = ptWire[p].x;
                     pt->y = ptWire[p].y;
@@ -6348,7 +6348,7 @@ ProcXkbGetDeviceInfo(ClientPtr client)
         xkbActionWireDesc *awire;
 
         sz = rep.nBtnsRtrn * SIZEOF(xkbActionWireDesc);
-        awire = (xkbActionWireDesc *) & dev->button->xkb_acts[rep.firstBtnRtrn];
+        awire = (xkbActionWireDesc *) &dev->button->xkb_acts[rep.firstBtnRtrn];
         WriteToClient(client, sz, awire);
         length -= sz;
     }
diff --git a/xkb/xkbout.c b/xkb/xkbout.c
index cd1ae0b..7bb6cea 100644
--- a/xkb/xkbout.c
+++ b/xkb/xkbout.c
@@ -522,7 +522,7 @@ XkbWriteXKBSymbols(FILE * file,
                     for (s = 0; s < XkbKeyGroupWidth(xkb, i, g); s++) {
                         if (s != 0)
                             fprintf(file, ", ");
-                        WriteXKBAction(file, xkb, (XkbAnyAction *) & acts[s]);
+                        WriteXKBAction(file, xkb, (XkbAnyAction *) &acts[s]);
                     }
                     fprintf(file, " ]");
                     acts += XkbKeyGroupsWidth(xkb, i);


More information about the Xquartz-changes mailing list