[Xquartz-changes] xserver: Branch 'server-1.13-apple' - 97 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Thu Jun 20 15:11:44 PDT 2013


Rebased ref, commits from common ancestor:
commit 38deebff15d2ea831abe0cd5d49fa831250e74a6
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 40a7e38..52d0b0a 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -1684,8 +1684,7 @@ fbFillRegionSolid(DrawablePtr pDrawable,
                   RegionPtr pRegion, FbBits and, FbBits xor);
 
 extern _X_EXPORT pixman_image_t *image_from_pict(PicturePtr pict,
-                                                 Bool has_clip,
-                                                 int *xoff, int *yoff);
+                                                 Bool has_clip);
 
 extern _X_EXPORT void free_pixman_pict(PicturePtr, pixman_image_t *);
 
diff --git a/fb/fbpict.c b/fb/fbpict.c
index 097a1a6..dc0ca3c 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -46,23 +46,18 @@ fbComposite(CARD8 op,
             INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, 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, width, height);
+                               xSrc, ySrc, xMask, yMask, xDst, yDst,
+                               width, height);
     }
 
     free_pixman_pict(pSrc, src);
@@ -143,20 +138,22 @@ create_conical_gradient_image(PictGradient * gradient)
 }
 
 static pixman_image_t *
-create_bits_picture(PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
+create_bits_picture(PicturePtr pict, 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((pixman_format_code_t) pict->format,
-                                     pixmap->drawable.width,
-                                     pixmap->drawable.height, (uint32_t *) bits,
+                                     pict->pDrawable->width,
+                                     pict->pDrawable->height, (uint32_t *) bits,
                                      stride * sizeof(FbStride));
 
     if (!image)
@@ -183,57 +180,31 @@ create_bits_picture(PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
         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);
 
 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, pict->transform);
     }
 
     switch (pict->repeatType) {
@@ -261,10 +232,8 @@ set_image_properties(pixman_image_t * image, PicturePtr pict, Bool has_clip,
      * as the alpha map for this operation
      */
     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);
+            image_from_pict_internal(pict->alphaMap, TRUE, TRUE);
 
         pixman_image_set_alpha_map(image, alpha_map, pict->alphaOrigin.x,
                                    pict->alphaOrigin.y);
@@ -298,8 +267,7 @@ set_image_properties(pixman_image_t * image, PicturePtr pict, Bool has_clip,
 }
 
 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;
 
@@ -307,7 +275,7 @@ image_from_pict_internal(PicturePtr pict, Bool has_clip, int *xoff, int *yoff,
         return NULL;
 
     if (pict->pDrawable) {
-        image = create_bits_picture(pict, has_clip, xoff, yoff);
+        image = create_bits_picture(pict, has_clip);
     }
     else if (pict->pSourcePict) {
         SourcePict *sp = pict->pSourcePict;
@@ -325,19 +293,17 @@ 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 bf82f8f..0145ce9 100644
--- a/fb/fbtrap.c
+++ b/fb/fbtrap.c
@@ -36,13 +36,12 @@ fbAddTraps(PicturePtr pPicture,
            INT16 x_off, INT16 y_off, int ntrap, xTrap * traps)
 {
     pixman_image_t *image;
-    int dst_xoff, dst_yoff;
 
-    if (!(image = image_from_pict(pPicture, FALSE, &dst_xoff, &dst_yoff)))
-        return;
-
-    pixman_add_traps(image, x_off + dst_xoff, y_off + dst_yoff,
-                     ntrap, (pixman_trap_t *) traps);
+    if (!(image = image_from_pict (pPicture, FALSE)))
+	return;
+    
+    pixman_add_traps(image, x_off, y_off,
+                     ntrap, (pixman_trap_t *)traps);
 
     free_pixman_pict(pPicture, image);
 }
@@ -52,13 +51,12 @@ fbRasterizeTrapezoid(PicturePtr pPicture,
                      xTrapezoid * trap, int x_off, int y_off)
 {
     pixman_image_t *image;
-    int dst_xoff, dst_yoff;
 
-    if (!(image = image_from_pict(pPicture, FALSE, &dst_xoff, &dst_yoff)))
+    if (!(image = image_from_pict (pPicture, FALSE)))
         return;
 
-    pixman_rasterize_trapezoid(image, (pixman_trapezoid_t *) trap,
-                               x_off + dst_xoff, y_off + dst_yoff);
+    pixman_rasterize_trapezoid(image, (pixman_trapezoid_t *)trap,
+                               x_off, y_off);
 
     free_pixman_pict(pPicture, image);
 }
@@ -68,14 +66,12 @@ fbAddTriangles(PicturePtr pPicture,
                INT16 x_off, INT16 y_off, int ntri, xTriangle * tris)
 {
     pixman_image_t *image;
-    int dst_xoff, dst_yoff;
 
-    if (!(image = image_from_pict(pPicture, FALSE, &dst_xoff, &dst_yoff)))
+    if (!(image = image_from_pict (pPicture, FALSE)))
         return;
-
-    pixman_add_triangles(image,
-                         dst_xoff + x_off, dst_yoff + y_off,
-                         ntri, (pixman_triangle_t *) tris);
+    
+    pixman_add_triangles(image, x_off, y_off, ntri,
+                         (pixman_triangle_t *)tris);
 
     free_pixman_pict(pPicture, image);
 }
@@ -98,13 +94,11 @@ fbShapes(CompositeShapesFunc composite,
          int16_t ySrc, int nshapes, int shape_size, const uint8_t * shapes)
 {
     pixman_image_t *src, *dst;
-    int src_xoff, src_yoff;
-    int dst_xoff, dst_yoff;
 
     miCompositeSourceValidate(pSrc);
 
-    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) {
         pixman_format_code_t format;
@@ -121,9 +115,8 @@ fbShapes(CompositeShapesFunc composite,
 
             for (i = 0; i < nshapes; ++i) {
                 composite(op, src, dst, format,
-                          xSrc + src_xoff,
-                          ySrc + src_yoff,
-                          dst_xoff, dst_yoff, 1, shapes + i * shape_size);
+                          xSrc, ySrc, 0, 0, 
+                          1, shapes + i * shape_size);
             }
         }
         else {
@@ -143,8 +136,8 @@ fbShapes(CompositeShapesFunc composite,
             }
 
             composite(op, src, dst, format,
-                      xSrc + src_xoff,
-                      ySrc + src_yoff, dst_xoff, dst_yoff, nshapes, shapes);
+                      xSrc, ySrc, 0, 0,
+                      nshapes, shapes);
         }
 
         DamageRegionProcessPending(pDst->pDrawable);
commit 48293b559e71203c0d8845dafa8ad8d099f093db
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 8b7c93f..3e972f7 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -489,7 +489,8 @@ void RootlessSetPixmapOfAncestors(WindowPtr pWin);
 void RootlessStartDrawing(WindowPtr pWin);
 void RootlessDamageRegion(WindowPtr pWin, RegionPtr prgn);
 Bool IsFramedWindow(WindowPtr pWin);
-#endif
+#include "../fb/fb.h"
+#endif 
 
 void
 miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
@@ -518,23 +519,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;
+#endif
+    
+    if (what == PW_BACKGROUND)
+    {
+#ifdef ROOTLESS
+        if(IsFramedWindow(pWin)) {
+            RootlessStartDrawing(pWin);
+            RootlessDamageRegion(pWin, prgn);
 
-    if (IsFramedWindow(pWin)) {
-        RootlessStartDrawing(pWin);
-        RootlessDamageRegion(pWin, prgn);
-
-        if (pWin->backgroundState == ParentRelative) {
-            if ((what == PW_BACKGROUND) ||
-                (what == PW_BORDER && !pWin->borderIsPixel))
+            if(pWin->backgroundState == ParentRelative) {
                 RootlessSetPixmapOfAncestors(pWin);
+            }
         }
-    }
 #endif
 
-    if (what == PW_BACKGROUND) {
         while (pWin->backgroundState == ParentRelative)
             pWin = pWin->parent;
 
@@ -559,6 +574,18 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     else {
         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;
 
@@ -567,6 +594,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;
@@ -629,6 +662,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 dbffa1f43c5a97f036c371433a23916c06d05e2e
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Jan 13 12:00:57 2012 -0800

    sdksyms.sh: Use CPPFLAGS, not CFLAGS
    
    CFLAGS can include flags which are not useful to the preprocessor
    or can even cause it to fail.  This fixes a build issue on darwin
    when building for more than one architecture.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index c3899b5..4f48b85 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -38,7 +38,7 @@ DIST_SUBDIRS = common ddc i2c x86emu int10 fbdevhw os-support \
 bin_PROGRAMS = Xorg
 nodist_Xorg_SOURCES = sdksyms.c
 
-AM_CFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@
+AM_CPPFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@
 INCLUDES = $(XORG_INCS) -I$(srcdir)/parser -I$(top_srcdir)/miext/cw \
 	-I$(srcdir)/ddc -I$(srcdir)/i2c -I$(srcdir)/modes -I$(srcdir)/ramdac \
 	-I$(srcdir)/dri -I$(srcdir)/dri2
@@ -115,7 +115,7 @@ CLEANFILES = sdksyms.c sdksyms.dep
 EXTRA_DIST += sdksyms.sh
 
 sdksyms.dep sdksyms.c: sdksyms.sh
-	$(AM_V_GEN)CPP='$(CPP)' AWK='$(AWK)' $(SHELL) $(srcdir)/sdksyms.sh $(top_srcdir) $(CFLAGS) $(AM_CFLAGS) $(INCLUDES)
+	$(AM_V_GEN)CPP='$(CPP)' AWK='$(AWK)' $(SHELL) $(srcdir)/sdksyms.sh $(top_srcdir) $(CPPFLAGS) $(AM_CPPFLAGS) $(INCLUDES)
 
 SDKSYMS_DEP = sdksyms.dep
 include $(SDKSYMS_DEP)
commit 86ef1e26c09fe45e55bfa53148a2fc0f3eb1dd79
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Wed Jan 2 09:56:19 2013 -0800

    XQuartz: Bump bundle to version 2.7.5
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/bundle/Info.plist.cpp b/hw/xquartz/bundle/Info.plist.cpp
index b0106c6..4b4a894 100644
--- a/hw/xquartz/bundle/Info.plist.cpp
+++ b/hw/xquartz/bundle/Info.plist.cpp
@@ -19,9 +19,9 @@
 	<key>CFBundlePackageType</key>
 		<string>APPL</string>
 	<key>CFBundleShortVersionString</key>
-		<string>2.7.4</string>
+		<string>2.7.5</string>
 	<key>CFBundleVersion</key>
-		<string>2.7.4</string>
+		<string>2.7.5</string>
 	<key>CFBundleSignature</key>
 		<string>x11a</string>
 	<key>CSResourcesFileMapped</key>
@@ -39,9 +39,9 @@
 	<key>LSApplicationCategoryType</key>
 		<string>public.app-category.utilities</string>
 	<key>NSHumanReadableCopyright</key>
-		<string>© 2003-2012 Apple Inc.
+		<string>© 2003-2013 Apple Inc.
 © 2003 XFree86 Project, Inc.
-© 2003-2012 X.org Foundation, Inc.
+© 2003-2013 X.org Foundation, Inc.
 </string>
 	<key>NSMainNibFile</key>
 		<string>main</string>
commit 4c1725bac6002103febe490f4cc5606e4b5e0ac8
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sat Nov 17 11:52:10 2012 -0500

    XQuartz: Opt-in to NSSupportsAutomaticGraphicsSwitching
    
    http://xquartz.macosforge.org/trac/ticket/668
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    (cherry picked from commit 14c9e245bae2447f0e57a3ea4daa8d2085fa8b8f)

diff --git a/hw/xquartz/bundle/Info.plist.cpp b/hw/xquartz/bundle/Info.plist.cpp
index f76c5fc..b0106c6 100644
--- a/hw/xquartz/bundle/Info.plist.cpp
+++ b/hw/xquartz/bundle/Info.plist.cpp
@@ -26,6 +26,8 @@
 		<string>x11a</string>
 	<key>CSResourcesFileMapped</key>
 		<true/>
+	<key>NSSupportsAutomaticGraphicsSwitching</key>
+		<true/>
 #ifdef XQUARTZ_SPARKLE
 	<key>SUEnableAutomaticChecks</key>
 		<true/>
commit 10c42f5752d790f745572a3f9fbd2ad7686e1372
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 17 15:50:48 2013 +1000

    xserver 1.13.4
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/configure.ac b/configure.ac
index b28d8e3..ad06e7a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,9 +26,9 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.60)
-AC_INIT([xorg-server], 1.13.3, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2013-03-07"
-RELEASE_NAME="Golden Needle"
+AC_INIT([xorg-server], 1.13.4, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2013-04-17"
+RELEASE_NAME="Pokey Stick"
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AM_MAINTAINER_MODE
commit 8039b6b7a31f6cf75fcbe4e472d8e9544808396c
Author: Dave Airlie <airlied at gmail.com>
Date:   Wed Apr 10 16:09:01 2013 +1000

    xf86: fix flush input to work with Linux evdev devices.
    
    So when we VT switch back and attempt to flush the input devices,
    we don't succeed because evdev won't return part of an event,
    since we were only asking for 4 bytes, we'd only get -EINVAL back.
    
    This could later cause events to be flushed that we shouldn't have
    gotten.
    
    This is a fix for CVE-2013-1940.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit 6ca03b9161d33b1d2b55a3a1a913cf88deb2343f)

diff --git a/hw/xfree86/os-support/shared/posix_tty.c b/hw/xfree86/os-support/shared/posix_tty.c
index ab3757a..4d08c1e 100644
--- a/hw/xfree86/os-support/shared/posix_tty.c
+++ b/hw/xfree86/os-support/shared/posix_tty.c
@@ -421,7 +421,8 @@ xf86FlushInput(int fd)
 {
     fd_set fds;
     struct timeval timeout;
-    char c[4];
+    /* this needs to be big enough to flush an evdev event. */
+    char c[256];
 
     DebugF("FlushingSerial\n");
     if (tcflush(fd, TCIFLUSH) == 0)
commit 87d7e3e3525a9bcfa08d64ee2a83341e19140db7
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Dec 18 14:12:40 2012 +1000

    dix: only show the cursor if a window defines one (#58398)
    
    e02f864fdf "Suppress cursor display until the first XDefineCursor() request"
    disabled cursor display a priori unless -retro is given.
    
    On a plain server, caling XFixesHideCursor() and XFixesShowCursor() would
    show the default root cursor, despite no client actually defining a cursor.
    
    Change the logic, disable CursorVisible by default and only enable it from
    the window's CWCursor logic. If no window ever defines a cursor, said cursor
    stays invisible.
    
    X.Org Bug 58398 <http://bugs.freedesktop.org/show_bug.cgi?id=58398>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Tested-by: Bastien Nocera <hadess at hadess.net>
    Reviewed-by: Daniel Martin <consume.noise at gmail.com>
    (cherry picked from commit c100211034ab69ce453a1644fb61c6808d7e3eda)

diff --git a/dix/window.c b/dix/window.c
index 49ef4a0..ff979d9 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -1431,6 +1431,8 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
                     }
                 }
 
+                CursorVisible = TRUE;
+
                 if (pWin->realized)
                     WindowHasNewCursor(pWin);
 
@@ -3467,6 +3469,8 @@ ChangeWindowDeviceCursor(WindowPtr pWin, DeviceIntPtr pDev, CursorPtr pCursor)
     }
 
  out:
+    CursorVisible = TRUE;
+
     if (pWin->realized)
         WindowHasNewCursor(pWin);
 
diff --git a/include/input.h b/include/input.h
index f0196f5..076e2c5 100644
--- a/include/input.h
+++ b/include/input.h
@@ -628,6 +628,11 @@ extern _X_HIDDEN void valuator_set_mode(DeviceIntPtr dev, int axis, int mode);
    xfixes/cursor.c uses it to determine if the cursor is enabled */
 extern Bool EnableCursor;
 
+/* Set to FALSE by default - ChangeWindowAttributes sets it to TRUE on
+ * CWCursor, xfixes/cursor.c uses it to determine if the cursor is enabled
+ */
+extern Bool CursorVisible;
+
 extern _X_EXPORT ValuatorMask *valuator_mask_new(int num_valuators);
 extern _X_EXPORT void valuator_mask_free(ValuatorMask **mask);
 extern _X_EXPORT void valuator_mask_set_range(ValuatorMask *mask,
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 4d4a75e..d6f61c2 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -139,8 +139,7 @@ typedef struct _CursorScreen {
 #define Unwrap(as,s,elt,backup)	(((backup) = (s)->elt), (s)->elt = (as)->elt)
 
 /* The cursor doesn't show up until the first XDefineCursor() */
-static Bool CursorVisible = FALSE;
-
+Bool CursorVisible = FALSE;
 Bool EnableCursor = TRUE;
 
 static Bool
@@ -152,12 +151,7 @@ CursorDisplayCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
 
     Unwrap(cs, pScreen, DisplayCursor, backupProc);
 
-    /*
-     * Have to check ConnectionInfo to distinguish client requests from
-     * initial root window setup.  Not a great way to do it, I admit.
-     */
-    if (ConnectionInfo)
-        CursorVisible = EnableCursor;
+    CursorVisible = CursorVisible && EnableCursor;
 
     if (cs->pCursorHideCounts != NULL || !CursorVisible) {
         ret = (*pScreen->DisplayCursor) (pDev, pScreen, NullCursor);
commit b1c01839d8aec4266fd3731a04a23e34f182bf69
Author: Daniel Martin <consume.noise at gmail.com>
Date:   Thu Dec 20 13:50:17 2012 +0100

    ephyr: Fix crash on 24bpp host framebuffer
    
    Use bytes_per_line and bits_per_pixel from the created XImage to fix
        https://bugzilla.redhat.com/show_bug.cgi?id=518960
    
    Signed-off-by: Daniel Martin <consume.noise at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit bd58ebe4cf3b0ce60f87fb26a3715f774dabd349)

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index e6520d0..c9672c0 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -237,13 +237,11 @@ ephyrMapFramebuffer(KdScreenInfo * screen)
     KdComputePointerMatrix(&m, ephyrRandr, screen->width, screen->height);
     KdSetPointerMatrix(&m);
 
-    priv->bytes_per_line =
-        ((screen->width * screen->fb.bitsPerPixel + 31) >> 5) << 2;
-
     buffer_height = ephyrBufferHeight(screen);
 
     priv->base =
-        hostx_screen_init(screen, screen->width, screen->height, buffer_height);
+        hostx_screen_init(screen, screen->width, screen->height, buffer_height,
+                          &priv->bytes_per_line, &screen->fb.bitsPerPixel);
 
     if ((scrpriv->randr & RR_Rotate_0) && !(scrpriv->randr & RR_Reflect_All)) {
         scrpriv->shadow = FALSE;
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 02729d6..dfbb989 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -617,7 +617,8 @@ hostx_set_cmap_entry(unsigned char idx,
  */
 void *
 hostx_screen_init(EphyrScreenInfo screen,
-                  int width, int height, int buffer_height)
+                  int width, int height, int buffer_height,
+                  int *bytes_per_line, int *bits_per_pixel)
 {
     int bitmap_pad;
     Bool shm_success = False;
@@ -694,6 +695,9 @@ hostx_screen_init(EphyrScreenInfo screen,
             malloc(host_screen->ximg->bytes_per_line * buffer_height);
     }
 
+    *bytes_per_line = host_screen->ximg->bytes_per_line;
+    *bits_per_pixel = host_screen->ximg->bits_per_pixel;
+
     XResizeWindow(HostX.dpy, host_screen->win, width, height);
 
     /* Ask the WM to keep our size static */
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index 31c4053..38b7b37 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -193,7 +193,8 @@ hostx_set_cmap_entry(unsigned char idx,
                      unsigned char r, unsigned char g, unsigned char b);
 
 void *hostx_screen_init(EphyrScreenInfo screen,
-                        int width, int height, int buffer_height);
+                        int width, int height, int buffer_height,
+                        int *bytes_per_line, int *bits_per_pixel);
 
 void
 
commit 4bd8e9ecc3dedb876b90b64fb8b140576d5a7b0b
Author: Aaron Plattner <aplattner at nvidia.com>
Date:   Mon Feb 11 14:31:56 2013 -0800

    xf86: use nt_list_for_each_entry_safe to walk InputHandlers in xf86Wakeup
    
    This is necessary when the input handler deletes itself from the
    list. Bug found by Maarten Lankhorst, this patch uses the list macros
    instead of open-coding the fix.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit da92690107d90061205340d4cdc98b73b59db9b2)

diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index 7e80fa9..b19553a 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -272,9 +272,9 @@ xf86Wakeup(pointer blockData, int err, pointer pReadmask)
     }
 
     if (err >= 0) {             /* we don't want the handlers called if select() */
-        IHPtr ih;               /* returned with an error condition, do we?      */
+        IHPtr ih, ih_tmp;       /* returned with an error condition, do we?      */
 
-        for (ih = InputHandlers; ih; ih = ih->next) {
+        nt_list_for_each_entry_safe(ih, ih_tmp, InputHandlers, next) {
             if (ih->enabled && ih->fd >= 0 && ih->ihproc &&
                 (FD_ISSET(ih->fd, ((fd_set *) pReadmask)) != 0)) {
                 ih->ihproc(ih->fd, ih->data);
commit eec5eb2f09682718e69f42491181ade0b093f52d
Author: Matt Dew <marcoz at osource.org>
Date:   Thu Mar 7 23:08:09 2013 -0700

    Bump version to 1.13.3

diff --git a/configure.ac b/configure.ac
index bc4f22e..b28d8e3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,9 +26,9 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.60)
-AC_INIT([xorg-server], 1.13.2.902, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2013-02-28"
-RELEASE_NAME="1.13.3-rc2"
+AC_INIT([xorg-server], 1.13.3, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2013-03-07"
+RELEASE_NAME="Golden Needle"
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AM_MAINTAINER_MODE
commit f7ac91301912d0d7ba4beba5e309e6cc8b435945
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jan 9 12:58:28 2013 +1000

    randr: cleanup provider properly
    
    So in the cold plug server shutdown case, we reap the resources
    before we call CloseScreen handlers, so the config->randr_provider
    is a dangling pointer when the xf86CrtcCloseScreen handler is called,
    
    however in the hot screen unplug case, we can't rely on automatically
    reaped resources, so we need to clean up the provider in the xf86CrtcCloseScreen
    case.
    
    This patch provides a cleanup callback from the randr provider removal
    into the DDX so it can cleanup properly, this then gets called by the automatic
    code for cold plug, or if hot unplug it gets called explicitly.
    
    Fixes a number of random server crashes on shutdown
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=58174
    Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=891140
    
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 13251cf..33f5a14 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -743,16 +743,8 @@ xf86CrtcCloseScreen(ScreenPtr screen)
     }
     /* detach any providers */
     if (config->randr_provider) {
-        if (config->randr_provider->offload_sink) {
-            DetachOffloadGPU(screen);
-            config->randr_provider->offload_sink = NULL;
-        }
-        else if (config->randr_provider->output_source) {
-            DetachOutputGPU(screen);
-            config->randr_provider->output_source = NULL;
-        }
-        else if (screen->current_master)
-            DetachUnboundGPU(screen);
+        RRProviderDestroy(config->randr_provider);
+        config->randr_provider = NULL;
     }
     return TRUE;
 }
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 3530abf..01fc9c5 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -1885,6 +1885,27 @@ xf86RandR13ConstrainCursorHarder(DeviceIntPtr dev, ScreenPtr screen, int mode, i
     }
 }
 
+static void
+xf86RandR14ProviderDestroy(ScreenPtr screen, RRProviderPtr provider)
+{
+    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
+    
+    if (config->randr_provider == provider) {
+        if (config->randr_provider->offload_sink) {
+            DetachOffloadGPU(screen);
+            config->randr_provider->offload_sink = NULL;
+        }
+        else if (config->randr_provider->output_source) {
+            DetachOutputGPU(screen);
+            config->randr_provider->output_source = NULL;
+        }
+        else if (screen->current_master)
+            DetachUnboundGPU(screen);
+    }
+    config->randr_provider = NULL;
+}
+
 static Bool
 xf86RandR12Init12(ScreenPtr pScreen)
 {
@@ -1914,6 +1935,7 @@ xf86RandR12Init12(ScreenPtr pScreen)
     rp->rrProviderSetProperty = xf86RandR14ProviderSetProperty;
     rp->rrProviderGetProperty = xf86RandR14ProviderGetProperty;
     rp->rrCrtcSetScanoutPixmap = xf86CrtcSetScanoutPixmap;
+    rp->rrProviderDestroy = xf86RandR14ProviderDestroy;
 
     pScrn->PointerMoved = xf86RandR12PointerMoved;
     pScrn->ChangeGamma = xf86RandR12ChangeGamma;
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 27aa101..70aaa3d 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -232,6 +232,9 @@ typedef Bool (*RRProviderSetOffloadSinkProcPtr)(ScreenPtr pScreen,
                                          RRProviderPtr offload_sink);
 
 
+typedef void (*RRProviderDestroyProcPtr)(ScreenPtr pScreen,
+                                         RRProviderPtr provider);
+
 /* These are for 1.0 compatibility */
 
 typedef struct _rrRefresh {
@@ -330,6 +333,9 @@ typedef struct _rrScrPriv {
     Bool discontiguous;
 
     RRProviderPtr provider;
+
+    RRProviderDestroyProcPtr rrProviderDestroy;
+
 } rrScrPrivRec, *rrScrPrivPtr;
 
 extern _X_EXPORT DevPrivateKeyRec rrPrivKeyRec;
diff --git a/randr/rrprovider.c b/randr/rrprovider.c
index c4ed515..b321e62 100644
--- a/randr/rrprovider.c
+++ b/randr/rrprovider.c
@@ -389,6 +389,8 @@ RRProviderDestroyResource (pointer value, XID pid)
     {
         rrScrPriv(pScreen);
 
+        if (pScrPriv->rrProviderDestroy)
+            (*pScrPriv->rrProviderDestroy)(pScreen, provider);
         pScrPriv->provider = NULL;
     }
     free(provider);
commit 4d98c7da78db66a20397112899dc5aa455a2fdd0
Author: Matt Dew <marcoz at osource.org>
Date:   Thu Feb 28 23:48:03 2013 -0700

    bump rev from 1.13.3-rc1 to 1.13.3-rc2

diff --git a/configure.ac b/configure.ac
index 9415a54..bc4f22e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,9 +26,9 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.60)
-AC_INIT([xorg-server], 1.13.2.901, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2013-02-15"
-RELEASE_NAME="1.13.3-rc1"
+AC_INIT([xorg-server], 1.13.2.902, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2013-02-28"
+RELEASE_NAME="1.13.3-rc2"
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AM_MAINTAINER_MODE
commit 412c4abbaec2c26b421f407427c1a9d5b7c2de23
Merge: e604b19 e7b4b83
Author: Matt Dew <marcoz at osource.org>
Date:   Mon Feb 18 13:23:07 2013 -0700

    Merge branch 'server-1.13-branch' of git://people.freedesktop.org/~whot/xserver into server-1.13-branch

commit e604b19fc54fee839bbe2d66930b36108ff03950
Author: Aaron Plattner <aplattner at nvidia.com>
Date:   Wed Jan 23 16:58:47 2013 -0800

    randr: unref the provider shared pixmap the appropriate number of times
    
    When an RandR shared pixmap is created in rrCreateSharedPixmap, it has a refcnt
    of 1.  Then, PixmapShareToSlave bumps the refcnt to 2.  However, there's no
    corresponding PixmapUnshareFromSlave where the refcnt can be decreased again,
    and there's no convenient common place where the refcnt can be decremented when
    the slave pixmap is destroyed.
    
    Fix this by just unreffing the pixmap twice in RRCrtcDetachScanoutPixmap.
    
    Signed-off-by: Aaron Plattner <aplattner at nvidia.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index e82d050..6e2eca5 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -372,6 +372,11 @@ RRCrtcDetachScanoutPixmap(RRCrtcPtr crtc)
     ret = pScrPriv->rrCrtcSetScanoutPixmap(crtc, NULL);
     if (crtc->scanout_pixmap) {
         master->StopPixmapTracking(mscreenpix, crtc->scanout_pixmap);
+        /*
+         * Unref the pixmap twice: once for the original reference, and once
+         * for the reference implicitly added by PixmapShareToSlave.
+         */
+        master->DestroyPixmap(crtc->scanout_pixmap->master_pixmap);
         master->DestroyPixmap(crtc->scanout_pixmap->master_pixmap);
         crtc->pScreen->DestroyPixmap(crtc->scanout_pixmap);
     }
commit e7b4b83679604919035d5aab544092aef5ea6034
Author: Carlos Garnacho <carlosg at gnome.org>
Date:   Wed Feb 6 14:07:22 2013 +0100

    dix: Set focus field on XI2 crossing events
    
    Set on DeviceEnterLeaveEvent() the xXIEnterEvent->focus field
    similarly to how the CoreEnterLeaveEvent() function above does
    for core events.
    
    This fixes bug https://bugzilla.gnome.org/show_bug.cgi?id=677329
    reported to GTK+, where focus handling on window managers with
    sloppy focus or no window manager present was broken due to this
    field being always set to FALSE.
    
    Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit 509b3c3dc82e7abce1900d5e1cddd90f23be5a87)

diff --git a/dix/events.c b/dix/events.c
index 904f0ba..a43c99a 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4561,6 +4561,7 @@ DeviceEnterLeaveEvent(DeviceIntPtr mouse,
 {
     GrabPtr grab = mouse->deviceGrab.grab;
     xXIEnterEvent *event;
+    WindowPtr focus;
     int filter;
     int btlen, len, i;
     DeviceIntPtr kbd;
@@ -4602,6 +4603,11 @@ DeviceEnterLeaveEvent(DeviceIntPtr mouse,
         event->group.locked_group = kbd->key->xkbInfo->state.locked_group;
     }
 
+    focus = (kbd) ? kbd->focus->win : None;
+    if ((focus != NoneWin) &&
+        ((pWin == focus) || (focus == PointerRootWin) || IsParent(focus, pWin)))
+        event->focus = TRUE;
+
     FixUpEventFromWindow(mouse->spriteInfo->sprite, (xEvent *) event, pWin,
                          None, FALSE);
 
commit 29a0c87f4d235898a526758b34c2abfdb656cdf4
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Jan 25 11:47:32 2013 +1000

    dix: when shutting down slave devices, shut down xtest devices last
    
    XTest devices are the first ones in the list, being initialised together
    with the master devices. If we disable the devices in-order and a device has
    a button down when being disabled, the XTest device is checked for a
    required button release (xkbAccessX.c's ProcessPointerEvent). This fails if
    the device is already NULL.
    
    Instead of putting the check there, disable the devices in the reverse order
    they are initialised. Disable physical slaves first, then xtest devices,
    then the master devices.
    
    Testcase: shut down server with a button still held down on a physical
    device
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit 3e4be4033aed78b2bb3a18d51f0963989efd1af3)

diff --git a/dix/devices.c b/dix/devices.c
index fd4916a..7d7888e 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -514,6 +514,12 @@ DisableAllDevices(void)
 {
     DeviceIntPtr dev, tmp;
 
+    /* Disable slave devices first, excluding XTest devices */
+    nt_list_for_each_entry_safe(dev, tmp, inputInfo.devices, next) {
+        if (!IsXTestDevice(dev, NULL) && !IsMaster(dev))
+            DisableDevice(dev, FALSE);
+    }
+    /* Disable XTest devices */
     nt_list_for_each_entry_safe(dev, tmp, inputInfo.devices, next) {
         if (!IsMaster(dev))
             DisableDevice(dev, FALSE);
commit d8a09a4b15a6830b3fd281540015015a5663952e
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Jan 11 14:22:07 2013 +1000

    dix: pre-scale relative events from abs devices to desktop ratio (#31636)
    
    Absolute devices may send relative events depending on the mode (synaptics
    by default, wacom per option). The relative events are added to the previous
    position, converted into device coordinates and then scaled into desktop
    coordinates for pointer movement.
    
    Because the device range must be mapped into the desktop coordinate range,
    this results in uneven scaling depending dimensions, e.g. on a setup with
    width == 2 * height, a relative movement of 10/10 in device coordinates
    results in a cursor movement of 20/10 (+ acceleration)
    
    Other commonly user-visible results:
    * the touchpad changing acceleration once an external monitor as added.
    * drawing a circle on a wacom tablet in relative mode gives an ellipsis in
      the same ratio as the desktop dimensions.
    
    Solution: pre-scale the incoming relative x/y coordinates by width/height
    ratio of the total desktop size. Then add them to the previous
    coordinates and scale back with the previous mapping, which will undo the
    pre-scaling and give us the right movement.
    
    X.Org Bug 31636 <http://bugs.freedesktop.org/show_bug.cgi?id=31636>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit 61a99aff9d33728a0b67920254d2d4d79f80cf39)

diff --git a/dix/getevents.c b/dix/getevents.c
index bf87ffa..7076783 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -787,11 +787,33 @@ add_to_scroll_valuator(DeviceIntPtr dev, ValuatorMask *mask, int valuator, doubl
  * @param[in,out] mask Valuator data for this event, modified in-place.
  */
 static void
-moveRelative(DeviceIntPtr dev, ValuatorMask *mask)
+moveRelative(DeviceIntPtr dev, int flags, ValuatorMask *mask)
 {
     int i;
     Bool clip_xy = IsMaster(dev) || !IsFloating(dev);
 
+    /* for abs devices in relative mode, we've just scaled wrong, since we
+       mapped the device's shape into the screen shape. Undo this. */
+    if ((flags & POINTER_ABSOLUTE) == 0 && dev->valuator &&
+        dev->valuator->axes[0].min_value < dev->valuator->axes[0].max_value) {
+
+        double ratio = 1.0 * screenInfo.width/screenInfo.height;
+
+        if (ratio > 1.0) {
+            double y;
+            if (valuator_mask_fetch_double(mask, 1, &y)) {
+                y *= ratio;
+                valuator_mask_set_double(mask, 1, y);
+            }
+        } else {
+            double x;
+            if (valuator_mask_fetch_double(mask, 0, &x)) {
+                x *= ratio;
+                valuator_mask_set_double(mask, 0, x);
+            }
+        }
+    }
+
     /* calc other axes, clip, drop back into valuators */
     for (i = 0; i < valuator_mask_size(mask); i++) {
         double val = dev->last.valuators[i];
@@ -1387,7 +1409,7 @@ fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type,
         if ((flags & POINTER_NORAW) == 0)
             set_raw_valuators(raw, &mask, raw->valuators.data);
 
-        moveRelative(pDev, &mask);
+        moveRelative(pDev, flags, &mask);
     }
 
     /* valuators are in device coordinate system in absolute coordinates */
commit 79f5430ba62e0020cb19e4ce72599a220d0bb2f9
Author: Sybren van Elderen <sowmestno at msn.com>
Date:   Tue Jan 29 15:43:57 2013 +1000

    dix: when scaling from desktop coord, take the total desktop size (#51904)
    
    Scaled is already in desktop coordinates, take the total width into account,
    not just the current screen's width.
    
    Fixes Xdmx pointer position calculation.
    
    X.Org Bug 51904 <http://bugs.freedesktop.org/show_bug.cgi?id=51904>
    
    Signed-off-by: Sybren van Elderen <sowmestno at msn.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit a191dbfe850ed9c6440346f59cb0078e0e844edc)

diff --git a/dix/getevents.c b/dix/getevents.c
index 241fcfd..bf87ffa 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -844,14 +844,14 @@ scale_from_screen(DeviceIntPtr dev, ValuatorMask *mask)
         scaled = valuator_mask_get_double(mask, 0) + scr->x;
         scaled = rescaleValuatorAxis(scaled,
                                      NULL, dev->valuator->axes + 0,
-                                     0, scr->width);
+                                     screenInfo.x, screenInfo.width);
         valuator_mask_set_double(mask, 0, scaled);
     }
     if (valuator_mask_isset(mask, 1)) {
         scaled = valuator_mask_get_double(mask, 1) + scr->y;
         scaled = rescaleValuatorAxis(scaled,
                                      NULL, dev->valuator->axes + 1,
-                                     0, scr->height);
+                                     screenInfo.y, screenInfo.height);
         valuator_mask_set_double(mask, 1, scaled);
     }
 }
commit fa6cbd099f65eea46e41ecffcc46135bae2face8
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Sat Jan 26 14:13:33 2013 +1000

    dmx: don't include dmx-config.h from xdmxconfig (#37502)
    
    dmx-config.h is a server header which includes dix-config.h. That again
    defines a bunch of server-specifics, including setting the size of XID to
    32 bit.
    
    libX11 uses unsigned long (8 bits on x86_64). XGCValues thus ends up being
    16 bytes smaller in xdmxconfig than in the library, causing garbage to be
    sent to the server.
    
    X.Org Bug 37502 <http://bugs.freedesktop.org/show_bug.cgi?id=37502>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit 1058fcf57fdcb94d92e7b5f4483b347853d5f8e6)

diff --git a/hw/dmx/config/xdmxconfig.c b/hw/dmx/config/xdmxconfig.c
index f308412..2121dd7 100644
--- a/hw/dmx/config/xdmxconfig.c
+++ b/hw/dmx/config/xdmxconfig.c
@@ -31,9 +31,6 @@
  *
  */
 
-#ifdef HAVE_DMX_CONFIG_H
-#include <dmx-config.h>
-#endif
 
 #include <stdio.h>
 #include <stdlib.h>
commit 63f928a9d702512db4c1e683c3b772a4d1f32010
Author: Daniel Martin <consume.noise at gmail.com>
Date:   Fri Dec 7 19:38:55 2012 +0100

    xfixes: Fix minor number in QueryVersion
    
    Due to a typo the major version number was passed as minor version to
    version_compare().
    
    Regression-from: ffd4874798ba54f86acac75779a15b4babeaa5f3
    
    Signed-off-by: Daniel Martin <consume.noise at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit 36740d02b9ca117f1404e077367fbbbe271a17d6)

diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c
index 52c57df..48af9ea 100644
--- a/xfixes/xfixes.c
+++ b/xfixes/xfixes.c
@@ -74,7 +74,7 @@ ProcXFixesQueryVersion(ClientPtr client)
 
     if (version_compare(stuff->majorVersion, stuff->minorVersion,
                         SERVER_XFIXES_MAJOR_VERSION,
-                        SERVER_XFIXES_MAJOR_VERSION) < 0) {
+                        SERVER_XFIXES_MINOR_VERSION) < 0) {
         rep.majorVersion = stuff->majorVersion;
         rep.minorVersion = stuff->minorVersion;
     }
commit bc4c3158ba3ef438426a2376f20f97d7f266828c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Dec 4 15:28:14 2012 +1000

    xkb: only post a XTest release if the XTest device has the button down
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit 5daa442fe15d9a87112a2def673c99a5f2506dcf)

diff --git a/xkb/xkbAccessX.c b/xkb/xkbAccessX.c
index 9631502..13051e0 100644
--- a/xkb/xkbAccessX.c
+++ b/xkb/xkbAccessX.c
@@ -732,8 +732,13 @@ ProcessPointerEvent(InternalEvent *ev, DeviceIntPtr mouse)
             if (rc != Success)
                 ErrorF("[xkb] bad sourceid '%d' on button release event.\n",
                         event->sourceid);
-            else if (!IsXTestDevice(source, GetMaster(dev, MASTER_POINTER)))
-                XkbFakeDeviceButton(dev, FALSE, event->detail.key);
+            else if (!IsXTestDevice(source, GetMaster(dev, MASTER_POINTER))) {
+                DeviceIntPtr xtest_device;
+
+                xtest_device = GetXTestDevice(GetMaster(dev, MASTER_POINTER));
+                if (button_is_down(xtest_device, ev->device_event.detail.button, BUTTON_PROCESSED))
+                    XkbFakeDeviceButton(dev, FALSE, event->detail.key);
+            }
         }
 
         if (xkbi)
commit b3b7be7d49ee9a253062661d6c72fa1f8ddff493
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Dec 4 15:03:37 2012 +1000

    xkb: always post XTest button up when the physical button released (#28808)
    
    Regression introduced by commit 2decff6393a44b56d80d53570718f95354fde454
      xkb: ProcesssPointerEvent must work on the VCP if it gets the VCP
    
    XTest buttons must be released when a physical button is released. This was
    fixed in 14327858391ebe929b806efb53ad79e789361883, but
    2decff6393a44b56d80d53570718f95354fde454 changed a condition that this code
    didn't get triggered anymore.
    
    "dev" for pointer events is now always the VCP which doesn't have a xkbi
    struct. So move this condition out and always trigger the XTest released for
    button events.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Tested-by: Frank Roscher <Frank-Roscher at gmx.net>
    (cherry picked from commit c4fee9d2ecd6fdd4c05b04c9f02b23f10f2938b8)

diff --git a/xkb/xkbAccessX.c b/xkb/xkbAccessX.c
index 21df85d..9631502 100644
--- a/xkb/xkbAccessX.c
+++ b/xkb/xkbAccessX.c
@@ -723,23 +723,22 @@ ProcessPointerEvent(InternalEvent *ev, DeviceIntPtr mouse)
         changed |= XkbPointerButtonMask;
     }
     else if (event->type == ET_ButtonRelease) {
-        if (xkbi) {
-            xkbi->lockedPtrButtons &= ~(1 << (event->detail.key & 0x7));
-
-            if (IsMaster(dev)) {
-                DeviceIntPtr source;
-                int rc;
-
-                rc = dixLookupDevice(&source, event->sourceid, serverClient,
-                                     DixWriteAccess);
-                if (rc != Success)
-                    ErrorF("[xkb] bad sourceid '%d' on button release event.\n",
-                           event->sourceid);
-                else if (!IsXTestDevice(source, GetMaster(dev, MASTER_POINTER)))
-                    XkbFakeDeviceButton(dev, FALSE, event->detail.key);
-            }
+        if (IsMaster(dev)) {
+            DeviceIntPtr source;
+            int rc;
+
+            rc = dixLookupDevice(&source, event->sourceid, serverClient,
+                    DixWriteAccess);
+            if (rc != Success)
+                ErrorF("[xkb] bad sourceid '%d' on button release event.\n",
+                        event->sourceid);
+            else if (!IsXTestDevice(source, GetMaster(dev, MASTER_POINTER)))
+                XkbFakeDeviceButton(dev, FALSE, event->detail.key);
         }
 
+        if (xkbi)
+            xkbi->lockedPtrButtons &= ~(1 << (event->detail.key & 0x7));
+
         changed |= XkbPointerButtonMask;
     }
 
commit c260ae1a0ca76dadc44e7031ffcb78e12ba4087e
Author: Matt Dew <marcoz at osource.org>
Date:   Sat Feb 16 00:08:59 2013 -0700

    Update release to 1.13.3-rc1

diff --git a/configure.ac b/configure.ac
index a21d38d..9415a54 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,9 +26,9 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.60)
-AC_INIT([xorg-server], 1.13.2, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2013-01-24"
-RELEASE_NAME="Silver Needle"
+AC_INIT([xorg-server], 1.13.2.901, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2013-02-15"
+RELEASE_NAME="1.13.3-rc1"
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AM_MAINTAINER_MODE
commit b6c59f73d2dabca6348ca5ceae978488c3a4856f
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sat Feb 9 20:53:02 2013 -0800

    XORG_TLS: Pick the first option that works (ie: prefer __thread)
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/m4/xorg-tls.m4 b/m4/xorg-tls.m4
index 237fdcd..e04f1ff 100644
--- a/m4/xorg-tls.m4
+++ b/m4/xorg-tls.m4
@@ -28,7 +28,7 @@ AC_DEFUN([XORG_TLS], [
         ac_cv_tls=none
         keywords="__thread __declspec(thread)"
         for kw in $keywords ; do
-            AC_TRY_COMPILE([int $kw test;], [], ac_cv_tls=$kw)
+            AC_TRY_COMPILE([int $kw test;], [], ac_cv_tls=$kw ; break ;)
         done
     ])
     AC_MSG_RESULT($ac_cv_tls)
commit 1c7c7d407edfb68ee5679b059a0cd72a59ac5d67
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sat Feb 9 20:40:10 2013 -0800

    os: Ensure <dix-config.h> is included in strndup.c
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/os/strndup.c b/os/strndup.c
index b604b9b..e0eddf1 100644
--- a/os/strndup.c
+++ b/os/strndup.c
@@ -27,6 +27,10 @@
  * SUCH DAMAGE.
  */
 
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
commit e2f4be5ba55268d8e92c2d7161cb5ff822b29126
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sat Feb 9 20:34:33 2013 -0800

    XQuartz: Ensure <dix-config.h> is included in capabilities.c
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/hw/xquartz/GL/capabilities.c b/hw/xquartz/GL/capabilities.c
index 4702595..5573629 100644
--- a/hw/xquartz/GL/capabilities.c
+++ b/hw/xquartz/GL/capabilities.c
@@ -20,6 +20,10 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
commit a2d9bade3830802ac810a1bd72e516411f1bef35
Author: Dave Airlie <airlied at gmail.com>
Date:   Tue Feb 5 07:46:06 2013 -0800

    randr: bump advertised RandR version to 1.4
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
    Tested-by: Aaron Plattner <aplattner at nvidia.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/include/protocol-versions.h b/include/protocol-versions.h
index cb8e213..3128f5f 100644
--- a/include/protocol-versions.h
+++ b/include/protocol-versions.h
@@ -65,7 +65,7 @@
 
 /* RandR */
 #define SERVER_RANDR_MAJOR_VERSION		1
-#define SERVER_RANDR_MINOR_VERSION		3
+#define SERVER_RANDR_MINOR_VERSION		4
 
 /* Record */
 #define SERVER_RECORD_MAJOR_VERSION		1
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 212b0a9..27aa101 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -57,7 +57,7 @@
 #define RANDR_13_INTERFACE 1    /* requires RANDR_12_INTERFACE */
 #define RANDR_GET_CRTC_INTERFACE 1
 
-#define RANDR_INTERFACE_VERSION 0x0103
+#define RANDR_INTERFACE_VERSION 0x0104
 
 typedef XID RRMode;
 typedef XID RROutput;
commit 3ffa491426f2eb5a5454032676c537c8bb56bb29
Merge: 1000271 dc1c70f
Author: Matt Dew <marcoz at osource.org>
Date:   Fri Jan 25 16:34:29 2013 -0700

    Merge branch 'server-1.13-branch' of git://people.freedesktop.org/~whot/xserver into server-1.13-branch

commit 100027127cf6ebcccd404eece2bf6862669fc8a9
Author: Matt Dew <marcoz at osource.org>
Date:   Thu Jan 24 22:53:34 2013 -0700

    Bump version number to 1.13.2

diff --git a/configure.ac b/configure.ac
index 649092b..a21d38d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,9 +26,9 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.60)
-AC_INIT([xorg-server], 1.13.1.901, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2013-01-03"
-RELEASE_NAME=""
+AC_INIT([xorg-server], 1.13.2, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2013-01-24"
+RELEASE_NAME="Silver Needle"
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AM_MAINTAINER_MODE
commit dc1c70f2993ed36284e248e9f22caa62811206ec
Author: Dave Airlie <airlied at gmail.com>
Date:   Tue Jan 22 07:39:53 2013 +1000

    xserver: fix build regression since 91ab237358c6e33da854914d3de493a9cbea7637
    
    inputstr, double defines TouchListener typedef, maybe some gcc handles it,
    but not all.
    
    fixes tinderbox
    
    Reported-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit 605dfc6804a05ff2bda5692fec26c37344fd95cb)

diff --git a/include/inputstr.h b/include/inputstr.h
index 3b16e21..9834243 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -327,8 +327,6 @@ typedef struct _TouchPointInfo {
     size_t history_size;        /* Size of history in elements */
 } TouchPointInfoRec;
 
-typedef struct _TouchListener TouchListener;
-
 typedef struct _DDXTouchPointInfo {
     uint32_t client_id;         /* touch ID as seen in client events */
     Bool active;                /* whether or not the touch is active */
commit 310ac850805364c39c8f36a6a1d4fc54b952ad9d
Author: Yuly Novikov <ynovikov at chromium.org>
Date:   Mon Nov 19 21:04:57 2012 -0500

    dix: Save touchpoint last coordinates before transform. #49347
    
    DDXTouchPointInfoRec.valuators used to store axis values after transform.
    This resulted in Coordinate Transformation Matrix
    being applied multiple times to the last coordinates,
    in the case when only pressure changes in the last touch event.
    
    Changed DDXTouchPointInfoRec.valuators to store values before transform.
    
    Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=49347
    
    Signed-off-by: Yuly Novikov <ynovikov at chromium.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit 3b9f1c701787965246638c1a6fd99fb2b6078114)
    
    Conflicts:
    	dix/getevents.c

diff --git a/dix/getevents.c b/dix/getevents.c
index 8b4379d..241fcfd 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -1951,32 +1951,27 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid,
     default:
         return 0;
     }
-    if (t->mode == XIDirectTouch && !(flags & TOUCH_CLIENT_ID)) {
-        if (!valuator_mask_isset(&mask, 0))
-            valuator_mask_set_double(&mask, 0,
-                                     valuator_mask_get_double(touchpoint.ti->
-                                                              valuators, 0));
-        if (!valuator_mask_isset(&mask, 1))
-            valuator_mask_set_double(&mask, 1,
-                                     valuator_mask_get_double(touchpoint.ti->
-                                                              valuators, 1));
-    }
 
     /* Get our screen event co-ordinates (root_x/root_y/event_x/event_y):
      * these come from the touchpoint in Absolute mode, or the sprite in
      * Relative. */
     if (t->mode == XIDirectTouch) {
-        transformAbsolute(dev, &mask);
-
         if (!(flags & TOUCH_CLIENT_ID)) {
-            for (i = 0; i < valuator_mask_size(&mask); i++) {
-                double val;
-
-                if (valuator_mask_fetch_double(&mask, i, &val))
-                    valuator_mask_set_double(touchpoint.ti->valuators, i, val);
-            }
+        for (i = 0; i < max(valuator_mask_size(&mask), 2); i++) {
+            double val;
+
+            if (valuator_mask_fetch_double(&mask, i, &val))
+                valuator_mask_set_double(touchpoint.ti->valuators, i, val);
+            /* If the device doesn't post new X and Y axis values,
+             * use the last values posted.
+             */
+            else if (i < 2 &&
+                valuator_mask_fetch_double(touchpoint.ti->valuators, i, &val))
+                valuator_mask_set_double(&mask, i, val);
+        }
         }
 
+        transformAbsolute(dev, &mask);
         clipAbsolute(dev, &mask);
     }
     else {
diff --git a/include/inputstr.h b/include/inputstr.h
index 227ad7a..3b16e21 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -335,7 +335,7 @@ typedef struct _DDXTouchPointInfo {
     uint32_t ddx_id;            /* touch ID given by the DDX */
     Bool emulate_pointer;
 
-    ValuatorMask *valuators;    /* last recorded axis values */
+    ValuatorMask *valuators;    /* last axis values as posted, pre-transform */
 } DDXTouchPointInfoRec;
 
 typedef struct _TouchClassRec {
commit d07dfb11c29172df12f8c86213e8c1488aa2d527
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Jan 9 13:58:56 2013 +1000

    xfree86: don't access the old input handler after freeing it
    
    Introduced in 323869f3298cbbfe864af9404a8aed1bf7995d79
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit f4a58469a298c226668fd8dce375bf22331c902d)

diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index 9e53361..7e80fa9 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -619,14 +619,16 @@ InputHandlerProc
 xf86SetConsoleHandler(InputHandlerProc proc, pointer data)
 {
     static IHPtr handler = NULL;
-    IHPtr old_handler = handler;
+    InputHandlerProc old_proc = NULL;
 
-    if (old_handler)
-        xf86RemoveGeneralHandler(old_handler);
+    if (handler) {
+        old_proc = handler->ihproc;
+        xf86RemoveGeneralHandler(handler);
+    }
 
     handler = xf86AddGeneralHandler(xf86Info.consoleFd, proc, data);
 
-    return (old_handler) ? old_handler->ihproc : NULL;
+    return old_proc;
 }
 
 static void
commit f7f566f9e3aa357d367ffc2c8b62b39c7d03f1e0
Author: Andreas Wettstein <wettstein509 at solnet.ch>
Date:   Wed Dec 19 18:13:21 2012 +0100

    xkb: Do not use base group as an array index.
    
    The base group is not brought into range and, therefore, using it as an array
    index crashed the X server.  Also, at this place, we should ignore locked
    groups, but not latched groups.  Therefore, use sum of base and latched groups,
    brought into range.
    
    Reproducible with:
    key <FK07> {
        type= "ONE_LEVEL",
        symbols[Group1]= [              NoSymbol ],
        actions[Group1]= [ LatchGroup(group=-1, clearLocks) ]
    };
    
    And hitting F7 will exceed the group level and access arbitrary memory.
    
    Signed-off-by: Andreas Wettstein <wettstein509 at solnet.ch>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit 3578cc3c2e1b5cb8eb191e2d12ad88e1bc9e6e1e)

diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index c23cd77..6c6af60 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -642,6 +642,7 @@ XkbComputeCompatState(XkbSrvInfoPtr xkbi)
     CARD16 grp_mask;
     XkbStatePtr state = &xkbi->state;
     XkbCompatMapPtr map;
+    XkbControlsPtr ctrls;
 
     if (!state || !xkbi->desc || !xkbi->desc->ctrls || !xkbi->desc->compat)
         return;
@@ -650,9 +651,14 @@ XkbComputeCompatState(XkbSrvInfoPtr xkbi)
     grp_mask = map->groups[state->group].mask;
     state->compat_state = state->mods | grp_mask;
     state->compat_lookup_mods = state->lookup_mods | grp_mask;
+    ctrls= xkbi->desc->ctrls;
 
-    if (xkbi->desc->ctrls->enabled_ctrls & XkbIgnoreGroupLockMask)
-        grp_mask = map->groups[state->base_group].mask;
+    if (ctrls->enabled_ctrls & XkbIgnoreGroupLockMask) {
+	unsigned char grp = state->base_group+state->latched_group;
+	if (grp >= ctrls->num_groups)
+	    grp = XkbAdjustGroup(XkbCharToInt(grp), ctrls);
+        grp_mask = map->groups[grp].mask;
+    }
     state->compat_grab_mods = state->grab_mods | grp_mask;
     return;
 }
commit da0c913da8d12bebb442e32313afb141d563cf05
Author: Carlos Garnacho <carlosg at gnome.org>
Date:   Wed Dec 19 18:42:39 2012 +0100

    render: Unwrap early on the animated cursor BlockHandler
    
    The loop above the previous call may end up triggering other
    handlers attaching to the same function slot, so unwrapping
    the handler after that could leave the just attached handler
    in a dangling but not unset state.
    
    This issue was most visible on the XO, where destroying a
    window with an animated cursor set and running  would trigger
    this inconsistent state, never calling the miSpriteBlockHandler
    again after the animated cursor is unset.
    
    Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit df746a73410b892a4d41a2934cf9cd2e8ad7ba51)

diff --git a/render/animcur.c b/render/animcur.c
index ebc5b8e..9cbba83 100644
--- a/render/animcur.c
+++ b/render/animcur.c
@@ -143,6 +143,8 @@ AnimCurScreenBlockHandler(ScreenPtr pScreen,
     Bool activeDevice = FALSE;
     CARD32 now = 0, soonest = ~0;       /* earliest time to wakeup again */
 
+    Unwrap(as, pScreen, BlockHandler);
+
     for (dev = inputInfo.devices; dev; dev = dev->next) {
         if (IsPointerDevice(dev) && pScreen == dev->spriteInfo->anim.pScreen) {
             if (!activeDevice) {
@@ -180,7 +182,6 @@ AnimCurScreenBlockHandler(ScreenPtr pScreen,
     if (activeDevice)
         AdjustWaitForDelay(pTimeout, soonest - now);
 
-    Unwrap(as, pScreen, BlockHandler);
     (*pScreen->BlockHandler) (pScreen, pTimeout, pReadmask);
     if (activeDevice)
         Wrap(as, pScreen, BlockHandler, AnimCurScreenBlockHandler);
commit 4cdd3bfc00e6077b5d41761e3b7ae823b277b382
Author: Carlos Garnacho <carlosg at gnome.org>
Date:   Wed Dec 19 18:42:38 2012 +0100

    mi: Ensure pointer emulating touch events update the sprite
    
    Different miPointerSpriteFuncRec implementations do a varying
    business at ultimately calling miPointerUpdateSprite(), this
    particularly fails when using the plain mi sprite on touch events,
    where the sprite is just moved/updated on cursor changes.
    
    So, ensure miPointerUpdateSprite() is called generically for
    pointer emulating touch events as with regular motion events.
    
    Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit 0fbd779a82919d5dbf8776be9b57a76c0eae6b14)

diff --git a/mi/mieq.c b/mi/mieq.c
index b2c7769..67d3928 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -623,7 +623,11 @@ mieqProcessInputEvents(void)
         mieqProcessDeviceEvent(dev, &event, screen);
 
         /* Update the sprite now. Next event may be from different device. */
-        if (event.any.type == ET_Motion && master)
+        if (master &&
+            (event.any.type == ET_Motion ||
+             ((event.any.type == ET_TouchBegin ||
+               event.any.type == ET_TouchUpdate) &&
+              event.device_event.flags & TOUCH_POINTER_EMULATED)))
             miPointerUpdateSprite(dev);
 
 #ifdef XQUARTZ
commit 7b5b7b14678747976b4309dc435a8b3ac30553da
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Jan 4 12:26:58 2013 +1000

    dix: remove already-moved hunk
    
    Should've been removed in bc1f90a615018c05994fae3e678dd2341256cd82a, but got
    left here due to a botched rebase.
    
    Fixes stray button events sent to clients after deactivating an async
    pointer grab on a pointer-emulating-touch.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit 0e1ab433f4048b3367bb2f01d16cd00502538e4d)

diff --git a/dix/events.c b/dix/events.c
index 47ba166..904f0ba 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1548,15 +1548,6 @@ DeactivatePointerGrab(DeviceIntPtr mouse)
         ReattachToOldMaster(mouse);
 
     ComputeFreezes();
-
-    /* If an explicit grab was deactivated, we must remove it from the head of
-     * all the touches' listener lists. */
-    for (i = 0; mouse->touch && i < mouse->touch->num_touches; i++) {
-        TouchPointInfoPtr ti = mouse->touch->touches + i;
-
-        if (ti->active && TouchResourceIsOwner(ti, grab_resource))
-            TouchListenerAcceptReject(mouse, ti, 0, XIRejectTouch);
-    }
 }
 
 /**
commit 66299cb7b850bc9260ad4b5c03e8720e3baeea98
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Dec 20 16:25:43 2012 +1000

    dix: check for the right device's xi2 mask
    
    events.c: In function 'DeactivatePointerGrab':
    events.c:1524:51: warning: 'dev' may be used uninitialized in this function
    [-Wuninitialized
    
    dev is unset when we get here, the device to check is "mouse".
    Introduced in ece8157a59751b3ed492fb2e1eb8d5f20221e195.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit 32a6d8a6b59c42f8d65002d7ca1cafb1957b656f)

diff --git a/dix/events.c b/dix/events.c
index f45e0fb..47ba166 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1519,7 +1519,7 @@ DeactivatePointerGrab(DeviceIntPtr mouse)
                emulate a ButtonRelease here. So pretend the listener
                already has the end event */
             if (grab->grabtype == CORE || grab->grabtype == XI ||
-                    !xi2mask_isset(dev->deviceGrab.grab->xi2mask, dev, XI_TouchBegin))
+                    !xi2mask_isset(mouse->deviceGrab.grab->xi2mask, mouse, XI_TouchBegin))
                 ti->listeners[0].state = LISTENER_HAS_END;
             TouchListenerAcceptReject(mouse, ti, 0, XIRejectTouch);
         }
commit 7c859fd5d1528fd5ea6816224cb9e22f0df0ee25
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Oct 30 12:44:08 2012 +1000

    dix: add resource type to touch listeners
    
    Instead of guessing what resource type the listener is and what property to
    retrieve, store the resource type in the listener directly.
    
    Breaks XIT test cases:
    TouchGrabTestMultipleTaps.PassiveGrabPointerEmulationMultipleTouchesFastSuccession
    
    Fixes https://bugs.freedesktop.org/show_bug.cgi?id=56557
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Chase Douglas <chase.douglas at ubuntu.com>
    (cherry picked from commit f59499b5d05fde83813709e9848152951592120d)

diff --git a/Xi/exevents.c b/Xi/exevents.c
index d3bcbb1..20038a6 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1315,13 +1315,9 @@ RetrieveTouchDeliveryData(DeviceIntPtr dev, TouchPointInfoPtr ti,
         *mask = (*grab)->xi2mask;
     }
     else {
-        if (listener->level == CORE)
-            rc = dixLookupWindow(win, listener->listener,
-                                 serverClient, DixSendAccess);
-        else
-            rc = dixLookupResourceByType((pointer *) win, listener->listener,
-                                         RT_INPUTCLIENT,
-                                         serverClient, DixSendAccess);
+        rc = dixLookupResourceByType((pointer *) win, listener->listener,
+                                     listener->resource_type,
+                                     serverClient, DixSendAccess);
         if (rc != Success)
             return FALSE;
 
@@ -1462,6 +1458,7 @@ DeliverTouchEmulatedEvent(DeviceIntPtr dev, TouchPointInfoPtr ti,
             l = &ti->listeners[ti->num_listeners - 1];
             l->listener = devgrab->resource;
             l->grab = devgrab;
+            //l->resource_type = RT_NONE;
 
             if (devgrab->grabtype != XI2 || devgrab->type != XI_TouchBegin)
                 l->type = LISTENER_POINTER_GRAB;
diff --git a/dix/touch.c b/dix/touch.c
index 17d99b8..2b30b7d 100644
--- a/dix/touch.c
+++ b/dix/touch.c
@@ -682,12 +682,13 @@ TouchResourceIsOwner(TouchPointInfoPtr ti, XID resource)
  * Add the resource to this touch's listeners.
  */
 void
-TouchAddListener(TouchPointInfoPtr ti, XID resource, enum InputLevel level,
-                 enum TouchListenerType type, enum TouchListenerState state,
-                 WindowPtr window,
+TouchAddListener(TouchPointInfoPtr ti, XID resource, int resource_type,
+                 enum InputLevel level, enum TouchListenerType type,
+                 enum TouchListenerState state, WindowPtr window,
                  GrabPtr grab)
 {
     ti->listeners[ti->num_listeners].listener = resource;
+    ti->listeners[ti->num_listeners].resource_type = resource_type;
     ti->listeners[ti->num_listeners].level = level;
     ti->listeners[ti->num_listeners].state = state;
     ti->listeners[ti->num_listeners].type = type;
@@ -748,7 +749,8 @@ TouchAddGrabListener(DeviceIntPtr dev, TouchPointInfoPtr ti,
         type = LISTENER_POINTER_GRAB;
     }
 
-    TouchAddListener(ti, grab->resource, grab->grabtype,
+    /* grab listeners are always RT_NONE since we keep the grab pointer */
+    TouchAddListener(ti, grab->resource, RT_NONE, grab->grabtype,
                      type, LISTENER_AWAITING_BEGIN, grab->window, grab);
 }
 
@@ -804,7 +806,7 @@ TouchAddRegularListener(DeviceIntPtr dev, TouchPointInfoPtr ti,
             if (!xi2mask_isset(iclients->xi2mask, dev, XI_TouchOwnership))
                 TouchEventHistoryAllocate(ti);
 
-            TouchAddListener(ti, iclients->resource, XI2,
+            TouchAddListener(ti, iclients->resource, RT_INPUTCLIENT, XI2,
                              type, LISTENER_AWAITING_BEGIN, win, NULL);
             return TRUE;
         }
@@ -819,7 +821,7 @@ TouchAddRegularListener(DeviceIntPtr dev, TouchPointInfoPtr ti,
                 continue;
 
             TouchEventHistoryAllocate(ti);
-            TouchAddListener(ti, iclients->resource, XI,
+            TouchAddListener(ti, iclients->resource, RT_INPUTCLIENT, XI,
                              LISTENER_POINTER_REGULAR, LISTENER_AWAITING_BEGIN,
                              win, NULL);
             return TRUE;
@@ -834,7 +836,7 @@ TouchAddRegularListener(DeviceIntPtr dev, TouchPointInfoPtr ti,
         /* window owner */
         if (IsMaster(dev) && (win->eventMask & core_filter)) {
             TouchEventHistoryAllocate(ti);
-            TouchAddListener(ti, win->drawable.id, CORE,
+            TouchAddListener(ti, win->drawable.id, RT_WINDOW, CORE,
                              LISTENER_POINTER_REGULAR, LISTENER_AWAITING_BEGIN,
                              win, NULL);
             return TRUE;
@@ -846,7 +848,7 @@ TouchAddRegularListener(DeviceIntPtr dev, TouchPointInfoPtr ti,
                 continue;
 
             TouchEventHistoryAllocate(ti);
-            TouchAddListener(ti, oclients->resource, CORE,
+            TouchAddListener(ti, oclients->resource, RT_OTHERCLIENT, CORE,
                              type, LISTENER_AWAITING_BEGIN, win, NULL);
             return TRUE;
         }
diff --git a/include/input.h b/include/input.h
index d83e426..f0196f5 100644
--- a/include/input.h
+++ b/include/input.h
@@ -560,7 +560,7 @@ extern void TouchEventHistoryPush(TouchPointInfoPtr ti, const DeviceEvent *ev);
 extern void TouchEventHistoryReplay(TouchPointInfoPtr ti, DeviceIntPtr dev,
                                     XID resource);
 extern Bool TouchResourceIsOwner(TouchPointInfoPtr ti, XID resource);
-extern void TouchAddListener(TouchPointInfoPtr ti, XID resource,
+extern void TouchAddListener(TouchPointInfoPtr ti, XID resource, int resource_type,
                              enum InputLevel level, enum TouchListenerType type,
                              enum TouchListenerState state, WindowPtr window, GrabPtr grab);
 extern Bool TouchRemoveListener(TouchPointInfoPtr ti, XID resource);
diff --git a/include/inputstr.h b/include/inputstr.h
index e21484b..227ad7a 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -301,6 +301,7 @@ typedef struct _ValuatorClassRec {
 typedef struct _TouchListener {
     XID listener;           /* grabs/event selection IDs receiving
                              * events for this touch */
+    int resource_type;      /* listener's resource type */
     enum TouchListenerType type;
     enum TouchListenerState state;
     enum InputLevel level;  /* matters only for emulating touches */
commit df12c4daa7236702ef52aa121705826e58bf6783
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Nov 27 11:21:17 2012 -0800

    input: Record grab pointer in TouchListener
    
    This places a pointer to the grab related to a TouchListener directly
    in the TouchListener structure rather than hoping to find the grab
    later on using the resource ID.
    
    Passive grabs have resource ID in the resource DB so they can be
    removed when a client exits, and those resource IDs get copied when
    activated, but implicit grabs are constructed on-the-fly and have no
    resource DB entry.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit 9ad0fdb135a1c336771aee1f6eab75a6ad874aff)

diff --git a/Xi/exevents.c b/Xi/exevents.c
index b691d20..d3bcbb1 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1197,7 +1197,6 @@ TouchRejected(DeviceIntPtr sourcedev, TouchPointInfoPtr ti, XID resource,
               TouchOwnershipEvent *ev)
 {
     Bool was_owner = (resource == ti->listeners[0].listener);
-    void *grab;
     int i;
 
     /* Send a TouchEnd event to the resource being removed, but only if they
@@ -1212,11 +1211,7 @@ TouchRejected(DeviceIntPtr sourcedev, TouchPointInfoPtr ti, XID resource,
 
     /* Remove the resource from the listener list, updating
      * ti->num_listeners, as well as ti->num_grabs if it was a grab. */
-    if (TouchRemoveListener(ti, resource)) {
-        if (dixLookupResourceByType(&grab, resource, RT_PASSIVEGRAB,
-                                    serverClient, DixGetAttrAccess) == Success)
-            ti->num_grabs--;
-    }
+    TouchRemoveListener(ti, resource);
 
     /* If the current owner was removed and there are further listeners, deliver
      * the TouchOwnership or TouchBegin event to the new owner. */
@@ -1310,21 +1305,10 @@ RetrieveTouchDeliveryData(DeviceIntPtr dev, TouchPointInfoPtr ti,
 
     if (listener->type == LISTENER_GRAB ||
         listener->type == LISTENER_POINTER_GRAB) {
-        rc = dixLookupResourceByType((pointer *) grab, listener->listener,
-                                     RT_PASSIVEGRAB,
-                                     serverClient, DixSendAccess);
-        if (rc != Success) {
-            /* the grab doesn't exist but we have a grabbing listener - this
-             * is an implicit/active grab */
-            rc = dixLookupClient(client, listener->listener, serverClient,
-                                 DixSendAccess);
-            if (rc != Success)
-                return FALSE;
-
-            *grab = dev->deviceGrab.grab;
-            if (!*grab)
-                return FALSE;
-        }
+
+        *grab = listener->grab;
+
+        BUG_RETURN_VAL(!*grab, FALSE);
 
         *client = rClient(*grab);
         *win = (*grab)->window;
@@ -1477,6 +1461,7 @@ DeliverTouchEmulatedEvent(DeviceIntPtr dev, TouchPointInfoPtr ti,
              */
             l = &ti->listeners[ti->num_listeners - 1];
             l->listener = devgrab->resource;
+            l->grab = devgrab;
 
             if (devgrab->grabtype != XI2 || devgrab->type != XI_TouchBegin)
                 l->type = LISTENER_POINTER_GRAB;
diff --git a/dix/events.c b/dix/events.c
index 3f75a91..f45e0fb 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1435,6 +1435,7 @@ UpdateTouchesForGrab(DeviceIntPtr mouse)
                 ti->listeners[0].type = LISTENER_POINTER_GRAB;
             else
                 ti->listeners[0].type = LISTENER_GRAB;
+            ti->listeners[0].grab = grab;
         }
     }
 }
diff --git a/dix/touch.c b/dix/touch.c
index f51f46d..17d99b8 100644
--- a/dix/touch.c
+++ b/dix/touch.c
@@ -684,13 +684,17 @@ TouchResourceIsOwner(TouchPointInfoPtr ti, XID resource)
 void
 TouchAddListener(TouchPointInfoPtr ti, XID resource, enum InputLevel level,
                  enum TouchListenerType type, enum TouchListenerState state,
-                 WindowPtr window)
+                 WindowPtr window,
+                 GrabPtr grab)
 {
     ti->listeners[ti->num_listeners].listener = resource;
     ti->listeners[ti->num_listeners].level = level;
     ti->listeners[ti->num_listeners].state = state;
     ti->listeners[ti->num_listeners].type = type;
     ti->listeners[ti->num_listeners].window = window;
+    ti->listeners[ti->num_listeners].grab = grab;
+    if (grab)
+        ti->num_grabs++;
     ti->num_listeners++;
 }
 
@@ -709,6 +713,11 @@ TouchRemoveListener(TouchPointInfoPtr ti, XID resource)
         if (ti->listeners[i].listener == resource) {
             int j;
 
+            if (ti->listeners[i].grab) {
+                ti->listeners[i].grab = NULL;
+                ti->num_grabs--;
+            }
+
             for (j = i; j < ti->num_listeners - 1; j++)
                 ti->listeners[j] = ti->listeners[j + 1];
             ti->num_listeners--;
@@ -740,8 +749,7 @@ TouchAddGrabListener(DeviceIntPtr dev, TouchPointInfoPtr ti,
     }
 
     TouchAddListener(ti, grab->resource, grab->grabtype,
-                     type, LISTENER_AWAITING_BEGIN, grab->window);
-    ti->num_grabs++;
+                     type, LISTENER_AWAITING_BEGIN, grab->window, grab);
 }
 
 /**
@@ -797,7 +805,7 @@ TouchAddRegularListener(DeviceIntPtr dev, TouchPointInfoPtr ti,
                 TouchEventHistoryAllocate(ti);
 
             TouchAddListener(ti, iclients->resource, XI2,
-                             type, LISTENER_AWAITING_BEGIN, win);
+                             type, LISTENER_AWAITING_BEGIN, win, NULL);
             return TRUE;
         }
     }
@@ -813,7 +821,7 @@ TouchAddRegularListener(DeviceIntPtr dev, TouchPointInfoPtr ti,
             TouchEventHistoryAllocate(ti);
             TouchAddListener(ti, iclients->resource, XI,
                              LISTENER_POINTER_REGULAR, LISTENER_AWAITING_BEGIN,
-                             win);
+                             win, NULL);
             return TRUE;
         }
     }
@@ -828,7 +836,7 @@ TouchAddRegularListener(DeviceIntPtr dev, TouchPointInfoPtr ti,
             TouchEventHistoryAllocate(ti);
             TouchAddListener(ti, win->drawable.id, CORE,
                              LISTENER_POINTER_REGULAR, LISTENER_AWAITING_BEGIN,
-                             win);
+                             win, NULL);
             return TRUE;
         }
 
@@ -839,7 +847,7 @@ TouchAddRegularListener(DeviceIntPtr dev, TouchPointInfoPtr ti,
 
             TouchEventHistoryAllocate(ti);
             TouchAddListener(ti, oclients->resource, CORE,
-                             type, LISTENER_AWAITING_BEGIN, win);
+                             type, LISTENER_AWAITING_BEGIN, win, NULL);
             return TRUE;
         }
     }
diff --git a/include/input.h b/include/input.h
index f8459b8..d83e426 100644
--- a/include/input.h
+++ b/include/input.h
@@ -562,7 +562,7 @@ extern void TouchEventHistoryReplay(TouchPointInfoPtr ti, DeviceIntPtr dev,
 extern Bool TouchResourceIsOwner(TouchPointInfoPtr ti, XID resource);
 extern void TouchAddListener(TouchPointInfoPtr ti, XID resource,
                              enum InputLevel level, enum TouchListenerType type,
-                             enum TouchListenerState state, WindowPtr window);
+                             enum TouchListenerState state, WindowPtr window, GrabPtr grab);
 extern Bool TouchRemoveListener(TouchPointInfoPtr ti, XID resource);
 extern void TouchSetupListeners(DeviceIntPtr dev, TouchPointInfoPtr ti,
                                 InternalEvent *ev);
diff --git a/include/inputstr.h b/include/inputstr.h
index 8d9dd71..e21484b 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -305,6 +305,7 @@ typedef struct _TouchListener {
     enum TouchListenerState state;
     enum InputLevel level;  /* matters only for emulating touches */
     WindowPtr window;
+    GrabPtr grab;
 } TouchListener;
 
 typedef struct _TouchPointInfo {
commit 5272f71cf8387efe87a19827a01daf2b0bbdfbf6
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Nov 27 11:21:16 2012 -0800

    input: Pull TouchListener declaration to top-level
    
    No reason to have a struct declared inside another struct
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit 91ab237358c6e33da854914d3de493a9cbea7637)

diff --git a/include/inputstr.h b/include/inputstr.h
index 5a38924..8d9dd71 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -298,6 +298,15 @@ typedef struct _ValuatorClassRec {
     int v_scroll_axis;          /* vert smooth-scrolling axis */
 } ValuatorClassRec;
 
+typedef struct _TouchListener {
+    XID listener;           /* grabs/event selection IDs receiving
+                             * events for this touch */
+    enum TouchListenerType type;
+    enum TouchListenerState state;
+    enum InputLevel level;  /* matters only for emulating touches */
+    WindowPtr window;
+} TouchListener;
+
 typedef struct _TouchPointInfo {
     uint32_t client_id;         /* touch ID as seen in client events */
     int sourceid;               /* Source device's ID for this touchpoint */
@@ -306,14 +315,7 @@ typedef struct _TouchPointInfo {
                                  * but still owned by a grab */
     SpriteRec sprite;           /* window trace for delivery */
     ValuatorMask *valuators;    /* last recorded axis values */
-    struct _TouchListener {
-        XID listener;           /* grabs/event selection IDs receiving
-                                 * events for this touch */
-        enum TouchListenerType type;
-        enum TouchListenerState state;
-        enum InputLevel level;  /* matters only for emulating touches */
-        WindowPtr window;
-    } *listeners;
+    TouchListener *listeners;   /* set of listeners */
     int num_listeners;
     int num_grabs;              /* number of open grabs on this touch
                                  * which have not accepted or rejected */
commit 041ab46aba357689484f91fc408725677d6dc2d4
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jan 8 11:19:09 2013 +1000

    xfree86: update the device state for all DGA events (#59100)
    
    DGA only handles master devices but it does intercept slave device events as
    well (since the event handlers are per event type, not per device).
    
    The DGA code must thus call into UpdateDeviceState to reset the button/key
    state on the slave device before it discards the remainder of the event.
    
    Test case:
    - Passive GrabModeSync on VCP
    - Press button
    - Enable DGA after ButtonPress
    - AllowEvents(SyncPointer)
    - Release button
    
    The button release is handled by DGAProcessPointerEvent but the device state
    is never updated, so the slave ends up with the button permanently down.
    And since the master's button state is the union of the slave states, the
    master has the button permanently down.
    
    X.Org Bug 59100 <http://bugs.freedesktop.org/show_bug.cgi?id=59100>
    
    Reported-by: Steven Elliott <selliott4 at austin.rr.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit ad3bc571348a7007a2960bf87ae739397c5511ee)

diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
index 38ee6f1..7f1a0c6 100644
--- a/hw/xfree86/common/xf86DGA.c
+++ b/hw/xfree86/common/xf86DGA.c
@@ -1033,6 +1033,9 @@ DGAProcessKeyboardEvent(ScreenPtr pScreen, DGAEvent * event, DeviceIntPtr keybd)
 
     UpdateDeviceState(keybd, &ev);
 
+    if (!IsMaster(keybd))
+        return;
+
     /*
      * Deliver the DGA event
      */
@@ -1084,6 +1087,9 @@ DGAProcessPointerEvent(ScreenPtr pScreen, DGAEvent * event, DeviceIntPtr mouse)
 
     UpdateDeviceState(mouse, &ev);
 
+    if (!IsMaster(mouse))
+        return;
+
     /*
      * Deliver the DGA event
      */
@@ -1191,9 +1197,6 @@ DGAHandleEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device)
     if (!pScreenPriv)
         return;
 
-    if (!IsMaster(device))
-        return;
-
     switch (event->subtype) {
     case KeyPress:
     case KeyRelease:
commit c201d00014c505055915eefbc1702dd1e84cbce7
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jan 8 10:13:53 2013 +1000

    xfree86: set event->detail for DGA pointer events
    
    Reported-by: Steven Elliott <selliott4 at austin.rr.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit c5f2818edbec2f87383baa6c6be5c389b73ca6f9)

diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
index a441dee..38ee6f1 100644
--- a/hw/xfree86/common/xf86DGA.c
+++ b/hw/xfree86/common/xf86DGA.c
@@ -1074,6 +1074,7 @@ DGAProcessPointerEvent(ScreenPtr pScreen, DGAEvent * event, DeviceIntPtr mouse)
     DeviceEvent ev = {
         .header = ET_Internal,
         .length = sizeof(ev),
+        .detail.key = event->detail,
         .type = event->subtype,
         .corestate = butc ? butc->state : 0
     };
commit de0ea3544f57ea1d940726a6dfac19f21d74d090
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Aug 22 10:34:07 2012 +1000

    dix: don't filter RawEvents if the grab window is not the root window (#53897)
    
    If a XI2.1+ client has a grab on a non-root window, it  must still receive
    raw events on the root window.
    
    Test case: register for XI_ButtonPress on window and XI_RawMotion on root.
    No raw events are received once the press activates an implicit grab on the
    window.
    
    X.Org Bug 53897 <http://bugs.freedesktop.org/show_bug.cgi?id=53897>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit 4e13dd90144dde47550aceea4db4b4329e531279)

diff --git a/dix/events.c b/dix/events.c
index e52dc54..3f75a91 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2240,7 +2240,7 @@ DeliverEventsToWindow(DeviceIntPtr pDev, WindowPtr pWin, xEvent
  * @return TRUE if the event should be discarded, FALSE otherwise.
  */
 static BOOL
-FilterRawEvents(const ClientPtr client, const GrabPtr grab)
+FilterRawEvents(const ClientPtr client, const GrabPtr grab, WindowPtr root)
 {
     XIClientPtr client_xi_version;
     int cmp;
@@ -2256,7 +2256,10 @@ FilterRawEvents(const ClientPtr client, const GrabPtr grab)
                           client_xi_version->minor_version, 2, 0);
     /* XI 2.0: if device is grabbed, skip
        XI 2.1: if device is grabbed by us, skip, we've already delivered */
-    return (cmp == 0) ? TRUE : SameClient(grab, client);
+    if (cmp == 0)
+        return TRUE;
+
+    return (grab->window != root) ? FALSE : SameClient(grab, client);
 }
 
 /**
@@ -2309,7 +2312,7 @@ DeliverRawEvent(RawDeviceEvent *ev, DeviceIntPtr device)
              */
             ic.next = NULL;
 
-            if (!FilterRawEvents(rClient(&ic), grab))
+            if (!FilterRawEvents(rClient(&ic), grab, root))
                 DeliverEventToInputClients(device, &ic, root, xi, 1,
                                            filter, NULL, &c, &m);
         }
commit 5ed2523f4dc6c471908c2d940cc40e4ad26aa84d
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Dec 12 11:02:19 2012 +1000

    xfree86: print message to the log when zapping the server
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit 3420a7778c7d5eaa638327f31dd460554c257bb1)

diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index 3ad34b5..9e53361 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -180,6 +180,7 @@ xf86ProcessActionEvent(ActionEvent action, void *arg)
     switch (action) {
     case ACTION_TERMINATE:
         if (!xf86Info.dontZap) {
+            xf86Msg(X_INFO, "Server zapped. Shutting down.\n");
 #ifdef XFreeXDGA
             DGAShutdown();
 #endif
commit 956700d14d01a6d8a1bb8b8f9b910ef044ad154b
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Nov 26 14:55:13 2012 +1000

    Xi: if a TouchEnd appears on a actively grabbing client, always accept
    
    Once the TouchEnd appears on the device, the touch is done. If the client
    still has a pointer grab, accept it to avoid clients with TouchOwnership
    selections to wait indefinitely for the actual touch event.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit 00def5144557cfe8bf535f926212a8e084dc7cf6)
    
    Conflicts:
    	Xi/exevents.c

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 106da3a..b691d20 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1576,32 +1576,41 @@ ProcessTouchEvent(InternalEvent *ev, DeviceIntPtr dev)
     else
         ti = TouchFindByClientID(dev, touchid);
 
-    /* Under the following circumstances we create a new touch record for an
-     * existing touch:
-     *
-     * - The touch may be pointer emulated
-     * - An explicit grab is active on the device
-     * - The grab is a pointer grab
-     *
-     * This allows for an explicit grab to receive pointer events for an already
-     * active touch.
-     */
-    if (!ti && type != ET_TouchBegin && emulate_pointer &&
-        dev->deviceGrab.grab && !dev->deviceGrab.fromPassiveGrab &&
+    /* Active pointer grab */
+    if (emulate_pointer && dev->deviceGrab.grab && !dev->deviceGrab.fromPassiveGrab &&
         (dev->deviceGrab.grab->grabtype == CORE ||
          dev->deviceGrab.grab->grabtype == XI ||
-         !xi2mask_isset(dev->deviceGrab.grab->xi2mask, dev, XI_TouchBegin))) {
-        ti = TouchBeginTouch(dev, ev->device_event.sourceid, touchid,
-                             emulate_pointer);
-        if (!ti) {
-            DebugF("[Xi] %s: Failed to create new dix record for explicitly "
-                   "grabbed touchpoint %d\n",
-                   dev->name, type, touchid);
-            return;
-        }
+         !xi2mask_isset(dev->deviceGrab.grab->xi2mask, dev, XI_TouchBegin)))
+    {
+        /* Active pointer grab on touch point and we get a TouchEnd - claim this
+         * touchpoint accepted, otherwise clients waiting for ownership will
+         * wait on this touchpoint until this client ungrabs, or the cows come
+         * home, whichever is earlier */
+        if (ti && type == ET_TouchEnd)
+            TouchListenerAcceptReject(dev, ti, 0, XIAcceptTouch);
+        else if (!ti && type != ET_TouchBegin) {
+            /* Under the following circumstances we create a new touch record for an
+             * existing touch:
+             *
+             * - The touch may be pointer emulated
+             * - An explicit grab is active on the device
+             * - The grab is a pointer grab
+             *
+             * This allows for an explicit grab to receive pointer events for an already
+             * active touch.
+             */
+            ti = TouchBeginTouch(dev, ev->device_event.sourceid, touchid,
+                                 emulate_pointer);
+            if (!ti) {
+                DebugF("[Xi] %s: Failed to create new dix record for explicitly "
+                       "grabbed touchpoint %d\n",
+                       dev->name, touchid);
+                return;
+            }
 
-        TouchBuildSprite(dev, ti, ev);
-        TouchSetupListeners(dev, ti, ev);
+            TouchBuildSprite(dev, ti, ev);
+            TouchSetupListeners(dev, ti, ev);
+        }
     }
 
     if (!ti) {
commit 39157fd2405ad855d0f60578b57e193a744bb075
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Nov 26 15:14:19 2012 +1000

    dix: when deactivating pointer-only grabs, don't emulate TouchEnd events
    
    A client with a pointer grab on a touch device must reject the touch when
    detactivating the grab while the touch is active. However, such a rejecting
    must not trigger a ButtonRelease event to be emulated and sent to the
    client.
    Set the grabbing listener's state to HAS_END, so we simply skip delivery to
    that client.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit ece8157a59751b3ed492fb2e1eb8d5f20221e195)

diff --git a/dix/events.c b/dix/events.c
index 9e0bbb3..e52dc54 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1513,8 +1513,15 @@ DeactivatePointerGrab(DeviceIntPtr mouse)
      * all the touches' listener lists. */
     for (i = 0; !wasPassive && mouse->touch && i < mouse->touch->num_touches; i++) {
         TouchPointInfoPtr ti = mouse->touch->touches + i;
-        if (ti->active && TouchResourceIsOwner(ti, grab_resource))
+        if (ti->active && TouchResourceIsOwner(ti, grab_resource)) {
+            /* Rejecting will generate a TouchEnd, but we must not
+               emulate a ButtonRelease here. So pretend the listener
+               already has the end event */
+            if (grab->grabtype == CORE || grab->grabtype == XI ||
+                    !xi2mask_isset(dev->deviceGrab.grab->xi2mask, dev, XI_TouchBegin))
+                ti->listeners[0].state = LISTENER_HAS_END;
             TouchListenerAcceptReject(mouse, ti, 0, XIRejectTouch);
+        }
     }
 
     TouchRemovePointerGrab(mouse);
commit e1626674333ef4d67f97d9960f58486c9f6cb11d
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Nov 26 12:23:54 2012 +1000

    dix: only reject active grabs on ungrab and do it before actually ungrabbing
    
    An active grab ungrabbing is the same as rejecting the grab, since the
    client is no longer interested in those events. So reject any touch grab,
    but do so before actually deactivating since we're interested in the
    TouchEnd for the current grabbing client.
    
    A passive grab otoh is _not_ like rejecting a grab, since it deactivates
    automatically when the touch ends.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit bc1f90a615018c05994fae3e678dd2341256cd82)

diff --git a/dix/events.c b/dix/events.c
index bf6eef2..9e0bbb3 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1503,11 +1503,20 @@ DeactivatePointerGrab(DeviceIntPtr mouse)
 {
     GrabPtr grab = mouse->deviceGrab.grab;
     DeviceIntPtr dev;
+    Bool wasPassive = mouse->deviceGrab.fromPassiveGrab;
     Bool wasImplicit = (mouse->deviceGrab.fromPassiveGrab &&
                         mouse->deviceGrab.implicitGrab);
     XID grab_resource = grab->resource;
     int i;
 
+    /* If an explicit grab was deactivated, we must remove it from the head of
+     * all the touches' listener lists. */
+    for (i = 0; !wasPassive && mouse->touch && i < mouse->touch->num_touches; i++) {
+        TouchPointInfoPtr ti = mouse->touch->touches + i;
+        if (ti->active && TouchResourceIsOwner(ti, grab_resource))
+            TouchListenerAcceptReject(mouse, ti, 0, XIRejectTouch);
+    }
+
     TouchRemovePointerGrab(mouse);
 
     mouse->valuator->motionHintWindow = NullWindow;
commit b72ffcf6ae146feaa08df80e65d293bc3a62331f
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Nov 22 13:49:34 2012 +1000

    dix: don't call ProcessInputEvents() when accepting/rejecting touches
    
    TouchListenerAcceptReject may be called during normal event processing, but
    ProcessInputEvents is not reentrant and calling it here smashes the event
    queue.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit 146f48c2934fc85ec095496da5c8f0102bc7f5b5)

diff --git a/dix/touch.c b/dix/touch.c
index 5f77be5..f51f46d 100644
--- a/dix/touch.c
+++ b/dix/touch.c
@@ -994,8 +994,6 @@ TouchListenerAcceptReject(DeviceIntPtr dev, TouchPointInfoPtr ti, int listener,
     for (i = 0; i < nev; i++)
         mieqProcessDeviceEvent(dev, events + i, NULL);
 
-    ProcessInputEvents();
-
     FreeEventList(events, GetMaximumEventsNum());
 
     return nev ? Success : BadMatch;
commit d5142c4e9db6175c5258749acc314833c40ac2fb
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Dec 14 11:34:15 2012 +1000

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

diff --git a/dix/events.c b/dix/events.c
index ddb5b34..bf6eef2 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -5027,7 +5027,7 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev,
     grab = grabInfo->grab;
     if (grab && grab->grabtype != grabtype)
         *status = AlreadyGrabbed;
-    if (grab && !SameClient(grab, client))
+    else if (grab && !SameClient(grab, client))
         *status = AlreadyGrabbed;
     else if ((!pWin->realized) ||
              (confineTo &&
commit 7800cf99f52081b7f6b8870d430730c595ffca60
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Dec 11 13:36:02 2012 +1000

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

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

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

diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
index 89f16d8..4dc3d76 100644
--- a/Xi/xichangehierarchy.c
+++ b/Xi/xichangehierarchy.c
@@ -304,15 +304,16 @@ remove_master(ClientPtr client, xXIRemoveMasterInfo * r, int flags[MAXDEVICES])
     flags[keybd->id] |= XIDeviceDisabled;
     flags[ptr->id] |= XIDeviceDisabled;
 
-    RemoveDevice(XTestptr, FALSE);
-    RemoveDevice(XTestkeybd, FALSE);
-    RemoveDevice(keybd, FALSE);
-    RemoveDevice(ptr, FALSE);
     flags[XTestptr->id] |= XISlaveRemoved;
     flags[XTestkeybd->id] |= XISlaveRemoved;
     flags[keybd->id] |= XIMasterRemoved;
     flags[ptr->id] |= XIMasterRemoved;
 
+    RemoveDevice(XTestptr, FALSE);
+    RemoveDevice(XTestkeybd, FALSE);
+    RemoveDevice(keybd, FALSE);
+    RemoveDevice(ptr, FALSE);
+
  unwind:
     return rc;
 }
commit 3a8c618a731aced34ddc8c69a1798e2cfd967fbd
Author: Matt Dew <marcoz at osource.org>
Date:   Thu Jan 3 23:36:00 2013 -0700

    version bump for 1.13.1.901 (rc1)

diff --git a/configure.ac b/configure.ac
index 67b1eb4..649092b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,9 +26,9 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.60)
-AC_INIT([xorg-server], 1.13.1, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2012-12-13"
-RELEASE_NAME="Chrysanthemum Tea"
+AC_INIT([xorg-server], 1.13.1.901, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2013-01-03"
+RELEASE_NAME=""
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AM_MAINTAINER_MODE
commit 95780608df676473f501a6cd73248da9f7be82a0
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Tue Dec 18 00:41:08 2012 -0800

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

diff --git a/mi/miinitext.c b/mi/miinitext.c
index d175440..a15e219 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -212,10 +212,12 @@ EnableDisableExtension(const char *name, Bool enable)
 void
 EnableDisableExtensionError(const char *name, Bool enable)
 {
-    ExtensionToggle *ext = &ExtensionToggleList[0];
+    ExtensionToggle *ext;
+    int i;
     Bool found = FALSE;
 
-    for (ext = &ExtensionToggleList[0]; ext->name != NULL; ext++) {
+    for (i = 0; i < ARRAY_SIZE(ExtensionToggleList); i++) {
+        ext = &ExtensionToggleList[i];
         if ((strcmp(name, ext->name) == 0) && (ext->disablePtr == NULL)) {
             ErrorF("[mi] Extension \"%s\" can not be disabled\n", name);
             found = TRUE;
@@ -226,7 +228,8 @@ EnableDisableExtensionError(const char *name, Bool enable)
         ErrorF("[mi] Extension \"%s\" is not recognized\n", name);
     ErrorF("[mi] Only the following extensions can be run-time %s:\n",
            enable ? "enabled" : "disabled");
-    for (ext = &ExtensionToggleList[0]; ext->name != NULL; ext++) {
+    for (i = 0; i < ARRAY_SIZE(ExtensionToggleList); i++) {
+        ext = &ExtensionToggleList[i];
         if (ext->disablePtr != NULL) {
             ErrorF("[mi]    %s\n", ext->name);
         }
commit a6d89f30dde50cbd1117e8639dfb99cc852cfd6a
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Dec 17 15:40:17 2012 +1000

    glx/dri2: initialise api to avoid indirect rendering failing randomly
    
    Running glxinfo under indirect rendering would randomly fail against the
    intel driver, as it would create a context with no attribs, and then the
    api value would be passed to the driver uninitialised.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index bce1bfa..b26e501 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -514,7 +514,7 @@ create_driver_context(__GLXDRIcontext * context,
         unsigned minor_ver;
         uint32_t flags;
         int reset;
-        int api;
+        int api = __DRI_API_OPENGL;
 
         if (num_attribs != 0) {
             if (!dri2_convert_glx_attribs(screen, num_attribs, attribs,
commit 65642ccb78aa2d4c4e17b9ac42e4ef625c4a6e8b
Author: Raphael Kubo da Costa <raphael.kubo.da.costa at intel.com>
Date:   Fri Nov 16 19:51:58 2012 +0200

    vfb: Initialize the GLX extension again.
    
    This should fix a regression in the 1.13.0 release: commit
    5f5bbbe543f65c48ecbb5cce80116a86ca3fbe86 removed a code path used by Xvfb
    and made it use the default one when initializing extensions. However, this
    meant the GLX extension was not initialized anymore since it is not part of
    the `staticExtensions' array.
    
    Since it is not possible to just add it to that array after commit
    aad428b8e21c77397c623b78706eb64b1fea77c9, adopt an approach similar to
    xwin's and xquartz's and initialize the extension from vfb's `InitOutput'.
    
    Signed-off-by: Raphael Kubo da Costa <raphael.kubo.da.costa at intel.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/vfb/InitOutput.c b/hw/vfb/InitOutput.c
index 955624f..5f20a1e 100644
--- a/hw/vfb/InitOutput.c
+++ b/hw/vfb/InitOutput.c
@@ -66,6 +66,7 @@ from The Open Group.
 #endif                          /* HAS_SHM */
 #include "dix.h"
 #include "miline.h"
+#include "glx_extinit.h"
 
 #define VFB_DEFAULT_WIDTH      1280
 #define VFB_DEFAULT_HEIGHT     1024
@@ -885,12 +886,30 @@ vfbScreenInit(ScreenPtr pScreen, int argc, char **argv)
 
 }                               /* end vfbScreenInit */
 
+static const ExtensionModule vfbExtensions[] = {
+#ifdef GLXEXT
+    { GlxExtensionInit, "GLX", &noGlxExtension },
+#endif
+};
+
+static
+void vfbExtensionInit(void)
+{
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(vfbExtensions); i++)
+        LoadExtension(&vfbExtensions[i], TRUE);
+}
+
 void
 InitOutput(ScreenInfo * screenInfo, int argc, char **argv)
 {
     int i;
     int NumFormats = 0;
 
+    if (serverGeneration == 1)
+        vfbExtensionInit();
+
     /* initialize pixmap formats */
 
     /* must have a pixmap depth to match every screen depth */
commit e348e4afc5323779b686ee8ff2f094359664c42e
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Tue Dec 18 01:29:12 2012 -0800

    XQuartz: Don't add the 15bit visual any more
    
    Mountain Lion only supports 32bit backing stores, so don't use 15bit visuals until libXplugin adapts
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    (cherry picked from commit ba4bb3bc1b87eb57cc34d2ad1f302c9d2a15c847)

diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index d26f18a..b3a1fb3 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -231,13 +231,15 @@ DarwinScreenInit(ScreenPtr pScreen, int argc, char **argv)
     }
 
     // TODO: Make PseudoColor visuals not suck in TrueColor mode
-    //    if(dfb->depth > 8)
-    //        miSetVisualTypesAndMasks(8, PseudoColorMask, 8, PseudoColor, 0, 0, 0);
-    if (dfb->depth > 15)
-        miSetVisualTypesAndMasks(15, TrueColorMask, 5, TrueColor,
-                                 RM_ARGB(0, 5, 5, 5), GM_ARGB(0, 5, 5,
-                                                              5),
-                                 BM_ARGB(0, 5, 5, 5));
+    // if(dfb->depth > 8)
+    //    miSetVisualTypesAndMasks(8, PseudoColorMask, 8, PseudoColor, 0, 0, 0);
+    //
+    // TODO: Re-add support for 15bit
+    // if (dfb->depth > 15)
+    //    miSetVisualTypesAndMasks(15, TrueColorMask, 5, TrueColor,
+    //                             RM_ARGB(0, 5, 5, 5), GM_ARGB(0, 5, 5,
+    //                                                          5),
+    //                             BM_ARGB(0, 5, 5, 5));
     if (dfb->depth > 24)
         miSetVisualTypesAndMasks(24, TrueColorMask, 8, TrueColor,
                                  RM_ARGB(0, 8, 8, 8), GM_ARGB(0, 8, 8,
diff --git a/hw/xquartz/xpr/xprScreen.c b/hw/xquartz/xpr/xprScreen.c
index efe2aa8..e376019 100644
--- a/hw/xquartz/xpr/xprScreen.c
+++ b/hw/xquartz/xpr/xprScreen.c
@@ -359,6 +359,10 @@ have_depth:
         dfb->blueMask = 0;
         break;
 
+#if 0
+    // Removed because Mountain Lion removed support for
+    // 15bit backing stores.  We can possibly re-add
+    // this once libXplugin is updated to work around it.
     case 15:
         dfb->visuals = TrueColorMask;     //LARGE_VISUALS;
         dfb->preferredCVC = TrueColor;
@@ -369,6 +373,7 @@ have_depth:
         dfb->greenMask = GM_ARGB(0, 5, 5, 5);
         dfb->blueMask = BM_ARGB(0, 5, 5, 5);
         break;
+#endif
 
     //        case 24:
     default:
commit 34fb39a960898f5a0bcc67f76f385ba8a91ea2ba
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Thu Sep 20 21:11:21 2012 -0700

    XQuartz: Add some verbose logging to debug xp_lock_window being unbalanced
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    (cherry picked from commit f54987de97720200ee94eba1c7a737d4ad8c55c8)

diff --git a/hw/xquartz/xpr/xprFrame.c b/hw/xquartz/xpr/xprFrame.c
index 01f1def..aad375b 100644
--- a/hw/xquartz/xpr/xprFrame.c
+++ b/hw/xquartz/xpr/xprFrame.c
@@ -49,6 +49,10 @@
 #include <pthread.h>
 #endif
 
+#ifdef DEBUG_XP_LOCK_WINDOW
+#include <execinfo.h>
+#endif
+
 #define DEFINE_ATOM_HELPER(func, atom_name)                      \
     static Atom func(void) {                                       \
         static int generation;                                      \
@@ -376,6 +380,18 @@ xprStartDrawing(RootlessFrameID wid, char **pixelData, int *bytesPerRow)
     unsigned int rowbytes[2];
     xp_error err;
 
+#ifdef DEBUG_XP_LOCK_WINDOW
+    void* callstack[128];
+    int i, frames = backtrace(callstack, 128);
+    char** strs = backtrace_symbols(callstack, frames);
+
+    ErrorF("=== LOCK %d ===\n", (int)x_cvt_vptr_to_uint(wid));
+    for (i = 0; i < frames; ++i) {
+        ErrorF("    %s\n", strs[i]);
+    }
+    free(strs);
+#endif
+
     err = xp_lock_window(x_cvt_vptr_to_uint(
                              wid), NULL, NULL, data, rowbytes, NULL);
     if (err != Success)
@@ -395,6 +411,18 @@ xprStopDrawing(RootlessFrameID wid, Bool flush)
 {
     xp_error err;
 
+#ifdef DEBUG_XP_LOCK_WINDOW
+    void* callstack[128];
+    int i, frames = backtrace(callstack, 128);
+    char** strs = backtrace_symbols(callstack, frames);
+
+    ErrorF("=== UNLOCK %d ===\n", (int)x_cvt_vptr_to_uint(wid));
+    for (i = 0; i < frames; ++i) {
+        ErrorF("    %s\n", strs[i]);
+    }
+    free(strs);
+#endif
+
     err = xp_unlock_window(x_cvt_vptr_to_uint(wid), flush);
     /* This should be a FatalError, but we started tripping over it.  Make it a
      * FatalError after http://xquartz.macosforge.org/trac/ticket/482 is fixed.
commit 06e2ecd0df9b81dd518ae6017ec42765520e2e93
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Thu Sep 20 21:49:40 2012 -0700

    XQuartz: Avoid a possible deadlock with DRI on OS X 10.7.5 and OS X 10.8.2
    
    <rdar://problem/12338921>
    http://bugs.winehq.org/show_bug.cgi?id=31751
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    (cherry picked from commit 25d26875bc9bd6fd23ae1b5280f015abf1b033b7)

diff --git a/hw/xquartz/xpr/dri.c b/hw/xquartz/xpr/dri.c
index 03af163..adba69c 100644
--- a/hw/xquartz/xpr/dri.c
+++ b/hw/xquartz/xpr/dri.c
@@ -64,6 +64,7 @@
 #include "mi.h"
 #include "mipointer.h"
 #include "rootless.h"
+#include "rootlessCommon.h"
 #include "x-hash.h"
 #include "x-hook.h"
 #include "driWrap.h"
@@ -380,6 +381,11 @@ DRICreateSurface(ScreenPtr pScreen, Drawable id,
     DRIDrawablePrivPtr pDRIDrawablePriv;
 
     if (pDrawable->type == DRAWABLE_WINDOW) {
+        /* <rdar://problem/12338921>
+         * http://bugs.winehq.org/show_bug.cgi?id=31751
+         */
+        RootlessStopDrawing((WindowPtr)pDrawable, FALSE);
+
         pDRIDrawablePriv = CreateSurfaceForWindow(pScreen,
                                                   (WindowPtr)pDrawable, &wid);
 
commit 92ecbf5f0f516aacb7f0034e3786c4454a07fe8d
Author: Matt Dew <marcoz at osource.org>
Date:   Thu Dec 13 21:05:24 2012 -0700

    No changes from 1.13.0.902 (rc2)
    
    Bump version to 1.13.1

diff --git a/configure.ac b/configure.ac
index ffd8a97..67b1eb4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,9 +26,9 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.60)
-AC_INIT([xorg-server], 1.13.0.902, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2012-12-06"
-RELEASE_NAME="Jasmine Tea"
+AC_INIT([xorg-server], 1.13.1, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2012-12-13"
+RELEASE_NAME="Chrysanthemum Tea"
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AM_MAINTAINER_MODE
commit ede07c1af35926c77c4e766cc02c00333b498460
Author: Matt Dew <marcoz at osource.org>
Date:   Thu Dec 6 22:46:46 2012 -0700

    Bump version

diff --git a/configure.ac b/configure.ac
index 590b773..ffd8a97 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,9 +26,9 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.60)
-AC_INIT([xorg-server], 1.13.0.901, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2012-11-22"
-RELEASE_NAME="Puer Tea"
+AC_INIT([xorg-server], 1.13.0.902, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2012-12-06"
+RELEASE_NAME="Jasmine Tea"
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AM_MAINTAINER_MODE
commit e2369dd404024415853108848c8d052e73e95461
Merge: d71a17c 79220f4
Author: Matt Dew <marcoz at osource.org>
Date:   Thu Dec 6 21:53:42 2012 -0700

    Merge branch 'server-1.13-branch' of git://people.freedesktop.org/~whot/xserver into server-1.13-branch

commit 79220f4390127d9971cbcf378530bf36172ef35a
Author: Daniel Martin <consume.noise at gmail.com>
Date:   Wed Nov 7 11:31:01 2012 +0100

    Xi: Fix modifier swapping in XIPassiveGrabDevice
    
    XIPassiveGrabDevice uses a list of uint32_t as modifier sets.
    
    The ModifierInfo struct represents the current modifier states and is
    therefor used in XIQueryPointer and various events.
    
    Signed-off-by: Daniel Martin <consume.noise at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit aa9a9ad08b8a6e7e95de7c2bf45d93dd50f9ca87)

diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
index ddab53d..62a3a46 100644
--- a/Xi/xipassivegrab.c
+++ b/Xi/xipassivegrab.c
@@ -50,7 +50,7 @@ int
 SProcXIPassiveGrabDevice(ClientPtr client)
 {
     int i;
-    xXIModifierInfo *mods;
+    uint32_t *mods;
 
     REQUEST(xXIPassiveGrabDeviceReq);
 
@@ -63,12 +63,10 @@ SProcXIPassiveGrabDevice(ClientPtr client)
     swaps(&stuff->mask_len);
     swaps(&stuff->num_modifiers);
 
-    mods = (xXIModifierInfo *) &stuff[1];
+    mods = (uint32_t *) &stuff[1];
 
     for (i = 0; i < stuff->num_modifiers; i++, mods++) {
-        swapl(&mods->base_mods);
-        swapl(&mods->latched_mods);
-        swapl(&mods->locked_mods);
+        swapl(mods);
     }
 
     return ProcXIPassiveGrabDevice(client);
commit 521f3fb566e67330a486874928a21ce201dba02b
Author: Sybren van Elderen <sowmestno at msn.com>
Date:   Tue Nov 27 19:27:10 2012 +0100

    hw/dmx: add update_desktop_dimensions() call
    
    The Xdmx server did not update the desktop dimensions when computing screen
    origins.
    
    Signed-off-by: Sybren van Elderen <sowmestno at msn.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit 6e18599d691036eca6ff082c17727d9ffb926984)

diff --git a/hw/dmx/dmxcursor.c b/hw/dmx/dmxcursor.c
index 1a77c7d..35aca81 100644
--- a/hw/dmx/dmxcursor.c
+++ b/hw/dmx/dmxcursor.c
@@ -346,6 +346,8 @@ dmxComputeScreenOrigins(void)
             screenInfo.screens[i]->y -= minY;
         }
     }
+
+    update_desktop_dimensions();
 }
 
 /** Recompute origin information in the #dmxScreens list.  This is
commit 73bd33b4d4e3df4a8097826695a8dbdc2fb5c920
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jun 26 10:30:35 2012 +1000

    xkb: fill in keycode and event type for slow keys enablement
    
    eventType is set for the type that triggered a XkbControlsNotify event.
    Technically, SlowKeys is triggered by a timer which doesn't have a matching
    core event type. So we used to use 0 here.
    
    Practically, the timer is triggered by a key press + hold and cancelled when
    the key is released before the timeout expires. So we might as well set
    KeyPress (keycode) in the ControlsNotify to give clients a chance to differ
    between timer-triggered SlowKeys and client-triggered ones.
    
    This is a chance in behaviour, though I suspect with little impact.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Acked-by: Daniel Stone <daniel at fooishbar.org>
    (cherry picked from commit 2c4388a00ec308bc2d48ba751ff510cd5c1b2384)

diff --git a/include/xkbsrv.h b/include/xkbsrv.h
index d584785..78b8f5a 100644
--- a/include/xkbsrv.h
+++ b/include/xkbsrv.h
@@ -171,6 +171,7 @@ typedef struct _XkbSrvInfo {
     KeyCode mouseKey;
     KeyCode inactiveKey;
     KeyCode slowKey;
+    KeyCode slowKeyEnableKey;
     KeyCode repeatKey;
     CARD8 krgTimerActive;
     CARD8 beepType;
diff --git a/xkb/xkbAccessX.c b/xkb/xkbAccessX.c
index c1af32e..21df85d 100644
--- a/xkb/xkbAccessX.c
+++ b/xkb/xkbAccessX.c
@@ -291,8 +291,8 @@ AccessXKRGExpire(OsTimerPtr timer, CARD32 now, pointer arg)
         return 4000;
     }
     xkbi->krgTimerActive = _OFF_TIMER;
-    cn.keycode = 0;
-    cn.eventType = 0;
+    cn.keycode = xkbi->slowKeyEnableKey;
+    cn.eventType = KeyPress;
     cn.requestMajor = 0;
     cn.requestMinor = 0;
     if (xkbi->desc->ctrls->enabled_ctrls & XkbSlowKeysMask) {
@@ -304,6 +304,7 @@ AccessXKRGExpire(OsTimerPtr timer, CARD32 now, pointer arg)
         LogMessage(X_INFO, "XKB SlowKeys are now enabled. Hold shift to disable.\n");
     }
 
+    xkbi->slowKeyEnableKey = 0;
     return 0;
 }
 
@@ -462,6 +463,7 @@ AccessXFilterPressEvent(DeviceEvent *event, DeviceIntPtr keybd)
     if (ctrls->enabled_ctrls & XkbAccessXKeysMask) {
         /* check for magic sequences */
         if ((sym[0] == XK_Shift_R) || (sym[0] == XK_Shift_L)) {
+            xkbi->slowKeyEnableKey = key;
             if (XkbAX_NeedFeedback(ctrls, XkbAX_SlowWarnFBMask)) {
                 xkbi->krgTimerActive = _KRG_WARN_TIMER;
                 xkbi->krgTimer = TimerSet(xkbi->krgTimer, 0, 4000,
commit 2def985466683cf3746c03f9ac318e5941d22f86
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Tue Nov 20 14:50:41 2012 -0500

    cursor: Revise edge cases for the pointer moving towards barriers
    
    Since barriers block the invisible line between pixels, that means
    that we need to explicitly check the boundaries, or else we'll have
    a potential off-by-one error. This fixes issues when trying to move
    down or right across a barrier and having the pointer visibly bounce.
    
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit a51b2c3913fc8556f6bd1c76805d045fc424c4bb)

diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 4eee592..4d4a75e 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -1090,7 +1090,11 @@ barrier_is_blocking(const struct PointerBarrier * barrier,
         if (dir & BarrierNegativeX && x1 == (barrier->x1 - 1))
             return FALSE;
         /* startpoint adjacent to barrier, moving towards -> block */
-        if (x1 == barrier->x1 && y1 >= barrier->y1 && y1 <= barrier->y2) {
+        if (dir & BarrierPositiveX && x1 == (barrier->x1 - 1) && y1 >= barrier->y1 && y1 <= barrier->y2) {
+            *distance = 0;
+            return TRUE;
+        }
+        if (dir & BarrierNegativeX && x1 == barrier->x1 && y1 >= barrier->y1 && y1 <= barrier->y2) {
             *distance = 0;
             return TRUE;
         }
@@ -1102,7 +1106,11 @@ barrier_is_blocking(const struct PointerBarrier * barrier,
         if (dir & BarrierNegativeY && y1 == (barrier->y1 - 1))
             return FALSE;
         /* startpoint adjacent to barrier, moving towards -> block */
-        if (y1 == barrier->y1 && x1 >= barrier->x1 && x1 <= barrier->x2) {
+        if (dir & BarrierPositiveY && y1 == (barrier->y1 - 1) && x1 >= barrier->x1 && x1 <= barrier->x2) {
+            *distance = 0;
+            return TRUE;
+        }
+        if (dir & BarrierNegativeY && y1 == barrier->y1 && x1 >= barrier->x1 && x1 <= barrier->x2) {
             *distance = 0;
             return TRUE;
         }
commit 4a957c9e81233344da0b5b9388ca2d97eedde7d5
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Nov 15 14:00:57 2012 +1000

    When resetting device idle time, reset XIAll(Master)Devices too (#56649)
    
    When the screen saver is forcibly deactivated, the idle time counter is
    reset for all devices but not for the fake XIAllDevices and
    XIAllMasterDevices. XScreenSaverQueryInfo uses XIAlldevices to fill the
    "idle" field, thus returning the wrong value.
    
    Regression introduced in
    commit 6aef209ebc2e54f5465da505a780f7b4cc273ee0
    Author: Peter Hutterer <peter.hutterer at who-t.net>
    Date:   Mon Mar 12 13:51:02 2012 +1000
    
        Change lastDeviceIdleTime to be per-device
    
    X.Org Bug 56649 <http://bugs.freedesktop.org/show_bug.cgi?id=56649>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Tested-by: Giacomo Perale <ghepeu at virgilio.it>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit 2dc6d9228456cbc274a1fcea478258e5ae4dc629)

diff --git a/Xext/saver.c b/Xext/saver.c
index ac4a633..f73e2a2 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -393,6 +393,8 @@ ScreenSaverFreeSuspend(pointer value, XID id)
             UpdateCurrentTimeIf();
             nt_list_for_each_entry(dev, inputInfo.devices, next)
                 lastDeviceEventTime[dev->id] = currentTime;
+            lastDeviceEventTime[XIAllDevices] = currentTime;
+            lastDeviceEventTime[XIAllMasterDevices] = currentTime;
             SetScreenSaverTimer();
         }
     }
diff --git a/dix/window.c b/dix/window.c
index cdd12dc..49ef4a0 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -3132,6 +3132,8 @@ dixSaveScreens(ClientPtr client, int on, int mode)
             UpdateCurrentTimeIf();
             nt_list_for_each_entry(dev, inputInfo.devices, next)
                 lastDeviceEventTime[dev->id] = currentTime;
+            lastDeviceEventTime[XIAllDevices] = currentTime;
+            lastDeviceEventTime[XIAllMasterDevices] = currentTime;
         }
         SetScreenSaverTimer();
     }
commit d71a17cfab6536df9df46a342a24dd415c020192
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sat Nov 10 10:26:08 2012 +0000

    xf86: select a fake output for headless servers
    
    Following commit 37d956e3ac9513b74078882dff489f9b0a7a5a28
    Author: Keith Packard <keithp at keithp.com>
    Date:   Mon Sep 10 11:14:20 2012 +1000
    
        xf86: fix compat output selection for no output GPUs
    
    headless servers can no longer startup as we no longer select a compat
    output for the fake framebuffer.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=56343
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit e54f71a2c7a1677a5c5032d1e7dc099d5204144b)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 177f7ac..13251cf 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -1847,6 +1847,10 @@ SetCompatOutput(xf86CrtcConfigPtr config)
         output = config->output[config->compat_output];
     }
 
+    /* All outputs are disconnected, select one to fake */
+    if (!output && config->num_output)
+        output = config->output[0];
+
     return output;
 }
 
commit 72ef659874ffe88e88d2f2a35a6e404782cefe9f
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Sep 10 11:14:20 2012 +1000

    xf86: fix compat output selection for no output GPUs
    
    This should work properly with dynamic outputs.
    
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit 37d956e3ac9513b74078882dff489f9b0a7a5a28)

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index e3eaf5f..177f7ac 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -66,6 +66,7 @@ xf86CrtcConfigInit(ScrnInfoPtr scrn, const xf86CrtcConfigFuncsRec * funcs)
     config = xnfcalloc(1, sizeof(xf86CrtcConfigRec));
 
     config->funcs = funcs;
+    config->compat_output = -1;
 
     scrn->privates[xf86CrtcConfigPrivateIndex].ptr = config;
 }
@@ -1841,7 +1842,7 @@ SetCompatOutput(xf86CrtcConfigPtr config)
     if (compat >= 0) {
         config->compat_output = compat;
     }
-    else {
+    else if (config->compat_output >= 0 && config->compat_output < config->num_output) {
         /* Don't change the compat output when no valid outputs found */
         output = config->output[config->compat_output];
     }
commit a2748aa6bde13b447a246606767535a30090cd02
Author: Dave Airlie <airlied at gmail.com>
Date:   Fri Nov 30 20:54:38 2012 +1000

    randr: call RRProviderInit in the proper place.
    
    No idea where this got lost across development cycles, but its
    definitely missing.
    
    Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=57448
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit e9ea96d6a88f197928c82b008953f1810de6f792)

diff --git a/randr/randr.c b/randr/randr.c
index da48c3f..f0decfc 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -264,6 +264,8 @@ RRInit(void)
             return FALSE;
         if (!RROutputInit())
             return FALSE;
+        if (!RRProviderInit())
+            return FALSE;
         RRGeneration = serverGeneration;
     }
     if (!dixRegisterPrivateKey(&rrPrivKeyRec, PRIVATE_SCREEN, 0))
commit c0e68f8e70e0b0fbb00992228c4651d5b0902759
Author: Matt Dew <marcoz at osource.org>
Date:   Thu Nov 22 21:37:57 2012 -0700

    Bump release info for this RC1.

diff --git a/configure.ac b/configure.ac
index ac3bf26..590b773 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,9 +26,9 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.60)
-AC_INIT([xorg-server], 1.13.0, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2012-09-05"
-RELEASE_NAME="Iced Tea"
+AC_INIT([xorg-server], 1.13.0.901, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2012-11-22"
+RELEASE_NAME="Puer Tea"
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AM_MAINTAINER_MODE
commit 395c9e17089a7e4ed46a747904b36b1fec94fab3
Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Mon Oct 29 12:57:54 2012 +0100

    EXA: Track source/mask pixmaps more explicitly for Composite fallback regions.
    
    In particular, make sure pExaScr->src/maskPix are cleared when the
    corresponding pictures aren't associated with drawables, i.e. solid or gradient
    pictures. Without this, we would in some cases associate the source/mask region
    with unrelated pixmaps from previous Composite fallbacks, resulting in random
    corruption.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=47266
    
    Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit 1ca096d5e07221025c4c4110528772b7d94f15ee)

diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index ea7e7fa..2e4759d 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -209,6 +209,7 @@ typedef struct {
     RegionRec srcReg;
     RegionRec maskReg;
     PixmapPtr srcPix;
+    PixmapPtr maskPix;
 
     DevPrivateKeyRec pixmapPrivateKeyRec;
     DevPrivateKeyRec gcPrivateKeyRec;
diff --git a/exa/exa_unaccel.c b/exa/exa_unaccel.c
index 5716138..b0a0011 100644
--- a/exa/exa_unaccel.c
+++ b/exa/exa_unaccel.c
@@ -442,6 +442,13 @@ ExaSrcValidate(DrawablePtr pDrawable,
     RegionPtr dst;
     int xoff, yoff;
 
+    if (pExaScr->srcPix == pPix)
+        dst = &pExaScr->srcReg;
+    else if (pExaScr->maskPix == pPix)
+        dst = &pExaScr->maskReg;
+    else
+        return;
+
     exaGetDrawableDeltas(pDrawable, pPix, &xoff, &yoff);
 
     box.x1 = x + xoff;
@@ -449,8 +456,6 @@ ExaSrcValidate(DrawablePtr pDrawable,
     box.x2 = box.x1 + width;
     box.y2 = box.y1 + height;
 
-    dst = (pExaScr->srcPix == pPix) ? &pExaScr->srcReg : &pExaScr->maskReg;
-
     RegionInit(&reg, &box, 1);
     RegionUnion(dst, dst, &reg);
     RegionUninit(&reg);
@@ -495,16 +500,19 @@ ExaPrepareCompositeReg(ScreenPtr pScreen,
         if (pSrc != pDst)
             RegionTranslate(pSrc->pCompositeClip,
                             -pSrc->pDrawable->x, -pSrc->pDrawable->y);
-    }
+    } else
+        pExaScr->srcPix = NULL;
 
     if (pMask && pMask->pDrawable) {
         pMaskPix = exaGetDrawablePixmap(pMask->pDrawable);
         RegionNull(&pExaScr->maskReg);
         maskReg = &pExaScr->maskReg;
+        pExaScr->maskPix = pMaskPix;
         if (pMask != pDst && pMask != pSrc)
             RegionTranslate(pMask->pCompositeClip,
                             -pMask->pDrawable->x, -pMask->pDrawable->y);
-    }
+    } else
+        pExaScr->maskPix = NULL;
 
     RegionTranslate(pDst->pCompositeClip,
                     -pDst->pDrawable->x, -pDst->pDrawable->y);
commit 7914986fb801f6ea98582db21c0d86b9b200b9ac
Merge: b3d25d8 1a4ec49
Author: Matt Dew <marcoz at osource.org>
Date:   Wed Nov 7 23:24:53 2012 -0700

    Merge branch 'server-1.13-branch' of git://people.freedesktop.org/~whot/xserver into server-1.13-branch

commit 1a4ec493bf3d3d14799340c03533cdcd44b841e8
Author: Carlos Garnacho <carlosg at gnome.org>
Date:   Wed Oct 31 19:29:45 2012 +0100

    Xi: Set modifier mask on touch events
    
    Button mask should be out-of-band with the emulated
    pointer events as touch devices don't truly have
    "buttons". Even though, it's handy to have the modifier
    mask from the paired keyboard on touch events.
    
    Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit b4e44b285ed0eee1d06514215a4b01d54f40094b)

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 5cf873c..106da3a 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1559,6 +1559,7 @@ ProcessTouchEvent(InternalEvent *ev, DeviceIntPtr dev)
     uint32_t touchid;
     int type = ev->any.type;
     int emulate_pointer = ! !(ev->device_event.flags & TOUCH_POINTER_EMULATED);
+    DeviceIntPtr kbd;
 
     if (!t)
         return;
@@ -1618,6 +1619,10 @@ ProcessTouchEvent(InternalEvent *ev, DeviceIntPtr dev)
     if (emulate_pointer && IsMaster(dev))
         CheckMotion(&ev->device_event, dev);
 
+    kbd = GetMaster(dev, KEYBOARD_OR_FLOAT);
+    event_set_state(NULL, kbd, &ev->device_event);
+    ev->device_event.corestate = event_get_corestate(NULL, kbd);
+
     /* Make sure we have a valid window trace for event delivery; must be
      * called after event type mutation. Touch end events are always processed
      * in order to end touch records. */
commit 2f99b38747e1a74cade10a7a45cee5eaec8ddea7
Author: Carlos Garnacho <carlosg at gnome.org>
Date:   Wed Oct 31 19:32:57 2012 +0100

    Xi: Update the device after delivering the emulated pointer event(#56558)
    
    Ensure emulated pointer events contain the state that applies before the
    event was processed, so the device state must be updated after delivering
    such emulated events.
    
    Co-authored-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit 863f32c930d71073ee5f78452b78bd459d024867)

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 4cbeb37..5cf873c 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1568,9 +1568,6 @@ ProcessTouchEvent(InternalEvent *ev, DeviceIntPtr dev)
     else
         touchid = ev->device_event.touchid;
 
-    if (emulate_pointer)
-        UpdateDeviceState(dev, &ev->device_event);
-
     if (type == ET_TouchBegin) {
         ti = TouchBeginTouch(dev, ev->device_event.sourceid, touchid,
                              emulate_pointer);
@@ -1617,6 +1614,7 @@ ProcessTouchEvent(InternalEvent *ev, DeviceIntPtr dev)
      * events which _only_ emulate motion just work normally */
     if (emulate_pointer && ev->any.type != ET_TouchUpdate)
         DeliverEmulatedMotionEvent(dev, ti, ev);
+
     if (emulate_pointer && IsMaster(dev))
         CheckMotion(&ev->device_event, dev);
 
@@ -1641,6 +1639,9 @@ ProcessTouchEvent(InternalEvent *ev, DeviceIntPtr dev)
         if (ev->any.type == ET_TouchEnd)
             TouchEndTouch(dev, ti);
     }
+
+    if (emulate_pointer)
+        UpdateDeviceState(dev, &ev->device_event);
 }
 
 /**
commit 10d9cd36b4966c8e3ea8e791152e1af166224ee8
Author: Carlos Garnacho <carlosg at gnome.org>
Date:   Thu Oct 25 15:03:50 2012 +0200

    Sync TouchListener memory allocation with population in TouchSetupListeners()
    
    The allocated TouchListener array may fall short by 1 if hitting the worst case
    situation where there's an active grab, passive grabs on each window in the
    sprite trace and event selection for touch in one of the windows. This may lead
    to memory corruptions as the array is overflown.
    
    Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit ced56f322ead10d1bc93fcd1f8e0ec3ae51292a3)

diff --git a/dix/touch.c b/dix/touch.c
index e64a626..5f77be5 100644
--- a/dix/touch.c
+++ b/dix/touch.c
@@ -572,8 +572,8 @@ TouchBuildSprite(DeviceIntPtr sourcedev, TouchPointInfoPtr ti,
         return FALSE;
 
     /* Mark which grabs/event selections we're delivering to: max one grab per
-     * window plus the bottom-most event selection. */
-    ti->listeners = calloc(sprite->spriteTraceGood + 1, sizeof(*ti->listeners));
+     * window plus the bottom-most event selection, plus any active grab. */
+    ti->listeners = calloc(sprite->spriteTraceGood + 2, sizeof(*ti->listeners));
     if (!ti->listeners) {
         sprite->spriteTraceGood = 0;
         return FALSE;
commit 835737244f84d34b0b9c5a93560710a2275dcc63
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Oct 18 15:11:31 2012 +1000

    dix: fix zaphod screen scrossing (#54654)
    
    POINTER_SCREEN coordinates are screen-relative. For a Zaphod setup, the
    coordinates after a screen crossing are already relative to the new screen's
    origin. Add that offset to the coordinates before re-setting.
    
    regression introduced by
    commit bafbd99080be49a17be97d2cc758fbe623369945
    Author: Peter Hutterer <peter.hutterer at who-t.net>
    Date:   Wed Aug 8 11:34:32 2012 +1000
    
        dix: work around scaling issues during WarpPointer (#53037)
    
    X.Org Bug 54654 <http://bugs.freedesktop.org/show_bug.cgi?id=54654>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit e7cd5cce740e653000fb1192b600268dcf77dde2)

diff --git a/dix/getevents.c b/dix/getevents.c
index 71d83c4..8b4379d 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -1400,8 +1400,9 @@ fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type,
        coordinates were.
      */
     if (flags & POINTER_SCREEN) {
-        screenx = sx;
-        screeny = sy;
+        scr = miPointerGetScreen(pDev);
+        screenx = sx + scr->x;
+        screeny = sy + scr->y;
     }
 
     scr = positionSprite(pDev, (flags & POINTER_ABSOLUTE) ? Absolute : Relative,
commit a3f11d2f6066d2120e84f0c33684943474aa8ae1
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Oct 17 14:13:29 2012 +1000

    Xi: don't deliver TouchEnd to a client waiting for TouchBegin (#55738)
    
    If a client is still waiting for the TouchBegin, don't deliver a TouchEnd
    event.
    
    X.Org Bug 55738 <http://bugs.freedesktop.org/show_bug.cgi?id=55738>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Tested-by: Thomas Jaeger <thjaeger at gmail.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit 676447190190d8546165e21be242cf16dd69f5ae)

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 6ed4991..4cbeb37 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1862,6 +1862,11 @@ DeliverTouchEndEvent(DeviceIntPtr dev, TouchPointInfoPtr ti, InternalEvent *ev,
         goto out;
     }
 
+    if (listener->state == LISTENER_AWAITING_BEGIN) {
+        listener->state = LISTENER_HAS_END;
+        goto out;
+    }
+
     /* Event in response to reject */
     if (ev->device_event.flags & TOUCH_REJECT) {
         if (listener->state != LISTENER_HAS_END)
commit 11319a922575f1da1d3c5774728c0dee12bab069
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Oct 11 16:03:33 2012 +1000

    xkb: ProcesssPointerEvent must work on the VCP if it gets the VCP
    
    For button release events, the current code picks the VCK. Because that has
    a XKB struct, it thinks this is a PointerKeys event and proceeds to send the
    release event through the XTest pointer. That has no effect in normal
    operation as the button is never down and an attempt is silently discarded
    (normal event processing continues with the VCP).
    
    On server shutdown, the XTest device is already removed, leading to a
    null-pointer derefernce when the device is checked for whether buttons are
    down (XkbFakeDeviceButton → button_is_down(xtest pointer)).
    
    The current state has only worked by accident, the right approach here is to
    handle the VCP's event as such and not switch to the keyboard.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit 2decff6393a44b56d80d53570718f95354fde454)

diff --git a/xkb/xkbAccessX.c b/xkb/xkbAccessX.c
index 082c0db..c1af32e 100644
--- a/xkb/xkbAccessX.c
+++ b/xkb/xkbAccessX.c
@@ -709,7 +709,7 @@ ProcessPointerEvent(InternalEvent *ev, DeviceIntPtr mouse)
     xkbDeviceInfoPtr xkbPrivPtr = XKBDEVICEINFO(mouse);
     DeviceEvent *event = &ev->device_event;
 
-    dev = IsFloating(mouse) ? mouse : GetMaster(mouse, MASTER_KEYBOARD);
+    dev = (IsMaster(mouse) || IsFloating(mouse)) ? mouse : GetMaster(mouse, MASTER_KEYBOARD);
 
     if (dev && dev->key) {
         xkbi = dev->key->xkbInfo;
commit 9ddc6ad9d02d886c1dba0496fc9480db64529bf2
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Thu Jun 7 14:12:06 2012 -0700

    End physically active touches when device is disabled
    
    Otherwise:
    
    * We can't end the touches while device is disabled
    * New touches after enabling the device may erroneously be mapped to old
      logical touches
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit 3b67cd26149eb991b5f015061a818af65369e668)

diff --git a/dix/devices.c b/dix/devices.c
index 66d4406..fd4916a 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -443,6 +443,7 @@ DisableDevice(DeviceIntPtr dev, BOOL sendevent)
     if (*prev != dev)
         return FALSE;
 
+    TouchEndPhysicallyActiveTouches(dev);
     ReleaseButtonsAndKeys(dev);
     SyncRemoveDeviceIdleTime(dev->idle_counter);
     dev->idle_counter = NULL;
diff --git a/dix/touch.c b/dix/touch.c
index 497ad7d..e64a626 100644
--- a/dix/touch.c
+++ b/dix/touch.c
@@ -1029,3 +1029,31 @@ TouchAcceptReject(ClientPtr client, DeviceIntPtr dev, int mode,
 
     return TouchListenerAcceptReject(dev, ti, i, mode);
 }
+
+/**
+ * End physically active touches for a device.
+ */
+void
+TouchEndPhysicallyActiveTouches(DeviceIntPtr dev)
+{
+    InternalEvent *eventlist = InitEventList(GetMaximumEventsNum());
+    int i;
+
+    OsBlockSignals();
+    mieqProcessInputEvents();
+    for (i = 0; i < dev->last.num_touches; i++) {
+        DDXTouchPointInfoPtr ddxti = dev->last.touches + i;
+
+        if (ddxti->active) {
+            int j;
+            int nevents = GetTouchEvents(eventlist, dev, ddxti->ddx_id,
+                                         XI_TouchEnd, 0, NULL);
+
+            for (j = 0; j < nevents; j++)
+                mieqProcessDeviceEvent(dev, eventlist + j, NULL);
+        }
+    }
+    OsReleaseSignals();
+
+    FreeEventList(eventlist, GetMaximumEventsNum());
+}
diff --git a/include/input.h b/include/input.h
index 5747f3c..f8459b8 100644
--- a/include/input.h
+++ b/include/input.h
@@ -579,6 +579,7 @@ extern int TouchListenerAcceptReject(DeviceIntPtr dev, TouchPointInfoPtr ti,
                                      int listener, int mode);
 extern int TouchAcceptReject(ClientPtr client, DeviceIntPtr dev, int mode,
                              uint32_t touchid, Window grab_window, XID *error);
+extern void TouchEndPhysicallyActiveTouches(DeviceIntPtr dev);
 
 /* misc event helpers */
 extern Mask GetEventMask(DeviceIntPtr dev, xEvent *ev, InputClientsPtr clients);
commit 36f9c2d1ddc8a35c0317db55044d05f07284ab38
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Oct 10 13:33:48 2012 +1000

    dix: fix crash on shutdown if a disabled device is still grabbed (XI1 grab)
    
    A disabled device doesn't have a sprite (less so a sprite->win) and triggers
    a NULL-pointer dereference on shutdown when all active grabs are released as
    part of the cleanup.
    
    Fix this by checking for sprite being non-null and setting the focus window
    to the NullWindow if it is. The rest of the patch just attempts to make
    things more readable.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit 4b7f00346daed20c96f3e8ea13ae411858a5424b)

diff --git a/dix/events.c b/dix/events.c
index c0e330b..ddb5b34 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1593,13 +1593,10 @@ DeactivateKeyboardGrab(DeviceIntPtr keybd)
 {
     GrabPtr grab = keybd->deviceGrab.grab;
     DeviceIntPtr dev;
-    WindowPtr focusWin = keybd->focus ? keybd->focus->win
-        : keybd->spriteInfo->sprite->win;
+    WindowPtr focusWin;
     Bool wasImplicit = (keybd->deviceGrab.fromPassiveGrab &&
                         keybd->deviceGrab.implicitGrab);
 
-    if (focusWin == FollowKeyboardWin)
-        focusWin = inputInfo.keyboard->focus->win;
     if (keybd->valuator)
         keybd->valuator->motionHintWindow = NullWindow;
     keybd->deviceGrab.grab = NullGrab;
@@ -1610,6 +1607,17 @@ DeactivateKeyboardGrab(DeviceIntPtr keybd)
         if (dev->deviceGrab.sync.other == grab)
             dev->deviceGrab.sync.other = NullGrab;
     }
+
+    if (keybd->focus)
+        focusWin = keybd->focus->win;
+    else if (keybd->spriteInfo->sprite)
+        focusWin = keybd->spriteInfo->sprite->win;
+    else
+        focusWin = NullWindow;
+
+    if (focusWin == FollowKeyboardWin)
+        focusWin = inputInfo.keyboard->focus->win;
+
     DoFocusEvents(keybd, grab->window, focusWin, NotifyUngrab);
 
     if (!wasImplicit && grab->grabtype == XI2)
commit b3d25d8d65e4a4864da232630758f125f8a1bfb4
Merge: 5a612aa b87edf1
Author: Matt Dew <marcoz at osource.org>
Date:   Thu Nov 1 22:17:59 2012 -0600

    Merge branch 'server-1.13-branch' of git://people.freedesktop.org/~airlied/xserver into server-1.13-branch

commit b87edf1acca7e57139cd6bdf5838c2b4179352dc
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Aug 27 15:22:44 2012 +1000

    xf86: fix multi-seat video device support. (v2)
    
    If we are not seat 0 the following apply:
    
    don't probe any bus other than platform
    don't probe any drivers other than platform
    assume the first platform device we match on the bus is the primary GPU.
    
    This just adds checks in the correct places to ensure this, and
    with this X can now start on a secondary seat for an output device.
    
    v2: fix Seat0 macros
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit 70e5766874a919039678bb2ed75f2ccea0cb4345)

diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c
index 6de8409..4ffbf7e 100644
--- a/hw/xfree86/common/xf86Bus.c
+++ b/hw/xfree86/common/xf86Bus.c
@@ -81,6 +81,8 @@ xf86CallDriverProbe(DriverPtr drv, Bool detect_only)
     if (drv->platformProbe != NULL) {
         foundScreen = xf86platformProbeDev(drv);
     }
+    if (ServerIsNotSeat0())
+        return foundScreen;
 #endif
 
 #ifdef XSERVER_LIBPCIACCESS
@@ -214,6 +216,8 @@ xf86BusProbe(void)
 {
 #ifdef XSERVER_PLATFORM_BUS
     xf86platformProbe();
+    if (ServerIsNotSeat0())
+        return;
 #endif
 #ifdef XSERVER_LIBPCIACCESS
     xf86PciProbe();
diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c
index 6a8fb90..0525e39 100644
--- a/hw/xfree86/common/xf86platformBus.c
+++ b/hw/xfree86/common/xf86platformBus.c
@@ -359,6 +359,9 @@ xf86platformProbeDev(DriverPtr drvp)
                     break;
             }
             else {
+                /* for non-seat0 servers assume first device is the master */
+                if (ServerIsNotSeat0())
+                    break;
                 if (xf86_platform_devices[j].pdev) {
                     if (xf86IsPrimaryPlatform(&xf86_platform_devices[j]))
                         break;
commit 1e8c960f8777a889fbc17c8711b3e68fd094427b
Author: Dave Airlie <airlied at gmail.com>
Date:   Thu Sep 13 18:44:06 2012 +1000

    config/udev: ignore change on drm devices
    
    for input devices we handle change like remove/add, but for
    drm devices we get change events when we hotplug outputs,
    so lets just ignore change at this level, and let the drivers
    handle it. We may in the future want to route driver udev
    from here instead.
    
    Reported-by: Timo Aaltonen <timo.aaltonen at canonical.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit e0b92f5f86f8ce71ab4c80e9902e51e2525f9705)

diff --git a/config/udev.c b/config/udev.c
index c2d00bb..454838f 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -300,9 +300,15 @@ wakeup_handler(pointer data, int err, pointer read_mask)
             return;
         action = udev_device_get_action(udev_device);
         if (action) {
-            if (!strcmp(action, "add") || !strcmp(action, "change")) {
+            if (!strcmp(action, "add")) {
                 device_removed(udev_device);
                 device_added(udev_device);
+            } else if (!strcmp(action, "change")) {
+                /* ignore change for the drm devices */
+                if (strcmp(udev_device_get_subsystem(udev_device), "drm")) {
+                    device_removed(udev_device);
+                    device_added(udev_device);
+                }
             }
             else if (!strcmp(action, "remove"))
                 device_removed(udev_device);
commit c7c07558919102f06aeb3fad5f856f04e6757a76
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Sep 10 14:48:37 2012 +1000

    xf86/platform: scan pci after probing devices
    
    This solves a race if we are trying to dynamically power off
    secondary GPUs. Its not the greatest fix ever but it probably
    as good as we can do for now.
    
    The GPU probing causes the devices to be powered up, then when
    we scan the PCI bus we get the correct information from the kernel,
    rather than a bunch of 0xff due to the device being powered off.
    
    drop gratuitous '&'.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit 10672a5abe7d4e924844d7e41c86c24d6367a52b)

diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c
index 24b9473..6a8fb90 100644
--- a/hw/xfree86/common/xf86platformBus.c
+++ b/hw/xfree86/common/xf86platformBus.c
@@ -213,11 +213,12 @@ xf86platformProbe(void)
     int i;
     Bool pci = TRUE;
 
+    config_odev_probe(xf86PlatformDeviceProbe);
+
     if (!xf86scanpci()) {
         pci = FALSE;
     }
 
-    config_odev_probe(&xf86PlatformDeviceProbe);
     for (i = 0; i < xf86_num_platform_devices; i++) {
         char *busid = xf86_get_platform_attrib(i, ODEV_ATTRIB_BUSID);
 
commit 39ebf87be749c59a06cb1763e11f14c722f77fbd
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 6 16:33:54 2012 +1000

    dri2: invalidate drawable after sharing pixmap
    
    After we share the pixmap, the backing storage may have changed,
    and we need to invalidate and buffers pointing at it.
    
    This fixes GL compositors and prime windows lacking contents initially.
    
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    (cherry picked from commit 22746df15b5f75dc85f5cf5b73932eb8a44cb89b)

diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index 23f589c..40963c3 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -766,6 +766,44 @@ static inline PixmapPtr GetDrawablePixmap(DrawablePtr drawable)
     }
 }
 
+/*
+ * A TraverseTree callback to invalidate all windows using the same
+ * pixmap
+ */
+static int
+DRI2InvalidateWalk(WindowPtr pWin, pointer data)
+{
+    if (pWin->drawable.pScreen->GetWindowPixmap(pWin) != data)
+        return WT_DONTWALKCHILDREN;
+    DRI2InvalidateDrawable(&pWin->drawable);
+    return WT_WALKCHILDREN;
+}
+
+static void
+DRI2InvalidateDrawableAll(DrawablePtr pDraw)
+{
+    if (pDraw->type == DRAWABLE_WINDOW) {
+        WindowPtr pWin = (WindowPtr) pDraw;
+        PixmapPtr pPixmap = pDraw->pScreen->GetWindowPixmap(pWin);
+
+        /*
+         * Find the top-most window using this pixmap
+         */
+        while (pWin->parent &&
+               pDraw->pScreen->GetWindowPixmap(pWin->parent) == pPixmap)
+            pWin = pWin->parent;
+
+        /*
+         * Walk the sub-tree to invalidate all of the
+         * windows using the same pixmap
+         */
+        TraverseTree(pWin, DRI2InvalidateWalk, pPixmap);
+        DRI2InvalidateDrawable(&pPixmap->drawable);
+    }
+    else
+        DRI2InvalidateDrawable(pDraw);
+}
+
 DrawablePtr DRI2UpdatePrime(DrawablePtr pDraw, DRI2BufferPtr pDest)
 {
     DRI2DrawablePtr pPriv = DRI2GetDrawable(pDraw);
@@ -831,6 +869,8 @@ DrawablePtr DRI2UpdatePrime(DrawablePtr pDraw, DRI2BufferPtr pDest)
     spix->screen_x = mpix->screen_x;
     spix->screen_y = mpix->screen_y;
 #endif
+
+    DRI2InvalidateDrawableAll(pDraw);
     return &spix->drawable;
 }
 
@@ -1048,18 +1088,7 @@ DRI2WaitSwap(ClientPtr client, DrawablePtr pDrawable)
     return FALSE;
 }
 
-/*
- * A TraverseTree callback to invalidate all windows using the same
- * pixmap
- */
-static int
-DRI2InvalidateWalk(WindowPtr pWin, pointer data)
-{
-    if (pWin->drawable.pScreen->GetWindowPixmap(pWin) != data)
-        return WT_DONTWALKCHILDREN;
-    DRI2InvalidateDrawable(&pWin->drawable);
-    return WT_WALKCHILDREN;
-}
+
 
 int
 DRI2SwapBuffers(ClientPtr client, DrawablePtr pDraw, CARD64 target_msc,
@@ -1162,26 +1191,7 @@ DRI2SwapBuffers(ClientPtr client, DrawablePtr pDraw, CARD64 target_msc,
      */
     *swap_target = pPriv->swap_count + pPriv->swapsPending;
 
-    if (pDraw->type == DRAWABLE_WINDOW) {
-        WindowPtr pWin = (WindowPtr) pDraw;
-        PixmapPtr pPixmap = pScreen->GetWindowPixmap(pWin);
-
-        /*
-         * Find the top-most window using this pixmap
-         */
-        while (pWin->parent &&
-               pScreen->GetWindowPixmap(pWin->parent) == pPixmap)
-            pWin = pWin->parent;
-
-        /*
-         * Walk the sub-tree to invalidate all of the
-         * windows using the same pixmap
-         */
-        TraverseTree(pWin, DRI2InvalidateWalk, pPixmap);
-        DRI2InvalidateDrawable(&pPixmap->drawable);
-    }
-    else
-        DRI2InvalidateDrawable(pDraw);
+    DRI2InvalidateDrawableAll(pDraw);
 
     return Success;
 }
commit 5a612aa44d2fda44317a242c2d8a5fb2afde76c6
Merge: 8f39a6b 0456d56
Author: Matt Dew <marcoz at osource.org>
Date:   Tue Oct 30 22:12:56 2012 -0600

    Merge branch 'server-1.13-branch' of git://people.freedesktop.org/~jturney/xserver into server-1.13-branch

commit 0456d56092e7617131c77b50a7e7f501e6d9d275
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Sep 7 14:58:06 2012 +0100

    Fix 'make distcheck' for hw/xwin
    
    Add some missing header files to _SOURCES so they get distributed properly
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>
    (cherry picked from commit a69429a17bf4630f6e26f61630a1c2b287202627)

diff --git a/hw/xwin/Makefile.am b/hw/xwin/Makefile.am
index 4c2f04e..33729a9 100644
--- a/hw/xwin/Makefile.am
+++ b/hw/xwin/Makefile.am
@@ -109,13 +109,16 @@ SRCS =	InitInput.c \
 	winclipboard.h \
 	winconfig.h \
 	win.h \
+	winglobals.h \
 	winkeybd.h \
 	winkeynames.h \
 	winlayouts.h \
 	winmessages.h \
+	winmonitors.h \
 	winmsg.h \
 	winms.h \
 	winmultiwindowclass.h \
+	winmultiwindowicons.h \
 	winprefs.h \
 	winresource.h \
 	winwindow.h \
diff --git a/hw/xwin/glx/Makefile.am b/hw/xwin/glx/Makefile.am
index 7222a9f..59f6879 100644
--- a/hw/xwin/glx/Makefile.am
+++ b/hw/xwin/glx/Makefile.am
@@ -6,7 +6,8 @@ libXwinGLX_la_SOURCES = \
 	glwindows.h \
 	glwrap.c \
 	indirect.c \
-	wgl_ext_api.c
+	wgl_ext_api.c \
+	wgl_ext_api.h
 
 if XWIN_MULTIWINDOW
 DEFS_MULTIWINDOW = -DXWIN_MULTIWINDOW
commit 018248136aae19887f10860f33f085f6211a4ceb
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Thu Sep 6 13:51:38 2012 +0100

    Fix compilation of Xorg DDX without XF86VIDMODE
    
    Fix compilation of Xorg DDX without XF86VIDMODE since 6e74fdda, by putting
    xf86vmode.c back under the XF86VIDMODE automake conditional it was accidentally
    taken out of.
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Tested-by: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    (cherry picked from commit 1d9fd7ffb03ff6e44f3a8736a94e4558203ce607)

diff --git a/hw/xfree86/common/Makefile.am b/hw/xfree86/common/Makefile.am
index f8fcde9..532d87b 100644
--- a/hw/xfree86/common/Makefile.am
+++ b/hw/xfree86/common/Makefile.am
@@ -15,6 +15,7 @@ XVSDKINCS = xf86xv.h xf86xvmc.h xf86xvpriv.h
 endif
 
 if XF86VIDMODE
+XF86VMODESOURCES = xf86vmode.c
 XF86VMODE_SDK = vidmodeproc.h
 endif
 
@@ -47,7 +48,7 @@ libcommon_la_SOURCES = xf86Configure.c xf86Bus.c xf86Config.c \
                       xf86VidMode.c xf86fbman.c xf86cmap.c \
                       xf86Helper.c xf86PM.c xf86Xinput.c xisb.c \
                       xf86Mode.c xorgHelper.c xf86Extensions.h \
-		      xf86Extensions.c xf86vmode.c \
+		      xf86Extensions.c $(XF86VMODESOURCES) \
                       $(XVSOURCES) $(BUSSOURCES) $(RANDRSOURCES)
 nodist_libcommon_la_SOURCES = xf86DefModeSet.c xf86Build.h
 libcommon_la_LIBADD = $(top_builddir)/config/libconfig.la
commit d46af347327bd60a4b2a8066b8b7af11f530590d
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Sun Sep 2 15:17:05 2012 +0100

    hw/xwin: Only add GLX extension once.
    
    Using of LoadExtension() to add GLX onto to the end of the list of extensions on
    every server regeneration leads to hilarious consequences (i.e. crashing) after
    the first regeneration :-)
    
    Possibly xf86ExtensionInit() and QuartzExtensionInit() need a similar fix.
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>
    Tested-by: Colin Harrison <colin.harrison at virgin.net>
    (cherry picked from commit 25741b1aa3a0fb39cb842a43ab52935673cfdefa)

diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c
index 37cd8b3..1cf0f02 100644
--- a/hw/xwin/InitOutput.c
+++ b/hw/xwin/InitOutput.c
@@ -164,7 +164,7 @@ void XwinExtensionInit(void)
     int i;
 
 #ifdef XWIN_GLX_WINDOWS
-    if ((g_fNativeGl) && (serverGeneration == 1)) {
+    if (g_fNativeGl) {
         /* install the native GL provider */
         glxWinPushNativeProvider();
     }
@@ -901,7 +901,8 @@ InitOutput(ScreenInfo * screenInfo, int argc, char *argv[])
 {
     int i;
 
-    XwinExtensionInit();
+    if (serverGeneration == 1)
+        XwinExtensionInit();
 
     /* Log the command line */
     winLogCommandLine(argc, argv);
commit cdd7413bbe1d8b9b64f5315ecd5ba5cdcba38a2c
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Sun Sep 2 14:55:25 2012 +0100

    Correct description of -displayfd option in man page.
    
    A display number, not a port number, is written to the specified fd.
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    (cherry picked from commit 7ceb85481280fecbf033f147f0f7834cad3890c6)

diff --git a/man/Xserver.man b/man/Xserver.man
index 8d243d6..b103551 100644
--- a/man/Xserver.man
+++ b/man/Xserver.man
@@ -130,7 +130,7 @@ causes the server to generate a core dump on fatal errors.
 .B \-displayfd \fIfd\fP
 specifies a file descriptor in the launching process.  Rather than specify
 a display number, the X server will attempt to listen on successively higher
-display numbers, and upon finding a free one, will write the port number back
+display numbers, and upon finding a free one, will write the display number back
 on this file descriptor as a newline-terminated string.  The \-pn option is
 ignored when using \-displayfd.
 .TP 8
commit 8f39a6b0b35764c8d5cac4c7bf66d5902c0ae9a5
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Oct 3 13:12:27 2012 +1000

    xfree86: add xf86UpdateDesktopDimensions()
    
    This call is required for external drivers (specifically NVIDIA) that do
    not share the xfree86 infrastructure to update the desktop dimensions.
    Without it, the driver would update the ScreenRecs but not update the total
    dimensions the input code relies on for transformation.
    
    This call is a thin wrapper around the already-existing internal call and
    should be backported to all stable series servers, with the minor ABI bump.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    CC: Andy Ritger <aritger at nvidia.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
    (cherry picked from commit 0a75bd640b3dc26b89d9e342999a7f4b7e98edbf)
    
    Conflicts:
    	hw/xfree86/common/xf86Module.h

diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index bb2903d..74da438 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -468,4 +468,8 @@ extern _X_EXPORT ScreenPtr xf86ScrnToScreen(ScrnInfoPtr pScrn);
 /* flags passed to xf86 allocate screen */
 #define XF86_ALLOCATE_GPU_SCREEN 1
 
+/* Update the internal total dimensions of all ScreenRecs together */
+extern _X_EXPORT void
+xf86UpdateDesktopDimensions(void);
+
 #endif                          /* _XF86_H */
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index f681a85..721159d 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1898,3 +1898,9 @@ xf86ScrnToScreen(ScrnInfoPtr pScrn)
         return screenInfo.screens[pScrn->scrnIndex];
     }
 }
+
+void
+xf86UpdateDesktopDimensions(void)
+{
+    update_desktop_dimensions();
+}
diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index 83f9790..f58b87e 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -80,7 +80,7 @@ typedef enum {
  * mask is 0xFFFF0000.
  */
 #define ABI_ANSIC_VERSION	SET_ABI_VERSION(0, 4)
-#define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(13, 0)
+#define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(13, 1)
 #define ABI_XINPUT_VERSION	SET_ABI_VERSION(18, 0)
 #define ABI_EXTENSION_VERSION	SET_ABI_VERSION(7, 0)
 #define ABI_FONT_VERSION	SET_ABI_VERSION(0, 6)
commit bea56fc9c460309c676e2ead2080be923d1061dc
Author: Yufeng Shen <miletus at chromium.org>
Date:   Mon Sep 24 14:03:31 2012 -0400

    dix: fix scale_to_desktop for edge ABS events
    
    Scale_to_desktop() converts ABS events from device coordinates
    to screen coordinates:
    [dev_X_min, dev_X_max]  -> [screen_X_min, screen_X_max]
    [dev_Y_min, dev_Y_max]  -> [screen_Y_min, screen_Y_max]
    
    An edge ABS event with X = dev_X_max (e.g., generated from the
    edge of a touchscreen) will be converted to have screen X value
    = screen_X_max, which, however, will be filterd out when xserver
    tries to find proper Window to receive the event, because the
    range check for a Window to receive events is
           window_X_min <= event_screen_X < window_X_max
    Events with event_screen_X = screen_X_max will fail the test get
    and rejected by the Window.
    
    To fix this, we change the device to screen coordinates mapping to
    [dev_X_min, dev_X_max]  -> [screen_X_min, screen_X_max-1]
    [dev_Y_min, dev_Y_max]  -> [screen_Y_min, screen_Y_max-1]
    
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    Signed-off-by: Yufeng Shen <miletus at chromium.org>
    Signed-off-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit 0b02150c27e98f996e10d7489f9f67a30e4e3497)

diff --git a/dix/getevents.c b/dix/getevents.c
index 4e62507..71d83c4 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -896,9 +896,9 @@ scale_to_desktop(DeviceIntPtr dev, ValuatorMask *mask,
 
     /* scale x&y to desktop coordinates */
     *screenx = rescaleValuatorAxis(x, dev->valuator->axes + 0, NULL,
-                                   screenInfo.x, screenInfo.width);
+                                   screenInfo.x, screenInfo.width - 1);
     *screeny = rescaleValuatorAxis(y, dev->valuator->axes + 1, NULL,
-                                   screenInfo.y, screenInfo.height);
+                                   screenInfo.y, screenInfo.height - 1);
 
     *devx = x;
     *devy = y;
commit f9709b8a63c70fd772286000757c8348a6ad5e1d
Author: Daniel Drake <dsd at laptop.org>
Date:   Fri Sep 7 21:48:35 2012 -0400

    Xi: Don't check for TOUCH_END, it's never set
    
    This flag is never set, so checking for it here means that we'll
    never release the simulated mouse button press after the user touches
    (and releases) the touchscreen for the first time.
    
    Fixes a problem where the XO laptop touchpad became totally
    unusable after touching the screen for the first time (since X then
    behaved as if the mouse button was held down all the time).
    
    Signed-off-by: Daniel Drake <dsd at laptop.org>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    (cherry picked from commit 3e6358ee6c33979329b78fe2097a1fdf76fb69cd)

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 494d07e..6ed4991 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -949,8 +949,6 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent *event)
 
         if (!(event->flags & TOUCH_POINTER_EMULATED))
             return DONT_PROCESS;
-        if (!(event->flags & TOUCH_END))
-            return DONT_PROCESS;
 
         DecreaseButtonCount(device, key, &t->buttonsDown, &t->motionMask,
                             &t->state);
commit f5fad30822ecd4d9767fd8078221910fbf038811
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Sep 28 11:49:29 2012 +1000

    dix: fix crash on XI 1.x grabs on disabled devices.  (#54934)
    
    If the device is disabled, the sprite window is NULL and dereferencing
    crashes the server.
    
    This is only triggered for XI 1.x grabs (ProcXGrabDevice) as XI2 grabs would
    trigger another code path, creating a sprite for the disabled device as if
    detaching it (which is wrong and fixed with this patch too).
    
    Grabbing a disabled device doesn't make sense as it won't send events
    anyway. However, the protocol specs do not prohibit it, so we need to keep
    it working.
    Luckily, oldWin is only used for focus out events, which aren't necessary
    given that the device is disabled.
    
    X.Org Bug 54934 <http://bugs.freedesktop.org/show_bug.cgi?id=54934>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at ubuntu.com>
    (cherry picked from commit 9d6b8365702e4648e793fea21ad22f7174558680)

diff --git a/dix/events.c b/dix/events.c
index 3b40446..c0e330b 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1555,11 +1555,13 @@ ActivateKeyboardGrab(DeviceIntPtr keybd, GrabPtr grab, TimeStamp time,
     WindowPtr oldWin;
 
     /* slave devices need to float for the duration of the grab. */
-    if (grab->grabtype == XI2 &&
+    if (grab->grabtype == XI2 && keybd->enabled &&
         !(passive & ImplicitGrabMask) && !IsMaster(keybd))
         DetachFromMaster(keybd);
 
-    if (grabinfo->grab)
+    if (!keybd->enabled)
+        oldWin = NULL;
+    else if (grabinfo->grab)
         oldWin = grabinfo->grab->window;
     else if (keybd->focus)
         oldWin = keybd->focus->win;
@@ -1569,7 +1571,8 @@ ActivateKeyboardGrab(DeviceIntPtr keybd, GrabPtr grab, TimeStamp time,
         oldWin = keybd->focus->win;
     if (keybd->valuator)
         keybd->valuator->motionHintWindow = NullWindow;
-    DoFocusEvents(keybd, oldWin, grab->window, NotifyGrab);
+    if (oldWin)
+        DoFocusEvents(keybd, oldWin, grab->window, NotifyGrab);
     if (syncEvents.playingEvents)
         grabinfo->grabTime = syncEvents.time;
     else
commit aacfc321b44eae15020875a2b2c9b6ff0e14dd8c
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Fri Sep 7 18:17:46 2012 +0100

    Touch: Fix duplicate TouchBegin selection with virtual devices
    
    Given the following scenario:
      1) client A selects for TouchBegin on window W for device D
      2) client B selects for TouchBegin on window W for XIAllDevices
      3) client C selects for TouchBegin on window W with device E
    
    Step 3 will fail with BadImplementation, because attempting to look up
    XIAllDevices or XIAllMasterDevices with dixLookupDevices doesn't work.
    This should succeed (or, if it was selecting for device D, fail with
    BadAccess as it would be a duplicate selection).
    
    Fix this by performing the appropriate lookup for virtual devices.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Chase Douglas <chase.douglas at ubuntu.com>
    (cherry picked from commit 3d2b768efae9936c6929c2bc13c7a1acc074ecd3)

diff --git a/Xi/xiselectev.c b/Xi/xiselectev.c
index 0e45cb8..ab1b624 100644
--- a/Xi/xiselectev.c
+++ b/Xi/xiselectev.c
@@ -180,8 +180,13 @@ ProcXISelectEvents(ClientPtr client)
                     if (CLIENT_ID(iclient->resource) == client->index)
                         continue;
 
-                    dixLookupDevice(&tmp, evmask->deviceid, serverClient,
-                                    DixReadAccess);
+                    if (evmask->deviceid == XIAllDevices)
+                        tmp = inputInfo.all_devices;
+                    else if (evmask->deviceid == XIAllMasterDevices)
+                        tmp = inputInfo.all_master_devices;
+                    else
+                        dixLookupDevice(&tmp, evmask->deviceid, serverClient,
+                                        DixReadAccess);
                     if (!tmp)
                         return BadImplementation;       /* this shouldn't happen */
 
commit e31e272f4fc8b2aa8e2101b89bb65bc1d6a5e1be
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Sep 20 05:56:39 2012 +1000

    dix: set the device transformation matrix
    
    The property handler is registered after setting the property, so
    dev->transform remains as all-zeros. That causes pixman_f_transform_invert()
    to fail (in transformAbsolute()) and invert remains as garbage. This
    may then cause a cursor jump to 0,0.
    
    Since the axes are not yet initialized here and we need to allow for drivers
    changing the matrix, we cannot use the property handler for matrix
    initialization, essentially duplicating the code.
    
    Triggered by the fix to (#49347) in 749a593e49adccdf1225be28a521412ec85333f4
    
    https://bugzilla.redhat.com/show_bug.cgi?id=852841
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at ubuntu.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>
    (cherry picked from commit 3d1051aecbb1955084804133cacd12c7f696833a)

diff --git a/dix/devices.c b/dix/devices.c
index 9cf04ed..66d4406 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -306,6 +306,9 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart)
     /* unity matrix */
     memset(transform, 0, sizeof(transform));
     transform[0] = transform[4] = transform[8] = 1.0f;
+    dev->transform.m[0][0] = 1.0;
+    dev->transform.m[1][1] = 1.0;
+    dev->transform.m[2][2] = 1.0;
 
     XIChangeDeviceProperty(dev, XIGetKnownProperty(XI_PROP_TRANSFORM),
                            XIGetKnownProperty(XATOM_FLOAT), 32,


More information about the Xquartz-changes mailing list