[Xquartz-changes] xserver: Branch 'server-1.11-apple' - 54 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Sat Apr 23 21:57:48 PDT 2011


Rebased ref, commits from common ancestor:
commit dd96986e9747b03d49feb479c2ca2a5f2f0b93df
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Oct 30 14:55:06 2010 -0700

    configure.ac: Add -fno-strict-aliasing to CFLAGS
    
    This should address https://bugs.freedesktop.org/show_bug.cgi?id=31238
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/configure.ac b/configure.ac
index 56e51a4..3e3146a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -86,6 +86,12 @@ XORG_PROG_RAWCPP
 # easier overrides at build time.
 XSERVER_CFLAGS='$(CWARNFLAGS)'
 
+dnl Explicitly add -fno-strict-aliasing since this option should disappear
+dnl from util-macros CWARNFLAGS
+if  test "x$GCC" = xyes ; then
+    XSERVER_CFLAGS="$XSERVER_CFLAGS -fno-strict-aliasing"
+fi
+
 dnl Check for dtrace program (needed to build Xserver dtrace probes)
 dnl Also checks for <sys/sdt.h>, since some Linux distros have an 
 dnl ISDN trace program named dtrace
commit 5300f0efb9af7d80822780e9e393ef29af41cad9
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Feb 12 19:48:52 2010 -0800

    fb: Revert fb changes that broke XQuartz
    
    http://bugs.freedesktop.org/show_bug.cgi?id=26124
    
    Revert "Fix source pictures getting random transforms after 2d6a8f668342a5190cdf43b5."
    Revert "fb: Adjust transform or composite coordinates for pixman operations"
    
    http://bugs.freedesktop.org/26124
    
    This reverts commit a72c65e9176c51de95db2fdbf4c5d946a4911695.
    This reverts commit a6bd5d2e482a5aa84acb3d4932e2a166d8670ef1.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/fb/fb.h b/fb/fb.h
index eaa21ad..e65a1c0 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -2049,11 +2049,8 @@ fbFillRegionSolid (DrawablePtr	pDrawable,
 		   FbBits	xor);
 
 extern _X_EXPORT pixman_image_t *
-image_from_pict (PicturePtr	pict,
-		 Bool		has_clip,
-		 int		*xoff,
-		 int		*yoff);
-
+image_from_pict (PicturePtr pict,
+		 Bool       has_clip);
 extern _X_EXPORT void free_pixman_pict (PicturePtr, pixman_image_t *);
 
 #endif /* _FB_H_ */
diff --git a/fb/fbpict.c b/fb/fbpict.c
index 133f422..093ae90 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -50,24 +50,19 @@ fbComposite (CARD8      op,
 	     CARD16     height)
 {
     pixman_image_t *src, *mask, *dest;
-    int src_xoff, src_yoff;
-    int msk_xoff, msk_yoff;
-    int dst_xoff, dst_yoff;
     
     miCompositeSourceValidate (pSrc);
     if (pMask)
 	miCompositeSourceValidate (pMask);
     
-    src = image_from_pict (pSrc, FALSE, &src_xoff, &src_yoff);
-    mask = image_from_pict (pMask, FALSE, &msk_xoff, &msk_yoff);
-    dest = image_from_pict (pDst, TRUE, &dst_xoff, &dst_yoff);
+    src = image_from_pict (pSrc, TRUE);
+    mask = image_from_pict (pMask, TRUE);
+    dest = image_from_pict (pDst, TRUE);
 
     if (src && dest && !(pMask && !mask))
     {
 	pixman_image_composite (op, src, mask, dest,
-				xSrc + src_xoff, ySrc + src_yoff,
-				xMask + msk_xoff, yMask + msk_yoff,
-				xDst + dst_xoff, yDst + dst_yoff,
+				xSrc, ySrc, xMask, yMask, xDst, yDst,
 				width, height);
     }
 
@@ -146,22 +141,22 @@ create_conical_gradient_image (PictGradient *gradient)
 
 static pixman_image_t *
 create_bits_picture (PicturePtr pict,
-		     Bool       has_clip,
-		     int	*xoff,
-		     int	*yoff)
+		     Bool       has_clip)
 {
-    PixmapPtr pixmap;
     FbBits *bits;
     FbStride stride;
-    int bpp;
+    int bpp, xoff, yoff;
     pixman_image_t *image;
     
-    fbGetDrawablePixmap (pict->pDrawable, pixmap, *xoff, *yoff);
-    fbGetPixmapBitsData(pixmap, bits, stride, bpp);
+    fbGetDrawable (pict->pDrawable, bits, stride, bpp, xoff, yoff);
+
+    bits = (FbBits*)((CARD8*)bits +
+		     (pict->pDrawable->y + yoff) * stride * sizeof(FbBits) +
+		     (pict->pDrawable->x + xoff) * (bpp / 8));
 
     image = pixman_image_create_bits (
 	pict->format,
-	pixmap->drawable.width, pixmap->drawable.height,
+	pict->pDrawable->width, pict->pDrawable->height,
 	(uint32_t *)bits, stride * sizeof (FbStride));
     
     
@@ -187,55 +182,33 @@ create_bits_picture (PicturePtr pict,
 	if (pict->clientClipType != CT_NONE)
 	    pixman_image_set_has_client_clip (image, TRUE);
 
-	if (*xoff || *yoff)
-	    pixman_region_translate (pict->pCompositeClip, *xoff, *yoff);
+	pixman_region_translate (pict->pCompositeClip, - pict->pDrawable->x, - pict->pDrawable->y);
 
 	pixman_image_set_clip_region (image, pict->pCompositeClip);
 
-	if (*xoff || *yoff)
-	    pixman_region_translate (pict->pCompositeClip, -*xoff, -*yoff);
+	pixman_region_translate (pict->pCompositeClip, pict->pDrawable->x, pict->pDrawable->y);
     }
     
     /* Indexed table */
     if (pict->pFormat->index.devPrivate)
 	pixman_image_set_indexed (image, pict->pFormat->index.devPrivate);
 
-    /* Add in drawable origin to position within the image */
-    *xoff += pict->pDrawable->x;
-    *yoff += pict->pDrawable->y;
-
     return image;
 }
 
 static pixman_image_t *
-image_from_pict_internal (PicturePtr pict, Bool has_clip, int *xoff, int *yoff, Bool is_alpha_map);
+image_from_pict_internal (PicturePtr pict, Bool has_clip, Bool is_alpha_map);
 
 static void
-set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int *xoff, int *yoff, Bool is_alpha_map)
+set_image_properties (pixman_image_t *image, PicturePtr pict, Bool is_alpha_map)
 {
     pixman_repeat_t repeat;
     pixman_filter_t filter;
     
     if (pict->transform)
     {
-	/* For source images, adjust the transform to account
-	 * for the drawable offset within the pixman image,
-	 * then set the offset to 0 as it will be used
-	 * to compute positions within the transformed image.
-	 */
-	if (!has_clip) {
-	    struct pixman_transform	adjusted;
-
-	    adjusted = *pict->transform;
-	    pixman_transform_translate(&adjusted,
-				       NULL,
-				       pixman_int_to_fixed(*xoff),
-				       pixman_int_to_fixed(*yoff));
-	    pixman_image_set_transform (image, &adjusted);
-	    *xoff = 0;
-	    *yoff = 0;
-	} else
-	    pixman_image_set_transform (image, pict->transform);
+	pixman_image_set_transform (
+	    image, (pixman_transform_t *)pict->transform);
     }
     
     switch (pict->repeatType)
@@ -265,8 +238,7 @@ set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int
      */
     if (pict->alphaMap && !is_alpha_map)
     {
-	int alpha_xoff, alpha_yoff;
-	pixman_image_t *alpha_map = image_from_pict_internal (pict->alphaMap, FALSE, &alpha_xoff, &alpha_yoff, TRUE);
+	pixman_image_t *alpha_map = image_from_pict_internal (pict->alphaMap, TRUE, TRUE);
 	
 	pixman_image_set_alpha_map (
 	    image, alpha_map, pict->alphaOrigin.x, pict->alphaOrigin.y);
@@ -299,7 +271,8 @@ set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int
 }
 
 static pixman_image_t *
-image_from_pict_internal (PicturePtr pict, Bool has_clip, int *xoff, int *yoff, Bool is_alpha_map)
+image_from_pict_internal (PicturePtr pict,
+		 Bool has_clip, Bool is_alpha_map)
 {
     pixman_image_t *image = NULL;
 
@@ -308,7 +281,7 @@ image_from_pict_internal (PicturePtr pict, Bool has_clip, int *xoff, int *yoff,
 
     if (pict->pDrawable)
     {
-	image = create_bits_picture (pict, has_clip, xoff, yoff);
+	image = create_bits_picture (pict, has_clip);
     }
     else if (pict->pSourcePict)
     {
@@ -329,19 +302,18 @@ image_from_pict_internal (PicturePtr pict, Bool has_clip, int *xoff, int *yoff,
 	    else if (sp->type == SourcePictTypeConical)
 		image = create_conical_gradient_image (gradient);
 	}
-	*xoff = *yoff = 0;
     }
     
     if (image)
-	set_image_properties (image, pict, has_clip, xoff, yoff, is_alpha_map);
+	set_image_properties (image, pict, is_alpha_map);
     
     return image;
 }
 
 pixman_image_t *
-image_from_pict (PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
+image_from_pict (PicturePtr pict, Bool has_clip)
 {
-    return image_from_pict_internal (pict, has_clip, xoff, yoff, FALSE);
+    return image_from_pict_internal (pict, has_clip, FALSE);
 }
 
 void
diff --git a/fb/fbtrap.c b/fb/fbtrap.c
index 2554fcc..06fbb22 100644
--- a/fb/fbtrap.c
+++ b/fb/fbtrap.c
@@ -37,8 +37,7 @@ fbAddTraps (PicturePtr	pPicture,
 	    int		ntrap,
 	    xTrap	*traps)
 {
-    int image_xoff, image_yoff;
-    pixman_image_t *image = image_from_pict (pPicture, FALSE, &image_xoff, &image_yoff);
+    pixman_image_t *image = image_from_pict (pPicture, FALSE);
 
     if (!image)
 	return;
@@ -54,8 +53,7 @@ fbRasterizeTrapezoid (PicturePtr    pPicture,
 		      int	    x_off,
 		      int	    y_off)
 {
-    int	mask_xoff, mask_yoff;
-    pixman_image_t *image = image_from_pict (pPicture, FALSE, &mask_xoff, &mask_yoff);
+    pixman_image_t *image = image_from_pict (pPicture, FALSE);
 
     if (!image)
 	return;
@@ -74,7 +72,7 @@ fbAddTriangles (PicturePtr  pPicture,
 {
     int image_xoff, image_yoff;
     pixman_image_t *image =
-	image_from_pict (pPicture, FALSE, &image_xoff, &image_yoff);
+	image_from_pict (pPicture, FALSE);
 
     if (!image)
 	return;
@@ -110,8 +108,8 @@ fbShapes (CompositeShapesFunc	composite,
     int src_xoff, src_yoff;
     int dst_xoff, dst_yoff;
 
-    src = image_from_pict (pSrc, FALSE, &src_xoff, &src_yoff);
-    dst = image_from_pict (pDst, TRUE, &dst_xoff, &dst_yoff);
+    src = image_from_pict (pSrc, FALSE);
+    dst = image_from_pict (pDst, TRUE);
 
     if (src && dst)
     {
commit 81da7346ad01ea1cf91d8131241c6e8c11a2ac30
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Apr 30 13:08:25 2010 -0700

    Workaround the GC clipping problem in miPaintWindow and add some debugging output.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/mi/miexpose.c b/mi/miexpose.c
index 94258b8..4f25c23 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -521,6 +521,7 @@ void RootlessSetPixmapOfAncestors(WindowPtr pWin);
 void RootlessStartDrawing(WindowPtr pWin);
 void RootlessDamageRegion(WindowPtr pWin, RegionPtr prgn);
 Bool IsFramedWindow(WindowPtr pWin);
+#include "../fb/fb.h"
 #endif 
 
 void
@@ -548,24 +549,37 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     Bool	solid = TRUE;
     DrawablePtr	drawable = &pWin->drawable;
 
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("START %d BS %d (pR = %ld)\n", what, pWin->backgroundState, ParentRelative);
+    ErrorF("      Rgn: %d %d %d %d\n", prgn->extents.x1, prgn->extents.y1,
+	                               prgn->extents.x2 - prgn->extents.x1,
+	                               prgn->extents.y2 - prgn->extents.y1);
+    ErrorF("      Win: %d %d (%d %d) %d %d\n", pWin->origin.x, pWin->origin.y,
+	                                       pWin->winSize.extents.x1, pWin->winSize.extents.y1,
+	                                       pWin->winSize.extents.x2 - pWin->winSize.extents.x1,
+					       pWin->winSize.extents.y2 - pWin->winSize.extents.y1);
+    ErrorF("     Draw: %d %d %d %d\n", pWin->drawable.x, pWin->drawable.y,
+				       pWin->drawable.width, pWin->drawable.height);
+#endif
+
 #ifdef ROOTLESS
     if(!drawable || drawable->type == UNDRAWABLE_WINDOW)
 	return;
-
-    if(IsFramedWindow(pWin)) {
-        RootlessStartDrawing(pWin);
-        RootlessDamageRegion(pWin, prgn);
-    
-        if(pWin->backgroundState == ParentRelative) {
-            if((what == PW_BACKGROUND) || 
-               (what == PW_BORDER && !pWin->borderIsPixel))
-                RootlessSetPixmapOfAncestors(pWin);
-        }
-    }
 #endif
     
     if (what == PW_BACKGROUND)
     {
+#ifdef ROOTLESS
+	if(IsFramedWindow(pWin)) {
+	    RootlessStartDrawing(pWin);
+	    RootlessDamageRegion(pWin, prgn);
+
+	    if(pWin->backgroundState == ParentRelative) {
+		RootlessSetPixmapOfAncestors(pWin);
+	    }
+	}
+#endif
+
 	while (pWin->backgroundState == ParentRelative)
 	    pWin = pWin->parent;
 
@@ -587,6 +601,18 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     {
 	PixmapPtr   pixmap;
 
+#ifdef ROOTLESS
+	if(IsFramedWindow(pWin)) {
+	    RootlessStartDrawing(pWin);
+	    RootlessDamageRegion(pWin, prgn);
+	    
+	    if(!pWin->borderIsPixel &&
+		pWin->backgroundState == ParentRelative) {
+		RootlessSetPixmapOfAncestors(pWin);
+	    }
+	}
+#endif
+
 	tile_x_off = drawable->x;
 	tile_y_off = drawable->y;
 	
@@ -595,6 +621,12 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
 	    return;
 	pixmap = (*pScreen->GetWindowPixmap) ((WindowPtr) drawable);
 	drawable = &pixmap->drawable;
+
+#ifdef XQUARTZ_CLIP_DEBUG
+	ErrorF("     Draw: %d %d %d %d\n",
+	       drawable->x, drawable->y, drawable->width, drawable->height);    
+#endif
+	
 #ifdef COMPOSITE
 	draw_x_off = pixmap->screen_x;
 	draw_y_off = pixmap->screen_y;
@@ -657,6 +689,57 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     ChangeGC (NullClient, pGC, gcmask, gcval);
     ValidateGC (drawable, pGC);
 
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("       GC: %d %d %d %d\n",
+	   pGC->pCompositeClip->extents.x1, pGC->pCompositeClip->extents.y1,
+	   pGC->pCompositeClip->extents.x2 - pGC->pCompositeClip->extents.x1,
+	   pGC->pCompositeClip->extents.y2 - pGC->pCompositeClip->extents.y1);
+#endif
+    
+#ifdef XQUARTZ
+    /* Looks like our clipping isn't set right for some reason:
+     * http://xquartz.macosforge.org/trac/ticket/290
+     */
+    if(what == PW_BORDER) {
+
+#if 0
+	if(solid) {
+#if 1
+	    fbFillRegionSolid(&pWin->drawable,
+			      prgn,
+			      0,
+			      fbReplicatePixel(fill.pixel,
+					       pWin->drawable.bitsPerPixel));
+#else
+	    fbFillRegionSolid(drawable,
+			      prgn,
+			      0,
+			      fbReplicatePixel(fill.pixel,
+					       drawable->bitsPerPixel));
+#endif
+	    return;
+	}
+#endif
+    
+	pGC->pCompositeClip->extents.x1 += prgn->extents.x1;
+	pGC->pCompositeClip->extents.y1 += prgn->extents.y1;
+	pGC->pCompositeClip->extents.x2 += prgn->extents.x1;
+	pGC->pCompositeClip->extents.y2 += prgn->extents.y1;
+	
+	if(pGC->pCompositeClip->extents.x2 > drawable->pScreen->width)
+	    pGC->pCompositeClip->extents.x2 = drawable->pScreen->width;
+	if(pGC->pCompositeClip->extents.y2 > drawable->pScreen->height)
+	    pGC->pCompositeClip->extents.y2 = drawable->pScreen->height;
+    }
+#endif
+
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("       GC: %d %d %d %d\n",
+	   pGC->pCompositeClip->extents.x1, pGC->pCompositeClip->extents.y1,
+	   pGC->pCompositeClip->extents.x2 - pGC->pCompositeClip->extents.x1,
+	   pGC->pCompositeClip->extents.y2 - pGC->pCompositeClip->extents.y1);    
+#endif
+
     numRects = RegionNumRects(prgn);
     pbox = RegionRects(prgn);
     for (i= numRects; --i >= 0; pbox++, prect++)
commit d849361fc35fa15352559eb8dd5aef446d065dca
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Apr 23 20:12:38 2011 -0700

    XQuartz: Silence warnings about deprecated functionality where it is an intended fallback
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 6a6c01c..d70cfd4 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -144,7 +144,15 @@ static mach_port_t checkin_or_register(char *bname) {
         exit(EXIT_FAILURE);
     }
 
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations" // bootstrap_register
+#endif
     kr = bootstrap_register(bootstrap_port, bname, mp);
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
     if (kr != KERN_SUCCESS) {
         fprintf(stderr, "bootstrap_register(): %s\n", mach_error_string(kr));
         exit(EXIT_FAILURE);
diff --git a/hw/xquartz/pbproxy/x-selection.m b/hw/xquartz/pbproxy/x-selection.m
index ef84f8b..e3d5113 100644
--- a/hw/xquartz/pbproxy/x-selection.m
+++ b/hw/xquartz/pbproxy/x-selection.m
@@ -625,6 +625,10 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato
 	/* TODO add the NSPICTPboardType back again, once we have conversion
 	 * functionality in send_image.
 	 */
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations" // NSPICTPboardType
+#endif
 
 	if ([pbtypes containsObject:NSPICTPboardType] 
 	    || [pbtypes containsObject:NSTIFFPboardType]) 
@@ -637,6 +641,10 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato
 	    ++count;
 	} 
 
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
 	if (count)
 	{
 	    /* We have a list of ATOMs to send. */
@@ -925,7 +933,14 @@ get_property(Window win, Atom property, struct propdata *pdata, Bool delete, Ato
 	    if (NO == [self send_image_tiff_reply:e pasteboard:pb type:imagetype]) 
 	  	return;
 	} 
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations" // NSPICTPboardType
+#endif
      	else if ([pbtypes containsObject:NSPICTPboardType])
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
 	{
 	    if (NO == [self send_image_pict_reply:e pasteboard:pb type:imagetype]) 
 		return;
diff --git a/hw/xquartz/quartzKeyboard.c b/hw/xquartz/quartzKeyboard.c
index 3ab5d52..af12de4 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -684,6 +684,11 @@ static Bool QuartzReadSystemKeymap(darwinKeyboardInfo *info) {
     }
 #endif
 
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations" // KLGetCurrentKeyboardLayout, KLGetKeyboardLayoutProperty
+#endif
+
 #if !defined(__LP64__) || MAC_OS_X_VERSION_MIN_REQUIRED < 1050
     if (chr_data == NULL) {
 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
@@ -717,6 +722,10 @@ static Bool QuartzReadSystemKeymap(darwinKeyboardInfo *info) {
     }
 #endif
 
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
     if(currentKeyLayoutRef)
         CFRelease(currentKeyLayoutRef);
@@ -773,10 +782,16 @@ static Bool QuartzReadSystemKeymap(darwinKeyboardInfo *info) {
                 }
 #if !defined(__LP64__) || MAC_OS_X_VERSION_MIN_REQUIRED < 1050
             } else { // kchr
-	      UInt32 c, state = 0, state2 = 0;
+                UInt32 c, state = 0, state2 = 0;
                 UInt16 code;
 
                 code = i | mods[j];
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations" // KeyTranslate
+#endif
+
                 c = KeyTranslate (chr_data, code, &state);
 
                 /* Dead keys are only processed on key-down, so ask
@@ -787,6 +802,10 @@ static Bool QuartzReadSystemKeymap(darwinKeyboardInfo *info) {
                 if (state != 0)
                     c = KeyTranslate (chr_data, code | 128, &state2);
 
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
                 /* Characters seem to be in MacRoman encoding. */
 
                 if (c != 0 && c != 0x0010) {
commit 13f028919ab9e0fcdc859c0c13f1f9315d279a3c
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Apr 23 12:55:39 2011 -0700

    XQuartz: xpr: Use a serial queue rather than pthread mutexes for window_hash
    
    Additionally removes some dead code and fixes double-locking in
    xprIsX11Window.  xprIsX11Window doesn't need to do any locking because
    those resources are protected by the called functions themselves.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel A. Steffen <dsteffen at apple.com>

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index e56bf0c..ddfa7f3 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -237,8 +237,7 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
                 
                 if ([self isActive]) {
                     [self deactivate];
-                    if (!_x_active && quartzProcs->IsX11Window([e window],
-                                                               [e windowNumber]))
+                    if (!_x_active && quartzProcs->IsX11Window([e windowNumber]))
                         [self activateX:YES];
                 }
             }
diff --git a/hw/xquartz/quartz.h b/hw/xquartz/quartz.h
index 67a7919..0a9c47a 100644
--- a/hw/xquartz/quartz.h
+++ b/hw/xquartz/quartz.h
@@ -70,7 +70,7 @@ typedef void (*UpdateScreenProc)(ScreenPtr pScreen);
 /*
  * Rootless helper functions
  */
-typedef Bool (*IsX11WindowProc)(void *nsWindow, int windowNumber);
+typedef Bool (*IsX11WindowProc)(int windowNumber);
 typedef void (*HideWindowsProc)(Bool hide);
 
 /*
diff --git a/hw/xquartz/xpr/xpr.h b/hw/xquartz/xpr/xpr.h
index af1a90c..ebd89de 100644
--- a/hw/xquartz/xpr/xpr.h
+++ b/hw/xquartz/xpr/xpr.h
@@ -38,7 +38,7 @@ Bool QuartzModeBundleInit(void);
 void AppleDRIExtensionInit(void);
 void xprAppleWMInit(void);
 Bool xprInit(ScreenPtr pScreen);
-Bool xprIsX11Window(void *nsWindow, int windowNumber);
+Bool xprIsX11Window(int windowNumber);
 WindowPtr xprGetXWindow(xp_window_id wid);
 
 void xprHideWindows(Bool hide);
diff --git a/hw/xquartz/xpr/xprFrame.c b/hw/xquartz/xpr/xprFrame.c
index f0e9a89..066cc0f 100644
--- a/hw/xquartz/xpr/xprFrame.c
+++ b/hw/xquartz/xpr/xprFrame.c
@@ -43,7 +43,11 @@
 #include "windowstr.h"
 #include "quartz.h"
 
+#ifdef HAVE_LIBDISPATCH
+#include <dispatch/dispatch.h>
+#else
 #include <pthread.h>
+#endif
 
 #define DEFINE_ATOM_HELPER(func,atom_name)                      \
 static Atom func (void) {                                       \
@@ -61,10 +65,12 @@ DEFINE_ATOM_HELPER(xa_native_window_id, "_NATIVE_WINDOW_ID")
 /* Maps xp_window_id -> RootlessWindowRec */
 static x_hash_table *window_hash;
 
-/* Need to guard window_hash since xprGetXWindowFromAppKit and xprIsX11Window
- * can be called from any thread.
- */
+/* Need to guard window_hash since xprIsX11Window can be called from any thread. */
+#ifdef HAVE_LIBDISPATCH
+static dispatch_queue_t window_hash_serial_q;
+#else
 static pthread_mutex_t window_hash_mutex;
+#endif
 
 /* Prototypes for static functions */
 static Bool xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
@@ -181,9 +187,15 @@ xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
         return FALSE;
     }
 
+#ifdef HAVE_LIBDISPATCH
+    dispatch_async(window_hash_serial_q, ^{
+        x_hash_table_insert(window_hash, pFrame->wid, pFrame);
+    });
+#else
     pthread_mutex_lock(&window_hash_mutex);
     x_hash_table_insert(window_hash, pFrame->wid, pFrame);
     pthread_mutex_unlock(&window_hash_mutex);
+#endif
 
     xprSetNativeProperty(pFrame);
 
@@ -199,9 +211,15 @@ xprDestroyFrame(RootlessFrameID wid)
 {
     xp_error err;
 
+#ifdef HAVE_LIBDISPATCH
+    dispatch_async(window_hash_serial_q, ^{
+        x_hash_table_remove(window_hash, wid);
+    });
+#else
     pthread_mutex_lock(&window_hash_mutex);
     x_hash_table_remove(window_hash, wid);
     pthread_mutex_unlock(&window_hash_mutex);
+#endif
 
     err = xp_destroy_window(x_cvt_vptr_to_uint(wid));
     if (err != Success)
@@ -253,6 +271,9 @@ xprResizeFrame(RootlessFrameID wid, ScreenPtr pScreen,
 static void xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid) {
     xp_window_changes wc;
     unsigned int mask = XP_STACKING;
+#ifdef HAVE_LIBDISPATCH
+    __block
+#endif
     RootlessWindowRec *winRec;
 
     /* Stack frame below nextWid it if it exists, or raise
@@ -266,8 +287,16 @@ static void xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid) {
         wc.sibling = x_cvt_vptr_to_uint(nextWid);
     }
 
+#ifdef HAVE_LIBDISPATCH
+    dispatch_sync(window_hash_serial_q, ^{
+        winRec = x_hash_table_lookup(window_hash, wid, NULL);
+    });
+#else
+    pthread_mutex_lock(&window_hash_mutex);
     winRec = x_hash_table_lookup(window_hash, wid, NULL);
-
+    pthread_mutex_unlock(&window_hash_mutex);
+#endif
+    
     if(winRec) {
         if(XQuartzIsRootless)
             wc.window_level = normal_window_levels[winRec->level];
@@ -447,8 +476,12 @@ xprInit(ScreenPtr pScreen)
     rootless_CopyWindow_threshold = xp_scroll_area_threshold;
 
     assert((window_hash = x_hash_table_new(NULL, NULL, NULL, NULL)));
+#ifdef HAVE_LIBDISPATCH
+    assert((window_hash_serial_q = dispatch_queue_create(LAUNCHD_ID_PREFIX".X11.xpr_window_hash", NULL)));
+#else
     assert(0 == pthread_mutex_init(&window_hash_mutex, NULL));
-
+#endif
+    
     return TRUE;
 }
 
@@ -460,60 +493,36 @@ xprInit(ScreenPtr pScreen)
 WindowPtr
 xprGetXWindow(xp_window_id wid)
 {
+#ifdef HAVE_LIBDISPATCH
+    RootlessWindowRec *winRec __block;
+    dispatch_sync(window_hash_serial_q, ^{
+        winRec = x_hash_table_lookup(window_hash, x_cvt_uint_to_vptr(wid), NULL);
+    });
+#else
     RootlessWindowRec *winRec;
-
-    winRec = x_hash_table_lookup(window_hash, x_cvt_uint_to_vptr(wid), NULL);
-
-    return winRec != NULL ? winRec->win : NULL;
-}
-
-#ifdef UNUSED_CODE
-/*
- * Given the id of a physical window, try to find the top-level (or root)
- * X window that it represents.
- */
-WindowPtr
-xprGetXWindowFromAppKit(int windowNumber)
-{
-    RootlessWindowRec *winRec;
-    Bool ret;
-    xp_window_id wid;
-
     pthread_mutex_lock(&window_hash_mutex);
-
-    if (xp_lookup_native_window(windowNumber, &wid))
-        ret = xprGetXWindow(wid) != NULL;
-    else
-        ret = FALSE;
-
-    pthread_mutex_unlock(&window_hash_mutex);
-
-    if (!ret) return NULL;
     winRec = x_hash_table_lookup(window_hash, x_cvt_uint_to_vptr(wid), NULL);
+    pthread_mutex_unlock(&window_hash_mutex);
+#endif
 
     return winRec != NULL ? winRec->win : NULL;
 }
-#endif
 
 /*
  * The windowNumber is an AppKit window number. Returns TRUE if xpr is
  * displaying a window with that number.
  */
 Bool
-xprIsX11Window(void *nsWindow, int windowNumber)
+xprIsX11Window(int windowNumber)
 {
     Bool ret;
     xp_window_id wid;
 
-    pthread_mutex_lock(&window_hash_mutex);
-
     if (xp_lookup_native_window(windowNumber, &wid))
         ret = xprGetXWindow(wid) != NULL;
     else
         ret = FALSE;
 
-    pthread_mutex_unlock(&window_hash_mutex);
-
     return ret;
 }
 
commit a0227127927e7a40239b7c3438db2ec175141889
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Apr 23 12:11:39 2011 -0700

    XQuartz: xpr: Initialize window_hash in xprInit
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/xpr/xprFrame.c b/hw/xquartz/xpr/xprFrame.c
index efb3737..f0e9a89 100644
--- a/hw/xquartz/xpr/xprFrame.c
+++ b/hw/xquartz/xpr/xprFrame.c
@@ -1,7 +1,7 @@
 /*
  * Xplugin rootless implementation frame functions
  *
- * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2002-2011 Apple Computer, Inc. All rights reserved.
  * Copyright (c) 2003 Torrey T. Lyons. All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -35,7 +35,6 @@
 #include "rootlessCommon.h"
 #include <Xplugin.h>
 #include "x-hash.h"
-#include "x-list.h"
 #include "applewmExt.h"
 
 #include "propertyst.h"
@@ -61,6 +60,10 @@ DEFINE_ATOM_HELPER(xa_native_window_id, "_NATIVE_WINDOW_ID")
 
 /* Maps xp_window_id -> RootlessWindowRec */
 static x_hash_table *window_hash;
+
+/* Need to guard window_hash since xprGetXWindowFromAppKit and xprIsX11Window
+ * can be called from any thread.
+ */
 static pthread_mutex_t window_hash_mutex;
 
 /* Prototypes for static functions */
@@ -178,12 +181,6 @@ xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
         return FALSE;
     }
 
-    if (window_hash == NULL)
-    {
-        window_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
-        pthread_mutex_init(&window_hash_mutex, NULL);
-    }
-
     pthread_mutex_lock(&window_hash_mutex);
     x_hash_table_insert(window_hash, pFrame->wid, pFrame);
     pthread_mutex_unlock(&window_hash_mutex);
@@ -256,6 +253,7 @@ xprResizeFrame(RootlessFrameID wid, ScreenPtr pScreen,
 static void xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid) {
     xp_window_changes wc;
     unsigned int mask = XP_STACKING;
+    RootlessWindowRec *winRec;
 
     /* Stack frame below nextWid it if it exists, or raise
        frame above everything otherwise. */
@@ -268,18 +266,16 @@ static void xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid) {
         wc.sibling = x_cvt_vptr_to_uint(nextWid);
     }
 
-    if(window_hash) {
-        RootlessWindowRec *winRec = x_hash_table_lookup(window_hash, wid, NULL);
-
-        if(winRec) {
-            if(XQuartzIsRootless)
-                wc.window_level = normal_window_levels[winRec->level];
-            else if(XQuartzShieldingWindowLevel)
-                wc.window_level = XQuartzShieldingWindowLevel + 1;
-            else
-                wc.window_level = rooted_window_levels[winRec->level];
-            mask |= XP_WINDOW_LEVEL;
-        }
+    winRec = x_hash_table_lookup(window_hash, wid, NULL);
+
+    if(winRec) {
+        if(XQuartzIsRootless)
+            wc.window_level = normal_window_levels[winRec->level];
+        else if(XQuartzShieldingWindowLevel)
+            wc.window_level = XQuartzShieldingWindowLevel + 1;
+        else
+            wc.window_level = rooted_window_levels[winRec->level];
+        mask |= XP_WINDOW_LEVEL;
     }
 
     xprConfigureWindow(x_cvt_vptr_to_uint(wid), mask, &wc);
@@ -450,6 +446,9 @@ xprInit(ScreenPtr pScreen)
     rootless_CopyBytes_threshold = xp_copy_bytes_threshold;
     rootless_CopyWindow_threshold = xp_scroll_area_threshold;
 
+    assert((window_hash = x_hash_table_new(NULL, NULL, NULL, NULL)));
+    assert(0 == pthread_mutex_init(&window_hash_mutex, NULL));
+
     return TRUE;
 }
 
@@ -463,9 +462,6 @@ xprGetXWindow(xp_window_id wid)
 {
     RootlessWindowRec *winRec;
 
-    if (window_hash == NULL)
-        return NULL;
-
     winRec = x_hash_table_lookup(window_hash, x_cvt_uint_to_vptr(wid), NULL);
 
     return winRec != NULL ? winRec->win : NULL;
@@ -483,11 +479,6 @@ xprGetXWindowFromAppKit(int windowNumber)
     Bool ret;
     xp_window_id wid;
 
-    if (window_hash == NULL)
-        return FALSE;
-
-    /* need to lock, since this function can be called by any thread */
-
     pthread_mutex_lock(&window_hash_mutex);
 
     if (xp_lookup_native_window(windowNumber, &wid))
@@ -514,11 +505,6 @@ xprIsX11Window(void *nsWindow, int windowNumber)
     Bool ret;
     xp_window_id wid;
 
-    if (window_hash == NULL)
-        return FALSE;
-
-    /* need to lock, since this function can be called by any thread */
-
     pthread_mutex_lock(&window_hash_mutex);
 
     if (xp_lookup_native_window(windowNumber, &wid))
commit c4fad6f4b0d99c0472d9bf2f7a9faf40389dcce7
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Apr 23 11:55:49 2011 -0700

    XQuartz: Use a lighter spinlock instead of a pthread_mutex_t in QuartzScreenSaver
    
    Currently, we only end up here through a call to QuartzShowFullscreen, and
    this is always on the same thread.  Future changes (such as further
    incorporating libdispatch) may allow this to change, but contention will
    remain minimal since the call is infrequent and it is short held.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel A. Steffen <dsteffen at apple.com>

diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index 4b72a89..0e71d36 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -62,7 +62,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <IOKit/pwr_mgt/IOPMLib.h>
-#include <pthread.h>
+#include <libkern/OSAtomic.h>
 #include <signal.h>
 
 #include <rootlessCommon.h>
@@ -279,10 +279,10 @@ static void pokeActivityCallback(CFRunLoopTimerRef timer, void *info) {
 static void QuartzScreenSaver(int state) {
     static CFRunLoopTimerRef pokeActivityTimer = NULL;
     static CFRunLoopTimerContext pokeActivityContext = { 0, NULL, NULL, NULL, NULL };
-    static pthread_mutex_t pokeActivityMutex = PTHREAD_MUTEX_INITIALIZER;
+    static OSSpinLock pokeActivitySpinLock = OS_SPINLOCK_INIT;
+
+    OSSpinLockLock(&pokeActivitySpinLock);
 
-    pthread_mutex_lock(&pokeActivityMutex);
-    
     if(state) {
         if(pokeActivityTimer == NULL)
             goto QuartzScreenSaverEnd;
@@ -303,7 +303,7 @@ static void QuartzScreenSaver(int state) {
         CFRunLoopAddTimer(CFRunLoopGetMain(), pokeActivityTimer, kCFRunLoopCommonModes);
     }
 QuartzScreenSaverEnd:
-    pthread_mutex_unlock(&pokeActivityMutex);
+    OSSpinLockUnlock(&pokeActivitySpinLock);
 }
 
 void QuartzShowFullscreen(int state) {
commit 5fd2d7807c4479b951f3e71953bdcaea99b1aaa5
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Apr 23 01:48:25 2011 -0700

    XQuartz: Remove the threadSafety dead-ish code
    
    It's been a few years now since we've needed this to debug thread
    boundaries, so punt it out to clean up the namespace polution.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index 61b04e0..76f624d 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -33,8 +33,7 @@ libXquartz_la_SOURCES = \
 	quartzCocoa.m \
 	quartzKeyboard.c \
 	quartzStartup.c \
-	quartzRandR.c \
-	threadSafety.c
+	quartzRandR.c
 
 EXTRA_DIST = \
 	X11Application.h \
@@ -50,5 +49,4 @@ EXTRA_DIST = \
 	quartzKeyboard.h \
 	quartzRandR.h \
 	sanitizedCarbon.h \
-	sanitizedCocoa.h \
-	threadSafety.h
+	sanitizedCocoa.h
diff --git a/hw/xquartz/darwin.h b/hw/xquartz/darwin.h
index 3602257..3ba5d82 100644
--- a/hw/xquartz/darwin.h
+++ b/hw/xquartz/darwin.h
@@ -34,8 +34,6 @@
 #include <X11/extensions/XKB.h>
 #include <assert.h>
 
-#include "threadSafety.h"
-
 #include "darwinfb.h"
 
 // From darwin.c
@@ -80,7 +78,7 @@ extern int              darwinMainScreenY;
 #ifdef ENABLE_DEBUG_LOG
 extern FILE *debug_log_fp;
 #define DEBUG_LOG_NAME "x11-debug.txt"
-#define DEBUG_LOG(msg, args...) if (debug_log_fp) fprintf(debug_log_fp, "%s:%s:%s:%d " msg, threadSafetyID(pthread_self()), __FILE__, __FUNCTION__, __LINE__, ##args ); fflush(debug_log_fp);
+#define DEBUG_LOG(msg, args...) if (debug_log_fp) fprintf(debug_log_fp, "%s:%s:%d " msg, __FILE__, __FUNCTION__, __LINE__, ##args ); fflush(debug_log_fp);
 #else
 #define DEBUG_LOG(msg, args...) 
 #endif
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 5bcee04..f3e1225 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -197,8 +197,6 @@ static void DarwinUpdateModifiers(
 static void DarwinEventHandler(int screenNum, InternalEvent *ie, DeviceIntPtr dev) {
     XQuartzEvent *e = &(ie->xquartz_event);
 
-    TA_SERVER();
-
     switch(e->subtype) {
         case kXquartzControllerNotify:
             DEBUG_LOG("kXquartzControllerNotify\n");
@@ -381,8 +379,6 @@ void ProcessInputEvents(void) {
     char nullbyte;
 	int x = sizeof(nullbyte);
     
-    TA_SERVER();
-
     mieqProcessInputEvents();
 
     // Empty the signaling pipe
diff --git a/hw/xquartz/quartzKeyboard.c b/hw/xquartz/quartzKeyboard.c
index 54f709a..3ab5d52 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -56,8 +56,6 @@
 
 #include "X11Application.h"
 
-#include "threadSafety.h"
-
 #ifdef NDEBUG
 #undef NDEBUG
 #include <assert.h>
diff --git a/hw/xquartz/quartzStartup.c b/hw/xquartz/quartzStartup.c
index 36c8182..00a9e48 100644
--- a/hw/xquartz/quartzStartup.c
+++ b/hw/xquartz/quartzStartup.c
@@ -84,10 +84,7 @@ void QuartzInitServer(int argc, char **argv, char **envp) {
     args->argv = argv;
     args->envp = envp;
     
-    APPKIT_THREAD_ID = pthread_self();
-    SERVER_THREAD_ID = create_thread(server_thread, args);
-
-    if (!SERVER_THREAD_ID) {
+    if (!create_thread(server_thread, args)) {
         FatalError("can't create secondary thread\n");
     }
 }
diff --git a/hw/xquartz/threadSafety.c b/hw/xquartz/threadSafety.c
deleted file mode 100644
index 85f85bd..0000000
--- a/hw/xquartz/threadSafety.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2008 Apple, 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 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 ABOVE LISTED COPYRIGHT HOLDER(S) 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.
- *
- * Except as contained in this notice, the name(s) of the above copyright
- * holders shall not be used in advertising or otherwise to promote the sale,
- * use or other dealings in this Software without prior written authorization.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "threadSafety.h"
-#include "os.h"
-
-pthread_t APPKIT_THREAD_ID;
-pthread_t SERVER_THREAD_ID;
-
-#include <AvailabilityMacros.h>
-
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
-#include <execinfo.h>
-
-void spewCallStack(void) {
-    void* callstack[128];
-    int i, frames = backtrace(callstack, 128);
-    char** strs = backtrace_symbols(callstack, frames);
-    
-    for (i = 0; i < frames; ++i) {
-        ErrorF("%s\n", strs[i]);
-    }
-    
-    free(strs);
-}
-#else
-void spewCallStack(void) {
-	return;
-}
-#endif
-
-void _threadSafetyAssert(pthread_t tid, const char *file, const char *fun, int line) {
-    if(pthread_equal(pthread_self(), tid))
-        return;
-    
-    /* NOOOO! */
-    ErrorF("Thread Assertion Failed: self=%s, expected=%s\n%s:%s:%d\n",
-           threadSafetyID(pthread_self()), threadSafetyID(tid),
-           file, fun, line);
-    spewCallStack();
-}
-
-const char *threadSafetyID(pthread_t tid) {
-    if(pthread_equal(tid, APPKIT_THREAD_ID)) {
-        return "Appkit Thread";
-    } else if(pthread_equal(tid, SERVER_THREAD_ID)) {
-        return "Xserver Thread";
-    } else {        
-        return "Unknown Thread";
-    }
-}
diff --git a/hw/xquartz/threadSafety.h b/hw/xquartz/threadSafety.h
deleted file mode 100644
index 3ff9eaf..0000000
--- a/hw/xquartz/threadSafety.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2008 Apple, 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 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 ABOVE LISTED COPYRIGHT HOLDER(S) 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.
- *
- * Except as contained in this notice, the name(s) of the above copyright
- * holders shall not be used in advertising or otherwise to promote the sale,
- * use or other dealings in this Software without prior written authorization.
- */
-
-#ifndef _XQ_THREAD_SAFETY_H_
-#define _XQ_THREAD_SAFETY_H_
-
-#define DEBUG_THREADS 1
-
-#include <pthread.h>
-
-extern pthread_t APPKIT_THREAD_ID;
-extern pthread_t SERVER_THREAD_ID;
-
-/* Dump the call stack */
-void spewCallStack(void);
-
-/* Print message to ErrorF if we're in the wrong thread */
-void _threadSafetyAssert(pthread_t tid, const char *file, const char *fun, int line);
-
-/* Get a string that identifies our thread nicely */
-const char *threadSafetyID(pthread_t tid);
-
-#define threadSafetyAssert(tid) _threadSafetyAssert(tid, __FILE__, __FUNCTION__, __LINE__)
-
-#ifdef DEBUG_THREADS
-#define TA_APPKIT() threadSafetyAssert(APPKIT_THREAD_ID)
-#define TA_SERVER() threadSafetyAssert(SERVER_THREAD_ID)
-#else
-#define TA_SERVER() 
-#define TA_APPKIT() 
-#endif
-
-#endif /* _XQ_THREAD_SAFETY_H_ */
diff --git a/hw/xquartz/xpr/xprEvent.c b/hw/xquartz/xpr/xprEvent.c
index 342b54c..cc86c47 100644
--- a/hw/xquartz/xpr/xprEvent.c
+++ b/hw/xquartz/xpr/xprEvent.c
@@ -57,8 +57,6 @@
 #include "xprEvent.h"
 
 Bool QuartzModeEventHandler(int screenNum, XQuartzEvent *e, DeviceIntPtr dev) {
-    TA_SERVER();
-    
     switch(e->subtype) {
         case kXquartzWindowState:
             DEBUG_LOG("kXquartzWindowState\n");
diff --git a/hw/xquartz/xpr/xprFrame.c b/hw/xquartz/xpr/xprFrame.c
index 15598e9..efb3737 100644
--- a/hw/xquartz/xpr/xprFrame.c
+++ b/hw/xquartz/xpr/xprFrame.c
@@ -44,8 +44,6 @@
 #include "windowstr.h"
 #include "quartz.h"
 
-#include "threadSafety.h"
-
 #include <pthread.h>
 
 #define DEFINE_ATOM_HELPER(func,atom_name)                      \
@@ -93,8 +91,6 @@ static inline xp_error
 xprConfigureWindow(xp_window_id id, unsigned int mask,
                    const xp_window_changes *values)
 {
-    TA_SERVER();
-
     return xp_configure_window(id, mask, values);
 }
 
@@ -106,8 +102,6 @@ xprSetNativeProperty(RootlessWindowPtr pFrame)
     unsigned int native_id;
     long data;
 
-    TA_SERVER();
-    
     err = xp_get_native_window(x_cvt_vptr_to_uint(pFrame->wid), &native_id);
     if (err == Success)
     {
@@ -137,8 +131,6 @@ xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
     unsigned int mask = 0;
     xp_error err;
 
-    TA_SERVER();
-    
     wc.x = newX;
     wc.y = newY;
     wc.width = pFrame->width;
@@ -209,8 +201,7 @@ static void
 xprDestroyFrame(RootlessFrameID wid)
 {
     xp_error err;
-    TA_SERVER();
-    
+
     pthread_mutex_lock(&window_hash_mutex);
     x_hash_table_remove(window_hash, wid);
     pthread_mutex_unlock(&window_hash_mutex);
@@ -229,8 +220,6 @@ xprMoveFrame(RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY)
 {
     xp_window_changes wc;
 
-    TA_SERVER();
-    
     wc.x = newX;
     wc.y = newY;
     //    ErrorF("xprMoveFrame(%d, %p, %d, %d)\n", wid, pScreen, newX, newY);
@@ -248,8 +237,6 @@ xprResizeFrame(RootlessFrameID wid, ScreenPtr pScreen,
 {
     xp_window_changes wc;
 
-    TA_SERVER();
-    
     wc.x = newX;
     wc.y = newY;
     wc.width = newW;
@@ -270,8 +257,6 @@ static void xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid) {
     xp_window_changes wc;
     unsigned int mask = XP_STACKING;
 
-    TA_SERVER();
-    
     /* Stack frame below nextWid it if it exists, or raise
        frame above everything otherwise. */
 
@@ -309,8 +294,6 @@ xprReshapeFrame(RootlessFrameID wid, RegionPtr pShape)
 {
     xp_window_changes wc;
 
-    TA_SERVER();
-    
     if (pShape != NULL)
     {
         wc.shape_nrects = RegionNumRects(pShape);
@@ -336,8 +319,6 @@ xprUnmapFrame(RootlessFrameID wid)
 {
     xp_window_changes wc;
 
-    TA_SERVER();
-    
     wc.stack_mode = XP_UNMAPPED;
     wc.sibling = 0;
 
@@ -356,8 +337,6 @@ xprStartDrawing(RootlessFrameID wid, char **pixelData, int *bytesPerRow)
     unsigned int rowbytes[2];
     xp_error err;
 
-    TA_SERVER();
-    
     err = xp_lock_window(x_cvt_vptr_to_uint(wid), NULL, NULL, data, rowbytes, NULL);
     if (err != Success)
         FatalError("Could not lock window %i for drawing.", (int)x_cvt_vptr_to_uint(wid));
@@ -374,8 +353,7 @@ static void
 xprStopDrawing(RootlessFrameID wid, Bool flush)
 {
     xp_error err;
-    TA_SERVER();
-    
+
     err = xp_unlock_window(x_cvt_vptr_to_uint(wid), flush);
     if(err != Success)
         FatalError("Could not unlock window %i after drawing.", (int)x_cvt_vptr_to_uint(wid));
@@ -388,8 +366,6 @@ xprStopDrawing(RootlessFrameID wid, Bool flush)
 static void
 xprUpdateRegion(RootlessFrameID wid, RegionPtr pDamage)
 {
-    TA_SERVER();
-    
     xp_flush_window(x_cvt_vptr_to_uint(wid));
 }
 
@@ -401,8 +377,6 @@ static void
 xprDamageRects(RootlessFrameID wid, int nrects, const BoxRec *rects,
                int shift_x, int shift_y)
 {
-    TA_SERVER();
-    
     xp_mark_window(x_cvt_vptr_to_uint(wid), nrects, rects, shift_x, shift_y);
 }
 
@@ -416,8 +390,6 @@ xprSwitchWindow(RootlessWindowPtr pFrame, WindowPtr oldWin)
 {
     DeleteProperty(serverClient, oldWin, xa_native_window_id());
 
-    TA_SERVER();
-    
     xprSetNativeProperty(pFrame);
 }
 
@@ -429,8 +401,6 @@ static Bool xprDoReorderWindow(RootlessWindowPtr pFrame)
 {
     WindowPtr pWin = pFrame->win;
 
-    TA_SERVER();
-    
     return AppleWMDoReorderWindow(pWin);
 }
 
@@ -443,8 +413,6 @@ static void
 xprCopyWindow(RootlessFrameID wid, int dstNrects, const BoxRec *dstRects,
               int dx, int dy)
 {
-    TA_SERVER();
-    
     xp_copy_window(x_cvt_vptr_to_uint(wid), x_cvt_vptr_to_uint(wid),
                    dstNrects, dstRects, dx, dy);
 }
@@ -479,8 +447,6 @@ xprInit(ScreenPtr pScreen)
 {
     RootlessInit(pScreen, &xprRootlessProcs);
 
-    TA_SERVER();
-    
     rootless_CopyBytes_threshold = xp_copy_bytes_threshold;
     rootless_CopyWindow_threshold = xp_scroll_area_threshold;
 
@@ -578,8 +544,6 @@ xprHideWindows(Bool hide)
     int screen;
     WindowPtr pRoot, pWin;
 
-    TA_SERVER();
-    
     for (screen = 0; screen < screenInfo.numScreens; screen++) {
         RootlessFrameID prevWid = NULL;
         pRoot = screenInfo.screens[screen]->root;
commit f63419a78f35a856209b43ed8b51597a80be6bec
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Apr 23 01:39:16 2011 -0700

    XQuartz: Use xorg_backtrace() instead of spewCallStack()
    
    Now that xorg_backtrace() produces pretty backtraces, we can use
    it instead.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 40d8a4e..5bcee04 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -113,7 +113,7 @@ void darwinEvents_lock(void) {
     if((err = pthread_mutex_lock(&mieq_lock))) {
         ErrorF("%s:%s:%d: Failed to lock mieq_lock: %d\n",
                __FILE__, __FUNCTION__, __LINE__, err);
-        spewCallStack();
+        xorg_backtrace();
     }
     if(darwinEvents == NULL) {
         pthread_cond_wait(&mieq_ready_cond, &mieq_lock);
@@ -126,7 +126,7 @@ void darwinEvents_unlock(void) {
     if((err = pthread_mutex_unlock(&mieq_lock))) {
         ErrorF("%s:%s:%d: Failed to unlock mieq_lock: %d\n",
                __FILE__, __FUNCTION__, __LINE__, err);
-        spewCallStack();
+        xorg_backtrace();
     }
 }
 
commit ce8295b6b3987fcac093f4e97de755f54d1eaeb1
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Apr 23 01:12:17 2011 -0700

    os/backtrace: Use backtrace_symbols where available
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/os/backtrace.c b/os/backtrace.c
index 7ca6dab..5ddb15c 100644
--- a/os/backtrace.c
+++ b/os/backtrace.c
@@ -37,21 +37,16 @@
 
 void xorg_backtrace(void)
 {
-    void *array[64];
-    const char *mod;
+    void *callstack[64];
     int size, i;
-    Dl_info info;
+    char **strs;
+
     ErrorF("\nBacktrace:\n");
-    size = backtrace(array, 64);
+    size = backtrace(callstack, 64);
+    strs = backtrace_symbols(callstack, size);
+
     for (i = 0; i < size; i++) {
-	dladdr(array[i], &info);
-	mod = (info.dli_fname && *info.dli_fname) ? info.dli_fname : "(vdso)";
-	if (info.dli_saddr)
-	    ErrorF("%d: %s (%s+0x%lx) [%p]\n", i, mod,
-		   info.dli_sname, (long unsigned int)((char *) array[i] - (char *) info.dli_saddr), array[i]);
-	else
-	    ErrorF("%d: %s (%p+0x%lx) [%p]\n", i, mod,
-		   info.dli_fbase, (long unsigned int)((char *) array[i] - (char *) info.dli_fbase), array[i]);
+        ErrorF("%s\n", strs[i]);
     }
 }
 
commit 9d51792b1c62aa54547f08372e54d279d8f9b014
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Apr 22 12:05:32 2011 -0700

    XQuartz: Fix compilation warnings with XPLUGIN_VERSION >= 4
    
    xprAppleWM.c:143: warning: initialization from incompatible pointer type
    xprAppleWM.c:144: warning: initialization from incompatible pointer type
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/applewmExt.h b/hw/xquartz/applewmExt.h
index 5ef8b54..f622f79 100644
--- a/hw/xquartz/applewmExt.h
+++ b/hw/xquartz/applewmExt.h
@@ -32,10 +32,12 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define _APPLEWMEXT_H_
 
 #include "window.h"
+#include <Xplugin.h>
 
 typedef int (*DisableUpdateProc)(void);
 typedef int (*EnableUpdateProc)(void);
 typedef int (*SetWindowLevelProc)(WindowPtr pWin, int level);
+#if XPLUGIN_VERSION < 4
 typedef int (*FrameGetRectProc)(int type, int class, const BoxRec *outer,
                                 const BoxRec *inner, BoxRec *ret);
 typedef int (*FrameHitTestProc)(int class, int x, int y,
@@ -45,6 +47,17 @@ typedef int (*FrameDrawProc)(WindowPtr pWin, int class, unsigned int attr,
                              const BoxRec *outer, const BoxRec *inner,
                              unsigned int title_len,
                              const unsigned char *title_bytes);
+#else
+typedef int (*FrameGetRectProc)(xp_frame_rect type, xp_frame_class class, const BoxRec *outer,
+                                const BoxRec *inner, BoxRec *ret);
+typedef int (*FrameHitTestProc)(xp_frame_class class, int x, int y,
+                                const BoxRec *outer,
+                                const BoxRec *inner, int *ret);
+typedef int (*FrameDrawProc)(WindowPtr pWin, xp_frame_class class, xp_frame_attr attr,
+                             const BoxRec *outer, const BoxRec *inner,
+                             unsigned int title_len,
+                             const unsigned char *title_bytes);
+#endif
 typedef int (*SendPSNProc)(uint32_t hi, uint32_t lo);
 typedef int (*AttachTransientProc)(WindowPtr pWinChild, WindowPtr pWinParent);
 
diff --git a/hw/xquartz/xpr/xprAppleWM.c b/hw/xquartz/xpr/xprAppleWM.c
index 21e6f98..b6b9a5f 100644
--- a/hw/xquartz/xpr/xprAppleWM.c
+++ b/hw/xquartz/xpr/xprAppleWM.c
@@ -114,8 +114,8 @@ static int xprAttachTransient(WindowPtr pWinChild, WindowPtr pWinParent) {
 
 static int xprFrameDraw(
     WindowPtr pWin,
-    int class,
-    unsigned int attr,
+    xp_frame_class class,
+    xp_frame_attr attr,
     const BoxRec *outer,
     const BoxRec *inner,
     unsigned int title_len,
commit 918a9c99cf2ebc73acb34b95f597904b93c690d9
Merge: 88c4622... 5f496bc...
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 22 11:20:16 2011 -0700

    Merge remote-tracking branch 'jeremyhu/master'

commit 88c4622b594a1725d0cee86bc82ad640d241c520
Author: Aaron Plattner <aplattner at nvidia.com>
Date:   Mon Apr 18 08:23:48 2011 -0700

    linux: Retry VT ioctls while errno == EINTR
    
    When the smart scheduler is enabled, the VT ioctls (particularly
    VT_WAITACTIVE) can be interrupted by the smart scheduler's SIGALRMs.
    Previously, this caused the server to immediately continue on to
    ScreenInit, almost certainly causing a crash or failure because the X
    server that owned the VT hadn't finished cleaning up.  As of commit
    7ee965a300c9eddcc1acacf9414cfe3e589222a8, it causes a FatalError
    instead.
    
    Retrying the ioctl as long as it fails with errno == EINTR fixes the
    problem and allows server regenerations to trigger VT switches that
    actually succeed.
    
    Signed-off-by: Aaron Plattner <aplattner at nvidia.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Cyril Brulebois <kibi at debian.org>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c
index 9c71a42..77dfb2f 100644
--- a/hw/xfree86/os-support/linux/lnx_init.c
+++ b/hw/xfree86/os-support/linux/lnx_init.c
@@ -62,17 +62,21 @@ drain_console(int fd, void *closure)
 static void
 switch_to(int vt, const char *from)
 {
-    if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, vt) < 0)
-        FatalError("%s: VT_ACTIVATE failed: %s\n", from, strerror(errno));
+    int ret;
 
-    if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, vt) < 0)
-        FatalError("%s: VT_WAITACTIVE failed: %s\n", from, strerror(errno));
+    SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_ACTIVATE, vt));
+    if (ret < 0)
+	FatalError("%s: VT_ACTIVATE failed: %s\n", from, strerror(errno));
+
+    SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_WAITACTIVE, vt));
+    if (ret < 0)
+	FatalError("%s: VT_WAITACTIVE failed: %s\n", from, strerror(errno));
 }
 
 void
 xf86OpenConsole(void)
 {
-    int i, fd = -1;
+    int i, fd = -1, ret;
     struct vt_mode VT;
     struct vt_stat vts;
     MessageType from = X_PROBED;
@@ -107,17 +111,19 @@ xf86OpenConsole(void)
 
             if (ShareVTs)
             {
-                if (ioctl(fd, VT_GETSTATE, &vts) == 0)
-                    xf86Info.vtno = vts.v_active;
-                else
-                    FatalError("xf86OpenConsole: Cannot find the current"
-                               " VT (%s)\n", strerror(errno));
+		SYSCALL(ret = ioctl(fd, VT_GETSTATE, &vts));
+		if (ret < 0)
+		    FatalError("xf86OpenConsole: Cannot find the current"
+			       " VT (%s)\n", strerror(errno));
+                xf86Info.vtno = vts.v_active;
             } else {
-	        if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) ||
-		    (xf86Info.vtno == -1))
-		    FatalError("xf86OpenConsole: Cannot find a free VT: %s\n",
-                               strerror(errno));
-            }
+		SYSCALL(ret = ioctl(fd, VT_OPENQRY, &xf86Info.vtno));
+		if (ret < 0)
+		    FatalError("xf86OpenConsole: Cannot find a free VT: "
+			       "%s\n", strerror(errno));
+		if (xf86Info.vtno == -1)
+		    FatalError("xf86OpenConsole: Cannot find a free VT\n");
+	    }
 	    close(fd);
 	}
 
@@ -159,7 +165,8 @@ xf86OpenConsole(void)
 	 * Linux doesn't switch to an active vt after the last close of a vt,
 	 * so we do this ourselves by remembering which is active now.
 	 */
-	if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) < 0)
+	SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts));
+	if (ret < 0)
 	    xf86Msg(X_WARNING,"xf86OpenConsole: VT_GETSTATE failed: %s\n",
 		    strerror(errno));
 	else
@@ -171,7 +178,7 @@ xf86OpenConsole(void)
 	     * Detach from the controlling tty to avoid char loss
 	     */
 	    if ((i = open("/dev/tty",O_RDWR)) >= 0) {
-		ioctl(i, TIOCNOTTY, 0);
+		SYSCALL(ioctl(i, TIOCNOTTY, 0));
 		close(i);
 	    }
 	}
@@ -186,9 +193,10 @@ xf86OpenConsole(void)
 	     */
             switch_to(xf86Info.vtno, "xf86OpenConsole");
 
-	    if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0)
-	        FatalError("xf86OpenConsole: VT_GETMODE failed %s\n",
-		           strerror(errno));
+	    SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_GETMODE, &VT));
+	    if (ret < 0)
+		FatalError("xf86OpenConsole: VT_GETMODE failed %s\n",
+			   strerror(errno));
 
 	    signal(SIGUSR1, xf86VTRequest);
 
@@ -196,20 +204,23 @@ xf86OpenConsole(void)
 	    VT.relsig = SIGUSR1;
 	    VT.acqsig = SIGUSR1;
 
-	    if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0)
-	        FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed: %s\n",
+	    SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_SETMODE, &VT));
+	    if (ret < 0)
+		FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed: %s\n",
 		    strerror(errno));
-	
-	    if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0)
-	        FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed %s\n",
-		           strerror(errno));
+
+	    SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS));
+	    if (ret < 0)
+		FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed %s\n",
+			   strerror(errno));
 
             tcgetattr(xf86Info.consoleFd, &tty_attr);
-            ioctl(xf86Info.consoleFd, KDGKBMODE, &tty_mode);
+	    SYSCALL(ioctl(xf86Info.consoleFd, KDGKBMODE, &tty_mode));
 
-            if (ioctl(xf86Info.consoleFd, KDSKBMODE, K_RAW) < 0)
-                FatalError("xf86OpenConsole: KDSKBMODE K_RAW failed %s\n",
-                        strerror(errno));
+	    SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSKBMODE, K_RAW));
+	    if (ret < 0)
+		FatalError("xf86OpenConsole: KDSKBMODE K_RAW failed %s\n",
+			strerror(errno));
 
             nTty = tty_attr;
             nTty.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
@@ -241,6 +252,7 @@ void
 xf86CloseConsole(void)
 {
     struct vt_mode   VT;
+    int ret;
 
     if (ShareVTs) {
         close(xf86Info.consoleFd);
@@ -253,20 +265,23 @@ xf86CloseConsole(void)
     };
 
     /* Back to text mode ... */
-    if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT) < 0)
+    SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT));
+    if (ret < 0)
 	xf86Msg(X_WARNING, "xf86CloseConsole: KDSETMODE failed: %s\n",
 		strerror(errno));
 
-    ioctl(xf86Info.consoleFd, KDSKBMODE, tty_mode);
+    SYSCALL(ioctl(xf86Info.consoleFd, KDSKBMODE, tty_mode));
     tcsetattr(xf86Info.consoleFd, TCSANOW, &tty_attr);
 
-    if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) 
+    SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_GETMODE, &VT));
+    if (ret < 0)
 	xf86Msg(X_WARNING, "xf86CloseConsole: VT_GETMODE failed: %s\n",
 		strerror(errno));
     else {
 	/* set dflt vt handling */
 	VT.mode = VT_AUTO;
-	if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0) 
+	SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_SETMODE, &VT));
+	if (ret < 0)
 	    xf86Msg(X_WARNING, "xf86CloseConsole: VT_SETMODE failed: %s\n",
 		    strerror(errno));
     }
commit 302bdc3c9678c028bed71dbe9c5ba04997626b6b
Merge: 001b6b8... 6f97fe5...
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 22 10:48:37 2011 -0700

    Merge remote-tracking branch 'whot/for-keith'

commit 5f496bc91941140ceaa3061472fda95bd812f2d2
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Apr 22 01:23:09 2011 -0700

    XQuartz: Do translation and handoff of NSEvent to X11 in a separate serial queue
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 1e36436..e56bf0c 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -61,6 +61,12 @@ extern int xpbproxy_run (void);
 #define XSERVER_VERSION "?"
 #endif
 
+#ifdef HAVE_LIBDISPATCH
+#include <dispatch/dispatch.h>
+
+static dispatch_queue_t eventTranslationQueue;
+#endif
+
 /* Stuck modifier / button state... force release when we context switch */
 static NSEventType keyState[NUM_KEYCODES];
 
@@ -385,7 +391,15 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
     
     if (for_appkit) [super sendEvent:e];
     
-    if (for_x) [self sendX11NSEvent:e];
+    if (for_x) {
+#ifdef HAVE_LIBDISPATCH
+        dispatch_async(eventTranslationQueue, ^{
+#endif
+            [self sendX11NSEvent:e];
+#ifdef HAVE_LIBDISPATCH
+        });
+#endif
+    }
 }
 
 - (void) set_window_menu:(NSArray *)list {
@@ -999,6 +1013,11 @@ void X11ApplicationMain (int argc, char **argv, char **envp) {
     aquaMenuBarHeight = NSHeight([[NSScreen mainScreen] frame]) -
     NSMaxY([[NSScreen mainScreen] visibleFrame]);
 
+#ifdef HAVE_LIBDISPATCH
+    eventTranslationQueue = dispatch_queue_create(LAUNCHD_ID_PREFIX".X11.NSEventsToX11EventsQueue", NULL);
+    assert(eventTranslationQueue != NULL);
+#endif
+    
     /* Set the key layout seed before we start the server */
 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
     last_key_layout = TISCopyCurrentKeyboardLayoutInputSource();    
commit 72bd232b117b2867282e0ae1855d779e126f912b
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Apr 22 00:39:12 2011 -0700

    XQuartz: Send tablet proximity events with tilt and pressure
    
    <rdar://problem/6257569>
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 988a86b..1e36436 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -1079,13 +1079,29 @@ static const char *untrusted_str(NSEvent *e) {
 #endif
 
 - (void) sendX11NSEvent:(NSEvent *)e {
-    NSPoint location = NSZeroPoint, tilt = NSZeroPoint;
+    NSPoint location = NSZeroPoint;
     int ev_button, ev_type;
-    float pressure = 0.0;
+    static float pressure = 0.0;       // static so ProximityOut will have the value from the previous tablet event
+    static NSPoint tilt;               // static so ProximityOut will have the value from the previous tablet event
+    static DeviceIntPtr darwinTabletCurrent = NULL;
+    static BOOL needsProximityIn = NO; // Do we do need to handle a pending ProximityIn once we have pressure/tilt?
     DeviceIntPtr pDev;
     int modifierFlags;
     BOOL isMouseOrTabletEvent, isTabletEvent;
 
+#ifdef HAVE_LIBDISPATCH
+    static dispatch_once_t once_pred;
+    dispatch_once(&once_pred, ^{
+        tilt = NSZeroPoint;
+        darwinTabletCurrent = darwinTabletStylus;
+    });
+#else
+    if(!darwinTabletCurrent) {
+        tilt = NSZeroPoint;
+        darwinTabletCurrent = darwinTabletStylus;
+    }
+#endif
+    
     isMouseOrTabletEvent =  [e type] == NSLeftMouseDown    ||  [e type] == NSOtherMouseDown    ||  [e type] == NSRightMouseDown    ||
                             [e type] == NSLeftMouseUp      ||  [e type] == NSOtherMouseUp      ||  [e type] == NSRightMouseUp      ||
                             [e type] == NSLeftMouseDragged ||  [e type] == NSOtherMouseDragged ||  [e type] == NSRightMouseDragged ||
@@ -1207,19 +1223,14 @@ static const char *untrusted_str(NSEvent *e) {
                         darwinTabletCurrent=darwinTabletCursor;
                         break;
                 }
-                
-                /* NSTabletProximityEventSubtype doesn't encode pressure ant tilt
-                 * So we just pretend the motion was caused by the mouse.  Hopefully
-                 * we'll have a better solution for this in the future (like maybe
-                 * NSTabletProximityEventSubtype will come from NSTabletPoint
-                 * rather than NSMouseMoved.
-                pressure = [e pressure];
-                tilt     = [e tilt];
-                pDev = darwinTabletCurrent;                
-                 */
 
-                DarwinSendProximityEvents([e isEnteringProximity] ? ProximityIn : ProximityOut,
-                                          location.x, location.y);
+                if([e isEnteringProximity])
+                    needsProximityIn = YES;
+                else
+                    DarwinSendProximityEvents(darwinTabletCurrent, ProximityOut,
+                                              location.x, location.y, pressure,
+                                              tilt.x, tilt.y);
+                return;
             }
 
 			if ([e type] == NSTabletPoint || [e subtype] == NSTabletPointEventSubtype) {
@@ -1227,6 +1238,14 @@ static const char *untrusted_str(NSEvent *e) {
                 tilt     = [e tilt];
                 
                 pDev = darwinTabletCurrent;
+                
+                if(needsProximityIn) {
+                    DarwinSendProximityEvents(darwinTabletCurrent, ProximityIn,
+                                              location.x, location.y, pressure,
+                                              tilt.x, tilt.y);
+
+                    needsProximityIn = NO;
+                }
             }
 
             if(!XQuartzServerVisible && noTestExtensions) {
@@ -1280,8 +1299,12 @@ static const char *untrusted_str(NSEvent *e) {
                     break;
             }
             
-			DarwinSendProximityEvents([e isEnteringProximity] ? ProximityIn : ProximityOut,
-                                      location.x, location.y);
+            if([e isEnteringProximity])
+                needsProximityIn = YES;
+            else
+                DarwinSendProximityEvents(darwinTabletCurrent, ProximityOut,
+                                          location.x, location.y, pressure,
+                                          tilt.x, tilt.y);
             break;
             
 		case NSScrollWheel:
diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index 3b6f0a2..00be74b 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -117,7 +117,6 @@ unsigned int            windowItemModMask = NX_COMMANDMASK;
 // devices
 DeviceIntPtr            darwinKeyboard = NULL;
 DeviceIntPtr            darwinPointer = NULL;
-DeviceIntPtr            darwinTabletCurrent = NULL;
 DeviceIntPtr            darwinTabletStylus = NULL;
 DeviceIntPtr            darwinTabletCursor = NULL;
 DeviceIntPtr            darwinTabletEraser = NULL;
@@ -492,8 +491,6 @@ void InitInput( int argc, char **argv )
     darwinTabletEraser = AddInputDevice(serverClient, DarwinTabletProc, TRUE);
     darwinTabletEraser->name = strdup("eraser");
 
-    darwinTabletCurrent = darwinTabletStylus;
-
     DarwinEQInit();
 
     QuartzInitInput(argc, argv);
diff --git a/hw/xquartz/darwin.h b/hw/xquartz/darwin.h
index e874af2..3602257 100644
--- a/hw/xquartz/darwin.h
+++ b/hw/xquartz/darwin.h
@@ -56,7 +56,6 @@ extern io_connect_t     darwinParamConnect;
 extern int              darwinEventReadFD;
 extern int              darwinEventWriteFD;
 extern DeviceIntPtr     darwinPointer;
-extern DeviceIntPtr     darwinTabletCurrent;
 extern DeviceIntPtr     darwinTabletCursor;
 extern DeviceIntPtr     darwinTabletStylus;
 extern DeviceIntPtr     darwinTabletEraser;
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index edf60c8..dc0b842 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -489,7 +489,7 @@ void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, floa
     DarwinPrepareValuators(pDev, valuators, screen, pointer_x, pointer_y, pressure, tilt_x, tilt_y);
     darwinEvents_lock(); {
         ValuatorMask mask;
-        valuator_mask_set_range(&mask, 0, (pDev == darwinTabletCurrent) ? 5 : 2, valuators);
+        valuator_mask_set_range(&mask, 0, (pDev == darwinPointer) ? 2 : 5, valuators);
         num_events = GetPointerEvents(darwinEvents, pDev, ev_type, ev_button, 
                                       POINTER_ABSOLUTE, &mask);
         for(i=0; i<num_events; i++) mieqEnqueue (pDev, (InternalEvent*)darwinEvents[i].event);
@@ -512,18 +512,18 @@ void DarwinSendKeyboardEvents(int ev_type, int keycode) {
     } darwinEvents_unlock();
 }
 
-void DarwinSendProximityEvents(int ev_type, float pointer_x, float pointer_y) {
-	int i, num_events;
+void DarwinSendProximityEvents(DeviceIntPtr pDev, int ev_type, float pointer_x, float pointer_y,  
+                               float pressure, float tilt_x, float tilt_y) {
+    int i, num_events;
     ScreenPtr screen;
-    DeviceIntPtr pDev = darwinTabletCurrent;
     int valuators[5];
 
-	DEBUG_LOG("DarwinSendProximityEvents(%d, %f, %f)\n", ev_type, pointer_x, pointer_y);
+    DEBUG_LOG("DarwinSendProximityEvents: %d l:%f,%f p:%f t:%f,%f\n", ev_type, pointer_x, pointer_y, pressure, tilt_x, tilt_y);
 
-	if(!darwinEvents) {
-		DEBUG_LOG("DarwinSendProximityEvents called before darwinEvents was initialized\n");
-		return;
-	}
+    if(!darwinEvents) {
+        DEBUG_LOG("DarwinSendProximityEvents called before darwinEvents was initialized\n");
+        return;
+    }
     
     screen = miPointerGetScreen(pDev);
     if(!screen) {
@@ -531,7 +531,7 @@ void DarwinSendProximityEvents(int ev_type, float pointer_x, float pointer_y) {
         return;
     }    
 
-    DarwinPrepareValuators(pDev, valuators, screen, pointer_x, pointer_y, 0.0f, 0.0f, 0.0f);
+    DarwinPrepareValuators(pDev, valuators, screen, pointer_x, pointer_y, pressure, tilt_x, tilt_y);
     darwinEvents_lock(); {
         ValuatorMask mask;
         valuator_mask_set_range(&mask, 0, 5, valuators);
diff --git a/hw/xquartz/darwinEvents.h b/hw/xquartz/darwinEvents.h
index 590305f..6769c8b 100644
--- a/hw/xquartz/darwinEvents.h
+++ b/hw/xquartz/darwinEvents.h
@@ -37,7 +37,8 @@ void DarwinEQPointerPost(DeviceIntPtr pDev, xEventPtr e);
 void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX);
 void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, float pointer_x, float pointer_y,
 			     float pressure, float tilt_x, float tilt_y);
-void DarwinSendProximityEvents(int ev_type, float pointer_x, float pointer_y);
+void DarwinSendProximityEvents(DeviceIntPtr pDev, int ev_type, float pointer_x, float pointer_y,
+                               float pressure, float tilt_x, float tilt_y);
 void DarwinSendKeyboardEvents(int ev_type, int keycode);
 void DarwinSendScrollEvents(float count_x, float count_y, float pointer_x, float pointer_y,
 			    float pressure, float tilt_x, float tilt_y);
commit 6f97fe5df16f947e52875187ff4f9e25fab33ad7
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Apr 21 14:55:22 2011 +1000

    dix: improve control flow in QueryTrackers
    
    If the velocity is 0, skip the remainder.
    If we're not in range, skip the remainder.
    
    No functional change.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index f4548b6..dfccf15 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -634,20 +634,20 @@ QueryTrackers(DeviceVelocityPtr vel, int cur_t){
 	    used_offset = offset;
 	} else if (initial_velocity != 0 && tracker_velocity != 0) {
 	    velocity_diff = fabs(initial_velocity - tracker_velocity);
-	    if (velocity_diff <= vel->max_diff ||
-		velocity_diff/(initial_velocity + tracker_velocity) < vel->max_rel_diff) {
-		/* we're in range with the initial velocity,
-		 * so this result is likely better
-		 * (it contains more information). */
-		result = tracker_velocity;
-		used_offset = offset;
-	    }else{
+
+	    if (velocity_diff > vel->max_diff &&
+		velocity_diff/(initial_velocity + tracker_velocity) >= vel->max_rel_diff) {
 		/* we're not in range, quit - it won't get better. */
 		DebugAccelF("(dix prtacc) query: tracker too different:"
 		            " old %2.2f initial %2.2f diff: %2.2f\n",
 		            tracker_velocity, initial_velocity, velocity_diff);
 		break;
 	    }
+	    /* we're in range with the initial velocity,
+	     * so this result is likely better
+	     * (it contains more information). */
+	    result = tracker_velocity;
+	    used_offset = offset;
 	}
     }
     if(offset == vel->num_tracker){
commit a0eda8cd36ffba2ecc79e0d7a1908c89b45e76c4
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Apr 21 14:45:09 2011 +1000

    dix: rename a bunch of variables to be more self-explanatory
    
    i → used_offset
    iveloc → initial_velocity
    res → result
    vdiff → velocity_diff
    vfac → velocity_factor
    tmp → tracker_velocity
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index bcaeb74..f4548b6 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -595,13 +595,14 @@ CalcTracker(const MotionTracker *tracker, int cur_t){
  */
 static float
 QueryTrackers(DeviceVelocityPtr vel, int cur_t){
-    int offset, dir = UNDEFINED, i = -1, age_ms;
+    int offset, dir = UNDEFINED, used_offset = -1, age_ms;
     /* initial velocity: a low-offset, valid velocity */
-    float iveloc = 0, res = 0, tmp, vdiff;
-    float vfac =  vel->corr_mul * vel->const_acceleration; /* premultiply */
+    float initial_velocity = 0, result = 0, velocity_diff;
+    float velocity_factor =  vel->corr_mul * vel->const_acceleration; /* premultiply */
     /* loop from current to older data */
     for(offset = 1; offset < vel->num_tracker; offset++){
 	MotionTracker *tracker = TRACKER(vel, offset);
+	float tracker_velocity;
 
 	age_ms = cur_t - tracker->time;
 
@@ -625,42 +626,42 @@ QueryTrackers(DeviceVelocityPtr vel, int cur_t){
 	    break;
 	}
 
-	tmp = CalcTracker(tracker, cur_t) * vfac;
+	tracker_velocity = CalcTracker(tracker, cur_t) * velocity_factor;
 
-	if ((iveloc == 0 || offset <= vel->initial_range) && tmp != 0) {
+	if ((initial_velocity == 0 || offset <= vel->initial_range) && tracker_velocity != 0) {
 	    /* set initial velocity and result */
-	    res = iveloc = tmp;
-	    i = offset;
-	} else if (iveloc != 0 && tmp != 0) {
-	    vdiff = fabs(iveloc - tmp);
-	    if (vdiff <= vel->max_diff ||
-		vdiff/(iveloc + tmp) < vel->max_rel_diff) {
+	    result = initial_velocity = tracker_velocity;
+	    used_offset = offset;
+	} else if (initial_velocity != 0 && tracker_velocity != 0) {
+	    velocity_diff = fabs(initial_velocity - tracker_velocity);
+	    if (velocity_diff <= vel->max_diff ||
+		velocity_diff/(initial_velocity + tracker_velocity) < vel->max_rel_diff) {
 		/* we're in range with the initial velocity,
 		 * so this result is likely better
 		 * (it contains more information). */
-		res = tmp;
-		i = offset;
+		result = tracker_velocity;
+		used_offset = offset;
 	    }else{
 		/* we're not in range, quit - it won't get better. */
 		DebugAccelF("(dix prtacc) query: tracker too different:"
 		            " old %2.2f initial %2.2f diff: %2.2f\n",
-		            tmp, iveloc, vdiff);
+		            tracker_velocity, initial_velocity, velocity_diff);
 		break;
 	    }
 	}
     }
     if(offset == vel->num_tracker){
 	DebugAccelF("(dix prtacc) query: last tracker in effect\n");
-	i = vel->num_tracker-1;
+	used_offset = vel->num_tracker-1;
     }
 #ifdef PTRACCEL_DEBUGGING
-    if(i>=0){
-	MotionTracker *tracker = TRACKER(vel, i);
+    if(used_offset >= 0){
+	MotionTracker *tracker = TRACKER(vel, used_offset);
 	DebugAccelF("(dix prtacc) result: offset %i [dx: %i dy: %i diff: %i]\n",
-	            i, tracker->dx, tracker->dy, cur_t - tracker->time);
+	            used_offset, tracker->dx, tracker->dy, cur_t - tracker->time);
     }
 #endif
-    return res;
+    return result;
 }
 
 #undef TRACKER_INDEX
commit e4901905903c5630a1092c69e42f313abd05187b
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 15:41:45 2011 +1000

    dix: reduce scope of tmp and mult.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index dcb4e4b..bcaeb74 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -1118,7 +1118,6 @@ acceleratePointerPredictable(
     ValuatorMask* val,
     CARD32 evtime)
 {
-    float tmp, mult; /* no need to init */
     int dx = 0, dy = 0, tmpi;
     DeviceVelocityPtr velocitydata = GetDevicePredictableAccelData(dev);
     Bool soften = TRUE;
@@ -1146,6 +1145,8 @@ acceleratePointerPredictable(
         }
 
         if (dev->ptrfeed && dev->ptrfeed->ctrl.num) {
+            float mult;
+
             /* invoke acceleration profile to determine acceleration */
             mult = ComputeAcceleration (dev, velocitydata,
                                         dev->ptrfeed->ctrl.threshold,
@@ -1163,6 +1164,7 @@ acceleratePointerPredictable(
                 /* Calculate the new delta (with accel) and drop it back
                  * into the valuator masks */
                 if (dx) {
+                    float tmp;
                     tmp = mult * fdx + dev->last.remainder[0];
                     /* Since it may not be apparent: lrintf() does not offer
                      * strong statements about rounding; however because we
@@ -1174,6 +1176,7 @@ acceleratePointerPredictable(
                     dev->last.remainder[0] = tmp - (float)tmpi;
                 }
                 if (dy) {
+                    float tmp;
                     tmp = mult * fdy + dev->last.remainder[1];
                     tmpi = lrintf(tmp);
                     valuator_mask_set(val, 1, tmpi);
commit 81c6e79f42cc263349e04c0d82b3a85d6b557885
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 15:39:27 2011 +1000

    dix: reduce the work done by ApplySoftening
    
    We can modify fdx/fdy in-place rather than requiring dx/dy as well. And the
    decision to soften can be made in the caller (unless decided by the velocity
    state).
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index a7101fc..dcb4e4b 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -708,21 +708,21 @@ ApplySimpleSoftening(int prev_delta, int delta)
 }
 
 
+/**
+ * Soften the delta based on previous deltas stored in vel.
+ *
+ * @param[in,out] fdx Delta X, modified in-place.
+ * @param[in,out] fdx Delta Y, modified in-place.
+ */
 static void
 ApplySoftening(
         DeviceVelocityPtr vel,
-        int dx,
-        int dy,
         float* fdx,
-        float* fdy,
-        BOOL do_soften)
+        float* fdy)
 {
-    if (do_soften && vel->use_softening) {
-        *fdx = ApplySimpleSoftening(vel->last_dx, dx);
-        *fdy = ApplySimpleSoftening(vel->last_dy, dy);
-    } else {
-        *fdx = dx;
-        *fdy = dy;
+    if (vel->use_softening) {
+        *fdx = ApplySimpleSoftening(vel->last_dx, *fdx);
+        *fdy = ApplySimpleSoftening(vel->last_dy, *fdy);
     }
 }
 
@@ -1118,7 +1118,7 @@ acceleratePointerPredictable(
     ValuatorMask* val,
     CARD32 evtime)
 {
-    float fdx, fdy, tmp, mult; /* no need to init */
+    float tmp, mult; /* no need to init */
     int dx = 0, dy = 0, tmpi;
     DeviceVelocityPtr velocitydata = GetDevicePredictableAccelData(dev);
     Bool soften = TRUE;
@@ -1153,10 +1153,11 @@ acceleratePointerPredictable(
                                             (float)dev->ptrfeed->ctrl.den);
 
             if(mult != 1.0f || velocitydata->const_acceleration != 1.0f) {
-                ApplySoftening(velocitydata,
-                               dx, dy,
-                               &fdx, &fdy,
-                               (mult > 1.0f) && soften);
+                float fdx = dx,
+                      fdy = dy;
+
+                if (mult > 1.0f && soften)
+                    ApplySoftening(velocitydata, &fdx, &fdy);
                 ApplyConstantDeceleration(velocitydata, &fdx, &fdy);
 
                 /* Calculate the new delta (with accel) and drop it back
commit 5870d507cee8547c0993791195fe04d96b271289
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 15:32:33 2011 +1000

    dix: split softening and constant deceleration into two functions
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index 98468bc..a7101fc 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -709,7 +709,7 @@ ApplySimpleSoftening(int prev_delta, int delta)
 
 
 static void
-ApplySofteningAndConstantDeceleration(
+ApplySoftening(
         DeviceVelocityPtr vel,
         int dx,
         int dy,
@@ -724,7 +724,11 @@ ApplySofteningAndConstantDeceleration(
         *fdx = dx;
         *fdy = dy;
     }
+}
 
+static void
+ApplyConstantDeceleration(DeviceVelocityPtr vel, float *fdx, float *fdy)
+{
     *fdx *= vel->const_acceleration;
     *fdy *= vel->const_acceleration;
 }
@@ -1149,10 +1153,11 @@ acceleratePointerPredictable(
                                             (float)dev->ptrfeed->ctrl.den);
 
             if(mult != 1.0f || velocitydata->const_acceleration != 1.0f) {
-                ApplySofteningAndConstantDeceleration(velocitydata,
-                                                      dx, dy,
-                                                      &fdx, &fdy,
-                                                      (mult > 1.0f) && soften);
+                ApplySoftening(velocitydata,
+                               dx, dy,
+                               &fdx, &fdy,
+                               (mult > 1.0f) && soften);
+                ApplyConstantDeceleration(velocitydata, &fdx, &fdy);
 
                 /* Calculate the new delta (with accel) and drop it back
                  * into the valuator masks */
commit 8ae90552f95f025ad09a17258d56603a424ca076
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 15:30:19 2011 +1000

    dix: use single return statement in ApplySimpleSoftening
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index 304a1c9..98468bc 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -697,12 +697,13 @@ static inline float
 ApplySimpleSoftening(int prev_delta, int delta)
 {
     float result = delta;
-    if (delta <= 1 && delta >= -1)
-        return result;
-    if (delta > prev_delta)
-        result -= 0.5;
-    else if (delta < prev_delta)
-        result += 0.5;
+
+    if (delta < -1 || delta > 1) {
+	if (delta > prev_delta)
+	    result -= 0.5;
+	else if (delta < prev_delta)
+	    result += 0.5;
+    }
     return result;
 }
 
commit c45f4cc6bd885855ecb54d9113010906d9ee58e2
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 15:28:32 2011 +1000

    dix: rename od, d to prev_delta, delta
    
    And res to result.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index a73bef8..304a1c9 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -694,16 +694,16 @@ ProcessVelocityData2D(
  * constant-velocity response
  */
 static inline float
-ApplySimpleSoftening(int od, int d)
+ApplySimpleSoftening(int prev_delta, int delta)
 {
-    float res = d;
-    if (d <= 1 && d >= -1)
-        return res;
-    if (d > od)
-        res -= 0.5;
-    else if (d < od)
-        res += 0.5;
-    return res;
+    float result = delta;
+    if (delta <= 1 && delta >= -1)
+        return result;
+    if (delta > prev_delta)
+        result -= 0.5;
+    else if (delta < prev_delta)
+        result += 0.5;
+    return result;
 }
 
 
commit 5ffe06bada85e98d46a071dad578d72f5b96cb51
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 15:26:11 2011 +1000

    dix: Don't use short as bool
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index 104d1fe..a73bef8 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -714,7 +714,7 @@ ApplySofteningAndConstantDeceleration(
         int dy,
         float* fdx,
         float* fdy,
-        short do_soften)
+        BOOL do_soften)
 {
     if (do_soften && vel->use_softening) {
         *fdx = ApplySimpleSoftening(vel->last_dx, dx);
commit 97c1967689d7990be86ee490690ac5a91935c875
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 15:02:46 2011 +1000

    dix: rename "res" to "result" for improved readability
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index 358750a..104d1fe 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -759,7 +759,7 @@ ComputeAcceleration(
     DeviceVelocityPtr vel,
     float threshold,
     float acc){
-    float res;
+    float result;
 
     if(vel->velocity <= 0){
 	DebugAccelF("(dix ptracc) profile skipped\n");
@@ -774,24 +774,24 @@ ComputeAcceleration(
 	 * current and previous velocity.
 	 * Though being the more natural choice, it causes a minor delay
 	 * in comparison, so it can be disabled. */
-	res = BasicComputeAcceleration(
+	result = BasicComputeAcceleration(
 	          dev, vel, vel->velocity, threshold, acc);
-	res += BasicComputeAcceleration(
+	result += BasicComputeAcceleration(
 	          dev, vel, vel->last_velocity, threshold, acc);
-	res += 4.0f * BasicComputeAcceleration(dev, vel,
+	result += 4.0f * BasicComputeAcceleration(dev, vel,
 	                   (vel->last_velocity + vel->velocity) / 2,
 	                   threshold, acc);
-	res /= 6.0f;
+	result /= 6.0f;
 	DebugAccelF("(dix ptracc) profile average [%.2f ... %.2f] is %.3f\n",
-	            vel->velocity, vel->last_velocity, res);
+	            vel->velocity, vel->last_velocity, result);
     }else{
-	res = BasicComputeAcceleration(dev, vel,
-	                               vel->velocity, threshold, acc);
+	result = BasicComputeAcceleration(dev, vel,
+	                                  vel->velocity, threshold, acc);
 	DebugAccelF("(dix ptracc) profile sample [%.2f] is %.3f\n",
                vel->velocity, res);
     }
 
-    return res;
+    return result;
 }
 
 
commit 1c162ebcaba78930f34639145a8ac01b87f8e6fd
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 14:56:44 2011 +1000

    dix: change ProcessVelocityData2D to BOOL.
    
    Don't confuse users with a return type of short, that's even less indicative
    that it returns 0/non-0 than "int".
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index a8066de..358750a 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -670,7 +670,7 @@ QueryTrackers(DeviceVelocityPtr vel, int cur_t){
  * Perform velocity approximation based on 2D 'mickeys' (mouse motion delta).
  * return true if non-visible state reset is suggested
  */
-short
+BOOL
 ProcessVelocityData2D(
     DeviceVelocityPtr vel,
     int dx,
diff --git a/include/ptrveloc.h b/include/ptrveloc.h
index c14e12d..6ca309c 100644
--- a/include/ptrveloc.h
+++ b/include/ptrveloc.h
@@ -106,7 +106,7 @@ InitVelocityData(DeviceVelocityPtr vel);
 extern _X_EXPORT void
 InitTrackers(DeviceVelocityPtr vel, int ntracker);
 
-extern _X_EXPORT short
+extern _X_EXPORT BOOL
 ProcessVelocityData2D(DeviceVelocityPtr vel, int dx, int dy, int time);
 
 extern _X_EXPORT float
commit 70b76286dbef99daabbafccd23f3ba436fe07b09
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 16:28:21 2011 +1000

    dix: add some more documentation to ptraccel code
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index 7c43ede..a8066de 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -548,6 +548,10 @@ GetDirection(int dx, int dy){
 #define TRACKER_INDEX(s, d) (((s)->num_tracker + (s)->cur_tracker - (d)) % (s)->num_tracker)
 #define TRACKER(s, d) &(s)->tracker[TRACKER_INDEX(s,d)]
 
+/**
+ * Add the delta motion to each tracker, then reset the latest tracker to
+ * 0/0 and set it as the current one.
+ */
 static inline void
 FeedTrackers(DeviceVelocityPtr vel, int dx, int dy, int cur_t)
 {
@@ -583,10 +587,11 @@ CalcTracker(const MotionTracker *tracker, int cur_t){
 }
 
 /* find the most plausible velocity. That is, the most distant
- * (in time) tracker which isn't too old, beyond a linear partition,
- * or simply too much off initial velocity.
+ * (in time) tracker which isn't too old, the movement vector was
+ * in the same octant, and where the velocity is within an
+ * acceptable range to the inital velocity.
  *
- * May return 0.
+ * @return The tracker's velocity or 0 if the above conditions are unmet
  */
 static float
 QueryTrackers(DeviceVelocityPtr vel, int cur_t){
@@ -613,7 +618,7 @@ QueryTrackers(DeviceVelocityPtr vel, int cur_t){
 	 * non-linearities are accounted for.
 	 */
 	dir &= tracker->dir;
-	if(dir == 0){
+	if(dir == 0){ /* we've changed octant of movement (e.g. NE → NW) */
 	    DebugAccelF("(dix prtacc) query: no longer linear\n");
 	    /* instead of breaking it we might also inspect the partition after,
 	     * but actual improvement with this is probably rare. */
@@ -745,6 +750,8 @@ BasicComputeAcceleration(
 
 /**
  * Compute acceleration. Takes into account averaging, nv-reset, etc.
+ * If the velocity has changed, an average is taken of 6 velocity factors:
+ * current velocity, last velocity and 4 times the average between the two.
  */
 static float
 ComputeAcceleration(
@@ -1146,6 +1153,8 @@ acceleratePointerPredictable(
                                                       &fdx, &fdy,
                                                       (mult > 1.0f) && soften);
 
+                /* Calculate the new delta (with accel) and drop it back
+                 * into the valuator masks */
                 if (dx) {
                     tmp = mult * fdx + dev->last.remainder[0];
                     /* Since it may not be apparent: lrintf() does not offer
commit 6b3a4cc6af240c12d05e27250b61e954eafe9f29
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 14:44:51 2011 +1000

    dix: don't pass the index for a tracker around, pass the tracker
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index 6cbb35c..7c43ede 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -546,6 +546,7 @@ GetDirection(int dx, int dy){
 
 /* convert offset (age) to array index */
 #define TRACKER_INDEX(s, d) (((s)->num_tracker + (s)->cur_tracker - (d)) % (s)->num_tracker)
+#define TRACKER(s, d) &(s)->tracker[TRACKER_INDEX(s,d)]
 
 static inline void
 FeedTrackers(DeviceVelocityPtr vel, int dx, int dy, int cur_t)
@@ -589,15 +590,15 @@ CalcTracker(const MotionTracker *tracker, int cur_t){
  */
 static float
 QueryTrackers(DeviceVelocityPtr vel, int cur_t){
-    int n, offset, dir = UNDEFINED, i = -1, age_ms;
+    int offset, dir = UNDEFINED, i = -1, age_ms;
     /* initial velocity: a low-offset, valid velocity */
     float iveloc = 0, res = 0, tmp, vdiff;
     float vfac =  vel->corr_mul * vel->const_acceleration; /* premultiply */
     /* loop from current to older data */
     for(offset = 1; offset < vel->num_tracker; offset++){
-	n = TRACKER_INDEX(vel, offset);
+	MotionTracker *tracker = TRACKER(vel, offset);
 
-	age_ms = cur_t - vel->tracker[n].time;
+	age_ms = cur_t - tracker->time;
 
 	/* bail out if data is too old and protect from overrun */
 	if (age_ms >= vel->reset_time || age_ms < 0) {
@@ -611,7 +612,7 @@ QueryTrackers(DeviceVelocityPtr vel, int cur_t){
 	 * even more precision we could subdivide as a final step, so possible
 	 * non-linearities are accounted for.
 	 */
-	dir &= vel->tracker[n].dir;
+	dir &= tracker->dir;
 	if(dir == 0){
 	    DebugAccelF("(dix prtacc) query: no longer linear\n");
 	    /* instead of breaking it we might also inspect the partition after,
@@ -619,7 +620,7 @@ QueryTrackers(DeviceVelocityPtr vel, int cur_t){
 	    break;
 	}
 
-	tmp = CalcTracker(&vel->tracker[n], cur_t) * vfac;
+	tmp = CalcTracker(tracker, cur_t) * vfac;
 
 	if ((iveloc == 0 || offset <= vel->initial_range) && tmp != 0) {
 	    /* set initial velocity and result */
@@ -647,18 +648,18 @@ QueryTrackers(DeviceVelocityPtr vel, int cur_t){
 	DebugAccelF("(dix prtacc) query: last tracker in effect\n");
 	i = vel->num_tracker-1;
     }
+#ifdef PTRACCEL_DEBUGGING
     if(i>=0){
-        n = TRACKER_INDEX(vel, i);
+	MotionTracker *tracker = TRACKER(vel, i);
 	DebugAccelF("(dix prtacc) result: offset %i [dx: %i dy: %i diff: %i]\n",
-	            i,
-	            vel->tracker[n].dx,
-	            vel->tracker[n].dy,
-	            cur_t - vel->tracker[n].time);
+	            i, tracker->dx, tracker->dy, cur_t - tracker->time);
     }
+#endif
     return res;
 }
 
 #undef TRACKER_INDEX
+#undef TRACKER
 
 /**
  * Perform velocity approximation based on 2D 'mickeys' (mouse motion delta).
commit 9e8645cacf5f1c398d7a6e837a36c66cf6cf0c9c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 14:23:29 2011 +1000

    dix: CalcTracker only uses the tracker, thus only pass the tracker.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index 474c031..6cbb35c 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -572,11 +572,9 @@ FeedTrackers(DeviceVelocityPtr vel, int dx, int dy, int cur_t)
  * This assumes linear motion.
  */
 static float
-CalcTracker(DeviceVelocityPtr vel, int offset, int cur_t){
-    int index = TRACKER_INDEX(vel, offset);
-    float dist = sqrt(  vel->tracker[index].dx * vel->tracker[index].dx
-                      + vel->tracker[index].dy * vel->tracker[index].dy);
-    int dtime = cur_t - vel->tracker[index].time;
+CalcTracker(const MotionTracker *tracker, int cur_t){
+    float dist = sqrt(tracker->dx * tracker->dx + tracker->dy * tracker->dy);
+    int dtime = cur_t - tracker->time;
     if(dtime > 0)
 	return dist / dtime;
     else
@@ -621,7 +619,7 @@ QueryTrackers(DeviceVelocityPtr vel, int cur_t){
 	    break;
 	}
 
-	tmp = CalcTracker(vel, offset, cur_t) * vfac;
+	tmp = CalcTracker(&vel->tracker[n], cur_t) * vfac;
 
 	if ((iveloc == 0 || offset <= vel->initial_range) && tmp != 0) {
 	    /* set initial velocity and result */
commit 62f4bef82d1252515689420f8aac198e2f29c4f1
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Apr 21 13:58:55 2011 +1000

    dix: use single return statement in DoGetDirection
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index f51b0cb..474c031 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -453,54 +453,61 @@ enum directions {
  */
 static int
 DoGetDirection(int dx, int dy){
-    float r;
-    int i1, i2;
+    int dir = 0;
+
     /* on insignificant mickeys, flag 135 degrees */
     if(abs(dx) < 2 && abs(dy) < 2){
-	/* first check diagonal cases */
-	if(dx > 0 && dy > 0)
-	    return E | SE | S;
-	if(dx > 0 && dy < 0)
-	    return N | NE | E;
-	if(dx < 0 && dy < 0)
-	    return W | NW | N;
-	if(dx < 0 && dy > 0)
-	    return W | SW | S;
+        /* first check diagonal cases */
+        if(dx > 0 && dy > 0)
+            dir = E | SE | S;
+        else if(dx > 0 && dy < 0)
+            dir =  N | NE | E;
+        else if(dx < 0 && dy < 0)
+            dir =  W | NW | N;
+        else if(dx < 0 && dy > 0)
+            dir =  W | SW | S;
         /* check axis-aligned directions */
-	if(dx > 0)
-            return NE | E | SE;
-        if(dx < 0)
-            return NW | W | SW;
-        if(dy > 0)
-            return SE | S | SW;
-        if(dy < 0)
-            return NE | N | NW;
-        return UNDEFINED; /* shouldn't happen */
-    }
-    /* else, compute angle and set appropriate flags */
+        else if(dx > 0)
+            dir =  NE | E | SE;
+        else if(dx < 0)
+            dir =  NW | W | SW;
+        else if(dy > 0)
+            dir =  SE | S | SW;
+        else if(dy < 0)
+            dir =  NE | N | NW;
+        else
+            dir = UNDEFINED; /* shouldn't happen */
+    } else { /* compute angle and set appropriate flags */
+        float r;
+        int i1, i2;
+
 #ifdef _ISOC99_SOURCE
-    r = atan2f(dy, dx);
+        r = atan2f(dy, dx);
 #else
-    r = atan2(dy, dx);
+        r = atan2(dy, dx);
 #endif
-    /* find direction.
-     *
-     * Add 360° to avoid r become negative since C has no well-defined
-     * modulo for such cases. Then divide by 45° to get the octant number,
-     * e.g.     0 <= r <= 1 is [0-45]°
-     *          1 <= r <= 2 is [45-90]°
-     *          etc.
-     * But we add extra 90° to match up with our N, S, etc. defines up
-     * there, rest stays the same.
-     */
-    r = (r+(M_PI*2.5))/(M_PI/4);
-    /* this intends to flag 2 directions (45 degrees each),
-     * except on very well-aligned mickeys. */
-    i1 = (int)(r+0.1) % 8;
-    i2 = (int)(r+0.9) % 8;
-    if(i1 < 0 || i1 > 7 || i2 < 0 || i2 > 7)
-	return UNDEFINED; /* shouldn't happen */
-    return 1 << i1 | 1 << i2;
+        /* find direction.
+         *
+         * Add 360° to avoid r become negative since C has no well-defined
+         * modulo for such cases. Then divide by 45° to get the octant
+         * number,  e.g.
+         *          0 <= r <= 1 is [0-45]°
+         *          1 <= r <= 2 is [45-90]°
+         *          etc.
+         * But we add extra 90° to match up with our N, S, etc. defines up
+         * there, rest stays the same.
+         */
+        r = (r+(M_PI*2.5))/(M_PI/4);
+        /* this intends to flag 2 directions (45 degrees),
+         * except on very well-aligned mickeys. */
+        i1 = (int)(r+0.1) % 8;
+        i2 = (int)(r+0.9) % 8;
+        if(i1 < 0 || i1 > 7 || i2 < 0 || i2 > 7)
+            dir = UNDEFINED; /* shouldn't happen */
+        else
+            dir = (1 << i1 | 1 << i2);
+    }
+    return dir;
 }
 
 #define DIRECTION_CACHE_RANGE 5
commit 5f8edbe47e3915f71a20f063a9e8b49591239600
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 13:12:53 2011 +1000

    dix: use single return value in GetDirection
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index c0e3e6c..f51b0cb 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -516,22 +516,21 @@ DoGetDirection(int dx, int dy){
 static int
 GetDirection(int dx, int dy){
     static int cache[DIRECTION_CACHE_SIZE][DIRECTION_CACHE_SIZE];
-    int i;
+    int dir;
     if (abs(dx) <= DIRECTION_CACHE_RANGE &&
 	abs(dy) <= DIRECTION_CACHE_RANGE) {
 	/* cacheable */
-	i = cache[DIRECTION_CACHE_RANGE+dx][DIRECTION_CACHE_RANGE+dy];
-	if(i != 0){
-	    return i;
-	}else{
-	    i = DoGetDirection(dx, dy);
-	    cache[DIRECTION_CACHE_RANGE+dx][DIRECTION_CACHE_RANGE+dy] = i;
-	    return i;
+	dir = cache[DIRECTION_CACHE_RANGE+dx][DIRECTION_CACHE_RANGE+dy];
+	if(dir == 0) {
+	    dir = DoGetDirection(dx, dy);
+	    cache[DIRECTION_CACHE_RANGE+dx][DIRECTION_CACHE_RANGE+dy] = dir;
 	}
     }else{
 	/* non-cacheable */
-	return DoGetDirection(dx, dy);
+	dir = DoGetDirection(dx, dy);
     }
+
+    return dir;
 }
 
 #undef DIRECTION_CACHE_RANGE
commit afaa17812513232785c8c629294190629197dfd8
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 13:12:35 2011 +1000

    dix: document GetDirection
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index ab2bca7..c0e3e6c 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -506,7 +506,13 @@ DoGetDirection(int dx, int dy){
 #define DIRECTION_CACHE_RANGE 5
 #define DIRECTION_CACHE_SIZE (DIRECTION_CACHE_RANGE*2+1)
 
-/* cache DoGetDirection(). */
+/* cache DoGetDirection().
+ * To avoid excessive use of direction calculation, cache the values for
+ * [-5..5] for both x/y. Anything outside of that is calcualted on the fly.
+ *
+ * @return A bitmask for N, NE, S, SE, etc. indicating the directions for
+ * this movement.
+ */
 static int
 GetDirection(int dx, int dy){
     static int cache[DIRECTION_CACHE_SIZE][DIRECTION_CACHE_SIZE];
commit df90db892d16143742eb3c09e048f5b76457a62e
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 11:49:57 2011 +1000

    dix: document DoGetDirection's maths
    
    This is the best explanation I can come up with, but it seems to hold true
    for my example values.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index 3bf8716..ab2bca7 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -483,8 +483,16 @@ DoGetDirection(int dx, int dy){
 #else
     r = atan2(dy, dx);
 #endif
-    /* find direction. We avoid r to become negative,
-     * since C has no well-defined modulo for such cases. */
+    /* find direction.
+     *
+     * Add 360° to avoid r become negative since C has no well-defined
+     * modulo for such cases. Then divide by 45° to get the octant number,
+     * e.g.     0 <= r <= 1 is [0-45]°
+     *          1 <= r <= 2 is [45-90]°
+     *          etc.
+     * But we add extra 90° to match up with our N, S, etc. defines up
+     * there, rest stays the same.
+     */
     r = (r+(M_PI*2.5))/(M_PI/4);
     /* this intends to flag 2 directions (45 degrees each),
      * except on very well-aligned mickeys. */
commit 7513190ec7bc08db1629b04d3f88f86ea2b1588e
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 11:47:21 2011 +1000

    dix: improve comment, directions flagged are 45° each
    
    The two directions returned by this calculation are always the two boundary
    conditions. Since we don't do quadrants but octants, the flagged ones are
    45° each. e.g. an angle of 35° flags E and NE.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index e95ccbe..3bf8716 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -486,7 +486,7 @@ DoGetDirection(int dx, int dy){
     /* find direction. We avoid r to become negative,
      * since C has no well-defined modulo for such cases. */
     r = (r+(M_PI*2.5))/(M_PI/4);
-    /* this intends to flag 2 directions (90 degrees),
+    /* this intends to flag 2 directions (45 degrees each),
      * except on very well-aligned mickeys. */
     i1 = (int)(r+0.1) % 8;
     i2 = (int)(r+0.9) % 8;
commit e804ae85fec290894af69c2e65df55e73b417287
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 11:12:35 2011 +1000

    dix: improve readbility of DoGetDirection.
    
    Use enums for the direction bits, not hardcoded bitfield values that are
    added up.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index a913666..e95ccbe 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -429,14 +429,27 @@ InitTrackers(DeviceVelocityPtr vel, int ntracker)
     vel->num_tracker = ntracker;
 }
 
+enum directions {
+    N   = (1 << 0),
+    NE  = (1 << 1),
+    E   = (1 << 2),
+    SE  = (1 << 3),
+    S   = (1 << 4),
+    SW  = (1 << 5),
+    W   = (1 << 6),
+    NW  = (1 << 7),
+    UNDEFINED = 0xFF
+};
 /**
  * return a bit field of possible directions.
- * 0 = N, 2 = E, 4 = S, 6 = W, in-between is as you guess.
  * There's no reason against widening to more precise directions (<45 degrees),
  * should it not perform well. All this is needed for is sort out non-linear
  * motion, so precision isn't paramount. However, one should not flag direction
  * too narrow, since it would then cut the linear segment to zero size way too
  * often.
+ *
+ * @return A bitmask for N, NE, S, SE, etc. indicating the directions for
+ * this movement.
  */
 static int
 DoGetDirection(int dx, int dy){
@@ -446,23 +459,23 @@ DoGetDirection(int dx, int dy){
     if(abs(dx) < 2 && abs(dy) < 2){
 	/* first check diagonal cases */
 	if(dx > 0 && dy > 0)
-	    return 4+8+16;
+	    return E | SE | S;
 	if(dx > 0 && dy < 0)
-	    return 1+2+4;
+	    return N | NE | E;
 	if(dx < 0 && dy < 0)
-	    return 1+128+64;
+	    return W | NW | N;
 	if(dx < 0 && dy > 0)
-	    return 16+32+64;
+	    return W | SW | S;
         /* check axis-aligned directions */
 	if(dx > 0)
-            return 2+4+8; /*E*/
+            return NE | E | SE;
         if(dx < 0)
-            return 128+64+32; /*W*/
+            return NW | W | SW;
         if(dy > 0)
-            return 32+16+8; /*S*/
+            return SE | S | SW;
         if(dy < 0)
-            return 128+1+2; /*N*/
-        return 255; /* shouldn't happen */
+            return NE | N | NW;
+        return UNDEFINED; /* shouldn't happen */
     }
     /* else, compute angle and set appropriate flags */
 #ifdef _ISOC99_SOURCE
@@ -478,7 +491,7 @@ DoGetDirection(int dx, int dy){
     i1 = (int)(r+0.1) % 8;
     i2 = (int)(r+0.9) % 8;
     if(i1 < 0 || i1 > 7 || i2 < 0 || i2 > 7)
-	return 255; /* shouldn't happen */
+	return UNDEFINED; /* shouldn't happen */
     return 1 << i1 | 1 << i2;
 }
 
@@ -558,7 +571,7 @@ CalcTracker(DeviceVelocityPtr vel, int offset, int cur_t){
  */
 static float
 QueryTrackers(DeviceVelocityPtr vel, int cur_t){
-    int n, offset, dir = 255, i = -1, age_ms;
+    int n, offset, dir = UNDEFINED, i = -1, age_ms;
     /* initial velocity: a low-offset, valid velocity */
     float iveloc = 0, res = 0, tmp, vdiff;
     float vfac =  vel->corr_mul * vel->const_acceleration; /* premultiply */
commit 709b291972f8c65f4427f36b45ee78c3895d1e6e
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 10:40:28 2011 +1000

    dix: only use a single return where only one is needed.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index c40fbc0..a913666 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -745,14 +745,14 @@ ComputeAcceleration(
 	res /= 6.0f;
 	DebugAccelF("(dix ptracc) profile average [%.2f ... %.2f] is %.3f\n",
 	            vel->velocity, vel->last_velocity, res);
-        return res;
     }else{
 	res = BasicComputeAcceleration(dev, vel,
 	                               vel->velocity, threshold, acc);
 	DebugAccelF("(dix ptracc) profile sample [%.2f] is %.3f\n",
                vel->velocity, res);
-	return res;
     }
+
+    return res;
 }
 
 
commit 8c528c667da7c7fba0ba07973a06b2d4613fbf70
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 13:14:11 2011 +1000

    dix: fix typo in direction calculation
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index ccd445e..c40fbc0 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -443,7 +443,7 @@ DoGetDirection(int dx, int dy){
     float r;
     int i1, i2;
     /* on insignificant mickeys, flag 135 degrees */
-    if(abs(dx) < 2 && abs(dy < 2)){
+    if(abs(dx) < 2 && abs(dy) < 2){
 	/* first check diagonal cases */
 	if(dx > 0 && dy > 0)
 	    return 4+8+16;
commit 47f8cba6f3ae24e5dcdc4e348bdaaaf00d25a91c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Apr 11 14:50:16 2011 +1000

    xfree86: removed unused "event" variable in xf86PostMotionEventM
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 4cc47f5..ef4542c 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -1013,7 +1013,6 @@ xf86PostMotionEventM(DeviceIntPtr	device,
                      const ValuatorMask	*mask)
 {
     int i = 0, nevents = 0;
-    DeviceEvent *event;
     int flags = 0;
 
     if (valuator_mask_num_valuators(mask) > 0)
@@ -1054,7 +1053,6 @@ xf86PostMotionEventM(DeviceIntPtr	device,
     nevents = GetPointerEvents(xf86Events, device, MotionNotify, 0, flags, mask);
 
     for (i = 0; i < nevents; i++) {
-        event = (DeviceEvent*)((xf86Events + i)->event);
         mieqEnqueue(device, (InternalEvent*)((xf86Events + i)->event));
     }
 }
commit c6212a3e5dc43bd3b5263b392cb75ec96cdf4e4f
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Apr 15 14:13:51 2011 +1000

    dix: silence compiler warning
    
    resource.c: In function 'AddResource':
    resource.c:493:3: warning: format '%lx' expects type 'long unsigned int',
    but argument 3 has type 'RESTYPE'
    
    RESTYPE is uint32_t, not long.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/resource.c b/dix/resource.c
index a04f49f..eb9f049 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -489,7 +489,7 @@ AddResource(XID id, RESTYPE type, pointer value)
     rrec = &clientTable[client];
     if (!rrec->buckets)
     {
-	ErrorF("[dix] AddResource(%lx, %lx, %lx), client=%d \n",
+	ErrorF("[dix] AddResource(%lx, %x, %lx), client=%d \n",
 		(unsigned long)id, type, (unsigned long)value, client);
         FatalError("client not in use\n");
     }
commit 196d679bed2e9959d2fca89d4ee4bbc551681d0b
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Apr 15 14:51:06 2011 +1000

    test: remove glib dependency
    
    The few features from the glib test suite we used can be replaced with
    assert and printf. This patch is a simple replacement for these two
        g_assert → assert
        g_test_message → printf
    
    g_test_init is removed and so is g_test_bug_base. g_test_run replaced with a
    simple return 0.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Acked-by: Tiago Vignatti <tiago.vignatti at nokia.com>
    Acked-by: Gaetan Nadon <memsize at videotron.ca>

diff --git a/configure.ac b/configure.ac
index 24fb184..1668740 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,7 +44,6 @@ XORG_ENABLE_DEVEL_DOCS
 XORG_WITH_XMLTO(0.0.20)
 XORG_WITH_FOP
 XORG_ENABLE_UNIT_TESTS
-XORG_WITH_GLIB
 XORG_LD_WRAP
 
 m4_ifndef([XORG_FONT_MACROS_VERSION], [m4_fatal([must install fontutil 1.1 or later before running autoconf/autogen])])
@@ -791,7 +790,6 @@ LIBXFONT="xfont >= 1.4.2"
 LIBXI="xi >= 1.2.99.1"
 LIBXTST="xtst >= 1.0.99.2"
 LIBPCIACCESS="pciaccess >= 0.8.0"
-LIBGLIB="glib-2.0 >= 2.16"
 LIBUDEV="libudev >= 143"
 LIBSELINUX="libselinux >= 2.0.86"
 LIBDBUS="dbus-1 >= 1.0"
diff --git a/test/Makefile.am b/test/Makefile.am
index f3265b7..fe9bc1f 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,5 +1,4 @@
 if ENABLE_UNIT_TESTS
-if HAVE_GLIB
 if HAVE_LD_WRAP
 SUBDIRS= . xi2
 noinst_PROGRAMS = xkb input xtest list
@@ -7,9 +6,9 @@ check_LTLIBRARIES = libxservertest.la
 
 TESTS=$(noinst_PROGRAMS)
 
-AM_CFLAGS = $(DIX_CFLAGS) $(GLIB_CFLAGS) @XORG_CFLAGS@
+AM_CFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@
 INCLUDES = @XORG_INCS@
-TEST_LDADD=libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS) $(GLIB_LIBS)
+TEST_LDADD=libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS)
 
 if SPECIAL_DTRACE_OBJECTS
 TEST_LDADD += $(OS_LIB) $(DIX_LIB)
@@ -38,7 +37,6 @@ libxservertest_la_LIBADD = \
             @XORG_LIBS@
 endif
 endif
-endif
 
 CLEANFILES=libxservertest.c
 
diff --git a/test/input.c b/test/input.c
index 89cce3f..ac37d67 100644
--- a/test/input.c
+++ b/test/input.c
@@ -40,7 +40,7 @@
 #include "dixgrabs.h"
 #include "eventstr.h"
 #include "inpututils.h"
-#include <glib.h>
+#include "assert.h"
 
 /**
  * Init a device with axes.
@@ -60,24 +60,24 @@ static void dix_init_valuators(void)
     memset(&dev, 0, sizeof(DeviceIntRec));
     dev.type = MASTER_POINTER; /* claim it's a master to stop ptracccel */
 
-    g_assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE);
-    g_assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute));
+    assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE);
+    assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute));
 
     val = dev.valuator;
-    g_assert(val);
-    g_assert(val->numAxes == num_axes);
-    g_assert(val->numMotionEvents == 0);
-    g_assert(val->axisVal);
+    assert(val);
+    assert(val->numAxes == num_axes);
+    assert(val->numMotionEvents == 0);
+    assert(val->axisVal);
 
     for (i = 0; i < num_axes; i++)
     {
-        g_assert(val->axisVal[i] == 0);
-        g_assert(val->axes->min_value == NO_AXIS_LIMITS);
-        g_assert(val->axes->max_value == NO_AXIS_LIMITS);
-        g_assert(val->axes->mode == Absolute);
+        assert(val->axisVal[i] == 0);
+        assert(val->axes->min_value == NO_AXIS_LIMITS);
+        assert(val->axes->max_value == NO_AXIS_LIMITS);
+        assert(val->axes->mode == Absolute);
     }
 
-    g_assert(dev.last.numValuators == num_axes);
+    assert(dev.last.numValuators == num_axes);
 }
 
 /* just check the known success cases, and that error cases set the client's
@@ -97,48 +97,48 @@ static void dix_check_grab_values(void)
     param.ownerEvents = FALSE;
 
     rc = CheckGrabValues(&client, &param);
-    g_assert(rc == Success);
+    assert(rc == Success);
 
     param.this_device_mode = GrabModeAsync;
     rc = CheckGrabValues(&client, &param);
-    g_assert(rc == Success);
+    assert(rc == Success);
 
     param.this_device_mode = GrabModeAsync + 1;
     rc = CheckGrabValues(&client, &param);
-    g_assert(rc == BadValue);
-    g_assert(client.errorValue == param.this_device_mode);
-    g_assert(client.errorValue == GrabModeAsync + 1);
+    assert(rc == BadValue);
+    assert(client.errorValue == param.this_device_mode);
+    assert(client.errorValue == GrabModeAsync + 1);
 
     param.this_device_mode = GrabModeSync;
     param.other_devices_mode = GrabModeAsync;
     rc = CheckGrabValues(&client, &param);
-    g_assert(rc == Success);
+    assert(rc == Success);
 
     param.other_devices_mode = GrabModeAsync + 1;
     rc = CheckGrabValues(&client, &param);
-    g_assert(rc == BadValue);
-    g_assert(client.errorValue == param.other_devices_mode);
-    g_assert(client.errorValue == GrabModeAsync + 1);
+    assert(rc == BadValue);
+    assert(client.errorValue == param.other_devices_mode);
+    assert(client.errorValue == GrabModeAsync + 1);
 
     param.other_devices_mode = GrabModeSync;
 
     param.modifiers = 1 << 13;
     rc = CheckGrabValues(&client, &param);
-    g_assert(rc == BadValue);
-    g_assert(client.errorValue == param.modifiers);
-    g_assert(client.errorValue == (1 << 13));
+    assert(rc == BadValue);
+    assert(client.errorValue == param.modifiers);
+    assert(client.errorValue == (1 << 13));
 
 
     param.modifiers = AnyModifier;
     param.ownerEvents = TRUE;
     rc = CheckGrabValues(&client, &param);
-    g_assert(rc == Success);
+    assert(rc == Success);
 
     param.ownerEvents = 3;
     rc = CheckGrabValues(&client, &param);
-    g_assert(rc == BadValue);
-    g_assert(client.errorValue == param.ownerEvents);
-    g_assert(client.errorValue == 3);
+    assert(rc == BadValue);
+    assert(client.errorValue == param.ownerEvents);
+    assert(client.errorValue == 3);
 }
 
 
@@ -160,21 +160,21 @@ static void dix_event_to_core(int type)
 
     /* EventToCore memsets the event to 0 */
 #define test_event() \
-    g_assert(rc == Success); \
-    g_assert(core); \
-    g_assert(count == 1); \
-    g_assert(core->u.u.type == type); \
-    g_assert(core->u.u.detail == detail); \
-    g_assert(core->u.keyButtonPointer.time == time); \
-    g_assert(core->u.keyButtonPointer.rootX == x); \
-    g_assert(core->u.keyButtonPointer.rootY == y); \
-    g_assert(core->u.keyButtonPointer.state == state); \
-    g_assert(core->u.keyButtonPointer.eventX == 0); \
-    g_assert(core->u.keyButtonPointer.eventY == 0); \
-    g_assert(core->u.keyButtonPointer.root == ROOT_WINDOW_ID); \
-    g_assert(core->u.keyButtonPointer.event == 0); \
-    g_assert(core->u.keyButtonPointer.child == 0); \
-    g_assert(core->u.keyButtonPointer.sameScreen == FALSE);
+    assert(rc == Success); \
+    assert(core); \
+    assert(count == 1); \
+    assert(core->u.u.type == type); \
+    assert(core->u.u.detail == detail); \
+    assert(core->u.keyButtonPointer.time == time); \
+    assert(core->u.keyButtonPointer.rootX == x); \
+    assert(core->u.keyButtonPointer.rootY == y); \
+    assert(core->u.keyButtonPointer.state == state); \
+    assert(core->u.keyButtonPointer.eventX == 0); \
+    assert(core->u.keyButtonPointer.eventY == 0); \
+    assert(core->u.keyButtonPointer.root == ROOT_WINDOW_ID); \
+    assert(core->u.keyButtonPointer.event == 0); \
+    assert(core->u.keyButtonPointer.child == 0); \
+    assert(core->u.keyButtonPointer.sameScreen == FALSE);
 
     x = 0;
     y = 0;
@@ -217,11 +217,11 @@ static void dix_event_to_core(int type)
     ev.root_x = x;
     ev.root_y = y;
     rc = EventToCore((InternalEvent*)&ev, &core, &count);
-    g_assert(rc == Success);
-    g_assert(core);
-    g_assert(count == 1);
-    g_assert(core->u.keyButtonPointer.rootX != x);
-    g_assert(core->u.keyButtonPointer.rootY != y);
+    assert(rc == Success);
+    assert(core);
+    assert(count == 1);
+    assert(core->u.keyButtonPointer.rootX != x);
+    assert(core->u.keyButtonPointer.rootY != y);
 
     x = 0x7FFF;
     y = 0x7FFF;
@@ -245,7 +245,7 @@ static void dix_event_to_core(int type)
     detail = 0xFFF; /* too big */
     ev.detail.key = detail;
     rc = EventToCore((InternalEvent*)&ev, &core, &count);
-    g_assert(rc == BadMatch);
+    assert(rc == BadMatch);
 
     detail = 0xFF; /* too big */
     ev.detail.key = detail;
@@ -257,11 +257,11 @@ static void dix_event_to_core(int type)
     state = 0x10000; /* too big */
     ev.corestate = state;
     rc = EventToCore((InternalEvent*)&ev, &core, &count);
-    g_assert(rc == Success);
-    g_assert(core);
-    g_assert(count == 1);
-    g_assert(core->u.keyButtonPointer.state != state);
-    g_assert(core->u.keyButtonPointer.state == (state & 0xFFFF));
+    assert(rc == Success);
+    assert(core);
+    assert(count == 1);
+    assert(core->u.keyButtonPointer.state != state);
+    assert(core->u.keyButtonPointer.state == (state & 0xFFFF));
 
 #undef test_event
 }
@@ -278,7 +278,7 @@ static void dix_event_to_core_fail(int evtype, int expected_rc)
 
     ev.type     = evtype;
     rc = EventToCore((InternalEvent*)&ev, &core, &count);
-    g_assert(rc == expected_rc);
+    assert(rc == expected_rc);
 }
 
 static void dix_event_to_core_conversion(void)
@@ -304,28 +304,28 @@ _dix_test_xi_convert(DeviceEvent *ev, int expected_rc, int expected_count)
     int rc;
 
     rc = EventToXI((InternalEvent*)ev, &xi, &count);
-    g_assert(rc == expected_rc);
-    g_assert(count >= expected_count);
+    assert(rc == expected_rc);
+    assert(count >= expected_count);
     if (count > 0){
         deviceKeyButtonPointer *kbp = (deviceKeyButtonPointer*)xi;
-        g_assert(kbp->type == IEventBase + ev->type);
-        g_assert(kbp->detail == ev->detail.key);
-        g_assert(kbp->time == ev->time);
-        g_assert((kbp->deviceid & ~MORE_EVENTS) == ev->deviceid);
-        g_assert(kbp->root_x == ev->root_x);
-        g_assert(kbp->root_y == ev->root_y);
-        g_assert(kbp->state == ev->corestate);
-        g_assert(kbp->event_x == 0);
-        g_assert(kbp->event_y == 0);
-        g_assert(kbp->root == ev->root);
-        g_assert(kbp->event == 0);
-        g_assert(kbp->child == 0);
-        g_assert(kbp->same_screen == FALSE);
+        assert(kbp->type == IEventBase + ev->type);
+        assert(kbp->detail == ev->detail.key);
+        assert(kbp->time == ev->time);
+        assert((kbp->deviceid & ~MORE_EVENTS) == ev->deviceid);
+        assert(kbp->root_x == ev->root_x);
+        assert(kbp->root_y == ev->root_y);
+        assert(kbp->state == ev->corestate);
+        assert(kbp->event_x == 0);
+        assert(kbp->event_y == 0);
+        assert(kbp->root == ev->root);
+        assert(kbp->event == 0);
+        assert(kbp->child == 0);
+        assert(kbp->same_screen == FALSE);
 
         while (--count > 0) {
             deviceValuator *v = (deviceValuator*)&xi[count];
-            g_assert(v->type == DeviceValuator);
-            g_assert(v->num_valuators <= 6);
+            assert(v->type == DeviceValuator);
+            assert(v->num_valuators <= 6);
         }
 
 
@@ -436,7 +436,7 @@ static void dix_event_to_xi1_conversion(void)
 static void xi2_struct_sizes(void)
 {
 #define compare(req) \
-    g_assert(sizeof(req) == sz_##req);
+    assert(sizeof(req) == sz_##req);
 
     compare(xXIQueryVersionReq);
     compare(xXIWarpPointerReq);
@@ -476,23 +476,23 @@ static void dix_grab_matching(void)
     a.grabtype = GRABTYPE_CORE;
     b.grabtype = GRABTYPE_XI2;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.grabtype = GRABTYPE_XI;
     b.grabtype = GRABTYPE_XI2;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.grabtype = GRABTYPE_XI;
     b.grabtype = GRABTYPE_CORE;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     /* XI2 grabs for different devices must fail, regardless of ignoreDevice
      * XI2 grabs for master devices must fail against a slave */
@@ -516,28 +516,28 @@ static void dix_grab_matching(void)
     b.device = &dev2;
 
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.device = &dev2;
     b.device = &dev1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&a, &b, TRUE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.device = inputInfo.all_master_devices;
     b.device = &dev1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&a, &b, TRUE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.device = &dev1;
     b.device = inputInfo.all_master_devices;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&a, &b, TRUE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     /* ignoreDevice FALSE must fail for different devices for CORE and XI */
     a.grabtype = GRABTYPE_XI;
@@ -547,7 +547,7 @@ static void dix_grab_matching(void)
     a.modifierDevice = &dev1;
     b.modifierDevice = &dev1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.grabtype = GRABTYPE_CORE;
     b.grabtype = GRABTYPE_CORE;
@@ -556,7 +556,7 @@ static void dix_grab_matching(void)
     a.modifierDevice = &dev1;
     b.modifierDevice = &dev1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     /* ignoreDevice FALSE must fail for different modifier devices for CORE
      * and XI */
@@ -567,7 +567,7 @@ static void dix_grab_matching(void)
     a.modifierDevice = &dev1;
     b.modifierDevice = &dev2;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.grabtype = GRABTYPE_CORE;
     b.grabtype = GRABTYPE_CORE;
@@ -576,7 +576,7 @@ static void dix_grab_matching(void)
     a.modifierDevice = &dev1;
     b.modifierDevice = &dev2;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     /* different event type must fail */
     a.grabtype = GRABTYPE_XI2;
@@ -588,9 +588,9 @@ static void dix_grab_matching(void)
     a.type = XI_KeyPress;
     b.type = XI_KeyRelease;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&a, &b, TRUE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.grabtype = GRABTYPE_CORE;
     b.grabtype = GRABTYPE_CORE;
@@ -601,9 +601,9 @@ static void dix_grab_matching(void)
     a.type = XI_KeyPress;
     b.type = XI_KeyRelease;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&a, &b, TRUE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.grabtype = GRABTYPE_XI;
     b.grabtype = GRABTYPE_XI;
@@ -614,9 +614,9 @@ static void dix_grab_matching(void)
     a.type = XI_KeyPress;
     b.type = XI_KeyRelease;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&a, &b, TRUE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     /* different modifiers must fail */
     a.grabtype = GRABTYPE_XI2;
@@ -630,23 +630,23 @@ static void dix_grab_matching(void)
     a.modifiersDetail.exact = 1;
     b.modifiersDetail.exact = 2;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.grabtype = GRABTYPE_CORE;
     b.grabtype = GRABTYPE_CORE;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.grabtype = GRABTYPE_XI;
     b.grabtype = GRABTYPE_XI;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     /* AnyModifier must fail for XI2 */
     a.grabtype = GRABTYPE_XI2;
@@ -654,9 +654,9 @@ static void dix_grab_matching(void)
     a.modifiersDetail.exact = AnyModifier;
     b.modifiersDetail.exact = 1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     /* XIAnyModifier must fail for CORE and XI */
     a.grabtype = GRABTYPE_XI;
@@ -664,18 +664,18 @@ static void dix_grab_matching(void)
     a.modifiersDetail.exact = XIAnyModifier;
     b.modifiersDetail.exact = 1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.grabtype = GRABTYPE_CORE;
     b.grabtype = GRABTYPE_CORE;
     a.modifiersDetail.exact = XIAnyModifier;
     b.modifiersDetail.exact = 1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     /* different detail must fail */
     a.grabtype = GRABTYPE_XI2;
@@ -685,23 +685,23 @@ static void dix_grab_matching(void)
     a.modifiersDetail.exact = 1;
     b.modifiersDetail.exact = 1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.grabtype = GRABTYPE_XI;
     b.grabtype = GRABTYPE_XI;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.grabtype = GRABTYPE_CORE;
     b.grabtype = GRABTYPE_CORE;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     /* detail of AnyModifier must fail */
     a.grabtype = GRABTYPE_XI2;
@@ -711,23 +711,23 @@ static void dix_grab_matching(void)
     a.modifiersDetail.exact = 1;
     b.modifiersDetail.exact = 1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.grabtype = GRABTYPE_CORE;
     b.grabtype = GRABTYPE_CORE;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.grabtype = GRABTYPE_XI;
     b.grabtype = GRABTYPE_XI;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     /* detail of XIAnyModifier must fail */
     a.grabtype = GRABTYPE_XI2;
@@ -737,23 +737,23 @@ static void dix_grab_matching(void)
     a.modifiersDetail.exact = 1;
     b.modifiersDetail.exact = 1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.grabtype = GRABTYPE_CORE;
     b.grabtype = GRABTYPE_CORE;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     a.grabtype = GRABTYPE_XI;
     b.grabtype = GRABTYPE_XI;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == FALSE);
+    assert(rc == FALSE);
 
     /* XIAnyModifier or AnyModifer must succeed */
     a.grabtype = GRABTYPE_XI2;
@@ -763,9 +763,9 @@ static void dix_grab_matching(void)
     a.modifiersDetail.exact = XIAnyModifier;
     b.modifiersDetail.exact = 1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == TRUE);
+    assert(rc == TRUE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == TRUE);
+    assert(rc == TRUE);
 
     a.grabtype = GRABTYPE_CORE;
     b.grabtype = GRABTYPE_CORE;
@@ -774,9 +774,9 @@ static void dix_grab_matching(void)
     a.modifiersDetail.exact = AnyModifier;
     b.modifiersDetail.exact = 1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == TRUE);
+    assert(rc == TRUE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == TRUE);
+    assert(rc == TRUE);
 
     a.grabtype = GRABTYPE_XI;
     b.grabtype = GRABTYPE_XI;
@@ -785,9 +785,9 @@ static void dix_grab_matching(void)
     a.modifiersDetail.exact = AnyModifier;
     b.modifiersDetail.exact = 1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == TRUE);
+    assert(rc == TRUE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == TRUE);
+    assert(rc == TRUE);
 
     /* AnyKey or XIAnyKeycode must succeed */
     a.grabtype = GRABTYPE_XI2;
@@ -797,9 +797,9 @@ static void dix_grab_matching(void)
     a.modifiersDetail.exact = 1;
     b.modifiersDetail.exact = 1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == TRUE);
+    assert(rc == TRUE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == TRUE);
+    assert(rc == TRUE);
 
     a.grabtype = GRABTYPE_CORE;
     b.grabtype = GRABTYPE_CORE;
@@ -808,9 +808,9 @@ static void dix_grab_matching(void)
     a.modifiersDetail.exact = 1;
     b.modifiersDetail.exact = 1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == TRUE);
+    assert(rc == TRUE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == TRUE);
+    assert(rc == TRUE);
 
     a.grabtype = GRABTYPE_XI;
     b.grabtype = GRABTYPE_XI;
@@ -819,9 +819,9 @@ static void dix_grab_matching(void)
     a.modifiersDetail.exact = 1;
     b.modifiersDetail.exact = 1;
     rc = GrabMatchesSecond(&a, &b, FALSE);
-    g_assert(rc == TRUE);
+    assert(rc == TRUE);
     rc = GrabMatchesSecond(&b, &a, FALSE);
-    g_assert(rc == TRUE);
+    assert(rc == TRUE);
 }
 
 static void test_bits_to_byte(int i)
@@ -829,9 +829,9 @@ static void test_bits_to_byte(int i)
         int expected_bytes;
         expected_bytes = (i + 7)/8;
 
-        g_assert(bits_to_bytes(i) >= i/8);
-        g_assert((bits_to_bytes(i) * 8) - i <= 7);
-        g_assert(expected_bytes == bits_to_bytes(i));
+        assert(bits_to_bytes(i) >= i/8);
+        assert((bits_to_bytes(i) * 8) - i <= 7);
+        assert(expected_bytes == bits_to_bytes(i));
 }
 
 static void test_bytes_to_int32(int i)
@@ -839,9 +839,9 @@ static void test_bytes_to_int32(int i)
         int expected_4byte;
         expected_4byte = (i + 3)/4;
 
-        g_assert(bytes_to_int32(i) <= i);
-        g_assert((bytes_to_int32(i) * 4) - i <= 3);
-        g_assert(expected_4byte == bytes_to_int32(i));
+        assert(bytes_to_int32(i) <= i);
+        assert((bytes_to_int32(i) * 4) - i <= 3);
+        assert(expected_4byte == bytes_to_int32(i));
 }
 
 static void test_pad_to_int32(int i)
@@ -849,13 +849,13 @@ static void test_pad_to_int32(int i)
         int expected_bytes;
         expected_bytes = ((i + 3)/4) * 4;
 
-        g_assert(pad_to_int32(i) >= i);
-        g_assert(pad_to_int32(i) - i <= 3);
-        g_assert(expected_bytes == pad_to_int32(i));
+        assert(pad_to_int32(i) >= i);
+        assert(pad_to_int32(i) - i <= 3);
+        assert(expected_bytes == pad_to_int32(i));
 }
 static void include_byte_padding_macros(void)
 {
-    g_test_message("Testing bits_to_bytes()");
+    printf("Testing bits_to_bytes()\n");
 
     /* the macros don't provide overflow protection */
     test_bits_to_byte(0);
@@ -868,7 +868,7 @@ static void include_byte_padding_macros(void)
     test_bits_to_byte(INT_MAX - 9);
     test_bits_to_byte(INT_MAX - 8);
 
-    g_test_message("Testing bytes_to_int32()");
+    printf("Testing bytes_to_int32()\n");
 
     test_bytes_to_int32(0);
     test_bytes_to_int32(1);
@@ -884,7 +884,7 @@ static void include_byte_padding_macros(void)
     test_bytes_to_int32(INT_MAX - 4);
     test_bytes_to_int32(INT_MAX - 3);
 
-    g_test_message("Testing pad_to_int32");
+    printf("Testing pad_to_int32\n");
 
     test_pad_to_int32(0);
     test_pad_to_int32(0);
@@ -910,47 +910,47 @@ static void xi_unregister_handlers(void)
     memset(&dev, 0, sizeof(dev));
 
     handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
-    g_assert(handler == 1);
+    assert(handler == 1);
     handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
-    g_assert(handler == 2);
+    assert(handler == 2);
     handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
-    g_assert(handler == 3);
+    assert(handler == 3);
 
-    g_test_message("Unlinking from front.");
+    printf("Unlinking from front.\n");
 
     XIUnregisterPropertyHandler(&dev, 4); /* NOOP */
-    g_assert(dev.properties.handlers->id == 3);
+    assert(dev.properties.handlers->id == 3);
     XIUnregisterPropertyHandler(&dev, 3);
-    g_assert(dev.properties.handlers->id == 2);
+    assert(dev.properties.handlers->id == 2);
     XIUnregisterPropertyHandler(&dev, 2);
-    g_assert(dev.properties.handlers->id == 1);
+    assert(dev.properties.handlers->id == 1);
     XIUnregisterPropertyHandler(&dev, 1);
-    g_assert(dev.properties.handlers == NULL);
+    assert(dev.properties.handlers == NULL);
 
     handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
-    g_assert(handler == 4);
+    assert(handler == 4);
     handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
-    g_assert(handler == 5);
+    assert(handler == 5);
     handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
-    g_assert(handler == 6);
+    assert(handler == 6);
     XIUnregisterPropertyHandler(&dev, 3); /* NOOP */
-    g_assert(dev.properties.handlers->next->next->next == NULL);
+    assert(dev.properties.handlers->next->next->next == NULL);
     XIUnregisterPropertyHandler(&dev, 4);
-    g_assert(dev.properties.handlers->next->next == NULL);
+    assert(dev.properties.handlers->next->next == NULL);
     XIUnregisterPropertyHandler(&dev, 5);
-    g_assert(dev.properties.handlers->next == NULL);
+    assert(dev.properties.handlers->next == NULL);
     XIUnregisterPropertyHandler(&dev, 6);
-    g_assert(dev.properties.handlers == NULL);
+    assert(dev.properties.handlers == NULL);
 
     handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
-    g_assert(handler == 7);
+    assert(handler == 7);
     handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
-    g_assert(handler == 8);
+    assert(handler == 8);
     handler = XIRegisterPropertyHandler(&dev, NULL, NULL, NULL);
-    g_assert(handler == 9);
+    assert(handler == 9);
 
     XIDeleteAllDeviceProperties(&dev);
-    g_assert(dev.properties.handlers == NULL);
+    assert(dev.properties.handlers == NULL);
     XIUnregisterPropertyHandler(&dev, 7); /* NOOP */
 
 }
@@ -960,44 +960,44 @@ static void cmp_attr_fields(InputAttributes *attr1,
 {
     char **tags1, **tags2;
 
-    g_assert(attr1 && attr2);
-    g_assert(attr1 != attr2);
-    g_assert(attr1->flags == attr2->flags);
+    assert(attr1 && attr2);
+    assert(attr1 != attr2);
+    assert(attr1->flags == attr2->flags);
 
     if (attr1->product != NULL)
     {
-        g_assert(attr1->product != attr2->product);
-        g_assert(strcmp(attr1->product, attr2->product) == 0);
+        assert(attr1->product != attr2->product);
+        assert(strcmp(attr1->product, attr2->product) == 0);
     } else
-        g_assert(attr2->product == NULL);
+        assert(attr2->product == NULL);
 
     if (attr1->vendor != NULL)
     {
-        g_assert(attr1->vendor != attr2->vendor);
-        g_assert(strcmp(attr1->vendor, attr2->vendor) == 0);
+        assert(attr1->vendor != attr2->vendor);
+        assert(strcmp(attr1->vendor, attr2->vendor) == 0);
     } else
-        g_assert(attr2->vendor == NULL);
+        assert(attr2->vendor == NULL);
 
     if (attr1->device != NULL)
     {
-        g_assert(attr1->device != attr2->device);
-        g_assert(strcmp(attr1->device, attr2->device) == 0);
+        assert(attr1->device != attr2->device);
+        assert(strcmp(attr1->device, attr2->device) == 0);
     } else
-        g_assert(attr2->device == NULL);
+        assert(attr2->device == NULL);
 
     if (attr1->pnp_id != NULL)
     {
-        g_assert(attr1->pnp_id != attr2->pnp_id);
-        g_assert(strcmp(attr1->pnp_id, attr2->pnp_id) == 0);
+        assert(attr1->pnp_id != attr2->pnp_id);
+        assert(strcmp(attr1->pnp_id, attr2->pnp_id) == 0);
     } else
-        g_assert(attr2->pnp_id == NULL);
+        assert(attr2->pnp_id == NULL);
 
     if (attr1->usb_id != NULL)
     {
-        g_assert(attr1->usb_id != attr2->usb_id);
-        g_assert(strcmp(attr1->usb_id, attr2->usb_id) == 0);
+        assert(attr1->usb_id != attr2->usb_id);
+        assert(strcmp(attr1->usb_id, attr2->usb_id) == 0);
     } else
-        g_assert(attr2->usb_id == NULL);
+        assert(attr2->usb_id == NULL);
 
     tags1 = attr1->tags;
     tags2 = attr2->tags;
@@ -1005,25 +1005,25 @@ static void cmp_attr_fields(InputAttributes *attr1,
     /* if we don't have any tags, skip the tag checking bits */
     if (!tags1)
     {
-        g_assert(!tags2);
+        assert(!tags2);
         return;
     }
 
     /* Don't lug around empty arrays */
-    g_assert(*tags1);
-    g_assert(*tags2);
+    assert(*tags1);
+    assert(*tags2);
 
     /* check for identical content, but duplicated */
     while (*tags1)
     {
-        g_assert(*tags1 != *tags2);
-        g_assert(strcmp(*tags1, *tags2) == 0);
+        assert(*tags1 != *tags2);
+        assert(strcmp(*tags1, *tags2) == 0);
         tags1++;
         tags2++;
     }
 
     /* ensure tags1 and tags2 have the same no of elements */
-    g_assert(!*tags2);
+    assert(!*tags2);
 
     /* check for not sharing memory */
     tags1 = attr1->tags;
@@ -1031,7 +1031,7 @@ static void cmp_attr_fields(InputAttributes *attr1,
     {
         tags2 = attr2->tags;
         while (*tags2)
-            g_assert(*tags1 != *tags2++);
+            assert(*tags1 != *tags2++);
 
         tags1++;
     }
@@ -1044,10 +1044,10 @@ static void dix_input_attributes(void)
     char *tags[4] = {"tag1", "tag2", "tag2", NULL};
 
     new = DuplicateInputAttributes(NULL);
-    g_assert(!new);
+    assert(!new);
 
     new = DuplicateInputAttributes(&orig);
-    g_assert(memcmp(&orig, new, sizeof(InputAttributes)) == 0);
+    assert(memcmp(&orig, new, sizeof(InputAttributes)) == 0);
 
     orig.product = "product name";
     new = DuplicateInputAttributes(&orig);
@@ -1097,69 +1097,69 @@ static void dix_input_valuator_masks(void)
         valuators[i] = i;
 
     mask = valuator_mask_new(nvaluators);
-    g_assert(mask != NULL);
-    g_assert(valuator_mask_size(mask) == 0);
-    g_assert(valuator_mask_num_valuators(mask) == 0);
+    assert(mask != NULL);
+    assert(valuator_mask_size(mask) == 0);
+    assert(valuator_mask_num_valuators(mask) == 0);
 
     for (i = 0; i < nvaluators; i++)
     {
-        g_assert(!valuator_mask_isset(mask, i));
+        assert(!valuator_mask_isset(mask, i));
         valuator_mask_set(mask, i, valuators[i]);
-        g_assert(valuator_mask_isset(mask, i));
-        g_assert(valuator_mask_get(mask, i) == valuators[i]);
-        g_assert(valuator_mask_size(mask) == i + 1);
-        g_assert(valuator_mask_num_valuators(mask) == i + 1);
+        assert(valuator_mask_isset(mask, i));
+        assert(valuator_mask_get(mask, i) == valuators[i]);
+        assert(valuator_mask_size(mask) == i + 1);
+        assert(valuator_mask_num_valuators(mask) == i + 1);
     }
 
     for (i = 0; i < nvaluators; i++)
     {
-        g_assert(valuator_mask_isset(mask, i));
+        assert(valuator_mask_isset(mask, i));
         valuator_mask_unset(mask, i);
         /* we're removing valuators from the front, so size should stay the
          * same until the last bit is removed */
         if (i < nvaluators - 1)
-            g_assert(valuator_mask_size(mask) == nvaluators);
-        g_assert(!valuator_mask_isset(mask, i));
+            assert(valuator_mask_size(mask) == nvaluators);
+        assert(!valuator_mask_isset(mask, i));
     }
 
-    g_assert(valuator_mask_size(mask) == 0);
+    assert(valuator_mask_size(mask) == 0);
     valuator_mask_zero(mask);
-    g_assert(valuator_mask_size(mask) == 0);
-    g_assert(valuator_mask_num_valuators(mask) == 0);
+    assert(valuator_mask_size(mask) == 0);
+    assert(valuator_mask_num_valuators(mask) == 0);
     for (i = 0; i < nvaluators; i++)
-        g_assert(!valuator_mask_isset(mask, i));
+        assert(!valuator_mask_isset(mask, i));
 
     first_val = 5;
     num_vals = 6;
 
     valuator_mask_set_range(mask, first_val, num_vals, valuators);
-    g_assert(valuator_mask_size(mask) == first_val + num_vals);
-    g_assert(valuator_mask_num_valuators(mask) == num_vals);
+    assert(valuator_mask_size(mask) == first_val + num_vals);
+    assert(valuator_mask_num_valuators(mask) == num_vals);
     for (i = 0; i < nvaluators; i++)
     {
         if (i < first_val || i >= first_val + num_vals)
-            g_assert(!valuator_mask_isset(mask, i));
+            assert(!valuator_mask_isset(mask, i));
         else
         {
-            g_assert(valuator_mask_isset(mask, i));
-            g_assert(valuator_mask_get(mask, i) == valuators[i - first_val]);
+            assert(valuator_mask_isset(mask, i));
+            assert(valuator_mask_get(mask, i) == valuators[i - first_val]);
         }
     }
 
     copy = valuator_mask_new(nvaluators);
     valuator_mask_copy(copy, mask);
-    g_assert(mask != copy);
-    g_assert(valuator_mask_size(mask) == valuator_mask_size(copy));
-    g_assert(valuator_mask_num_valuators(mask) == valuator_mask_num_valuators(copy));
+    assert(mask != copy);
+    assert(valuator_mask_size(mask) == valuator_mask_size(copy));
+    assert(valuator_mask_num_valuators(mask) == valuator_mask_num_valuators(copy));
 
     for (i = 0; i < nvaluators; i++)
     {
-        g_assert(valuator_mask_isset(mask, i) == valuator_mask_isset(copy, i));
-        g_assert(valuator_mask_get(mask, i) == valuator_mask_get(copy, i));
+        assert(valuator_mask_isset(mask, i) == valuator_mask_isset(copy, i));
+        assert(valuator_mask_get(mask, i) == valuator_mask_get(copy, i));
     }
 
     valuator_mask_free(&mask);
-    g_assert(mask == NULL);
+    assert(mask == NULL);
 }
 
 static void dix_valuator_mode(void)
@@ -1172,24 +1172,24 @@ static void dix_valuator_mode(void)
     memset(&dev, 0, sizeof(DeviceIntRec));
     dev.type = MASTER_POINTER; /* claim it's a master to stop ptracccel */
 
-    g_assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE);
-    g_assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute));
+    assert(InitValuatorClassDeviceStruct(NULL, 0, atoms, 0, 0) == FALSE);
+    assert(InitValuatorClassDeviceStruct(&dev, num_axes, atoms, 0, Absolute));
 
     for (i = 0; i < num_axes; i++)
     {
-        g_assert(valuator_get_mode(&dev, i) == Absolute);
+        assert(valuator_get_mode(&dev, i) == Absolute);
         valuator_set_mode(&dev, i, Relative);
-        g_assert(dev.valuator->axes[i].mode == Relative);
-        g_assert(valuator_get_mode(&dev, i) == Relative);
+        assert(dev.valuator->axes[i].mode == Relative);
+        assert(valuator_get_mode(&dev, i) == Relative);
     }
 
     valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Absolute);
     for (i = 0; i < num_axes; i++)
-        g_assert(valuator_get_mode(&dev, i) == Absolute);
+        assert(valuator_get_mode(&dev, i) == Absolute);
 
     valuator_set_mode(&dev, VALUATOR_MODE_ALL_AXES, Relative);
     for (i = 0; i < num_axes; i++)
-        g_assert(valuator_get_mode(&dev, i) == Relative);
+        assert(valuator_get_mode(&dev, i) == Relative);
 }
 
 static void include_bit_test_macros(void)
@@ -1199,13 +1199,13 @@ static void include_bit_test_macros(void)
 
     for (i = 0; i < sizeof(mask)/sizeof(mask[0]); i++)
     {
-        g_assert(BitIsOn(mask, i) == 0);
+        assert(BitIsOn(mask, i) == 0);
         SetBit(mask, i);
-        g_assert(BitIsOn(mask, i) == 1);
-        g_assert(!!(mask[i/8] & (1 << (i % 8))));
-        g_assert(CountBits(mask, sizeof(mask)) == 1);
+        assert(BitIsOn(mask, i) == 1);
+        assert(!!(mask[i/8] & (1 << (i % 8))));
+        assert(CountBits(mask, sizeof(mask)) == 1);
         ClearBit(mask, i);
-        g_assert(BitIsOn(mask, i) == 0);
+        assert(BitIsOn(mask, i) == 0);
     }
 }
 
@@ -1221,10 +1221,10 @@ static void dix_valuator_alloc(void)
     {
         v = AllocValuatorClass(v, num_axes);
 
-        g_assert(v);
-        g_assert(v->numAxes == num_axes);
-        g_assert(((void*)v->axisVal - (void*)v) % sizeof(double) == 0);
-        g_assert(((void*)v->axes - (void*)v) % sizeof(double) == 0);
+        assert(v);
+        assert(v->numAxes == num_axes);
+        assert(((void*)v->axisVal - (void*)v) % sizeof(double) == 0);
+        assert(((void*)v->axes - (void*)v) % sizeof(double) == 0);
         num_axes ++;
     }
 
@@ -1233,22 +1233,19 @@ static void dix_valuator_alloc(void)
 
 int main(int argc, char** argv)
 {
-    g_test_init(&argc, &argv,NULL);
-    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
-
-    g_test_add_func("/dix/input/valuator-masks", dix_input_valuator_masks);
-    g_test_add_func("/dix/input/attributes", dix_input_attributes);
-    g_test_add_func("/dix/input/init-valuators", dix_init_valuators);
-    g_test_add_func("/dix/input/event-core-conversion", dix_event_to_core_conversion);
-    g_test_add_func("/dix/input/event-xi1-conversion", dix_event_to_xi1_conversion);
-    g_test_add_func("/dix/input/check-grab-values", dix_check_grab_values);
-    g_test_add_func("/dix/input/xi2-struct-sizes", xi2_struct_sizes);
-    g_test_add_func("/dix/input/grab_matching", dix_grab_matching);
-    g_test_add_func("/dix/input/valuator_mode", dix_valuator_mode);
-    g_test_add_func("/include/byte_padding_macros", include_byte_padding_macros);
-    g_test_add_func("/include/bit_test_macros", include_bit_test_macros);
-    g_test_add_func("/Xi/xiproperty/register-unregister", xi_unregister_handlers);
-    g_test_add_func("/dix/input/valuator-alloc", dix_valuator_alloc);
-
-    return g_test_run();
+    dix_input_valuator_masks();
+    dix_input_attributes();
+    dix_init_valuators();
+    dix_event_to_core_conversion();
+    dix_event_to_xi1_conversion();
+    dix_check_grab_values();
+    xi2_struct_sizes();
+    dix_grab_matching();
+    dix_valuator_mode();
+    include_byte_padding_macros();
+    include_bit_test_macros();
+    xi_unregister_handlers();
+    dix_valuator_alloc();
+
+    return 0;
 }
diff --git a/test/list.c b/test/list.c
index a87d2db..b101c76 100644
--- a/test/list.c
+++ b/test/list.c
@@ -28,7 +28,7 @@
 #include <X11/Xlib.h>
 #include <list.h>
 #include <string.h>
-#include <glib.h>
+#include <assert.h>
 
 struct parent {
     int a;
@@ -56,10 +56,10 @@ test_list_init(void)
     list_init(&parent.children);
 
     /* test we haven't touched anything else. */
-    g_assert(parent.a == tmp.a);
-    g_assert(parent.b == tmp.b);
+    assert(parent.a == tmp.a);
+    assert(parent.b == tmp.b);
 
-    g_assert(list_is_empty(&parent.children));
+    assert(list_is_empty(&parent.children));
 }
 
 static void
@@ -72,19 +72,19 @@ test_list_add(void)
     list_init(&parent.children);
 
     list_add(&child[0].node, &parent.children);
-    g_assert(!list_is_empty(&parent.children));
+    assert(!list_is_empty(&parent.children));
 
     c = list_first_entry(&parent.children, struct child, node);
-    g_assert(memcmp(c, &child[0], sizeof(struct child)) == 0);
+    assert(memcmp(c, &child[0], sizeof(struct child)) == 0);
 
     /* note: list_add prepends */
     list_add(&child[1].node, &parent.children);
     c = list_first_entry(&parent.children, struct child, node);
-    g_assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
+    assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
 
     list_add(&child[2].node, &parent.children);
     c = list_first_entry(&parent.children, struct child, node);
-    g_assert(memcmp(c, &child[2], sizeof(struct child)) == 0);
+    assert(memcmp(c, &child[2], sizeof(struct child)) == 0);
 };
 
 static void
@@ -97,40 +97,40 @@ test_list_del(void)
     list_init(&parent.children);
 
     list_add(&child[0].node, &parent.children);
-    g_assert(!list_is_empty(&parent.children));
+    assert(!list_is_empty(&parent.children));
 
     list_del(&parent.children);
-    g_assert(list_is_empty(&parent.children));
+    assert(list_is_empty(&parent.children));
 
     list_add(&child[0].node, &parent.children);
     list_del(&child[0].node);
-    g_assert(list_is_empty(&parent.children));
+    assert(list_is_empty(&parent.children));
 
     list_add(&child[0].node, &parent.children);
     list_add(&child[1].node, &parent.children);
 
     c = list_first_entry(&parent.children, struct child, node);
-    g_assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
+    assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
 
     /* delete first node */
     list_del(&child[1].node);
-    g_assert(!list_is_empty(&parent.children));
-    g_assert(list_is_empty(&child[1].node));
+    assert(!list_is_empty(&parent.children));
+    assert(list_is_empty(&child[1].node));
     c = list_first_entry(&parent.children, struct child, node);
-    g_assert(memcmp(c, &child[0], sizeof(struct child)) == 0);
+    assert(memcmp(c, &child[0], sizeof(struct child)) == 0);
 
     /* delete last node */
     list_add(&child[1].node, &parent.children);
     list_del(&child[0].node);
     c = list_first_entry(&parent.children, struct child, node);
-    g_assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
+    assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
 
     /* delete list head */
     list_add(&child[0].node, &parent.children);
     list_del(&parent.children);
-    g_assert(list_is_empty(&parent.children));
-    g_assert(!list_is_empty(&child[1].node));
-    g_assert(!list_is_empty(&child[2].node));
+    assert(list_is_empty(&parent.children));
+    assert(!list_is_empty(&child[1].node));
+    assert(!list_is_empty(&child[2].node));
 }
 
 static void
@@ -148,29 +148,26 @@ test_list_for_each(void)
     list_add(&child[0].node, &parent.children);
 
     list_for_each_entry(c, &parent.children, node) {
-        g_assert(memcmp(c, &child[i], sizeof(struct child)) == 0);
+        assert(memcmp(c, &child[i], sizeof(struct child)) == 0);
         i++;
     }
 
     /* foreach on empty list */
     list_del(&parent.children);
-    g_assert(list_is_empty(&parent.children));
+    assert(list_is_empty(&parent.children));
 
     list_for_each_entry(c, &parent.children, node) {
-        g_assert(0); /* we must not get here */
+        assert(0); /* we must not get here */
     }
 }
 
 
 int main(int argc, char** argv)
 {
-    g_test_init(&argc, &argv,NULL);
-    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
+    test_list_init();
+    test_list_add();
+    test_list_del();
+    test_list_for_each();
 
-    g_test_add_func("/list/init", test_list_init);
-    g_test_add_func("/list/add", test_list_add);
-    g_test_add_func("/list/del", test_list_del);
-    g_test_add_func("/list/for_each", test_list_for_each);
-
-    return g_test_run();
+    return 0;
 }
diff --git a/test/xi2/Makefile.am b/test/xi2/Makefile.am
index c6165e0..b15d8ba 100644
--- a/test/xi2/Makefile.am
+++ b/test/xi2/Makefile.am
@@ -1,5 +1,4 @@
 if ENABLE_UNIT_TESTS
-if HAVE_GLIB
 if HAVE_LD_WRAP
 noinst_PROGRAMS =  \
 	protocol-xiqueryversion \
@@ -15,9 +14,9 @@ noinst_PROGRAMS =  \
 
 TESTS=$(noinst_PROGRAMS)
 
-AM_CFLAGS = $(DIX_CFLAGS) $(GLIB_CFLAGS) @XORG_CFLAGS@
+AM_CFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@
 INCLUDES = @XORG_INCS@
-TEST_LDADD=../libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS) $(GLIB_LIBS)
+TEST_LDADD=../libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS)
 COMMON_SOURCES=protocol-common.h protocol-common.c
 
 if SPECIAL_DTRACE_OBJECTS
@@ -56,4 +55,3 @@ protocol_xipassivegrabdevice_SOURCES=$(COMMON_SOURCES) protocol-xipassivegrabdev
 protocol_xiwarppointer_SOURCES=$(COMMON_SOURCES) protocol-xiwarppointer.c
 endif
 endif
-endif
diff --git a/test/xi2/protocol-common.c b/test/xi2/protocol-common.c
index 10d82a5..6ffc697 100644
--- a/test/xi2/protocol-common.c
+++ b/test/xi2/protocol-common.c
@@ -29,7 +29,6 @@
 #include "extinit.h" /* for XInputExtensionInit */
 #include "exglobals.h"
 #include "xkbsrv.h" /* for XkbInitPrivates */
-#include <glib.h>
 
 #include "protocol-common.h"
 
@@ -134,7 +133,7 @@ void init_window(WindowPtr window, WindowPtr parent, int id)
     }
     window->parent = parent;
     window->optional = calloc(1, sizeof(WindowOptRec));
-    g_assert(window->optional);
+    assert(window->optional);
 }
 
 extern DevPrivateKeyRec miPointerScreenKeyRec;
@@ -171,7 +170,7 @@ void init_simple(void)
 
 void __wrap_WriteToClient(ClientPtr client, int len, void *data)
 {
-    g_assert(reply_handler != NULL);
+    assert(reply_handler != NULL);
 
     (*reply_handler)(client, len, data, userdata);
 }
diff --git a/test/xi2/protocol-common.h b/test/xi2/protocol-common.h
index afa0878..18c61e6 100644
--- a/test/xi2/protocol-common.h
+++ b/test/xi2/protocol-common.h
@@ -29,6 +29,7 @@
 #include "windowstr.h"
 #include "scrnintstr.h"
 #include "exevents.h"
+#include <assert.h>
 
 #ifndef PROTOCOL_COMMON_H
 #define PROTOCOL_COMMON_H
@@ -38,11 +39,11 @@ extern int BadDevice;
 /* Check default values in a reply */
 #define reply_check_defaults(rep, len, type) \
     { \
-        g_assert((len) >= sz_x##type##Reply); \
-        g_assert((rep)->repType == X_Reply); \
-        g_assert((rep)->RepType == X_##type); \
-        g_assert((rep)->sequenceNumber == CLIENT_SEQUENCE); \
-        g_assert((rep)->length >= (sz_x##type##Reply - 32)/4); \
+        assert((len) >= sz_x##type##Reply); \
+        assert((rep)->repType == X_Reply); \
+        assert((rep)->RepType == X_##type); \
+        assert((rep)->sequenceNumber == CLIENT_SEQUENCE); \
+        assert((rep)->length >= (sz_x##type##Reply - 32)/4); \
     }
 
 /* initialise default values for request */
diff --git a/test/xi2/protocol-eventconvert.c b/test/xi2/protocol-eventconvert.c
index 0478c33..edba974 100644
--- a/test/xi2/protocol-eventconvert.c
+++ b/test/xi2/protocol-eventconvert.c
@@ -25,7 +25,6 @@
 #endif
 
 #include <stdint.h>
-#include <glib.h>
 
 #include "inputstr.h"
 #include "eventstr.h"
@@ -33,7 +32,6 @@
 #include "exevents.h"
 #include <X11/extensions/XI2proto.h>
 
-
 static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
                                    BOOL swap)
 {
@@ -58,21 +56,21 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
     }
 
 
-    g_assert(out->type == GenericEvent);
-    g_assert(out->extension == 0); /* IReqCode defaults to 0 */
-    g_assert(out->evtype == GetXI2Type((InternalEvent*)in));
-    g_assert(out->time == in->time);
-    g_assert(out->detail == in->detail.button);
-    g_assert(out->deviceid == in->deviceid);
-    g_assert(out->valuators_len >= bytes_to_int32(bits_to_bytes(sizeof(in->valuators.mask))));
-    g_assert(out->flags == 0); /* FIXME: we don't set the flags yet */
+    assert(out->type == GenericEvent);
+    assert(out->extension == 0); /* IReqCode defaults to 0 */
+    assert(out->evtype == GetXI2Type((InternalEvent*)in));
+    assert(out->time == in->time);
+    assert(out->detail == in->detail.button);
+    assert(out->deviceid == in->deviceid);
+    assert(out->valuators_len >= bytes_to_int32(bits_to_bytes(sizeof(in->valuators.mask))));
+    assert(out->flags == 0); /* FIXME: we don't set the flags yet */
 
     ptr = (unsigned char*)&out[1];
     bits_set = 0;
 
     for (i = 0; out->valuators_len && i < sizeof(in->valuators.mask) * 8; i++)
     {
-        g_assert (XIMaskIsSet(in->valuators.mask, i) == XIMaskIsSet(ptr, i));
+        assert (XIMaskIsSet(in->valuators.mask, i) == XIMaskIsSet(ptr, i));
         if (XIMaskIsSet(in->valuators.mask, i))
             bits_set++;
     }
@@ -81,13 +79,13 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
      * set. Each bit set represents 2 8-byte values, hence the
      * 'bits_set * 4' */
     len = out->valuators_len + bits_set * 4;
-    g_assert(out->length == len);
+    assert(out->length == len);
 
     nvals = 0;
 
     for (i = 0; out->valuators_len && i < MAX_VALUATORS; i++)
     {
-        g_assert (XIMaskIsSet(in->valuators.mask, i) == XIMaskIsSet(ptr, i));
+        assert (XIMaskIsSet(in->valuators.mask, i) == XIMaskIsSet(ptr, i));
         if (XIMaskIsSet(in->valuators.mask, i))
         {
             FP3232 vi, vo;
@@ -106,8 +104,8 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
                 swapl(&vo.frac, n);
             }
 
-            g_assert(vi.integral == vo.integral);
-            g_assert(vi.frac == vo.frac);
+            assert(vi.integral == vo.integral);
+            assert(vi.frac == vo.frac);
 
             raw_value = value + bits_set;
 
@@ -123,8 +121,8 @@ static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
                 swapl(&vo.frac, n);
             }
 
-            g_assert(vi.integral == vo.integral);
-            g_assert(vi.frac == vo.frac);
+            assert(vi.integral == vo.integral);
+            assert(vi.frac == vo.frac);
 
             nvals++;
         }
@@ -137,7 +135,7 @@ static void test_XIRawEvent(RawDeviceEvent *in)
     int rc;
 
     rc = EventToXI2((InternalEvent*)in, (xEvent**)&out);
-    g_assert(rc == Success);
+    assert(rc == Success);
 
     test_values_XIRawEvent(in, out, FALSE);
 
@@ -158,24 +156,24 @@ static void test_convert_XIFocusEvent(void)
     in.header = ET_Internal;
     in.type = ET_Enter;
     rc = EventToXI2((InternalEvent*)&in, &out);
-    g_assert(rc == Success);
-    g_assert(out == NULL);
+    assert(rc == Success);
+    assert(out == NULL);
 
     in.header = ET_Internal;
     in.type = ET_FocusIn;
     rc = EventToXI2((InternalEvent*)&in, &out);
-    g_assert(rc == Success);
-    g_assert(out == NULL);
+    assert(rc == Success);
+    assert(out == NULL);
 
     in.header = ET_Internal;
     in.type = ET_FocusOut;
     rc = EventToXI2((InternalEvent*)&in, &out);
-    g_assert(rc == BadImplementation);
+    assert(rc == BadImplementation);
 
     in.header = ET_Internal;
     in.type = ET_Leave;
     rc = EventToXI2((InternalEvent*)&in, &out);
-    g_assert(rc == BadImplementation);
+    assert(rc == BadImplementation);
 }
 
 
@@ -186,7 +184,7 @@ static void test_convert_XIRawEvent(void)
 
     memset(&in, 0, sizeof(in));
 
-    g_test_message("Testing all event types");
+    printf("Testing all event types\n");
     in.header = ET_Internal;
     in.type = ET_RawMotion;
     test_XIRawEvent(&in);
@@ -207,7 +205,7 @@ static void test_convert_XIRawEvent(void)
     in.type = ET_RawButtonRelease;
     test_XIRawEvent(&in);
 
-    g_test_message("Testing details and other fields");
+    printf("Testing details and other fields\n");
     in.detail.button = 1L;
     test_XIRawEvent(&in);
     in.detail.button = 1L << 8;
@@ -239,7 +237,7 @@ static void test_convert_XIRawEvent(void)
     in.deviceid = ~0 & 0xFF;
     test_XIRawEvent(&in);
 
-    g_test_message("Testing valuator masks");
+    printf("Testing valuator masks\n");
     for (i = 0; i < sizeof(in.valuators.mask) * 8; i++)
     {
         XISetMask(in.valuators.mask, i);
@@ -301,14 +299,14 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
         swapl(&out->flags, n);
     }
 
-    g_assert(out->extension == 0); /* IReqCode defaults to 0 */
-    g_assert(out->evtype == GetXI2Type((InternalEvent*)in));
-    g_assert(out->time == in->time);
-    g_assert(out->detail == in->detail.button);
-    g_assert(out->length >= 12);
+    assert(out->extension == 0); /* IReqCode defaults to 0 */
+    assert(out->evtype == GetXI2Type((InternalEvent*)in));
+    assert(out->time == in->time);
+    assert(out->detail == in->detail.button);
+    assert(out->length >= 12);
 
-    g_assert(out->deviceid == in->deviceid);
-    g_assert(out->sourceid == in->sourceid);
+    assert(out->deviceid == in->deviceid);
+    assert(out->sourceid == in->sourceid);
 
     switch (in->type) {
         case ET_KeyPress:
@@ -318,41 +316,41 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
             flagmask = 0;
             break;
     }
-    g_assert((out->flags & ~flagmask) == 0);
+    assert((out->flags & ~flagmask) == 0);
 
-    g_assert(out->root == in->root);
-    g_assert(out->event == None); /* set in FixUpEventFromWindow */
-    g_assert(out->child == None); /* set in FixUpEventFromWindow */
+    assert(out->root == in->root);
+    assert(out->event == None); /* set in FixUpEventFromWindow */
+    assert(out->child == None); /* set in FixUpEventFromWindow */
 
-    g_assert(out->mods.base_mods == in->mods.base);
-    g_assert(out->mods.latched_mods == in->mods.latched);
-    g_assert(out->mods.locked_mods == in->mods.locked);
-    g_assert(out->mods.effective_mods == in->mods.effective);
+    assert(out->mods.base_mods == in->mods.base);
+    assert(out->mods.latched_mods == in->mods.latched);
+    assert(out->mods.locked_mods == in->mods.locked);
+    assert(out->mods.effective_mods == in->mods.effective);
 
-    g_assert(out->group.base_group == in->group.base);
-    g_assert(out->group.latched_group == in->group.latched);
-    g_assert(out->group.locked_group == in->group.locked);
-    g_assert(out->group.effective_group == in->group.effective);
+    assert(out->group.base_group == in->group.base);
+    assert(out->group.latched_group == in->group.latched);
+    assert(out->group.locked_group == in->group.locked);
+    assert(out->group.effective_group == in->group.effective);
 
-    g_assert(out->event_x == 0); /* set in FixUpEventFromWindow */
-    g_assert(out->event_y == 0); /* set in FixUpEventFromWindow */
+    assert(out->event_x == 0); /* set in FixUpEventFromWindow */
+    assert(out->event_y == 0); /* set in FixUpEventFromWindow */
 
-    g_assert(out->root_x == FP1616(in->root_x, in->root_x_frac));
-    g_assert(out->root_y == FP1616(in->root_y, in->root_y_frac));
+    assert(out->root_x == FP1616(in->root_x, in->root_x_frac));
+    assert(out->root_y == FP1616(in->root_y, in->root_y_frac));
 
     buttons = 0;
     for (i = 0; i < bits_to_bytes(sizeof(in->buttons)); i++)
     {
         if (XIMaskIsSet(in->buttons, i))
         {
-            g_assert(out->buttons_len >= bytes_to_int32(bits_to_bytes(i)));
+            assert(out->buttons_len >= bytes_to_int32(bits_to_bytes(i)));
             buttons++;
         }
     }
 
     ptr = (unsigned char*)&out[1];
     for (i = 0; i < sizeof(in->buttons) * 8; i++)
-        g_assert(XIMaskIsSet(in->buttons, i) == XIMaskIsSet(ptr, i));
+        assert(XIMaskIsSet(in->buttons, i) == XIMaskIsSet(ptr, i));
 
 
     valuators = 0;
@@ -360,7 +358,7 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
         if (XIMaskIsSet(in->valuators.mask, i))
             valuators++;
 
-    g_assert(out->valuators_len >= bytes_to_int32(bits_to_bytes(valuators)));
+    assert(out->valuators_len >= bytes_to_int32(bits_to_bytes(valuators)));
 
     ptr += out->buttons_len * 4;
     values = (FP3232*)(ptr + out->valuators_len * 4);
@@ -368,11 +366,11 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
                 i < (out->valuators_len * 4) * 8; i++)
     {
         if (i > sizeof(in->valuators.mask) * 8)
-            g_assert(!XIMaskIsSet(ptr, i));
+            assert(!XIMaskIsSet(ptr, i));
         else if (i > out->valuators_len * 4 * 8)
-            g_assert(!XIMaskIsSet(in->valuators.mask, i));
+            assert(!XIMaskIsSet(in->valuators.mask, i));
         else {
-            g_assert(XIMaskIsSet(in->valuators.mask, i) ==
+            assert(XIMaskIsSet(in->valuators.mask, i) ==
                      XIMaskIsSet(ptr, i));
 
             if (XIMaskIsSet(ptr, i))
@@ -392,8 +390,8 @@ static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
                 }
 
 
-                g_assert(vi.integral == vo.integral);
-                g_assert(vi.frac == vo.frac);
+                assert(vi.integral == vo.integral);
+                assert(vi.frac == vo.frac);
                 values++;
             }
         }
@@ -406,7 +404,7 @@ static void test_XIDeviceEvent(DeviceEvent *in)
     int rc;
 
     rc = EventToXI2((InternalEvent*)in, (xEvent**)&out);
-    g_assert(rc == Success);
+    assert(rc == Success);
 
     test_values_XIDeviceEvent(in, out, FALSE);
 
@@ -425,7 +423,7 @@ static void test_convert_XIDeviceEvent(void)
 
     memset(&in, 0, sizeof(in));
 
-    g_test_message("Testing simple field values");
+    printf("Testing simple field values\n");
     in.header = ET_Internal;
     in.type = ET_Motion;
     in.length = sizeof(DeviceEvent);
@@ -449,7 +447,7 @@ static void test_convert_XIDeviceEvent(void)
 
     test_XIDeviceEvent(&in);
 
-    g_test_message("Testing field ranges");
+    printf("Testing field ranges\n");
     /* 32 bit */
     in.detail.button = 1L;
     test_XIDeviceEvent(&in);
@@ -597,7 +595,7 @@ static void test_convert_XIDeviceEvent(void)
     in.mods.effective = ~0 & 0xFF;
     test_XIDeviceEvent(&in);
 
-    g_test_message("Testing button masks");
+    printf("Testing button masks\n");
     for (i = 0; i < sizeof(in.buttons) * 8; i++)
     {
         XISetMask(in.buttons, i);
@@ -611,7 +609,7 @@ static void test_convert_XIDeviceEvent(void)
         test_XIDeviceEvent(&in);
     }
 
-    g_test_message("Testing valuator masks");
+    printf("Testing valuator masks\n");
     for (i = 0; i < sizeof(in.valuators.mask) * 8; i++)
     {
         XISetMask(in.valuators.mask, i);
@@ -656,12 +654,12 @@ static void test_values_XIDeviceChangedEvent(DeviceChangedEvent *in,
         swaps(&out->num_classes, n);
     }
 
-    g_assert(out->type == GenericEvent);
-    g_assert(out->extension == 0); /* IReqCode defaults to 0 */
-    g_assert(out->evtype == GetXI2Type((InternalEvent*)in));
-    g_assert(out->time == in->time);
-    g_assert(out->deviceid == in->deviceid);
-    g_assert(out->sourceid == in->sourceid);
+    assert(out->type == GenericEvent);
+    assert(out->extension == 0); /* IReqCode defaults to 0 */
+    assert(out->evtype == GetXI2Type((InternalEvent*)in));
+    assert(out->time == in->time);
+    assert(out->deviceid == in->deviceid);
+    assert(out->sourceid == in->sourceid);
 
     ptr = (unsigned char*)&out[1];
     for (i = 0; i < out->num_classes; i++)
@@ -689,11 +687,11 @@ static void test_values_XIDeviceChangedEvent(DeviceChangedEvent *in,
                         swaps(&b->num_buttons, n);
                     }
 
-                    g_assert(b->length ==
+                    assert(b->length ==
                             bytes_to_int32(sizeof(xXIButtonInfo)) +
                             bytes_to_int32(bits_to_bytes(b->num_buttons)) +
                             b->num_buttons);
-                    g_assert(b->num_buttons == in->buttons.num_buttons);
+                    assert(b->num_buttons == in->buttons.num_buttons);
 
                     names = (Atom*)((char*)&b[1] +
                             pad_to_int32(bits_to_bytes(b->num_buttons)));
@@ -704,7 +702,7 @@ static void test_values_XIDeviceChangedEvent(DeviceChangedEvent *in,
                             char n;
                             swapl(&names[j], n);
                         }
-                        g_assert(names[j] == in->buttons.names[j]);
+                        assert(names[j] == in->buttons.names[j]);
                     }
                 }
                 break;
@@ -719,10 +717,10 @@ static void test_values_XIDeviceChangedEvent(DeviceChangedEvent *in,
                         swaps(&k->num_keycodes, n);
                     }
 
-                    g_assert(k->length ==
+                    assert(k->length ==
                             bytes_to_int32(sizeof(xXIKeyInfo)) +
                             k->num_keycodes);
-                    g_assert(k->num_keycodes == in->keys.max_keycode -
+                    assert(k->num_keycodes == in->keys.max_keycode -
                             in->keys.min_keycode + 1);
 
                     kc = (uint32_t*)&k[1];
@@ -733,21 +731,22 @@ static void test_values_XIDeviceChangedEvent(DeviceChangedEvent *in,
                             char n;
                             swapl(&kc[j], n);
                         }
-                        g_assert(kc[j] >= in->keys.min_keycode);
-                        g_assert(kc[j] <= in->keys.max_keycode);
+                        assert(kc[j] >= in->keys.min_keycode);
+                        assert(kc[j] <= in->keys.max_keycode);
                     }
                 }
                 break;
             case XIValuatorClass:
                 {
                     xXIValuatorInfo *v = (xXIValuatorInfo*)any;
-                    g_assert(v->length ==
+                    assert(v->length ==
                              bytes_to_int32(sizeof(xXIValuatorInfo)));
 
                 }
                 break;
             default:
-                g_error("Invalid class type.\n");
+                printf("Invalid class type.\n\n");
+                assert(1);
                 break;
         }
 
@@ -762,7 +761,7 @@ static void test_XIDeviceChangedEvent(DeviceChangedEvent *in)
     int rc;
 
     rc = EventToXI2((InternalEvent*)in, (xEvent**)&out);
-    g_assert(rc == Success);
+    assert(rc == Success);
 
     test_values_XIDeviceChangedEvent(in, out, FALSE);
 
@@ -779,7 +778,7 @@ static void test_convert_XIDeviceChangedEvent(void)
     DeviceChangedEvent in;
     int i;
 
-    g_test_message("Testing simple field values");
+    printf("Testing simple field values\n");
     memset(&in, 0, sizeof(in));
     in.header = ET_Internal;
     in.type = ET_DeviceChanged;
@@ -905,13 +904,10 @@ static void test_convert_XIDeviceChangedEvent(void)
 
 int main(int argc, char** argv)
 {
-    g_test_init(&argc, &argv,NULL);
-    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
-
-    g_test_add_func("/xi2/eventconvert/XIRawEvent", test_convert_XIRawEvent);
-    g_test_add_func("/xi2/eventconvert/XIFocusEvent", test_convert_XIFocusEvent);
-    g_test_add_func("/xi2/eventconvert/XIDeviceEvent", test_convert_XIDeviceEvent);
-    g_test_add_func("/xi2/eventconvert/XIDeviceChangedEvent", test_convert_XIDeviceChangedEvent);
+    test_convert_XIRawEvent();
+    test_convert_XIFocusEvent();
+    test_convert_XIDeviceEvent();
+    test_convert_XIDeviceChangedEvent();
 
-    return g_test_run();
+    return 0;
 }
diff --git a/test/xi2/protocol-xigetclientpointer.c b/test/xi2/protocol-xigetclientpointer.c
index 6b4d049..5e45e7b 100644
--- a/test/xi2/protocol-xigetclientpointer.c
+++ b/test/xi2/protocol-xigetclientpointer.c
@@ -39,7 +39,6 @@
 #include "exevents.h"
 
 #include "protocol-common.h"
-#include <glib.h>
 
 struct {
     int cp_is_set;
@@ -79,9 +78,9 @@ static void reply_XIGetClientPointer(ClientPtr client, int len, char *data, void
 
     reply_check_defaults(rep, len, XIGetClientPointer);
 
-    g_assert(rep->set == test_data.cp_is_set);
+    assert(rep->set == test_data.cp_is_set);
     if (rep->set)
-        g_assert(rep->deviceid == test_data.dev->id);
+        assert(rep->deviceid == test_data.dev->id);
 }
 
 static void request_XIGetClientPointer(ClientPtr client, xXIGetClientPointerReq* req, int error)
@@ -92,19 +91,19 @@ static void request_XIGetClientPointer(ClientPtr client, xXIGetClientPointerReq*
     test_data.win = req->win;
 
     rc = ProcXIGetClientPointer(&client_request);
-    g_assert(rc == error);
+    assert(rc == error);
 
     if (rc == BadWindow)
-        g_assert(client_request.errorValue == req->win);
+        assert(client_request.errorValue == req->win);
 
     client_request.swapped = TRUE;
     swapl(&req->win, n);
     swaps(&req->length, n);
     rc = SProcXIGetClientPointer(&client_request);
-    g_assert(rc == error);
+    assert(rc == error);
 
     if (rc == BadWindow)
-        g_assert(client_request.errorValue == req->win);
+        assert(client_request.errorValue == req->win);
 
 }
 
@@ -121,21 +120,21 @@ static void test_XIGetClientPointer(void)
 
     client_request = init_client(request.length, &request);
 
-    g_test_message("Testing invalid window");
+    printf("Testing invalid window\n");
     request.win = INVALID_WINDOW_ID;
     request_XIGetClientPointer(&client_request, &request, BadWindow);
 
     test_data.cp_is_set = FALSE;
 
-    g_test_message("Testing window None, unset ClientPointer.");
+    printf("Testing window None, unset ClientPointer.\n");
     request.win = None;
     request_XIGetClientPointer(&client_request, &request, Success);
 
-    g_test_message("Testing valid window, unset ClientPointer.");
+    printf("Testing valid window, unset ClientPointer.\n");
     request.win = CLIENT_WINDOW_ID;
     request_XIGetClientPointer(&client_request, &request, Success);
 
-    g_test_message("Testing valid window, set ClientPointer.");
+    printf("Testing valid window, set ClientPointer.\n");
     client_window.clientPtr = devices.vcp;
     test_data.dev = devices.vcp;
     test_data.cp_is_set = TRUE;
@@ -144,7 +143,7 @@ static void test_XIGetClientPointer(void)
 
     client_window.clientPtr = NULL;
 
-    g_test_message("Testing window None, set ClientPointer.");
+    printf("Testing window None, set ClientPointer.\n");
     client_request.clientPtr = devices.vcp;
     test_data.dev = devices.vcp;
     test_data.cp_is_set = TRUE;
@@ -154,14 +153,10 @@ static void test_XIGetClientPointer(void)
 
 int main(int argc, char** argv)
 {
-    g_test_init(&argc, &argv,NULL);
-    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
-
     init_simple();
     client_window = init_client(0, NULL);
 
+    test_XIGetClientPointer();
 
-    g_test_add_func("/xi2/protocol/XIGetClientPointer", test_XIGetClientPointer);
-
-    return g_test_run();
+    return 0;
 }
diff --git a/test/xi2/protocol-xigetselectedevents.c b/test/xi2/protocol-xigetselectedevents.c
index 97aae15..55de773 100644
--- a/test/xi2/protocol-xigetselectedevents.c
+++ b/test/xi2/protocol-xigetselectedevents.c
@@ -48,7 +48,6 @@
 #include "exevents.h"
 
 #include "protocol-common.h"
-#include <glib.h>
 
 static void reply_XIGetSelectedEvents(ClientPtr client, int len, char *data, void *userdata);
 static void reply_XIGetSelectedEvents_data(ClientPtr client, int len, char *data, void *userdata);
@@ -100,7 +99,7 @@ static void reply_XIGetSelectedEvents(ClientPtr client, int len, char *data, voi
 
     reply_check_defaults(rep, len, XIGetSelectedEvents);
 
-    g_assert(rep->num_masks == test_data.num_masks_expected);
+    assert(rep->num_masks == test_data.num_masks_expected);
 
     reply_handler = reply_XIGetSelectedEvents_data;
 }
@@ -121,11 +120,11 @@ static void reply_XIGetSelectedEvents_data(ClientPtr client, int len, char *data
             swaps(&mask->mask_len, n);
         }
 
-        g_assert(mask->deviceid < 6);
-        g_assert(mask->mask_len <= (((XI2LASTEVENT + 8)/8) + 3)/4) ;
+        assert(mask->deviceid < 6);
+        assert(mask->mask_len <= (((XI2LASTEVENT + 8)/8) + 3)/4) ;
 
         bitmask = (unsigned char*)&mask[1];
-        g_assert(memcmp(bitmask,
+        assert(memcmp(bitmask,
                     test_data.mask[mask->deviceid],
                     mask->mask_len * 4) == 0);
 
@@ -145,14 +144,14 @@ static void request_XIGetSelectedEvents(xXIGetSelectedEventsReq* req, int error)
     reply_handler = reply_XIGetSelectedEvents;
 
     rc = ProcXIGetSelectedEvents(&client);
-    g_assert(rc == error);
+    assert(rc == error);
 
     reply_handler = reply_XIGetSelectedEvents;
     client.swapped = TRUE;
     swapl(&req->win, n);
     swaps(&req->length, n);
     rc = SProcXIGetSelectedEvents(&client);
-    g_assert(rc == error);
+    assert(rc == error);
 }
 
 static void test_XIGetSelectedEvents(void)
@@ -165,11 +164,11 @@ static void test_XIGetSelectedEvents(void)
 
     request_init(&request, XIGetSelectedEvents);
 
-    g_test_message("Testing for BadWindow on invalid window.");
+    printf("Testing for BadWindow on invalid window.\n");
     request.win = None;
     request_XIGetSelectedEvents(&request, BadWindow);
 
-    g_test_message("Testing for zero-length (unset) masks.");
+    printf("Testing for zero-length (unset) masks.\n");
     /* No masks set yet */
     test_data.num_masks_expected = 0;
     request.win = ROOT_WINDOW_ID;
@@ -181,7 +180,7 @@ static void test_XIGetSelectedEvents(void)
     memset(test_data.mask, 0,
            sizeof(test_data.mask));
 
-    g_test_message("Testing for valid masks");
+    printf("Testing for valid masks\n");
     memset(&dev, 0, sizeof(dev)); /* dev->id is enough for XISetEventMask */
     request.win = ROOT_WINDOW_ID;
 
@@ -210,7 +209,7 @@ static void test_XIGetSelectedEvents(void)
         }
     }
 
-    g_test_message("Testing removing all masks");
+    printf("Testing removing all masks\n");
     /* Unset all masks one-by-one */
     for (j = MAXDEVICES - 1; j >= 0; j--)
     {
@@ -229,13 +228,10 @@ static void test_XIGetSelectedEvents(void)
 
 int main(int argc, char** argv)
 {
-    g_test_init(&argc, &argv,NULL);
-    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
-
     init_simple();
 
-    g_test_add_func("/xi2/protocol/XIGetSelectedEvents", test_XIGetSelectedEvents);
+    test_XIGetSelectedEvents();
 
-    return g_test_run();
+    return 0;
 }
 
diff --git a/test/xi2/protocol-xipassivegrabdevice.c b/test/xi2/protocol-xipassivegrabdevice.c
index 36742d6..a61c154 100644
--- a/test/xi2/protocol-xipassivegrabdevice.c
+++ b/test/xi2/protocol-xipassivegrabdevice.c
@@ -39,7 +39,6 @@
 #include "exevents.h"
 
 #include "protocol-common.h"
-#include <glib.h>
 
 static ClientRec client_request;
 #define N_MODS 7
@@ -116,12 +115,12 @@ static void reply_XIPassiveGrabDevice_data(ClientPtr client, int len, char *data
 
         /* 1 - 7 is the range we use for the global modifiers array
          * above */
-        g_assert(mods->modifiers > 0);
-        g_assert(mods->modifiers <= 7);
-        g_assert(mods->modifiers % 2 == 1); /* because we fail odd ones */
-        g_assert(mods->status != Success);
-        g_assert(mods->pad0 == 0);
-        g_assert(mods->pad1 == 0);
+        assert(mods->modifiers > 0);
+        assert(mods->modifiers <= 7);
+        assert(mods->modifiers % 2 == 1); /* because we fail odd ones */
+        assert(mods->status != Success);
+        assert(mods->pad0 == 0);
+        assert(mods->pad1 == 0);
     }
 
     reply_handler = reply_XIPassiveGrabDevice;
@@ -134,10 +133,10 @@ static void request_XIPassiveGrabDevice(ClientPtr client, xXIPassiveGrabDeviceRe
     int modifiers;
 
     rc = ProcXIPassiveGrabDevice(&client_request);
-    g_assert(rc == error);
+    assert(rc == error);
 
     if (rc != Success)
-        g_assert(client_request.errorValue == errval);
+        assert(client_request.errorValue == errval);
 
     client_request.swapped = TRUE;
     swaps(&req->length, n);
@@ -157,10 +156,10 @@ static void request_XIPassiveGrabDevice(ClientPtr client, xXIPassiveGrabDeviceRe
     }
 
     rc = SProcXIPassiveGrabDevice(&client_request);
-    g_assert(rc == error);
+    assert(rc == error);
 
     if (rc != Success)
-        g_assert(client_request.errorValue == errval);
+        assert(client_request.errorValue == errval);
 }
 
 static unsigned char *data[4096]; /* the request buffer */
@@ -177,20 +176,20 @@ static void test_XIPassiveGrabDevice(void)
     reply_handler = reply_XIPassiveGrabDevice;
     client_request = init_client(request->length, request);
 
-    g_test_message("Testing invalid device");
+    printf("Testing invalid device\n");
     request->deviceid = 12;
     request_XIPassiveGrabDevice(&client_request, request, BadDevice, request->deviceid);
 
     request->deviceid = XIAllMasterDevices;
 
-    g_test_message("Testing invalid grab types");
+    printf("Testing invalid grab types\n");
     for (i = XIGrabtypeFocusIn + 1; i < 0xFF; i++)
     {
         request->grab_type = i;
         request_XIPassiveGrabDevice(&client_request, request, BadValue, request->grab_type);
     }
 
-    g_test_message("Testing invalid grab type + detail combinations");
+    printf("Testing invalid grab type + detail combinations\n");
     request->grab_type = XIGrabtypeEnter;
     request->detail = 1;
     request_XIPassiveGrabDevice(&client_request, request, BadValue, request->detail);
@@ -200,7 +199,7 @@ static void test_XIPassiveGrabDevice(void)
 
     request->detail = 0;
 
-    g_test_message("Testing invalid masks");
+    printf("Testing invalid masks\n");
     mask = (unsigned char*)&request[1];
 
     request->mask_len = bytes_to_int32(XI2LASTEVENT + 1);
@@ -227,12 +226,9 @@ static void test_XIPassiveGrabDevice(void)
 
 int main(int argc, char** argv)
 {
-    g_test_init(&argc, &argv,NULL);
-    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
-
     init_simple();
 
-    g_test_add_func("/xi2/protocol/XIPassiveGrab", test_XIPassiveGrabDevice);
+    test_XIPassiveGrabDevice();
 
-    return g_test_run();
+    return 0;
 }
diff --git a/test/xi2/protocol-xiquerydevice.c b/test/xi2/protocol-xiquerydevice.c
index 508fc4d..cb1cc81 100644
--- a/test/xi2/protocol-xiquerydevice.c
+++ b/test/xi2/protocol-xiquerydevice.c
@@ -38,7 +38,6 @@
 #include "xiquerydevice.h"
 
 #include "protocol-common.h"
-#include <glib.h>
 /*
  * Protocol testing for XIQueryDevice request and reply.
  *
@@ -74,11 +73,11 @@ static void reply_XIQueryDevice(ClientPtr client, int len, char* data, void *use
     reply_check_defaults(rep, len, XIQueryDevice);
 
     if (querydata->which_device == XIAllDevices)
-        g_assert(rep->num_devices == devices.num_devices);
+        assert(rep->num_devices == devices.num_devices);
     else if (querydata->which_device == XIAllMasterDevices)
-        g_assert(rep->num_devices == devices.num_master_devices);
+        assert(rep->num_devices == devices.num_master_devices);
     else
-        g_assert(rep->num_devices == 1);
+        assert(rep->num_devices == 1);
 
     querydata->num_devices_in_reply = rep->num_devices;
     reply_handler = reply_XIQueryDevice_data;
@@ -107,46 +106,46 @@ static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void
         }
 
         if (querydata->which_device > XIAllMasterDevices)
-            g_assert(info->deviceid == querydata->which_device);
+            assert(info->deviceid == querydata->which_device);
 
-        g_assert(info->deviceid >=  2); /* 0 and 1 is reserved */
+        assert(info->deviceid >=  2); /* 0 and 1 is reserved */
 
 
         switch(info->deviceid)
         {
             case 2:  /* VCP */
                 dev = devices.vcp;
-                g_assert(info->use == XIMasterPointer);
-                g_assert(info->attachment == devices.vck->id);
-                g_assert(info->num_classes == 3); /* 2 axes + button */
+                assert(info->use == XIMasterPointer);
+                assert(info->attachment == devices.vck->id);
+                assert(info->num_classes == 3); /* 2 axes + button */
                 break;
             case 3:  /* VCK */
                 dev = devices.vck;
-                g_assert(info->use == XIMasterKeyboard);
-                g_assert(info->attachment == devices.vcp->id);
-                g_assert(info->num_classes == 1);
+                assert(info->use == XIMasterKeyboard);
+                assert(info->attachment == devices.vcp->id);
+                assert(info->num_classes == 1);
                 break;
             case 4:  /* mouse */
                 dev = devices.mouse;
-                g_assert(info->use == XISlavePointer);
-                g_assert(info->attachment == devices.vcp->id);
-                g_assert(info->num_classes == 3); /* 2 axes + button */
+                assert(info->use == XISlavePointer);
+                assert(info->attachment == devices.vcp->id);
+                assert(info->num_classes == 3); /* 2 axes + button */
                 break;
             case 5:  /* keyboard */
                 dev = devices.kbd;
-                g_assert(info->use == XISlaveKeyboard);
-                g_assert(info->attachment == devices.vck->id);
-                g_assert(info->num_classes == 1);
+                assert(info->use == XISlaveKeyboard);
+                assert(info->attachment == devices.vck->id);
+                assert(info->num_classes == 1);
                 break;
 
             default:
                 /* We shouldn't get here */
-                g_assert(0);
+                assert(0);
                 break;
         }
-        g_assert(info->enabled == dev->enabled);
-        g_assert(info->name_len == strlen(dev->name));
-        g_assert(strncmp((char*)&info[1], dev->name, info->name_len) == 0);
+        assert(info->enabled == dev->enabled);
+        assert(info->name_len == strlen(dev->name));
+        assert(strncmp((char*)&info[1], dev->name, info->name_len) == 0);
 
         any = (xXIAnyInfo*)((char*)&info[1] + ((info->name_len + 3)/4) * 4);
         for (j = 0; j < info->num_classes; j++)
@@ -171,9 +170,9 @@ static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void
                         if (client->swapped)
                             swaps(&ki->num_keycodes, n);
 
-                        g_assert(any->type == XIKeyClass);
-                        g_assert(ki->num_keycodes == (xkb->max_key_code - xkb->min_key_code + 1));
-                        g_assert(any->length == (2 + ki->num_keycodes));
+                        assert(any->type == XIKeyClass);
+                        assert(ki->num_keycodes == (xkb->max_key_code - xkb->min_key_code + 1));
+                        assert(any->length == (2 + ki->num_keycodes));
 
                         kc = (uint32_t*)&ki[1];
                         for (k = 0; k < ki->num_keycodes; k++, kc++)
@@ -181,15 +180,15 @@ static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void
                             if (client->swapped)
                                 swapl(kc, n);
 
-                            g_assert(*kc >= xkb->min_key_code);
-                            g_assert(*kc <= xkb->max_key_code);
+                            assert(*kc >= xkb->min_key_code);
+                            assert(*kc <= xkb->max_key_code);
                         }
                         break;
                     }
                 case 2: /* VCP and mouse have the same properties */
                 case 4:
                     {
-                        g_assert(any->type == XIButtonClass ||
+                        assert(any->type == XIButtonClass ||
                                 any->type == XIValuatorClass);
 
                         if (any->type == XIButtonClass)
@@ -200,10 +199,10 @@ static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void
                             if (client->swapped)
                                 swaps(&bi->num_buttons, n);
 
-                            g_assert(bi->num_buttons == devices.vcp->button->numButtons);
+                            assert(bi->num_buttons == devices.vcp->button->numButtons);
 
                             len = 2 + bi->num_buttons + bytes_to_int32(bits_to_bytes(bi->num_buttons));
-                            g_assert(bi->length == len);
+                            assert(bi->length == len);
                         } else if (any->type == XIValuatorClass)
                         {
                             xXIValuatorInfo *vi = (xXIValuatorInfo*)any;
@@ -219,17 +218,17 @@ static void reply_XIQueryDevice_data(ClientPtr client, int len, char *data, void
                                 swapl(&vi->resolution, n);
                             }
 
-                            g_assert(vi->length == 11);
-                            g_assert(vi->number == 0 ||
+                            assert(vi->length == 11);
+                            assert(vi->number == 0 ||
                                      vi->number == 1);
-                            g_assert(vi->mode == XIModeRelative);
+                            assert(vi->mode == XIModeRelative);
                             /* device was set up as relative, so standard
                              * values here. */
-                            g_assert(vi->min.integral == -1);
-                            g_assert(vi->min.frac == 0);
-                            g_assert(vi->max.integral == -1);
-                            g_assert(vi->max.frac == 0);
-                            g_assert(vi->resolution == 0);
+                            assert(vi->min.integral == -1);
+                            assert(vi->min.frac == 0);
+                            assert(vi->max.integral == -1);
+                            assert(vi->max.frac == 0);
+                            assert(vi->resolution == 0);
                         }
                     }
                     break;
@@ -257,10 +256,10 @@ static void request_XIQueryDevice(struct test_data *querydata,
 
     request.deviceid = deviceid;
     rc = ProcXIQueryDevice(&client);
-    g_assert(rc == error);
+    assert(rc == error);
 
     if (rc != Success)
-        g_assert(client.errorValue == deviceid);
+        assert(client.errorValue == deviceid);
 
     reply_handler = reply_XIQueryDevice;
 
@@ -268,10 +267,10 @@ static void request_XIQueryDevice(struct test_data *querydata,
     swaps(&request.length, n);
     swaps(&request.deviceid, n);
     rc = SProcXIQueryDevice(&client);
-    g_assert(rc == error);
+    assert(rc == error);
 
     if (rc != Success)
-        g_assert(client.errorValue == deviceid);
+        assert(client.errorValue == deviceid);
 }
 
 static void test_XIQueryDevice(void)
@@ -284,16 +283,16 @@ static void test_XIQueryDevice(void)
     userdata = &data;
     request_init(&request, XIQueryDevice);
 
-    g_test_message("Testing XIAllDevices.");
+    printf("Testing XIAllDevices.\n");
     request_XIQueryDevice(&data, XIAllDevices, Success);
-    g_test_message("Testing XIAllMasterDevices.");
+    printf("Testing XIAllMasterDevices.\n");
     request_XIQueryDevice(&data, XIAllMasterDevices, Success);
 
-    g_test_message("Testing existing device ids.");
+    printf("Testing existing device ids.\n");
     for (i = 2; i < 6; i++)
         request_XIQueryDevice(&data, i, Success);
 
-    g_test_message("Testing non-existing device ids.");
+    printf("Testing non-existing device ids.\n");
     for (i = 6; i <= 0xFFFF; i++)
         request_XIQueryDevice(&data, i, BadDevice);
 
@@ -304,13 +303,10 @@ static void test_XIQueryDevice(void)
 
 int main(int argc, char** argv)
 {
-    g_test_init(&argc, &argv,NULL);
-    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
-
     init_simple();
 
-    g_test_add_func("/dix/xi2protocol/XIQueryDevice", test_XIQueryDevice);
+    test_XIQueryDevice();
 
-    return g_test_run();
+    return 0;
 }
 
diff --git a/test/xi2/protocol-xiquerypointer.c b/test/xi2/protocol-xiquerypointer.c
index a42d595..0985ec7 100644
--- a/test/xi2/protocol-xiquerypointer.c
+++ b/test/xi2/protocol-xiquerypointer.c
@@ -39,7 +39,6 @@
 #include "exevents.h"
 
 #include "protocol-common.h"
-#include <glib.h>
 
 static ClientRec client_request;
 static void reply_XIQueryPointer_data(ClientPtr client, int len,
@@ -96,18 +95,18 @@ static void reply_XIQueryPointer(ClientPtr client, int len, char *data,
 
     reply_check_defaults(rep, len, XIQueryPointer);
 
-    g_assert(rep->root == root.drawable.id);
-    g_assert(rep->same_screen == xTrue);
+    assert(rep->root == root.drawable.id);
+    assert(rep->same_screen == xTrue);
 
     sprite = test_data.dev->spriteInfo->sprite;
-    g_assert((rep->root_x >> 16) == sprite->hot.x);
-    g_assert((rep->root_y >> 16) == sprite->hot.y);
+    assert((rep->root_x >> 16) == sprite->hot.x);
+    assert((rep->root_y >> 16) == sprite->hot.y);
 
     if (test_data.win == &root)
     {
-        g_assert(rep->root_x == rep->win_x);
-        g_assert(rep->root_y == rep->win_y);
-        g_assert(rep->child == window.drawable.id);
+        assert(rep->root_x == rep->win_x);
+        assert(rep->root_y == rep->win_y);
+        assert(rep->child == window.drawable.id);
     } else
     {
         int x, y;
@@ -115,13 +114,13 @@ static void reply_XIQueryPointer(ClientPtr client, int len, char *data,
         x = sprite->hot.x - window.drawable.x;
         y = sprite->hot.y - window.drawable.y;
 
-        g_assert((rep->win_x >> 16) == x);
-        g_assert((rep->win_y >> 16) == y);
-        g_assert(rep->child == None);
+        assert((rep->win_x >> 16) == x);
+        assert((rep->win_y >> 16) == y);
+        assert(rep->child == None);
     }
 
 
-    g_assert(rep->same_screen == xTrue);
+    assert(rep->same_screen == xTrue);
 
     reply_handler = reply_XIQueryPointer_data;
 }
@@ -137,19 +136,19 @@ static void request_XIQueryPointer(ClientPtr client, xXIQueryPointerReq* req, in
     int rc;
 
     rc = ProcXIQueryPointer(&client_request);
-    g_assert(rc == error);
+    assert(rc == error);
 
     if (rc == BadDevice)
-        g_assert(client_request.errorValue == req->deviceid);
+        assert(client_request.errorValue == req->deviceid);
 
     client_request.swapped = TRUE;
     swaps(&req->deviceid, n);
     swaps(&req->length, n);
     rc = SProcXIQueryPointer(&client_request);
-    g_assert(rc == error);
+    assert(rc == error);
 
     if (rc == BadDevice)
-        g_assert(client_request.errorValue == req->deviceid);
+        assert(client_request.errorValue == req->deviceid);
 }
 
 static void test_XIQueryPointer(void)
@@ -209,12 +208,9 @@ static void test_XIQueryPointer(void)
 
 int main(int argc, char** argv)
 {
-    g_test_init(&argc, &argv,NULL);
-    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
-
     init_simple();
 
-    g_test_add_func("/xi2/protocol/XIQueryPointer", test_XIQueryPointer);
+    test_XIQueryPointer();
 
-    return g_test_run();
+    return 0;
 }
diff --git a/test/xi2/protocol-xiqueryversion.c b/test/xi2/protocol-xiqueryversion.c
index 46e62ac..3bb356e 100644
--- a/test/xi2/protocol-xiqueryversion.c
+++ b/test/xi2/protocol-xiqueryversion.c
@@ -46,7 +46,6 @@
 #include "xiqueryversion.h"
 
 #include "protocol-common.h"
-#include <glib.h>
 
 extern XExtensionVersion XIVersion;
 
@@ -74,14 +73,14 @@ static void reply_XIQueryVersion(ClientPtr client, int len, char* data, void *us
 
     reply_check_defaults(rep, len, XIQueryVersion);
 
-    g_assert(rep->length == 0);
+    assert(rep->length == 0);
 
     sver = versions->major_server * 1000 + versions->minor_server;
     cver = versions->major_client * 1000 + versions->minor_client;
     ver = rep->major_version * 1000 + rep->minor_version;
 
-    g_assert(ver >= 2000);
-    g_assert((sver > cver) ? ver == cver : ver == sver);
+    assert(ver >= 2000);
+    assert((sver > cver) ? ver == cver : ver == sver);
 }
 
 /**
@@ -115,7 +114,7 @@ static void request_XIQueryVersion(int smaj, int smin, int cmaj, int cmin, int e
     request.major_version = versions.major_client;
     request.minor_version = versions.minor_client;
     rc = ProcXIQueryVersion(&client);
-    g_assert(rc == error);
+    assert(rc == error);
 
     client.swapped = TRUE;
 
@@ -124,7 +123,7 @@ static void request_XIQueryVersion(int smaj, int smin, int cmaj, int cmin, int e
     swaps(&request.minor_version, n);
 
     rc = SProcXIQueryVersion(&client);
-    g_assert(rc == error);
+    assert(rc == error);
 }
 
 /* Client version less than 2.0 must return BadValue, all other combinations
@@ -133,23 +132,23 @@ static void test_XIQueryVersion(void)
 {
     reply_handler = reply_XIQueryVersion;
 
-    g_test_message("Server version 2.0 - client versions [1..3].0");
+    printf("Server version 2.0 - client versions [1..3].0\n");
     /* some simple tests to catch common errors quickly */
     request_XIQueryVersion(2, 0, 1, 0, BadValue);
     request_XIQueryVersion(2, 0, 2, 0, Success);
     request_XIQueryVersion(2, 0, 3, 0, Success);
 
-    g_test_message("Server version 3.0 - client versions [1..3].0");
+    printf("Server version 3.0 - client versions [1..3].0\n");
     request_XIQueryVersion(3, 0, 1, 0, BadValue);
     request_XIQueryVersion(3, 0, 2, 0, Success);
     request_XIQueryVersion(3, 0, 3, 0, Success);
 
-    g_test_message("Server version 2.0 - client versions [1..3].[1..3]");
+    printf("Server version 2.0 - client versions [1..3].[1..3]\n");
     request_XIQueryVersion(2, 0, 1, 1, BadValue);
     request_XIQueryVersion(2, 0, 2, 2, Success);
     request_XIQueryVersion(2, 0, 3, 3, Success);
 
-    g_test_message("Server version 2.2 - client versions [1..3].0");
+    printf("Server version 2.2 - client versions [1..3].0\n");
     request_XIQueryVersion(2, 2, 1, 0, BadValue);
     request_XIQueryVersion(2, 2, 2, 0, Success);
     request_XIQueryVersion(2, 2, 3, 0, Success);
@@ -158,7 +157,7 @@ static void test_XIQueryVersion(void)
     /* this one takes a while */
     unsigned int cmin, cmaj, smin, smaj;
 
-    g_test_message("Testing all combinations.");
+    printf("Testing all combinations.\n");
     for (smaj = 2; smaj <= 0xFFFF; smaj++)
         for (smin = 0; smin <= 0xFFFF; smin++)
             for (cmin = 0; cmin <= 0xFFFF; cmin++)
@@ -175,12 +174,9 @@ static void test_XIQueryVersion(void)
 
 int main(int argc, char** argv)
 {
-    g_test_init(&argc, &argv,NULL);
-    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
-
     init_simple();
 
-    g_test_add_func("/xi2/protocol/XIQueryVersion", test_XIQueryVersion);
+    test_XIQueryVersion();
 
-    return g_test_run();
+    return 0;
 }
diff --git a/test/xi2/protocol-xiselectevents.c b/test/xi2/protocol-xiselectevents.c
index f951a14..fa422e2 100644
--- a/test/xi2/protocol-xiselectevents.c
+++ b/test/xi2/protocol-xiselectevents.c
@@ -58,7 +58,6 @@
 #include "xiselectev.h"
 
 #include "protocol-common.h"
-#include <glib.h>
 
 static unsigned char *data[4096 * 20]; /* the request data buffer */
 
@@ -107,7 +106,7 @@ static void request_XISelectEvent(xXISelectEventsReq *req, int error)
     client = init_client(req->length, req);
 
     rc = ProcXISelectEvents(&client);
-    g_assert(rc == error);
+    assert(rc == error);
 
     client.swapped = TRUE;
 
@@ -124,7 +123,7 @@ static void request_XISelectEvent(xXISelectEventsReq *req, int error)
     swaps(&req->length, n);
     swaps(&req->num_masks, n);
     rc = SProcXISelectEvents(&client);
-    g_assert(rc == error);
+    assert(rc == error);
 }
 
 static void request_XISelectEvents_masks(xXISelectEventsReq *req)
@@ -250,7 +249,7 @@ static void test_XISelectEvents(void)
 
     request_init(req, XISelectEvents);
 
-    g_test_message("Testing for BadValue on zero-length masks");
+    printf("Testing for BadValue on zero-length masks\n");
     /* zero masks are BadValue, regardless of the window */
     req->num_masks = 0;
 
@@ -263,7 +262,7 @@ static void test_XISelectEvents(void)
     req->win = CLIENT_WINDOW_ID;
     request_XISelectEvent(req, BadValue);
 
-    g_test_message("Testing for BadWindow.");
+    printf("Testing for BadWindow.\n");
     /* None window is BadWindow, regardless of the masks.
      * We don't actually need to set the masks here, BadWindow must occur
      * before checking the masks.
@@ -283,7 +282,7 @@ static void test_XISelectEvents(void)
     req->num_masks = 0xFFFC;
     request_XISelectEvent(req, BadWindow);
 
-    g_test_message("Triggering num_masks/length overflow");
+    printf("Triggering num_masks/length overflow\n");
     req->win = ROOT_WINDOW_ID;
     /* Integer overflow - req->length can't hold that much */
     req->num_masks = 0xFFFF;
@@ -292,14 +291,14 @@ static void test_XISelectEvents(void)
     req->win = ROOT_WINDOW_ID;
     req->num_masks = 1;
 
-    g_test_message("Triggering bogus mask length error");
+    printf("Triggering bogus mask length error\n");
     mask = (xXIEventMask*)&req[1];
     mask->deviceid = 0;
     mask->mask_len = 0xFFFF;
     request_XISelectEvent(req, BadLength);
 
     /* testing various device ids */
-    g_test_message("Testing existing device ids.");
+    printf("Testing existing device ids.\n");
     for (i = 0; i < 6; i++)
     {
         mask = (xXIEventMask*)&req[1];
@@ -310,7 +309,7 @@ static void test_XISelectEvents(void)
         request_XISelectEvent(req, Success);
     }
 
-    g_test_message("Testing non-existing device ids.");
+    printf("Testing non-existing device ids.\n");
     for (i = 6; i <= 0xFFFF; i++)
     {
         req->win = ROOT_WINDOW_ID;
@@ -326,13 +325,10 @@ static void test_XISelectEvents(void)
 
 int main(int argc, char** argv)
 {
-    g_test_init(&argc, &argv,NULL);
-    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
-
     init_simple();
 
-    g_test_add_func("/xi2/protocol/XISelectEvents", test_XISelectEvents);
+    test_XISelectEvents();
 
-    return g_test_run();
+    return 0;
 }
 
diff --git a/test/xi2/protocol-xisetclientpointer.c b/test/xi2/protocol-xisetclientpointer.c
index 2e638ee..c266b65 100644
--- a/test/xi2/protocol-xisetclientpointer.c
+++ b/test/xi2/protocol-xisetclientpointer.c
@@ -46,7 +46,6 @@
 #include "exevents.h"
 
 #include "protocol-common.h"
-#include <glib.h>
 
 static ClientRec client_window;
 static ClientRec client_request;
@@ -72,20 +71,20 @@ static void request_XISetClientPointer(xXISetClientPointerReq* req, int error)
     client_request = init_client(req->length, req);
 
     rc = ProcXISetClientPointer(&client_request);
-    g_assert(rc == error);
+    assert(rc == error);
 
     if (rc == BadDevice)
-        g_assert(client_request.errorValue == req->deviceid);
+        assert(client_request.errorValue == req->deviceid);
 
     client_request.swapped = TRUE;
     swapl(&req->win, n);
     swaps(&req->length, n);
     swaps(&req->deviceid, n);
     rc = SProcXISetClientPointer(&client_request);
-    g_assert(rc == error);
+    assert(rc == error);
 
     if (rc == BadDevice)
-        g_assert(client_request.errorValue == req->deviceid);
+        assert(client_request.errorValue == req->deviceid);
 
 }
 
@@ -98,36 +97,36 @@ static void test_XISetClientPointer(void)
 
     request.win = CLIENT_WINDOW_ID;
 
-    g_test_message("Testing BadDevice error for XIAllDevices and XIMasterDevices.");
+    printf("Testing BadDevice error for XIAllDevices and XIMasterDevices.\n");
     request.deviceid = XIAllDevices;
     request_XISetClientPointer(&request, BadDevice);
 
     request.deviceid = XIAllMasterDevices;
     request_XISetClientPointer(&request, BadDevice);
 
-    g_test_message("Testing Success for VCP and VCK.");
+    printf("Testing Success for VCP and VCK.\n");
     request.deviceid = devices.vcp->id; /* 2 */
     request_XISetClientPointer(&request, Success);
-    g_assert(client_window.clientPtr->id == 2);
+    assert(client_window.clientPtr->id == 2);
 
     request.deviceid = devices.vck->id; /* 3 */
     request_XISetClientPointer(&request, Success);
-    g_assert(client_window.clientPtr->id == 2);
+    assert(client_window.clientPtr->id == 2);
 
-    g_test_message("Testing BadDevice error for all other devices.");
+    printf("Testing BadDevice error for all other devices.\n");
     for (i = 4; i <= 0xFFFF; i++)
     {
         request.deviceid = i;
         request_XISetClientPointer(&request, BadDevice);
     }
 
-    g_test_message("Testing window None");
+    printf("Testing window None\n");
     request.win = None;
     request.deviceid = devices.vcp->id; /* 2 */
     request_XISetClientPointer(&request, Success);
-    g_assert(client_request.clientPtr->id == 2);
+    assert(client_request.clientPtr->id == 2);
 
-    g_test_message("Testing invalid window");
+    printf("Testing invalid window\n");
     request.win = INVALID_WINDOW_ID;
     request.deviceid = devices.vcp->id;
     request_XISetClientPointer(&request, BadWindow);
@@ -137,13 +136,10 @@ static void test_XISetClientPointer(void)
 
 int main(int argc, char** argv)
 {
-    g_test_init(&argc, &argv,NULL);
-    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
-
     init_simple();
     client_window = init_client(0, NULL);
 
-    g_test_add_func("/xi2/protocol/XISetClientPointer", test_XISetClientPointer);
+    test_XISetClientPointer();
 
-    return g_test_run();
+    return 0;
 }
diff --git a/test/xi2/protocol-xiwarppointer.c b/test/xi2/protocol-xiwarppointer.c
index 75b7617..0c8db45 100644
--- a/test/xi2/protocol-xiwarppointer.c
+++ b/test/xi2/protocol-xiwarppointer.c
@@ -39,7 +39,6 @@
 #include "exevents.h"
 
 #include "protocol-common.h"
-#include <glib.h>
 
 static int expected_x = SPRITE_X;
 static int expected_y = SPRITE_Y;
@@ -70,8 +69,8 @@ int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access
 static Bool ScreenSetCursorPosition(DeviceIntPtr dev, ScreenPtr screen,
                                     int x, int y, Bool generateEvent)
 {
-    g_assert(x == expected_x);
-    g_assert(y == expected_y);
+    assert(x == expected_x);
+    assert(y == expected_y);
     return TRUE;
 }
 
@@ -83,12 +82,12 @@ static void request_XIWarpPointer(ClientPtr client, xXIWarpPointerReq* req,
     int rc;
 
     rc = ProcXIWarpPointer(client);
-    g_assert(rc == error);
+    assert(rc == error);
 
     if (rc == BadDevice)
-        g_assert(client->errorValue == req->deviceid);
+        assert(client->errorValue == req->deviceid);
     else if (rc == BadWindow)
-        g_assert(client->errorValue == req->dst_win ||
+        assert(client->errorValue == req->dst_win ||
                  client->errorValue == req->src_win);
 
 
@@ -105,12 +104,12 @@ static void request_XIWarpPointer(ClientPtr client, xXIWarpPointerReq* req,
     swaps(&req->deviceid, n);
 
     rc = SProcXIWarpPointer(client);
-    g_assert(rc == error);
+    assert(rc == error);
 
     if (rc == BadDevice)
-        g_assert(client->errorValue == req->deviceid);
+        assert(client->errorValue == req->deviceid);
     else if (rc == BadWindow)
-        g_assert(client->errorValue == req->dst_win ||
+        assert(client->errorValue == req->dst_win ||
                  client->errorValue == req->src_win);
 
     client->swapped = FALSE;
@@ -204,13 +203,10 @@ static void test_XIWarpPointer(void)
 
 int main(int argc, char** argv)
 {
-    g_test_init(&argc, &argv,NULL);
-    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
-
     init_simple();
     screen.SetCursorPosition = ScreenSetCursorPosition;
 
-    g_test_add_func("/xi2/protocol/XIWarpPointer", test_XIWarpPointer);
+    test_XIWarpPointer();
 
-    return g_test_run();
+    return 0;
 }
diff --git a/test/xkb.c b/test/xkb.c
index 6fbb26a..421153c 100644
--- a/test/xkb.c
+++ b/test/xkb.c
@@ -46,8 +46,7 @@
 #include <X11/extensions/XKMformat.h>
 #include "xkbfile.h"
 #include "../xkb/xkb.h"
-
-#include <glib.h>
+#include <assert.h>
 
 /**
  * Initialize an empty XkbRMLVOSet.
@@ -62,16 +61,16 @@ static void xkb_get_rules_test(void)
     XkbGetRulesDflts(&rmlvo);
 
 
-    g_assert(rmlvo.rules);
-    g_assert(rmlvo.model);
-    g_assert(rmlvo.layout);
-    g_assert(rmlvo.variant);
-    g_assert(rmlvo.options);
-    g_assert(strcmp(rmlvo.rules, XKB_DFLT_RULES) == 0);
-    g_assert(strcmp(rmlvo.model, XKB_DFLT_MODEL) == 0);
-    g_assert(strcmp(rmlvo.layout, XKB_DFLT_LAYOUT) == 0);
-    g_assert(strcmp(rmlvo.variant, XKB_DFLT_VARIANT) == 0);
-    g_assert(strcmp(rmlvo.options, XKB_DFLT_OPTIONS) == 0);
+    assert(rmlvo.rules);
+    assert(rmlvo.model);
+    assert(rmlvo.layout);
+    assert(rmlvo.variant);
+    assert(rmlvo.options);
+    assert(strcmp(rmlvo.rules, XKB_DFLT_RULES) == 0);
+    assert(strcmp(rmlvo.model, XKB_DFLT_MODEL) == 0);
+    assert(strcmp(rmlvo.layout, XKB_DFLT_LAYOUT) == 0);
+    assert(strcmp(rmlvo.variant, XKB_DFLT_VARIANT) == 0);
+    assert(strcmp(rmlvo.options, XKB_DFLT_OPTIONS) == 0);
 }
 
 /**
@@ -95,17 +94,17 @@ static void xkb_set_rules_test(void)
     XkbGetRulesDflts(&rmlvo_new);
 
     /* XkbGetRulesDflts strdups the values */
-    g_assert(rmlvo.rules != rmlvo_new.rules);
-    g_assert(rmlvo.model != rmlvo_new.model);
-    g_assert(rmlvo.layout != rmlvo_new.layout);
-    g_assert(rmlvo.variant != rmlvo_new.variant);
-    g_assert(rmlvo.options != rmlvo_new.options);
-
-    g_assert(strcmp(rmlvo.rules, rmlvo_new.rules) == 0);
-    g_assert(strcmp(rmlvo.model, rmlvo_new.model) == 0);
-    g_assert(strcmp(rmlvo.layout, rmlvo_new.layout) == 0);
-    g_assert(strcmp(rmlvo.variant, rmlvo_new.variant) == 0);
-    g_assert(strcmp(rmlvo.options, rmlvo_new.options) == 0);
+    assert(rmlvo.rules != rmlvo_new.rules);
+    assert(rmlvo.model != rmlvo_new.model);
+    assert(rmlvo.layout != rmlvo_new.layout);
+    assert(rmlvo.variant != rmlvo_new.variant);
+    assert(rmlvo.options != rmlvo_new.options);
+
+    assert(strcmp(rmlvo.rules, rmlvo_new.rules) == 0);
+    assert(strcmp(rmlvo.model, rmlvo_new.model) == 0);
+    assert(strcmp(rmlvo.layout, rmlvo_new.layout) == 0);
+    assert(strcmp(rmlvo.variant, rmlvo_new.variant) == 0);
+    assert(strcmp(rmlvo.options, rmlvo_new.options) == 0);
 }
 
 
@@ -145,29 +144,26 @@ static void xkb_set_get_rules_test(void)
 
     /* This test is iffy, because strictly we may be comparing against already
      * freed memory */
-    g_assert(strcmp(rmlvo.rules, rmlvo_backup.rules) == 0);
-    g_assert(strcmp(rmlvo.model, rmlvo_backup.model) == 0);
-    g_assert(strcmp(rmlvo.layout, rmlvo_backup.layout) == 0);
-    g_assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0);
-    g_assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0);
+    assert(strcmp(rmlvo.rules, rmlvo_backup.rules) == 0);
+    assert(strcmp(rmlvo.model, rmlvo_backup.model) == 0);
+    assert(strcmp(rmlvo.layout, rmlvo_backup.layout) == 0);
+    assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0);
+    assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0);
 
     XkbGetRulesDflts(&rmlvo);
-    g_assert(strcmp(rmlvo.rules, rmlvo_backup.rules) == 0);
-    g_assert(strcmp(rmlvo.model, rmlvo_backup.model) == 0);
-    g_assert(strcmp(rmlvo.layout, rmlvo_backup.layout) == 0);
-    g_assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0);
-    g_assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0);
+    assert(strcmp(rmlvo.rules, rmlvo_backup.rules) == 0);
+    assert(strcmp(rmlvo.model, rmlvo_backup.model) == 0);
+    assert(strcmp(rmlvo.layout, rmlvo_backup.layout) == 0);
+    assert(strcmp(rmlvo.variant, rmlvo_backup.variant) == 0);
+    assert(strcmp(rmlvo.options, rmlvo_backup.options) == 0);
 }
 
 
 int main(int argc, char** argv)
 {
-    g_test_init(&argc, &argv,NULL);
-    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
-
-    g_test_add_func("/xkb/set-get-rules", xkb_set_get_rules_test);
-    g_test_add_func("/xkb/get-rules", xkb_get_rules_test);
-    g_test_add_func("/xkb/set-rules", xkb_set_rules_test);
+    xkb_set_get_rules_test();
+    xkb_get_rules_test();
+    xkb_set_rules_test();
 
-    return g_test_run();
+    return 0;
 }
diff --git a/test/xtest.c b/test/xtest.c
index 6ea6862..2ab4650 100644
--- a/test/xtest.c
+++ b/test/xtest.c
@@ -33,8 +33,6 @@
 #include "xkbsrv.h"
 #include "xserver-properties.h"
 
-#include <glib.h>
-
 /**
  */
 
@@ -65,14 +63,14 @@ static void xtest_init_devices(void)
     /* this also inits the xtest devices */
     InitCoreDevices();
 
-    g_assert(xtestpointer);
-    g_assert(xtestkeyboard);
-    g_assert(IsXTestDevice(xtestpointer, NULL));
-    g_assert(IsXTestDevice(xtestkeyboard, NULL));
-    g_assert(IsXTestDevice(xtestpointer, inputInfo.pointer));
-    g_assert(IsXTestDevice(xtestkeyboard, inputInfo.keyboard));
-    g_assert(GetXTestDevice(inputInfo.pointer) == xtestpointer);
-    g_assert(GetXTestDevice(inputInfo.keyboard) == xtestkeyboard);
+    assert(xtestpointer);
+    assert(xtestkeyboard);
+    assert(IsXTestDevice(xtestpointer, NULL));
+    assert(IsXTestDevice(xtestkeyboard, NULL));
+    assert(IsXTestDevice(xtestpointer, inputInfo.pointer));
+    assert(IsXTestDevice(xtestkeyboard, inputInfo.keyboard));
+    assert(GetXTestDevice(inputInfo.pointer) == xtestpointer);
+    assert(GetXTestDevice(inputInfo.keyboard) == xtestkeyboard);
 }
 
 /**
@@ -87,32 +85,29 @@ static void xtest_properties(void)
     Atom xtest_prop = XIGetKnownProperty(XI_PROP_XTEST_DEVICE);
 
     rc = XIGetDeviceProperty(xtestpointer, xtest_prop, &prop);
-    g_assert(rc == Success);
-    g_assert(prop);
+    assert(rc == Success);
+    assert(prop);
 
     rc = XIGetDeviceProperty(xtestkeyboard, xtest_prop, &prop);
-    g_assert(rc == Success);
-    g_assert(prop != NULL);
+    assert(rc == Success);
+    assert(prop != NULL);
 
     rc = XIChangeDeviceProperty(xtestpointer, xtest_prop,
                                 XA_INTEGER, 8, PropModeReplace, 1, &value, FALSE);
-    g_assert(rc == BadAccess);
+    assert(rc == BadAccess);
     rc = XIChangeDeviceProperty(xtestkeyboard, xtest_prop,
                                 XA_INTEGER, 8, PropModeReplace, 1, &value, FALSE);
-    g_assert(rc == BadAccess);
+    assert(rc == BadAccess);
 }
 
 
 
 int main(int argc, char** argv)
 {
-    g_test_init(&argc, &argv,NULL);
-    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
-
-    g_test_add_func("/dix/xtest/init", xtest_init_devices);
-    g_test_add_func("/dix/xtest/properties", xtest_properties);
+    xtest_init_devices();
+    xtest_properties();
 
-    return g_test_run();
+    return 0;
 }
 
 
commit 071a6ac4d0c347aa7fc6efe37f4f6992524d7ef1
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Apr 11 15:22:52 2011 +1000

    input: remove GetKeyboardValuatorEvents, this is now unnecessary.
    
    GetKeyboardValuatorEvents handles NULL valuator masks already, so the
    GetKeyboardEvents wrapper is not needed. Rename GKVE to GKE.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xext/xtest.c b/Xext/xtest.c
index 6780aa6..18e1ef7 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -423,7 +423,7 @@ ProcXTestFakeInput(ClientPtr client)
             break;
         case KeyPress:
         case KeyRelease:
-            nevents = GetKeyboardEvents(xtest_evlist, dev, type, ev->u.u.detail);
+            nevents = GetKeyboardEvents(xtest_evlist, dev, type, ev->u.u.detail, NULL);
             break;
     }
 
diff --git a/dix/devices.c b/dix/devices.c
index 58bda0d..3f46ad6 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -2392,7 +2392,7 @@ ReleaseButtonsAndKeys(DeviceIntPtr dev)
     {
         if (BitIsOn(k->down, i))
         {
-            nevents = GetKeyboardEvents(eventlist, dev, KeyRelease, i);
+            nevents = GetKeyboardEvents(eventlist, dev, KeyRelease, i, NULL);
             for (j = 0; j < nevents; j++)
                 mieqProcessDeviceEvent(dev, (InternalEvent*)(eventlist+j)->event, NULL);
         }
diff --git a/dix/getevents.c b/dix/getevents.c
index 644b388..0fa8046 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -616,8 +616,8 @@ updateMotionHistory(DeviceIntPtr pDev, CARD32 ms, ValuatorMask *mask,
 
 
 /**
- * Returns the maximum number of events GetKeyboardEvents,
- * GetKeyboardValuatorEvents, and GetPointerEvents will ever return.
+ * Returns the maximum number of events GetKeyboardEvents
+ * and GetPointerEvents will ever return.
  *
  * This MUST be absolutely constant, from init until exit.
  */
@@ -926,19 +926,6 @@ updateHistory(DeviceIntPtr dev, ValuatorMask *mask, CARD32 ms)
 }
 
 /**
- * Convenience wrapper around GetKeyboardValuatorEvents, that takes no
- * valuators.
- */
-int
-GetKeyboardEvents(EventList *events, DeviceIntPtr pDev, int type, int key_code) {
-    ValuatorMask mask;
-
-    valuator_mask_zero(&mask);
-    return GetKeyboardValuatorEvents(events, pDev, type, key_code, &mask);
-}
-
-
-/**
  * Returns a set of InternalEvents for KeyPress/KeyRelease, optionally
  * also with valuator events.
  *
@@ -947,8 +934,8 @@ GetKeyboardEvents(EventList *events, DeviceIntPtr pDev, int type, int key_code)
  * place via GetMaximumEventsNum(), and for freeing it.
  */
 int
-GetKeyboardValuatorEvents(EventList *events, DeviceIntPtr pDev, int type,
-                          int key_code, const ValuatorMask *mask_in) {
+GetKeyboardEvents(EventList *events, DeviceIntPtr pDev, int type,
+                  int key_code, const ValuatorMask *mask_in) {
     int num_events = 0;
     CARD32 ms = 0;
     DeviceEvent *event;
diff --git a/hw/dmx/input/dmxevents.c b/hw/dmx/input/dmxevents.c
index 0360517..15d80f5 100644
--- a/hw/dmx/input/dmxevents.c
+++ b/hw/dmx/input/dmxevents.c
@@ -453,8 +453,8 @@ static int dmxTranslateAndEnqueueExtEvent(DMXLocalInputInfoPtr dmxLocal,
         if (block)
             dmxSigioBlock();
         GetEventList(&events);
-        nevents = GetKeyboardValuatorEvents(events, pDevice, event,
-                                            ke->keycode, &mask);
+        nevents = GetKeyboardEvents(events, pDevice, event,
+                                    ke->keycode, &mask);
         for (i = 0; i < nevents; i++)
             mieqEnqueue(pDevice, (InternalEvent*)(events + i)->event);
 
@@ -685,7 +685,7 @@ void dmxEnqueue(DevicePtr pDev, int type, int detail, KeySym keySym,
 
         GetEventList(&events);
         /*ErrorF("KEY %d  sym %d\n", detail, (int) keySym);*/
-        nevents = GetKeyboardEvents(events, p, type, detail);
+        nevents = GetKeyboardEvents(events, p, type, detail, NULL);
         for (i = 0; i < nevents; i++)
             mieqEnqueue(p, (InternalEvent*)(events + i)->event);
         return;
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index e3bc4c5..f21475f 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -1804,7 +1804,7 @@ KdReleaseAllKeys (void)
             if (key_is_down(ki->dixdev, key, KEY_POSTED | KEY_PROCESSED)) {
                 KdHandleKeyboardEvent(ki, KeyRelease, key);
                 GetEventList(&kdEvents);
-                nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, KeyRelease, key);
+                nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, KeyRelease, key, NULL);
                 for (i = 0; i < nEvents; i++)
                     KdQueueEvent (ki->dixdev, (kdEvents + i)->event);
             }
@@ -1864,7 +1864,7 @@ KdEnqueueKeyboardEvent(KdKeyboardInfo   *ki,
 
         GetEventList(&kdEvents);
 
-        nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, type, key_code);
+        nEvents = GetKeyboardEvents(kdEvents, ki->dixdev, type, key_code, NULL);
         for (i = 0; i < nEvents; i++)
             KdQueueEvent(ki->dixdev, (InternalEvent *)((kdEvents + i)->event));
     }
diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index 84c0d18..3006ad1 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -399,7 +399,7 @@ xf86ReleaseKeys(DeviceIntPtr pDev)
          i++) {
         if (key_is_down(pDev, i, KEY_POSTED)) {
             sigstate = xf86BlockSIGIO ();
-            nevents = GetKeyboardEvents(xf86Events, pDev, KeyRelease, i);
+            nevents = GetKeyboardEvents(xf86Events, pDev, KeyRelease, i, NULL);
             for (j = 0; j < nevents; j++)
                 mieqEnqueue(pDev, (InternalEvent*)(xf86Events + j)->event);
             xf86UnblockSIGIO(sigstate);
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index ae22ef2..4cc47f5 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -1252,16 +1252,9 @@ xf86PostKeyEventM(DeviceIntPtr	device,
     }
 #endif
 
-    if (is_absolute) {
-        nevents = GetKeyboardValuatorEvents(xf86Events, device,
-                                            is_down ? KeyPress : KeyRelease,
-                                            key_code, mask);
-    }
-    else {
-        nevents = GetKeyboardEvents(xf86Events, device,
-                                    is_down ? KeyPress : KeyRelease,
-                                    key_code);
-    }
+    nevents = GetKeyboardEvents(xf86Events, device,
+                                is_down ? KeyPress : KeyRelease,
+                                key_code, mask);
 
     for (i = 0; i < nevents; i++)
         mieqEnqueue(device, (InternalEvent*)((xf86Events + i)->event));
diff --git a/hw/xnest/Events.c b/hw/xnest/Events.c
index 5ff6d21..5c80086 100644
--- a/hw/xnest/Events.c
+++ b/hw/xnest/Events.c
@@ -108,7 +108,7 @@ xnestQueueKeyEvent(int type, unsigned int keycode)
 
   GetEventList(&xnestEvents);
   lastEventTime = GetTimeInMillis();
-  n = GetKeyboardEvents(xnestEvents, xnestKeyboardDevice, type, keycode);
+  n = GetKeyboardEvents(xnestEvents, xnestKeyboardDevice, type, keycode, NULL);
   for (i = 0; i < n; i++)
     mieqEnqueue(xnestKeyboardDevice, (InternalEvent*)(xnestEvents + i)->event);
 }
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 16fec4a..451129e 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -482,7 +482,7 @@ void DarwinSendKeyboardEvents(int ev_type, int keycode) {
 	}
 
     darwinEvents_lock(); {
-        num_events = GetKeyboardEvents(darwinEvents, darwinKeyboard, ev_type, keycode + MIN_KEYCODE);
+        num_events = GetKeyboardEvents(darwinEvents, darwinKeyboard, ev_type, keycode + MIN_KEYCODE, NULL);
         for(i=0; i<num_events; i++) mieqEnqueue(darwinKeyboard, (InternalEvent*)darwinEvents[i].event);
         if(num_events > 0) DarwinPokeEQ();
     } darwinEvents_unlock();
diff --git a/hw/xwin/winkeybd.c b/hw/xwin/winkeybd.c
index 9e5a9b0..912e2de 100644
--- a/hw/xwin/winkeybd.c
+++ b/hw/xwin/winkeybd.c
@@ -485,7 +485,7 @@ winSendKeyEvent (DWORD dwKey, Bool fDown)
   g_winKeyState[dwKey] = fDown;
 
   GetEventList(&events);
-  nevents = GetKeyboardEvents(events, g_pwinKeyboard, fDown ? KeyPress : KeyRelease, dwKey + MIN_KEYCODE);
+  nevents = GetKeyboardEvents(events, g_pwinKeyboard, fDown ? KeyPress : KeyRelease, dwKey + MIN_KEYCODE, NULL);
 
   for (i = 0; i < nevents; i++)
     mieqEnqueue(g_pwinKeyboard, (InternalEvent*)events[i].event);
diff --git a/include/input.h b/include/input.h
index 4aad304..86078da 100644
--- a/include/input.h
+++ b/include/input.h
@@ -465,12 +465,6 @@ extern _X_EXPORT int GetKeyboardEvents(
     EventListPtr events,
     DeviceIntPtr pDev,
     int type,
-    int key_code);
-
-extern int GetKeyboardValuatorEvents(
-    EventListPtr events,
-    DeviceIntPtr pDev,
-    int type,
     int key_code,
     const ValuatorMask *mask);
 
commit 91a735328c59db006f0ed52b49e9c59895796c0c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Mar 9 10:45:55 2011 +1000

    test: add some XIPassiveGrab protocol testing.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Acked-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/test/xi2/Makefile.am b/test/xi2/Makefile.am
index 1b9bfe0..c6165e0 100644
--- a/test/xi2/Makefile.am
+++ b/test/xi2/Makefile.am
@@ -8,6 +8,7 @@ noinst_PROGRAMS =  \
 	protocol-xigetselectedevents \
         protocol-xisetclientpointer \
         protocol-xigetclientpointer \
+        protocol-xipassivegrabdevice \
         protocol-xiquerypointer \
         protocol-xiwarppointer \
         protocol-eventconvert
@@ -30,6 +31,7 @@ protocol_xigetselectedevents_LDADD=$(TEST_LDADD)
 protocol_xisetclientpointer_LDADD=$(TEST_LDADD)
 protocol_xigetclientpointer_LDADD=$(TEST_LDADD)
 protocol_xiquerypointer_LDADD=$(TEST_LDADD)
+protocol_xipassivegrabdevice_LDADD=$(TEST_LDADD)
 protocol_xiwarppointer_LDADD=$(TEST_LDADD)
 protocol_eventconvert_LDADD=$(TEST_LDADD)
 
@@ -39,6 +41,7 @@ protocol_xiselectevents_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,dixLookupWindow -Wl,-wra
 protocol_xigetselectedevents_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow -Wl,-wrap,AddResource
 protocol_xisetclientpointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,dixLookupClient
 protocol_xigetclientpointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupClient
+protocol_xipassivegrabdevice_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,GrabButton -Wl,-wrap,dixLookupWindow -Wl,-wrap,WriteToClient
 protocol_xiquerypointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow
 protocol_xiwarppointer_LDFLAGS=$(AM_LDFLAGS) -Wl,-wrap,WriteToClient -Wl,-wrap,dixLookupWindow
 
@@ -49,6 +52,7 @@ protocol_xigetselectedevents_SOURCES=$(COMMON_SOURCES) protocol-xigetselectedeve
 protocol_xisetclientpointer_SOURCES=$(COMMON_SOURCES) protocol-xisetclientpointer.c
 protocol_xigetclientpointer_SOURCES=$(COMMON_SOURCES) protocol-xigetclientpointer.c
 protocol_xiquerypointer_SOURCES=$(COMMON_SOURCES) protocol-xiquerypointer.c
+protocol_xipassivegrabdevice_SOURCES=$(COMMON_SOURCES) protocol-xipassivegrabdevice.c
 protocol_xiwarppointer_SOURCES=$(COMMON_SOURCES) protocol-xiwarppointer.c
 endif
 endif
diff --git a/test/xi2/protocol-xipassivegrabdevice.c b/test/xi2/protocol-xipassivegrabdevice.c
new file mode 100644
index 0000000..36742d6
--- /dev/null
+++ b/test/xi2/protocol-xipassivegrabdevice.c
@@ -0,0 +1,238 @@
+/**
+ * Copyright © 2011 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.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+/*
+ * Protocol testing for XIPassiveGrab request.
+ */
+#include <stdint.h>
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/extensions/XI2proto.h>
+#include "inputstr.h"
+#include "windowstr.h"
+#include "scrnintstr.h"
+#include "xipassivegrab.h"
+#include "exevents.h"
+
+#include "protocol-common.h"
+#include <glib.h>
+
+static ClientRec client_request;
+#define N_MODS 7
+static uint32_t modifiers[N_MODS] = {1, 2, 3, 4, 5, 6, 7};
+
+struct test_data {
+    int num_modifiers;
+} testdata;
+
+int __wrap_GrabButton(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
+                      int button, GrabParameters *param, GrabType grabtype,
+                      GrabMask *mask);
+static void reply_XIPassiveGrabDevice_data(ClientPtr client, int len, char *data, void *userdata);
+
+int __wrap_dixLookupWindow(WindowPtr *win, XID id, ClientPtr client, Mask access)
+{
+    if (id == root.drawable.id)
+    {
+        *win = &root;
+        return Success;
+    } else if (id == window.drawable.id)
+    {
+        *win = &window;
+        return Success;
+    }
+
+    return __real_dixLookupWindow(win, id, client, access);
+}
+
+int __wrap_GrabButton(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
+                      int button, GrabParameters *param, GrabType grabtype,
+                      GrabMask *mask)
+{
+    /* Fail every odd modifier */
+    if (param->modifiers % 2)
+        return BadAccess;
+
+    return Success;
+}
+
+static void reply_XIPassiveGrabDevice(ClientPtr client, int len, char *data, void *userdata)
+{
+    xXIPassiveGrabDeviceReply *rep = (xXIPassiveGrabDeviceReply*)data;
+
+    if (client->swapped)
+    {
+        char n;
+        swaps(&rep->sequenceNumber, n);
+        swapl(&rep->length, n);
+        swaps(&rep->num_modifiers, n);
+
+        testdata.num_modifiers = rep->num_modifiers;
+    }
+
+    reply_check_defaults(rep, len, XIPassiveGrabDevice);
+
+    /* ProcXIPassiveGrabDevice sends the data in two batches, let the second
+     * handler handle the modifier data */
+    if (rep->num_modifiers > 0)
+        reply_handler = reply_XIPassiveGrabDevice_data;
+}
+
+static void reply_XIPassiveGrabDevice_data(ClientPtr client, int len, char *data, void *userdata)
+{
+    int i;
+    int n;
+
+    xXIGrabModifierInfo *mods = (xXIGrabModifierInfo*)data;
+
+    for (i = 0; i < testdata.num_modifiers; i++, mods++)
+    {
+        if (client->swapped)
+            swapl(&mods->modifiers, n);
+
+        /* 1 - 7 is the range we use for the global modifiers array
+         * above */
+        g_assert(mods->modifiers > 0);
+        g_assert(mods->modifiers <= 7);
+        g_assert(mods->modifiers % 2 == 1); /* because we fail odd ones */
+        g_assert(mods->status != Success);
+        g_assert(mods->pad0 == 0);
+        g_assert(mods->pad1 == 0);
+    }
+
+    reply_handler = reply_XIPassiveGrabDevice;
+}
+
+static void request_XIPassiveGrabDevice(ClientPtr client, xXIPassiveGrabDeviceReq* req, int error, int errval)
+{
+    char n;
+    int rc;
+    int modifiers;
+
+    rc = ProcXIPassiveGrabDevice(&client_request);
+    g_assert(rc == error);
+
+    if (rc != Success)
+        g_assert(client_request.errorValue == errval);
+
+    client_request.swapped = TRUE;
+    swaps(&req->length, n);
+    swapl(&req->time, n);
+    swapl(&req->grab_window, n);
+    swapl(&req->cursor, n);
+    swapl(&req->detail, n);
+    swaps(&req->deviceid, n);
+    modifiers = req->num_modifiers;
+    swaps(&req->num_modifiers, n);
+    swaps(&req->mask_len, n);
+
+    while(modifiers--)
+    {
+        CARD32 *mod = ((CARD32*)(req + 1)) + modifiers;
+        swapl(mod, n);
+    }
+
+    rc = SProcXIPassiveGrabDevice(&client_request);
+    g_assert(rc == error);
+
+    if (rc != Success)
+        g_assert(client_request.errorValue == errval);
+}
+
+static unsigned char *data[4096]; /* the request buffer */
+static void test_XIPassiveGrabDevice(void)
+{
+    int i;
+    xXIPassiveGrabDeviceReq *request = (xXIPassiveGrabDeviceReq*)data;
+    unsigned char *mask;
+
+    request_init(request, XIPassiveGrabDevice);
+
+    request->grab_window = CLIENT_WINDOW_ID;
+
+    reply_handler = reply_XIPassiveGrabDevice;
+    client_request = init_client(request->length, request);
+
+    g_test_message("Testing invalid device");
+    request->deviceid = 12;
+    request_XIPassiveGrabDevice(&client_request, request, BadDevice, request->deviceid);
+
+    request->deviceid = XIAllMasterDevices;
+
+    g_test_message("Testing invalid grab types");
+    for (i = XIGrabtypeFocusIn + 1; i < 0xFF; i++)
+    {
+        request->grab_type = i;
+        request_XIPassiveGrabDevice(&client_request, request, BadValue, request->grab_type);
+    }
+
+    g_test_message("Testing invalid grab type + detail combinations");
+    request->grab_type = XIGrabtypeEnter;
+    request->detail = 1;
+    request_XIPassiveGrabDevice(&client_request, request, BadValue, request->detail);
+
+    request->grab_type = XIGrabtypeFocusIn;
+    request_XIPassiveGrabDevice(&client_request, request, BadValue, request->detail);
+
+    request->detail = 0;
+
+    g_test_message("Testing invalid masks");
+    mask = (unsigned char*)&request[1];
+
+    request->mask_len = bytes_to_int32(XI2LASTEVENT + 1);
+    request->length += request->mask_len;
+    SetBit(mask, XI2LASTEVENT + 1);
+    request_XIPassiveGrabDevice(&client_request, request, BadValue, XI2LASTEVENT + 1);
+
+    ClearBit(mask, XI2LASTEVENT + 1);
+
+    /* tested all special cases now, test a few valid cases */
+
+    /* no modifiers */
+    request->deviceid = XIAllDevices;
+    request->grab_type = XIGrabtypeButton;
+    request->detail = XIAnyButton;
+    request_XIPassiveGrabDevice(&client_request, request, Success, 0);
+
+    /* some modifiers */
+    request->num_modifiers = N_MODS;
+    request->length += N_MODS;
+    memcpy((uint32_t*)(request + 1) + request->mask_len, modifiers, sizeof(modifiers));
+    request_XIPassiveGrabDevice(&client_request, request, Success, 0);
+}
+
+int main(int argc, char** argv)
+{
+    g_test_init(&argc, &argv,NULL);
+    g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
+
+    init_simple();
+
+    g_test_add_func("/xi2/protocol/XIPassiveGrab", test_XIPassiveGrabDevice);
+
+    return g_test_run();
+}
commit 60b08e013dd1e971f82e5bc8708d3f120c217497
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Mar 9 10:44:48 2011 +1000

    Xi: don't swap the status byte in the XIPassiveGrab replies
    
    Reported-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
index 5b4cc46..ae43433 100644
--- a/Xi/xipassivegrab.c
+++ b/Xi/xipassivegrab.c
@@ -43,6 +43,7 @@
 #include "exevents.h"
 #include "xipassivegrab.h"
 #include "dixgrabs.h"
+#include "misc.h"
 
 int
 SProcXIPassiveGrabDevice(ClientPtr client)
@@ -87,6 +88,7 @@ ProcXIPassiveGrabDevice(ClientPtr client)
     GrabParameters param;
     void *tmp;
     int mask_len;
+    int n;
 
     REQUEST(xXIPassiveGrabDeviceReq);
     REQUEST_AT_LEAST_SIZE(xXIPassiveGrabDeviceReq);
@@ -195,6 +197,9 @@ ProcXIPassiveGrabDevice(ClientPtr client)
 
             info->status = status;
             info->modifiers = *modifiers;
+            if (client->swapped)
+                swapl(&info->modifiers, n);
+
             rep.num_modifiers++;
             rep.length += bytes_to_int32(sizeof(xXIGrabModifierInfo));
         }
@@ -202,10 +207,8 @@ ProcXIPassiveGrabDevice(ClientPtr client)
 
     WriteReplyToClient(client, sizeof(rep), &rep);
     if (rep.num_modifiers)
-    {
-	client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
-        WriteSwappedDataToClient(client, rep.length * 4, (char*)modifiers_failed);
-    }
+        WriteToClient(client, rep.length * 4, (char*)modifiers_failed);
+
     free(modifiers_failed);
     return ret;
 }
commit a3f37f3698880aec508b5ecfb88daf39360610aa
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Mar 9 10:07:19 2011 +1000

    Xi: exit with error value if CheckGrabValues failed.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
index 22f905e..5b4cc46 100644
--- a/Xi/xipassivegrab.c
+++ b/Xi/xipassivegrab.c
@@ -159,6 +159,8 @@ ProcXIPassiveGrabDevice(ClientPtr client)
 	return status;
 
     status = CheckGrabValues(client, &param);
+    if (status != Success)
+        return status;
 
     modifiers = (uint32_t*)&stuff[1] + stuff->mask_len;
     modifiers_failed = calloc(stuff->num_modifiers, sizeof(xXIGrabModifierInfo));
commit f4d9ff73b161d84d3fcacc5834fa714c113c7a10
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Mar 9 09:54:12 2011 +1000

    Xi: fix reply swapping function check for XIPassiveGrabDevice
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xi/extinit.c b/Xi/extinit.c
index 0b7280d..51e0078 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -511,7 +511,7 @@ SReplyIDispatch(ClientPtr client, int len, xGrabDeviceReply * rep)
         SRepXIQueryDevice(client, len, (xXIQueryDeviceReply*)rep);
     else if (rep->RepType == X_XIGrabDevice)
 	SRepXIGrabDevice(client, len, (xXIGrabDeviceReply *) rep);
-    else if (rep->RepType == X_XIGrabDevice)
+    else if (rep->RepType == X_XIPassiveGrabDevice)
 	SRepXIPassiveGrabDevice(client, len, (xXIPassiveGrabDeviceReply *) rep);
     else if (rep->RepType == X_XIListProperties)
 	SRepXIListProperties(client, len, (xXIListPropertiesReply *) rep);
commit 2a49ffa3c94819e9f28dd939f23ee8a675258172
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Mar 9 09:53:47 2011 +1000

    Xi: return the bad device ID if a passive grab fails with BadDevice.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
index 3319ef9..22f905e 100644
--- a/Xi/xipassivegrab.c
+++ b/Xi/xipassivegrab.c
@@ -99,7 +99,10 @@ ProcXIPassiveGrabDevice(ClientPtr client)
     {
         ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess);
         if (ret != Success)
+        {
+            client->errorValue = stuff->deviceid;
             return ret;
+        }
     }
 
     if (stuff->grab_type != XIGrabtypeButton &&
commit 315aa8444b13f827237674535eb2ad55a2066808
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Mar 23 10:32:35 2011 +1000

    configure: actually require macros 1.13
    
    Introduced in 6a5bf15fa99cf5b2358b3b3e2f29e5044aa8724a
    
    Reported-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/configure.ac b/configure.ac
index 9e04ff0..24fb184 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,7 +35,7 @@ AM_MAINTAINER_MODE
 # Require xorg-macros minimum of 1.13 for XORG_ENABLE_UNIT_TESTS
 m4_ifndef([XORG_MACROS_VERSION],
           [m4_fatal([must install xorg-macros 1.13 or later before running autoconf/autogen])])
-XORG_MACROS_VERSION(1.10)
+XORG_MACROS_VERSION(1.13)
 XORG_DEFAULT_OPTIONS
 XORG_WITH_DOXYGEN(1.6.1)
 XORG_CHECK_SGML_DOCTOOLS(1.5)
commit f0f0eec869d932a2d9228ff3e41e9e7cda155e68
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Apr 11 11:24:29 2011 +1000

    Xi: silence valgrind warning. (#36120)
    
    Conditional jump or move depends on uninitialised value(s)
       at 0x4357A1: GetEventMask (events.c:454)
       by 0x43B9E8: DeliverEventsToWindow (events.c:2029)
       by 0x4E0C59: SendEventToAllWindows (exevents.c:2125)
       by 0x4E8301: XISendDeviceHierarchyEvent (xichangehierarchy.c:118)
       by 0x426F99: DisableDevice (devices.c:507)
       by 0x46BF72: xf86Wakeup (xf86Events.c:457)
       by 0x432ABA: WakeupHandler (dixutils.c:419)
       by 0x45B708: WaitForSomething (WaitFor.c:235)
       by 0x42E8D9: Dispatch (dispatch.c:367)
       by 0x422DC9: main (main.c:287)
     Uninitialised value was created by a stack allocation
       at 0x4E8190: XISendDeviceHierarchyEvent (xichangehierarchy.c:61)
    
    Conditional jump or move depends on uninitialised value(s)
       at 0x43BB78: DeliverEventsToWindow (events.c:2010)
       by 0x4DDEEA: FindInterestedChildren (exevents.c:2103)
       by 0x4DDEFF: FindInterestedChildren (exevents.c:2104)
       by 0x4DDEFF: FindInterestedChildren (exevents.c:2104)
       by 0x4DDEFF: FindInterestedChildren (exevents.c:2104)
       by 0x4DDEFF: FindInterestedChildren (exevents.c:2104)
       by 0x4E0C6F: SendEventToAllWindows (exevents.c:2127)
       by 0x4E8301: XISendDeviceHierarchyEvent (xichangehierarchy.c:118)
       by 0x426F99: DisableDevice (devices.c:507)
       by 0x46BF72: xf86Wakeup (xf86Events.c:457)
       by 0x432ABA: WakeupHandler (dixutils.c:419)
       by 0x45B708: WaitForSomething (WaitFor.c:235)
     Uninitialised value was created by a stack allocation
       at 0x4E8190: XISendDeviceHierarchyEvent (xichangehierarchy.c:61)
    
    Set the type of dummyDev to SLAVE. The jump listed above comes from a check
    to IsMaster() in GetEventMask() that would then set the
    XIAllMasterDevices mask.
    Hierarchy events can only be set for XIAllDevices so the above IsMaster()
    check had no effect and the device type doesn't really matter anyway beyond
    shuting up valgrind.
    
    Also initialize dummyDev to 0 to ease future debugging.
    
    X.Org Bug 36120 <http://bugs.freedesktop.org/show_bug.cgi?id=36120>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
index a3dcab5..0736a5a 100644
--- a/Xi/xichangehierarchy.c
+++ b/Xi/xichangehierarchy.c
@@ -116,7 +116,9 @@ void XISendDeviceHierarchyEvent(int flags[MAXDEVICES])
 
     ev->length = bytes_to_int32(ev->num_info * sizeof(xXIHierarchyInfo));
 
+    memset(&dummyDev, 0, sizeof(dummyDev));
     dummyDev.id = XIAllDevices;
+    dummyDev.type = SLAVE;
     SendEventToAllWindows(&dummyDev, (XI_HierarchyChangedMask >> 8), (xEvent*)ev, 1);
     free(ev);
 }
commit 419a27b5219a739f2fbd50cc96a1b54c469e4a88
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Apr 12 10:17:07 2011 +1000

    Xi: fix valuator alignment in DeepCopyDeviceClasses (#36119)
    
    commit 678f5396c91b3d0c7572ed579b0a4fb62b2b4655 only fixed the
    initialization, not the copy. After a slave device change, the valuator
    were out of alignment again.
    
    X.Org Bug 36119 <http://bugs.freedesktop.org/show_bug.cgi?id=36119>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 18803c9..76d5c37 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -535,6 +535,7 @@ DeepCopyPointerClasses(DeviceIntPtr from, DeviceIntPtr to)
     if (from->valuator)
     {
         ValuatorClassPtr v;
+
         if (!to->valuator)
         {
             classes = to->unused_classes;
@@ -543,18 +544,14 @@ DeepCopyPointerClasses(DeviceIntPtr from, DeviceIntPtr to)
                 classes->valuator = NULL;
         }
 
-        to->valuator = realloc(to->valuator, sizeof(ValuatorClassRec) +
-                from->valuator->numAxes * sizeof(AxisInfo) +
-                from->valuator->numAxes * sizeof(double));
-        v = to->valuator;
+        v = AllocValuatorClass(to->valuator, from->valuator->numAxes);
+
         if (!v)
             FatalError("[Xi] no memory for class shift.\n");
 
-        v->numAxes = from->valuator->numAxes;
-        v->axes = (AxisInfoPtr)&v[1];
+        to->valuator = v;
         memcpy(v->axes, from->valuator->axes, v->numAxes * sizeof(AxisInfo));
 
-        v->axisVal = (double*)(v->axes + from->valuator->numAxes);
         v->sourceid = from->id;
     } else if (to->valuator && !from->valuator)
     {
diff --git a/dix/devices.c b/dix/devices.c
index 534931c..58bda0d 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1221,13 +1221,46 @@ InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons, Atom* labels,
     return TRUE;
 }
 
+/**
+ * Allocate a valuator class and set up the pointers for the axis values
+ * appropriately.
+ *
+ * @param src If non-NULL, the memory is reallocated from src. If NULL, the
+ * memory is calloc'd.
+ * @parma numAxes Number of axes to allocate.
+ * @return The allocated valuator struct.
+ */
+ValuatorClassPtr
+AllocValuatorClass(ValuatorClassPtr src, int numAxes)
+{
+    ValuatorClassPtr v;
+    /* force alignment with double */
+    union align_u { ValuatorClassRec valc; double d; } *align;
+    int size;
+
+    size = sizeof(union align_u) + numAxes * (sizeof(double) + sizeof(AxisInfo));
+    align = (union align_u *) realloc(src, size);
+
+    if (!align)
+        return NULL;
+
+    if (!src)
+        memset(align, 0, size);
+
+    v = &align->valc;
+    v->numAxes = numAxes;
+    v->axisVal = (double*)(align + 1);
+    v->axes = (AxisInfoPtr)(v->axisVal + numAxes);
+
+    return v;
+}
+
 Bool
 InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels,
                               int numMotionEvents, int mode)
 {
     int i;
     ValuatorClassPtr valc;
-    union align_u { ValuatorClassRec valc; double d; } *align;
 
     if (!dev)
         return FALSE;
@@ -1240,13 +1273,10 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels,
         numAxes = MAX_VALUATORS;
     }
 
-    align = (union align_u *) calloc(1, sizeof(union align_u) +
-				     numAxes * sizeof(double) +
-				     numAxes * sizeof(AxisInfo));
-    if (!align)
-	return FALSE;
+    valc = AllocValuatorClass(NULL, numAxes);
+    if (!valc)
+        return FALSE;
 
-    valc = &align->valc;
     valc->sourceid = dev->id;
     valc->motion = NULL;
     valc->first_motion = 0;
@@ -1254,9 +1284,6 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels,
 
     valc->numMotionEvents = numMotionEvents;
     valc->motionHintWindow = NullWindow;
-    valc->numAxes = numAxes;
-    valc->axisVal = (double *)(align + 1);
-    valc->axes = (AxisInfoPtr)(valc->axisVal + numAxes);
 
     if (mode & OutOfProximity)
         InitProximityClassDeviceStruct(dev);
diff --git a/include/input.h b/include/input.h
index 2bb85ff..4aad304 100644
--- a/include/input.h
+++ b/include/input.h
@@ -102,6 +102,7 @@ typedef unsigned long Leds;
 typedef struct _OtherClients *OtherClientsPtr;
 typedef struct _InputClients *InputClientsPtr;
 typedef struct _DeviceIntRec *DeviceIntPtr;
+typedef struct _ValuatorClassRec *ValuatorClassPtr;
 typedef struct _ClassesRec *ClassesPtr;
 typedef struct _SpriteRec *SpritePtr;
 typedef union _GrabMask GrabMask;
@@ -300,6 +301,10 @@ extern _X_EXPORT Bool InitButtonClassDeviceStruct(
     Atom* /* labels */,
     CARD8* /*map*/);
 
+extern _X_INTERNAL ValuatorClassPtr AllocValuatorClass(
+    ValuatorClassPtr src,
+    int numAxes);
+
 extern _X_EXPORT Bool InitValuatorClassDeviceStruct(
     DeviceIntPtr /*device*/,
     int /*numAxes*/,
diff --git a/include/inputstr.h b/include/inputstr.h
index f63df80..bd7c78d 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -283,7 +283,7 @@ typedef struct _ValuatorClassRec {
     unsigned short	  numAxes;
     double		  *axisVal; /* always absolute, but device-coord system */
     ValuatorAccelerationRec	accelScheme;
-} ValuatorClassRec, *ValuatorClassPtr;
+} ValuatorClassRec;
 
 typedef struct _ButtonClassRec {
     int			sourceid;
diff --git a/test/input.c b/test/input.c
index c13b4f2..89cce3f 100644
--- a/test/input.c
+++ b/test/input.c
@@ -1209,6 +1209,28 @@ static void include_bit_test_macros(void)
     }
 }
 
+/**
+ * Ensure that val->axisVal and val->axes are aligned on doubles.
+ */
+static void dix_valuator_alloc(void)
+{
+    ValuatorClassPtr v = NULL;
+    int num_axes = 0;
+
+    while (num_axes < 5)
+    {
+        v = AllocValuatorClass(v, num_axes);
+
+        g_assert(v);
+        g_assert(v->numAxes == num_axes);
+        g_assert(((void*)v->axisVal - (void*)v) % sizeof(double) == 0);
+        g_assert(((void*)v->axes - (void*)v) % sizeof(double) == 0);
+        num_axes ++;
+    }
+
+    free(v);
+}
+
 int main(int argc, char** argv)
 {
     g_test_init(&argc, &argv,NULL);
@@ -1226,7 +1248,7 @@ int main(int argc, char** argv)
     g_test_add_func("/include/byte_padding_macros", include_byte_padding_macros);
     g_test_add_func("/include/bit_test_macros", include_bit_test_macros);
     g_test_add_func("/Xi/xiproperty/register-unregister", xi_unregister_handlers);
-
+    g_test_add_func("/dix/input/valuator-alloc", dix_valuator_alloc);
 
     return g_test_run();
 }
commit 7762de65e153790ee9f63903964d168a6680d815
Author: Alexandr Shadchin <alexandr.shadchin at gmail.com>
Date:   Sat Apr 9 17:45:10 2011 +0600

    Simplify auto-detect mouse for WSCONS_SUPPORT
    
    Signed-off-by: Alexandr Shadchin <Alexandr.Shadchin at gmail.com>
    Reviewed-by: Matthieu Herrbb <matthieu.herrb at laas.fr>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c
index c712df7..9752669 100644
--- a/hw/xfree86/common/xf86Configure.c
+++ b/hw/xfree86/common/xf86Configure.c
@@ -63,6 +63,9 @@ static char *DFLT_MOUSE_PROTO = "auto";
 #elif defined(linux)
 static char DFLT_MOUSE_DEV[] = "/dev/input/mice";
 static char DFLT_MOUSE_PROTO[] = "auto";
+#elif defined(WSCONS_SUPPORT)
+static char *DFLT_MOUSE_DEV = "/dev/wsmouse";
+static char *DFLT_MOUSE_PROTO = "wsmouse";
 #else
 static char *DFLT_MOUSE_DEV = "/dev/mouse";
 static char *DFLT_MOUSE_PROTO = "auto";
@@ -154,16 +157,6 @@ configureInputSection (void)
     /* Crude mechanism to auto-detect mouse (os dependent) */
     { 
 	int fd;
-#ifdef WSCONS_SUPPORT
-	fd = open("/dev/wsmouse", 0);
-	if (fd >= 0) {
-	    DFLT_MOUSE_DEV = "/dev/wsmouse";
-	    DFLT_MOUSE_PROTO = "wsmouse";
-	    close(fd);
-	} else {
-	    ErrorF("cannot open /dev/wsmouse\n");
-	}
-#endif
 
 	fd = open(DFLT_MOUSE_DEV, 0);
 	if (fd != -1) {
commit 001b6b8b70734db1fa2f68e45c1db8337ba9f662
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Apr 15 13:01:37 2011 -0400

    glx: Make --disable-dri not disable AIGLX
    
    Either the DRI1 or DRI2 loaders are sufficient.
    
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/configure.ac b/configure.ac
index 9e04ff0..eeaa29b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1006,7 +1006,7 @@ else
 fi
 AM_CONDITIONAL(GLX, test "x$GLX" = xyes)
 
-if test "x$AIGLX" = xyes -a "x$GLX" = xyes -a "x$DRI" = xyes; then
+if test "x$AIGLX" = xyes -a "x$GLX" = xyes -a \( "x$DRI" = xyes -o "x$DRI2" = xyes \); then
 	AC_DEFINE(AIGLX, 1, [Build AIGLX loader])
 else
 	AIGLX=no
diff --git a/glx/Makefile.am b/glx/Makefile.am
index 72531f2..ef8677a 100644
--- a/glx/Makefile.am
+++ b/glx/Makefile.am
@@ -48,10 +48,13 @@ glapi_sources =					\
 	glthread.h
 
 libglxdri_la_SOURCES = \
-        glxdri.c \
         extension_string.c \
         extension_string.h
 
+if DRI
+libglxdri_la_SOURCES += glxdri.c
+endif
+
 if DRI2_AIGLX
 libglxdri_la_SOURCES += glxdri2.c
 endif
commit f8540b9dcc1fba886be5c4ce7ea0d74952cb48c4
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Apr 15 12:57:05 2011 -0400

    glx: Use 0 rather than garbage for unknown INTEL_swap_event types
    
    Otherwise the garbage you return could well be numerically identical to
    one of the swap type tokens, and apps which rely on us to tell the truth
    would be in trouble.
    
    Reviewed-by: Jesse Barnes <jbarnes at virtuousgeek.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index e8961e2..d979717 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -184,6 +184,7 @@ __glXdriSwapEvent(ClientPtr client, void *data, int type, CARD64 ust,
 	break;
     default:
 	/* unknown swap completion type */
+	wire.event_type = 0;
 	break;
     }
     wire.drawable = drawable->drawId;
commit dc0cf7596782087bdda0e7f9cd2f60907c45b2c4
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Mar 29 10:09:46 2011 -0400

    Revert "composite: Don't backfill non-bg-None windows"
    
    This reverts commit 6dd775f57d2f94f0ddaee324aeec33b9b66ed5bc.
    
    Bugzilla: https://bugs.freedesktop.org/34427
    
    Acked-by: Alex Deucher <alexdeucher at gmail.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/composite/compalloc.c b/composite/compalloc.c
index e4064f6..7164c0d 100644
--- a/composite/compalloc.c
+++ b/composite/compalloc.c
@@ -508,17 +508,6 @@ compUnredirectOneSubwindow (WindowPtr pParent, WindowPtr pWin)
     return Success;
 }
 
-static int
-bgNoneVisitWindow(WindowPtr pWin, void *null)
-{
-    if (pWin->backgroundState != BackgroundPixmap)
-	return WT_WALKCHILDREN;
-    if (pWin->background.pixmap != None)
-	return WT_WALKCHILDREN;
-
-    return WT_STOPWALKING;
-}
-
 static PixmapPtr
 compNewPixmap (WindowPtr pWin, int x, int y, int w, int h, Bool map)
 {
@@ -539,21 +528,6 @@ compNewPixmap (WindowPtr pWin, int x, int y, int w, int h, Bool map)
     if (!map)
 	return pPixmap;
 
-    /*
-     * If there's no bg=None in the tree, we're done.
-     *
-     * We could optimize this more by collection the regions of all the
-     * bg=None subwindows and feeding that in as the clip for the
-     * CopyArea below, but since window trees are shallow these days it
-     * might not be worth the effort.
-     */
-    if (TraverseTree(pWin, bgNoneVisitWindow, NULL) == WT_NOMATCH)
-	return pPixmap;
-
-    /*
-     * Copy bits from the parent into the new pixmap so that it will
-     * have "reasonable" contents in case for background None areas.
-     */
     if (pParent->drawable.depth == pWin->drawable.depth)
     {
 	GCPtr	pGC = GetScratchGC (pWin->drawable.depth, pScreen);
commit 6a433b67ca15fd1ea58334e607f867554f227451
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Mar 28 12:30:09 2011 -0400

    glx: Fix lifetime tracking for pixmaps
    
    GLX pixmaps take a reference on the underlying pixmap; X and GLX pixmap
    IDs can be destroyed in either order with no error.  Only windows need
    to be tracked under both XIDs.
    
    Fixes piglit/glx-pixmap-life.
    
    Reviewed-by: Michel Dänzer <michel at daenzer.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 66d4c7e..d5b764f 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -1127,10 +1127,11 @@ DoCreateGLXDrawable(ClientPtr client, __GLXscreen *pGlxScreen,
 	return BadAlloc;
     }
 
-    /* Add the glx drawable under the XID of the underlying X drawable
-     * too.  That way we'll get a callback in DrawableGone and can
-     * clean up properly when the drawable is destroyed. */
-    if (drawableId != glxDrawableId &&
+    /*
+     * Windows aren't refcounted, so track both the X and the GLX window
+     * so we get called regardless of destruction order.
+     */
+    if (drawableId != glxDrawableId && type == GLX_DRAWABLE_WINDOW &&
 	!AddResource(pDraw->id, __glXDrawableRes, pGlxDraw)) {
 	pGlxDraw->destroy (pGlxDraw);
 	return BadAlloc;
@@ -1161,6 +1162,8 @@ DoCreateGLXPixmap(ClientPtr client, __GLXscreen *pGlxScreen, __GLXconfig *config
     err = DoCreateGLXDrawable(client, pGlxScreen, config, pDraw, drawableId,
 			      glxDrawableId, GLX_DRAWABLE_PIXMAP);
 
+    ((PixmapPtr)pDraw)->refcnt++;
+
     return err;
 }
 
diff --git a/glx/glxext.c b/glx/glxext.c
index 3f3dd79..9cfc096 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -118,15 +118,15 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 {
     __GLXcontext *c, *next;
 
-    /* If this drawable was created using glx 1.3 drawable
-     * constructors, we added it as a glx drawable resource under both
-     * its glx drawable ID and it X drawable ID.  Remove the other
-     * resource now so we don't a callback for freed memory. */
-    if (glxPriv->drawId != glxPriv->pDraw->id) {
-	if (xid == glxPriv->drawId)
-	    FreeResourceByType(glxPriv->pDraw->id, __glXDrawableRes, TRUE);
-	else
-	    FreeResourceByType(glxPriv->drawId, __glXDrawableRes, TRUE);
+    if (glxPriv->type == GLX_DRAWABLE_WINDOW) {
+        /* If this was created by glXCreateWindow, free the matching resource */
+        if (glxPriv->drawId != glxPriv->pDraw->id) {
+            if (xid == glxPriv->drawId)
+                FreeResourceByType(glxPriv->pDraw->id, __glXDrawableRes, TRUE);
+            else
+                FreeResourceByType(glxPriv->drawId, __glXDrawableRes, TRUE);
+        }
+        /* otherwise this window was implicitly created by MakeCurrent */
     }
 
     for (c = glxAllContexts; c; c = next) {
@@ -143,6 +143,10 @@ static Bool DrawableGone(__GLXdrawable *glxPriv, XID xid)
 	    c->readPriv = NULL;
     }
 
+    /* drop our reference to any backing pixmap */
+    if (glxPriv->type == GLX_DRAWABLE_PIXMAP)
+        glxPriv->pDraw->pScreen->DestroyPixmap((PixmapPtr)glxPriv->pDraw);
+
     glxPriv->destroy(glxPriv);
 
     return True;


More information about the Xquartz-changes mailing list