xserver: Branch 'xwayland' - 40 commits

Kristian Høgsberg krh at kemper.freedesktop.org
Fri Sep 6 15:33:21 PDT 2013


Rebased ref, commits from common ancestor:
commit 37be48d9273cc0695f425492db51be55def25fb2
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Fri Aug 16 13:51:08 2013 +0100

    XWayland: Support 16bpp X surfaces in DRM/SHM
    
    Properly look at the window's visual to determine which format we should
    use for allocation.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/xwayland/xwayland-drm.c b/hw/xfree86/xwayland/xwayland-drm.c
index bfa0b74..428711b 100644
--- a/hw/xfree86/xwayland/xwayland-drm.c
+++ b/hw/xfree86/xwayland/xwayland-drm.c
@@ -225,10 +225,18 @@ xwl_create_window_buffer_drm(struct xwl_window *xwl_window,
 	if (screen->visuals[i].vid == visual)
 	    break;
 
-    if (screen->visuals[i].nplanes == 32)
+    switch (screen->visuals[i].nplanes) {
+    case 32:
 	format = WL_DRM_FORMAT_ARGB8888;
-    else
+        break;
+    case 24:
+    default:
 	format = WL_DRM_FORMAT_XRGB8888;
+        break;
+    case 16:
+        format = WL_DRM_FORMAT_RGB565;
+        break;
+    }
 
     xwl_window->buffer =
       wl_drm_create_buffer(xwl_window->xwl_screen->drm,
diff --git a/hw/xfree86/xwayland/xwayland.c b/hw/xfree86/xwayland/xwayland.c
index 6a515f5..36f7cbf 100644
--- a/hw/xfree86/xwayland/xwayland.c
+++ b/hw/xfree86/xwayland/xwayland.c
@@ -277,19 +277,43 @@ xwl_create_window_buffer_shm(struct xwl_window *xwl_window,
 			     PixmapPtr pixmap, int fd)
 {
     struct wl_shm_pool *pool;
-    int size, stride;
+    WindowPtr window = xwl_window->window;
+    ScreenPtr screen = window->drawable.pScreen;
+    VisualID visual = wVisual(window);
+    uint32_t format;
+    int size, stride, bpp, i;
+
+    for (i = 0; i < screen->numVisuals; i++)
+        if (screen->visuals[i].vid == visual)
+            break;
+
+    switch (screen->visuals[i].nplanes) {
+    case 32:
+        format = WL_SHM_FORMAT_ARGB8888;
+        bpp = 4;
+        break;
+    case 24:
+    default:
+        format = WL_SHM_FORMAT_XRGB8888;
+        bpp = 4;
+        break;
+#ifdef WL_SHM_FORMAT_RGB565
+    case 16:
+        /* XXX: Check run-time protocol version too */
+        format = WL_SHM_FORMAT_RGB565;
+        bpp = 2;
+        break;
+#endif
+    }
 
-    stride = pixmap->drawable.width * 4;
+    stride = pixmap->drawable.width * bpp;
+    size = stride * pixmap->drawable.height;
 
-    size = pixmap->drawable.width * pixmap->drawable.height * 4;
     pool = wl_shm_create_pool(xwl_window->xwl_screen->shm, fd, size);
     xwl_window->buffer =  wl_shm_pool_create_buffer(pool, 0,
 			   pixmap->drawable.width,
 			   pixmap->drawable.height,
-			   stride,
-			   pixmap->drawable.depth == 32 ?
-			   WL_SHM_FORMAT_ARGB8888 :
-			   WL_SHM_FORMAT_XRGB8888);
+			   stride, format);
     wl_shm_pool_destroy(pool);
 
     return xwl_window->buffer ? Success : BadDrawable;
commit 308512cf23835ec7c95ea6e524d178dc6835ebb8
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Fri Aug 16 13:20:39 2013 +0100

    XFree86: Only run Wayland code if building support
    
    i.e. hide xorgWayland usage behind #ifdef XORG_WAYLAND.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index c68b8db..ee19fc4 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -118,7 +118,9 @@ static ModuleDefault ModuleDefaults[] = {
     {.name = "fb",.toLoad = TRUE,.load_opt = NULL},
     {.name = "shadow",.toLoad = TRUE,.load_opt = NULL},
 #endif
+#ifdef XORG_WAYLAND
     {.name = "xwayland",.toLoad = FALSE,.load_opt=NULL},
+#endif
     {.name = NULL,.toLoad = FALSE,.load_opt=NULL}
 };
 
@@ -264,6 +266,7 @@ xf86ModulelistFromConfig(pointer **optlist)
     /*
      * Set the xwayland module to autoload if requested.
      */
+#ifdef XORG_WAYLAND
     if (xorgWayland) {
         for (i=0 ; ModuleDefaults[i].name != NULL ; i++) {
             if (strcmp(ModuleDefaults[i].name, "xwayland") == 0) {
@@ -271,7 +274,8 @@ xf86ModulelistFromConfig(pointer **optlist)
             }
         }
     }
-    
+#endif
+
     if (xf86configptr->conf_modules) {
         /* Walk the disable list and let people know what we've parsed to
          * not be loaded 
@@ -887,10 +891,12 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
             xf86Info.autoAddGPU ? "A" : "Not a");
 
     /* FIXME: Do that at the right place (before xf86Msg). */
+#ifdef XORG_WAYLAND
     if (xorgWayland) {
             xf86Info.autoAddDevices = FALSE;
             xf86Info.autoEnableDevices = FALSE;
     }
+#endif
 
     /*
      * Set things up based on the config file information.  Some of these
@@ -982,9 +988,11 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
     }
 #endif
 
+#ifdef XORG_WAYLAND
     if (xorgWayland) /* Don't force input devices */
 	xf86Info.forceInputDevices = FALSE;
     else /* if we're not hotplugging, force some input devices to exist */
+#endif
 	xf86Info.forceInputDevices = !(xf86Info.autoAddDevices && xf86Info.autoEnableDevices);
 
     /* when forcing input devices, we use kbd. otherwise evdev, so use the
commit 3b70231c7afe74067921da8a24dd5c0b8472bfa7
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Nov 7 17:15:13 2012 +1100

    XWayland: Don't hardcode DRM libs and -lwayland-client
    
    Take -lwayland-client from configure.ac, and only use DRM if we've
    actually asked for it.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/xwayland/Makefile.am b/hw/xfree86/xwayland/Makefile.am
index b739145..22ab154 100644
--- a/hw/xfree86/xwayland/Makefile.am
+++ b/hw/xfree86/xwayland/Makefile.am
@@ -7,13 +7,13 @@ AM_CPPFLAGS =					\
 	-I$(srcdir)/../modes
 
 libxwayland_la_LTLIBRARIES = libxwayland.la
-libxwayland_la_CFLAGS = \
+AM_CFLAGS = \
 	-DHAVE_XORG_CONFIG_H \
-	@DIX_CFLAGS@ @XORG_CFLAGS@ @LIBDRM_CFLAGS@ \
+	@DIX_CFLAGS@ @XORG_CFLAGS@ @XWAYLAND_CFLAGS@ \
 	-I$(top_srcdir)/hw/xfree86/common \
 	-I$(top_srcdir)/hw/xfree86/os-support/bus
 
-libxwayland_la_LDFLAGS = -module -avoid-version @LIBDRM_LIBS@ -lwayland-client
+libxwayland_la_LDFLAGS = -module -avoid-version @XWAYLAND_LIBS@
 libxwayland_ladir = $(moduledir)/extensions
 libxwayland_la_SOURCES =			\
 	xwayland.c				\
@@ -28,6 +28,8 @@ libxwayland_la_SOURCES =			\
 	xserver-protocol.c
 
 if DRM
+AM_CFLAGS += @LIBDRM_CFLAGS@
+libxwayland_la_LDFLAGS += @LIBDRM_LIBS@
 libxwayland_la_SOURCES += xwayland-drm.c
 endif
 
commit effdcec86df9508047e6c8ba30e9f081992cface
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Oct 16 17:14:01 2012 +1100

    xwayland: Introduce an auto mode for --enable-wayland
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/configure.ac b/configure.ac
index 6863d17..fd46b1b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -635,7 +635,7 @@ AC_ARG_ENABLE(windowswm,      AS_HELP_STRING([--enable-windowswm], [Build XWin w
 AC_ARG_ENABLE(libdrm,         AS_HELP_STRING([--enable-libdrm], [Build Xorg with libdrm support (default: enabled)]), [DRM=$enableval],[DRM=yes])
 AC_ARG_ENABLE(clientids,      AS_HELP_STRING([--disable-clientids], [Build Xorg with client ID tracking (default: enabled)]), [CLIENTIDS=$enableval], [CLIENTIDS=yes])
 AC_ARG_ENABLE(pciaccess, AS_HELP_STRING([--enable-pciaccess], [Build Xorg with pciaccess library (default: enabled)]), [PCI=$enableval], [PCI=yes])
-AC_ARG_ENABLE(wayland,      AS_HELP_STRING([--disable-wayland], [Build Wayland extension (default: enabled)]), [WAYLAND=$enableval], [WAYLAND=yes])
+AC_ARG_ENABLE(wayland,      AS_HELP_STRING([--disable-wayland], [Build Wayland extension (default: auto)]), [WAYLAND=$enableval], [WAYLAND=auto])
 
 dnl DDXes.
 AC_ARG_ENABLE(xorg,    	      AS_HELP_STRING([--enable-xorg], [Build Xorg server (default: auto)]), [XORG=$enableval], [XORG=auto])
@@ -1020,12 +1020,16 @@ if test "x$MITSHM" = xauto; then
 	MITSHM="$ac_cv_sysv_ipc"
 fi
 
-AM_CONDITIONAL(WAYLAND, [test "x$WAYLAND" = xyes])
+WAYLAND_MODULES="wayland-client libdrm"
+if test "x$WAYLAND" = xauto; then
+        PKG_CHECK_MODULES(XWAYLAND, $WAYLAND_MODULES, [WAYLAND=yes], [WAYLAND=no]) 
+fi
 if test "x$WAYLAND" = xyes; then
+        PKG_CHECK_MODULES(XWAYLAND, $WAYLAND_MODULES)
 	AC_DEFINE(XORG_WAYLAND, 1, [Support wayland mode])
-	REQUIRED_MODULES="$REQUIRED_MODULES wayland-client"
 	WAYLAND_SCANNER_RULES(['$(top_srcdir)/hw/xfree86/xwayland'])
 fi
+AM_CONDITIONAL(WAYLAND, [test "x$WAYLAND" = xyes])
 
 AM_CONDITIONAL(MITSHM, [test "x$MITSHM" = xyes])
 if test "x$MITSHM" = xyes; then
commit 7dd6b4b54d63d804fadab5ea4e27c5eb6105fcab
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Nov 7 17:22:42 2012 +1100

    XWayland: Don't send out-of-bounds damage co-ordinates
    
    Make sure we don't send damage regions larger than the buffer.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/xwayland/xwayland.c b/hw/xfree86/xwayland/xwayland.c
index 2047a85..6a515f5 100644
--- a/hw/xfree86/xwayland/xwayland.c
+++ b/hw/xfree86/xwayland/xwayland.c
@@ -346,15 +346,14 @@ void xwl_screen_post_damage(struct xwl_screen *xwl_screen)
 
     xorg_list_for_each_entry(xwl_window, &xwl_screen->damage_window_list,
 			     link_damage) {
-
 	region = DamageRegion(xwl_window->damage);
 	count = RegionNumRects(region);
 	for (i = 0; i < count; i++) {
 	    box = &RegionRects(region)[i];
 	    wl_surface_damage(xwl_window->surface,
 			      box->x1, box->y1,
-			      box->x2 - box->x1 + 1,
-			      box->y2 - box->y1 + 1);
+			      box->x2 - box->x1,
+			      box->y2 - box->y1);
 	}
 	wl_surface_attach(xwl_window->surface,
 			  xwl_window->buffer,
commit 28e8031cf6a23ef6a6333aea60389820931c36b8
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Fri Aug 16 13:21:21 2013 +0100

    XFree86: Load wlshm driver as fallback for Wayland
    
    Since fbdev or vesa are unlikely to be too useful there ...
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c
index 95d58fe..d5a3370 100644
--- a/hw/xfree86/common/xf86AutoConfig.c
+++ b/hw/xfree86/common/xf86AutoConfig.c
@@ -283,10 +283,15 @@ listPossibleVideoDrivers(char *matches[], int nmatches)
 #if !defined(sun)
     /* Fallback to platform default frame buffer driver */
     if (i < (nmatches - 1)) {
+#ifdef XORG_WAYLAND
+        if (xorgWayland)
+            matches[i++] = xnfstrdup("wlshm");
+        else
+#endif
 #if !defined(__linux__) && defined(__sparc__)
-        matches[i++] = xnfstrdup("wsfb");
+            matches[i++] = xnfstrdup("wsfb");
 #else
-        matches[i++] = xnfstrdup("fbdev");
+            matches[i++] = xnfstrdup("fbdev");
 #endif
     }
 #endif                          /* !sun */
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 5b5cbac..c68b8db 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -519,7 +519,11 @@ xf86InputDriverlistFromConfig(void)
 static void
 fixup_video_driver_list(char **drivers)
 {
-    static const char *fallback[4] = { "vesa", "fbdev", "wsfb", NULL };
+    static const char *fallback_hw[4] = { "vesa", "fbdev", "wsfb", NULL };
+#ifdef XORG_WAYLAND
+    static const char *fallback_wayland[2] = { "wlshm", NULL };
+#endif
+    const char **fallbacks;
     char **end, **drv;
     char *x;
     int i;
@@ -532,9 +536,15 @@ fixup_video_driver_list(char **drivers)
      * for each of the fallback drivers, if we find it in the list,
      * swap it with the last available non-fallback driver.
      */
-    for (i = 0; fallback[i]; i++) {
+#ifdef XORG_WAYLAND
+    if (xorgWayland)
+        fallbacks = fallback_wl;
+    else
+#endif
+        fallbacks = fallback_hw;
+    for (i = 0; fallbacks[i]; i++) {
         for (drv = drivers; drv != end; drv++) {
-            if (strstr(*drv, fallback[i])) {
+            if (strstr(*drv, fallbacks[i])) {
                 x = *drv;
                 *drv = *end;
                 *end = x;
commit 5071479b4e32a1dc3c1fecb0ad6469d510d6b599
Author: Jonas Ã…dahl <jadahl at gmail.com>
Date:   Sun Sep 1 23:14:43 2013 +0200

    xwayland: Probe outputs on preinit
    
    When running xwayland, calls to xf86SetDesiredModes() would fail due to
    the probed modes list not being populated. This was previously done
    indirectly by calling xf86InitialConfiguration() and now needs to be
    done explicitly instead.
    
    Signed-off-by: Jonas Ã…dahl <jadahl at gmail.com>

diff --git a/hw/xfree86/xwayland/xwayland-output.c b/hw/xfree86/xwayland/xwayland-output.c
index 28003ba..53829c3 100644
--- a/hw/xfree86/xwayland/xwayland-output.c
+++ b/hw/xfree86/xwayland/xwayland-output.c
@@ -431,6 +431,8 @@ xwayland_screen_preinit_output(struct xwl_screen *xwl_screen, ScrnInfoPtr scrnin
             FatalError("failed to dispatch Wayland events: %s\n", strerror(errno));
     }
 
+    xf86ProbeOutputModes(scrninfo, 0, 0);
+
     xwl_screen->outputs_initialized = TRUE;
 
     xf86SetScrnInfoModes(scrninfo);
commit 74d617e86852c83d97deec7712b076be48a8dba1
Author: Giovanni Campagna <gcampagn at redhat.com>
Date:   Thu Aug 22 16:23:48 2013 +0200

    xwayland: add support for multiple outputs
    
    Drop xf86InitialConfiguration, which just gets in the way
    of the compositor doing its own output arrangement, and transform
    wayland events into the appropriate low-level xf86 calls to
    keep the screen size updated.
    
    Kristian: after the rebase it was crashing for me too, had to fix
    the patch a bit. This one should work, and also gives sensible (though
    not perfect) results for xrandr clients.
    Tested with weston/x11 and mutter-wayland/kms.

diff --git a/hw/xfree86/xwayland/xwayland-output.c b/hw/xfree86/xwayland/xwayland-output.c
index 3cfeb7f..28003ba 100644
--- a/hw/xfree86/xwayland/xwayland-output.c
+++ b/hw/xfree86/xwayland/xwayland-output.c
@@ -36,6 +36,7 @@
 #include <cursorstr.h>
 #include <xf86Crtc.h>
 #include <mipointrst.h>
+#include <randrstr.h>
 
 #include "xwayland.h"
 #include "xwayland-private.h"
@@ -182,6 +183,10 @@ xwl_output_create(struct xwl_screen *xwl_screen)
     struct xwl_output *xwl_output;
     xf86OutputPtr xf86output;
     xf86CrtcPtr xf86crtc;
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(xwl_screen->scrninfo);
+    int crtcId, outputId;
+    static int nameId;
+    char *name;
 
     xwl_output = calloc(sizeof *xwl_output, 1);
     if (xwl_output == NULL) {
@@ -189,19 +194,41 @@ xwl_output_create(struct xwl_screen *xwl_screen)
 	return NULL;
     }
 
+    nameId++;
+    if (asprintf(&name, "XWAYLAND-%d", nameId) < 0) {
+        ErrorF("create_output ENOMEM");
+        free(xwl_output);
+        return NULL;
+    }
+
     xwl_output->xwl_screen = xwl_screen;
 
+    xf86crtc = xf86CrtcCreate(xwl_screen->scrninfo, &crtc_funcs);
+    xf86crtc->enabled = TRUE;
+    xf86crtc->driver_private = xwl_output;
+
+    for (crtcId = 0; crtcId < xf86_config->num_crtc; crtcId++) {
+        if (xf86_config->crtc[crtcId] == xf86crtc)
+            break;
+    }
+
     xf86output = xf86OutputCreate(xwl_screen->scrninfo,
-				  &output_funcs, "XWAYLAND-1");
+				  &output_funcs, name);
     xf86output->driver_private = xwl_output;
-    xf86output->possible_crtcs = 1;
-    xf86output->possible_clones = 1;
+    xf86output->possible_crtcs = 1 << crtcId;
 
-    xf86crtc = xf86CrtcCreate(xwl_screen->scrninfo, &crtc_funcs);
-    xf86crtc->driver_private = xwl_output;
+    for (outputId = 0; outputId < xf86_config->num_output; outputId++) {
+        if (xf86_config->output[outputId] == xf86output)
+            break;
+    }
+
+    xf86output->possible_clones = 1 << outputId;
 
     xwl_output->xf86output = xf86output;
     xwl_output->xf86crtc = xf86crtc;
+    xwl_output->xf86output->crtc = xf86crtc;
+
+    free(name);
 
     return xwl_output;
 }
@@ -219,6 +246,32 @@ static const xf86CrtcConfigFuncsRec config_funcs = {
     resize
 };
 
+static Rotation
+wl_transform_to_xrandr (enum wl_output_transform transform)
+{
+  switch (transform)
+    {
+    case WL_OUTPUT_TRANSFORM_NORMAL:
+      return RR_Rotate_0;
+    case WL_OUTPUT_TRANSFORM_90:
+      return RR_Rotate_90;
+    case WL_OUTPUT_TRANSFORM_180:
+      return RR_Rotate_180;
+    case WL_OUTPUT_TRANSFORM_270:
+      return RR_Rotate_270;
+    case WL_OUTPUT_TRANSFORM_FLIPPED:
+      return RR_Reflect_X | RR_Rotate_0;
+    case WL_OUTPUT_TRANSFORM_FLIPPED_90:
+      return RR_Reflect_X | RR_Rotate_90;
+    case WL_OUTPUT_TRANSFORM_FLIPPED_180:
+      return RR_Reflect_X | RR_Rotate_180;
+    case WL_OUTPUT_TRANSFORM_FLIPPED_270:
+      return RR_Reflect_X | RR_Rotate_270;
+    }
+
+  return RR_Rotate_0;
+}
+
 static void
 display_handle_geometry(void *data, struct wl_output *wl_output, int x, int y,
 			int physical_width, int physical_height, int subpixel,
@@ -253,6 +306,7 @@ display_handle_geometry(void *data, struct wl_output *wl_output, int x, int y,
 
     xwl_output->x = x;
     xwl_output->y = y;
+    xwl_output->rotation = wl_transform_to_xrandr (transform);
 
     xorg_list_append (&xwl_output->link, &xwl_screen->output_list);
 }
@@ -262,11 +316,49 @@ display_handle_mode(void *data, struct wl_output *wl_output, uint32_t flags,
 		    int width, int height, int refresh)
 {
     struct xwl_output *xwl_output = data;
+    struct xwl_screen *xwl_screen = xwl_output->xwl_screen;
+    ScreenPtr pScreen = xwl_screen->screen;
+    ScrnInfoPtr scrn = xwl_screen->scrninfo;
+    CARD16 width_mm, height_mm;
+    DisplayModePtr mode;
+    rrScrPrivPtr rp;
 
-    if (flags & WL_OUTPUT_MODE_CURRENT) {
-	xwl_output->width = width;
-	xwl_output->height = height;
+    if (!(flags & WL_OUTPUT_MODE_CURRENT))
+	return;
+
+    xwl_output->width = width;
+    xwl_output->height = height;
+
+    if (xwl_output->x + xwl_output->width > scrn->virtualX ||
+	xwl_output->y + xwl_output->height > scrn->virtualY) {
+	/* Fake a RandR request to resize the screen. It will bounce
+	   back to our crtc_resize, which does nothing.
+	*/
+	/* Preupdate virtualX / virtualY, so that crtc_resize returns TRUE */
+	scrn->virtualX = xwl_output->x + xwl_output->width;
+	scrn->virtualY = xwl_output->y + xwl_output->height;
+
+	/* Ignore the compositor provided values for mm_width/mm_height,
+	   as it doesn't make sense to sum the values of different outputs.
+	   Just make the DPI 96 */
+	width_mm = (scrn->virtualX / 96.0) * 25.4 + 0.5;
+	height_mm = (scrn->virtualY / 96.0) * 25.4 + 0.5;
+
+	/* But! When the server starts, the RandR stuff is not initialized,
+	   so we can't call rrGetScrPriv. We updated virtualX/Y anyway, let's
+	   hope it's enough.
+	*/
+	if (xwl_screen->outputs_initialized) {
+	    rp = rrGetScrPriv(pScreen);
+	    if (rp->rrScreenSetSize)
+		rp->rrScreenSetSize(pScreen, scrn->virtualX, scrn->virtualY, width_mm, height_mm);
+	}
     }
+
+    xwl_output->xf86crtc->enabled = TRUE;
+    mode = xf86CVTMode(width, height, refresh, TRUE, FALSE);
+    xf86CrtcSetModeTransform(xwl_output->xf86crtc, mode, xwl_output->rotation,
+                             NULL, xwl_output->x, xwl_output->y);
 }
 
 static const struct wl_output_listener output_listener = {
@@ -339,5 +431,7 @@ xwayland_screen_preinit_output(struct xwl_screen *xwl_screen, ScrnInfoPtr scrnin
             FatalError("failed to dispatch Wayland events: %s\n", strerror(errno));
     }
 
-    xf86InitialConfiguration(scrninfo, TRUE);
+    xwl_screen->outputs_initialized = TRUE;
+
+    xf86SetScrnInfoModes(scrninfo);
 }
diff --git a/hw/xfree86/xwayland/xwayland-private.h b/hw/xfree86/xwayland/xwayland-private.h
index 7005db2..b0b2201 100644
--- a/hw/xfree86/xwayland/xwayland-private.h
+++ b/hw/xfree86/xwayland/xwayland-private.h
@@ -63,6 +63,7 @@ struct xwl_screen {
     struct xorg_list		 window_list;
     struct xorg_list		 authenticate_client_list;
     uint32_t			 serial;
+    Bool                         outputs_initialized;
 
     CreateWindowProcPtr		 CreateWindow;
     DestroyWindowProcPtr	 DestroyWindow;
@@ -82,6 +83,7 @@ struct xwl_output {
     xf86OutputPtr		 xf86output;
     xf86CrtcPtr			 xf86crtc;
     int32_t                      name;
+    Rotation                     rotation;
 };
 
 
commit 744ffc9aaee0c5a1d6a60d9ee9001ebe9bef1823
Author: Giovanni Campagna <gcampagn at redhat.com>
Date:   Wed Aug 21 09:53:26 2013 +0200

    xwayland: handle global object destruction
    
    Certain global objects, such as outputs, can be destroyed during
    the session. We must handle that and not crash.

diff --git a/hw/xfree86/xwayland/xwayland-drm.c b/hw/xfree86/xwayland/xwayland-drm.c
index 1514ef5..bfa0b74 100644
--- a/hw/xfree86/xwayland/xwayland-drm.c
+++ b/hw/xfree86/xwayland/xwayland-drm.c
@@ -119,8 +119,15 @@ drm_handler(void *data, struct wl_registry *registry, uint32_t id,
     }
 }
 
+static void
+global_remove(void *data, struct wl_registry *registry, uint32_t name)
+{
+    /* Nothing to do here, wl_drm should not be removed */
+}
+
 static const struct wl_registry_listener drm_listener = {
     drm_handler,
+    global_remove
 };
 
 int
diff --git a/hw/xfree86/xwayland/xwayland-input.c b/hw/xfree86/xwayland/xwayland-input.c
index 2f8e0c7..d031b34 100644
--- a/hw/xfree86/xwayland/xwayland-input.c
+++ b/hw/xfree86/xwayland/xwayland-input.c
@@ -597,8 +597,15 @@ input_handler(void *data, struct wl_registry *registry, uint32_t id,
     }
 }
 
+static void
+global_remove(void *data, struct wl_registry *registry, uint32_t name)
+{
+    /* FIXME */
+}
+
 static const struct wl_registry_listener input_listener = {
     input_handler,
+    global_remove,
 };
 
 void
diff --git a/hw/xfree86/xwayland/xwayland-output.c b/hw/xfree86/xwayland/xwayland-output.c
index 8f087f6..3cfeb7f 100644
--- a/hw/xfree86/xwayland/xwayland-output.c
+++ b/hw/xfree86/xwayland/xwayland-output.c
@@ -95,6 +95,14 @@ crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
 {
 }
 
+static void
+crtc_destroy(xf86CrtcPtr crtc)
+{
+    /* Nothing to do here, we only destroy CRTCs when instructed to do
+       so by wl_output changes
+    */
+}
+
 static const xf86CrtcFuncsRec crtc_funcs = {
     .dpms                = crtc_dpms,
     .set_mode_major      = crtc_set_mode_major,
@@ -106,7 +114,7 @@ static const xf86CrtcFuncsRec crtc_funcs = {
     .shadow_create       = crtc_shadow_create,
     .shadow_allocate     = crtc_shadow_allocate,
     .shadow_destroy      = crtc_shadow_destroy,
-    .destroy		 = NULL, /* XXX */
+    .destroy		 = crtc_destroy,
 };
 
 static void
@@ -246,7 +254,7 @@ display_handle_geometry(void *data, struct wl_output *wl_output, int x, int y,
     xwl_output->x = x;
     xwl_output->y = y;
 
-    xwl_screen->xwl_output = xwl_output;
+    xorg_list_append (&xwl_output->link, &xwl_screen->output_list);
 }
 
 static void
@@ -277,13 +285,39 @@ global_handler(void *data, struct wl_registry *registry, uint32_t id,
 	xwl_output = xwl_output_create(xwl_screen);
 	xwl_output->output = wl_registry_bind(registry, id,
 	                                      &wl_output_interface, 1);
+	xwl_output->name = id;
 	wl_output_add_listener(xwl_output->output,
 			       &output_listener, xwl_output);
     }
 }
 
+void
+xwl_output_remove(struct xwl_output *xwl_output)
+{
+    xorg_list_del (&xwl_output->link);
+    xf86OutputDestroy (xwl_output->xf86output);
+    xf86CrtcDestroy (xwl_output->xf86crtc);
+
+    wl_output_destroy (xwl_output->output);
+}
+
+static void
+global_remove(void *data, struct wl_registry *registry, uint32_t name)
+{
+    struct xwl_screen *xwl_screen = data;
+    struct xwl_output *xwl_output, *tmp;
+
+    xorg_list_for_each_entry_safe (xwl_output, tmp, &xwl_screen->output_list, link) {
+	if (xwl_output->name == name) {
+	    xwl_output_remove(xwl_output);
+	    break;
+	}
+    }
+}  
+
 static const struct wl_registry_listener global_listener = {
     global_handler,
+    global_remove
 };
 
 void
@@ -299,7 +333,7 @@ xwayland_screen_preinit_output(struct xwl_screen *xwl_screen, ScrnInfoPtr scrnin
     wl_registry_add_listener(xwl_screen->output_registry, &global_listener,
                              xwl_screen);
 
-    while (!xwl_screen->xwl_output) {
+    while (xwl_screen->output_list.next == &xwl_screen->output_list) {
         ret = wl_display_roundtrip(xwl_screen->display);
         if (ret == -1)
             FatalError("failed to dispatch Wayland events: %s\n", strerror(errno));
diff --git a/hw/xfree86/xwayland/xwayland-private.h b/hw/xfree86/xwayland/xwayland-private.h
index e427316..7005db2 100644
--- a/hw/xfree86/xwayland/xwayland-private.h
+++ b/hw/xfree86/xwayland/xwayland-private.h
@@ -44,7 +44,6 @@ struct xwl_screen {
     ScrnInfoPtr			 scrninfo;
     int				 drm_fd;
     int				 wayland_fd;
-    struct xwl_output		*xwl_output;
     struct wl_display		*display;
     struct wl_registry          *registry;
     struct wl_registry          *drm_registry;
@@ -58,6 +57,7 @@ struct xwl_screen {
     uint32_t			 flags;
     char			*device_name;
     uint32_t			 authenticated;
+    struct xorg_list		 output_list;
     struct xorg_list		 seat_list;
     struct xorg_list		 damage_window_list;
     struct xorg_list		 window_list;
@@ -74,12 +74,14 @@ struct xwl_screen {
 };
 
 struct xwl_output {
+    struct xorg_list             link;
     struct wl_output		*output;
     struct xwl_screen		*xwl_screen;
     int32_t			 x, y, width, height;
     xf86Monitor			 xf86monitor;
     xf86OutputPtr		 xf86output;
     xf86CrtcPtr			 xf86crtc;
+    int32_t                      name;
 };
 
 
@@ -127,6 +129,8 @@ Bool xwl_drm_initialised(struct xwl_screen *screen);
 
 void xwl_seat_set_cursor(struct xwl_seat *xwl_seat);
 
+void xwl_output_remove(struct xwl_output *output);
+
 extern const struct xserver_listener xwl_server_listener;
 
 #endif /* _XWAYLAND_PRIVATE_H_ */
diff --git a/hw/xfree86/xwayland/xwayland.c b/hw/xfree86/xwayland/xwayland.c
index 880b7ec..2047a85 100644
--- a/hw/xfree86/xwayland/xwayland.c
+++ b/hw/xfree86/xwayland/xwayland.c
@@ -103,8 +103,15 @@ registry_global(void *data, struct wl_registry *registry, uint32_t id,
     }
 }
 
+static void
+global_remove(void *data, struct wl_registry *registry, uint32_t name)
+{
+    /* Nothing to do here, wl_compositor and wl_shm should not be removed */
+}
+
 static const struct wl_registry_listener registry_listener = {
     registry_global,
+    global_remove
 };
 
 static void
@@ -230,6 +237,7 @@ xwl_screen_pre_init(ScrnInfoPtr scrninfo, struct xwl_screen *xwl_screen,
 	return FALSE;
     }
 
+    xorg_list_init(&xwl_screen->output_list);
     xorg_list_init(&xwl_screen->seat_list);
     xorg_list_init(&xwl_screen->damage_window_list);
     xorg_list_init(&xwl_screen->window_list);
@@ -318,12 +326,13 @@ void xwl_screen_close(struct xwl_screen *xwl_screen)
 
 void xwl_screen_destroy(struct xwl_screen *xwl_screen)
 {
-    if (xwl_screen->xwl_output) {
-	xf86OutputDestroy(xwl_screen->xwl_output->xf86output);
-	xf86CrtcDestroy(xwl_screen->xwl_output->xf86crtc);
+    struct xwl_output *xwl_output, *tmp;
+
+    xorg_list_for_each_entry_safe (xwl_output, tmp, &xwl_screen->output_list, link) {
+	xwl_output_remove(xwl_output);
+	break;
     }
 
-    free(xwl_screen->xwl_output);
     free(xwl_screen);
 }
 
commit e5a4d968e3e60544d26dcde0e198662e7fb6d046
Author: Giovanni Campagna <gcampagn at redhat.com>
Date:   Wed Aug 21 09:53:25 2013 +0200

    xwayland-shm: don't create alpha buffers if the window doesn't have alpha
    
    If the window is using a 24 bit visual, we must request a buffer
    format without alpha, or garbage is rendered.

diff --git a/hw/xfree86/xwayland/xwayland.c b/hw/xfree86/xwayland/xwayland.c
index f59bfe4..880b7ec 100644
--- a/hw/xfree86/xwayland/xwayland.c
+++ b/hw/xfree86/xwayland/xwayland.c
@@ -278,7 +278,10 @@ xwl_create_window_buffer_shm(struct xwl_window *xwl_window,
     xwl_window->buffer =  wl_shm_pool_create_buffer(pool, 0,
 			   pixmap->drawable.width,
 			   pixmap->drawable.height,
-			   stride, WL_SHM_FORMAT_ARGB8888);
+			   stride,
+			   pixmap->drawable.depth == 32 ?
+			   WL_SHM_FORMAT_ARGB8888 :
+			   WL_SHM_FORMAT_XRGB8888);
     wl_shm_pool_destroy(pool);
 
     return xwl_window->buffer ? Success : BadDrawable;
commit 1efa0e26bf7f8746aeba5df16d1965f60a52ef43
Author: Kristian Høgsberg <krh at bitplanet.net>
Date:   Wed Aug 21 23:02:58 2013 -0700

    xwayland: Add a HW_WAYLAND flag to let drivers explicitly opt-in

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 98adaab..2d3bb01 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -547,11 +547,14 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
             if (!(flags & HW_SKIP_CONSOLE))
                 xorgHWOpenConsole = TRUE;
 
-	    if (xorgWayland &&
-		(NEED_IO_ENABLED(flags) || !(flags & HW_SKIP_CONSOLE))) {
+	    if (xorgWayland) {
+                if (flags != HW_WAYLAND) {
+                    xf86DeleteDriver(i);
+                    continue;
+                }
 
-		xf86DeleteDriver(i);
-		continue;
+                want_hw_access = FALSE;
+                xorgHWOpenConsole = FALSE;
 	    }
         }
 
diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h
index 4c2d147..976fa30 100644
--- a/hw/xfree86/common/xf86str.h
+++ b/hw/xfree86/common/xf86str.h
@@ -288,6 +288,7 @@ typedef struct {
 #define HW_MMIO 2
 #define HW_SKIP_CONSOLE 4
 #define NEED_IO_ENABLED(x) (x & HW_IO)
+#define HW_WAYLAND 8
 
 typedef CARD32 xorgHWFlags;
 
commit e1b336aeb211f3cffdda03217ce9b9c0ff10dc74
Author: Kristian Høgsberg <krh at redhat.com>
Date:   Fri Sep 18 22:08:16 2009 -0400

    Add xwayland module
    
    Squashed and rebased from the xwayland-1.12 branch.  Contributions from
    
      Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
      Corentin Chary <corentin.chary at gmail.com>
      Daniel Stone <daniel at fooishbar.org>
      Kristian Høgsberg <krh at bitplanet.net>
      Robert Bragg <robert at linux.intel.com>
      Scott Moreau <oreaus at gmail.com>
      Tiago Vignatti <tiago.vignatti at intel.com>

diff --git a/configure.ac b/configure.ac
index 2b6c7c4..6863d17 100644
--- a/configure.ac
+++ b/configure.ac
@@ -635,6 +635,7 @@ AC_ARG_ENABLE(windowswm,      AS_HELP_STRING([--enable-windowswm], [Build XWin w
 AC_ARG_ENABLE(libdrm,         AS_HELP_STRING([--enable-libdrm], [Build Xorg with libdrm support (default: enabled)]), [DRM=$enableval],[DRM=yes])
 AC_ARG_ENABLE(clientids,      AS_HELP_STRING([--disable-clientids], [Build Xorg with client ID tracking (default: enabled)]), [CLIENTIDS=$enableval], [CLIENTIDS=yes])
 AC_ARG_ENABLE(pciaccess, AS_HELP_STRING([--enable-pciaccess], [Build Xorg with pciaccess library (default: enabled)]), [PCI=$enableval], [PCI=yes])
+AC_ARG_ENABLE(wayland,      AS_HELP_STRING([--disable-wayland], [Build Wayland extension (default: enabled)]), [WAYLAND=$enableval], [WAYLAND=yes])
 
 dnl DDXes.
 AC_ARG_ENABLE(xorg,    	      AS_HELP_STRING([--enable-xorg], [Build Xorg server (default: auto)]), [XORG=$enableval], [XORG=auto])
@@ -1018,6 +1019,14 @@ fi
 if test "x$MITSHM" = xauto; then
 	MITSHM="$ac_cv_sysv_ipc"
 fi
+
+AM_CONDITIONAL(WAYLAND, [test "x$WAYLAND" = xyes])
+if test "x$WAYLAND" = xyes; then
+	AC_DEFINE(XORG_WAYLAND, 1, [Support wayland mode])
+	REQUIRED_MODULES="$REQUIRED_MODULES wayland-client"
+	WAYLAND_SCANNER_RULES(['$(top_srcdir)/hw/xfree86/xwayland'])
+fi
+
 AM_CONDITIONAL(MITSHM, [test "x$MITSHM" = xyes])
 if test "x$MITSHM" = xyes; then
 	AC_DEFINE(MITSHM, 1, [Support MIT-SHM extension])
@@ -1111,12 +1120,13 @@ case "$DRI2,$HAVE_DRI2PROTO" in
 esac
 AM_CONDITIONAL(DRI2, test "x$DRI2" = xyes)
 
-if test "x$DRI" = xyes || test "x$DRI2" = xyes || test "x$CONFIG_UDEV_KMS" = xyes; then
+if test "x$DRI" = xyes || test "x$DRI2" = xyes || test "x$CONFIG_UDEV_KMS" = xyes || test "x$WAYLAND" = xyes ; then
 	if test "x$DRM" = xyes; then
 		AC_DEFINE(WITH_LIBDRM, 1, [Building with libdrm support])
 		PKG_CHECK_MODULES([LIBDRM], $LIBDRM)
 	fi
 fi
+AM_CONDITIONAL(DRM, test "x$DRM" = xyes)
 
 if test "x$DRI2" = xyes; then
 	save_CFLAGS=$CFLAGS
@@ -2272,6 +2282,7 @@ hw/xfree86/dixmods/Makefile
 hw/xfree86/doc/Makefile
 hw/xfree86/dri/Makefile
 hw/xfree86/dri2/Makefile
+hw/xfree86/xwayland/Makefile
 hw/xfree86/exa/Makefile
 hw/xfree86/exa/man/Makefile
 hw/xfree86/fbdevhw/Makefile
diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index d568e0d..c542632 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -9,6 +9,10 @@ DRI2_SUBDIR = dri2
 DRI2_LIB = dri2/libdri2.la
 endif
 
+if WAYLAND
+WAYLAND_SUBDIR = xwayland
+endif
+
 if XF86UTILS
 XF86UTILS_SUBDIR = utils
 endif
@@ -27,12 +31,12 @@ endif
 
 SUBDIRS = common ddc x86emu $(INT10_SUBDIR) os-support parser \
 	  ramdac $(VGAHW_SUBDIR) loader modes $(DRI_SUBDIR) \
-	  $(DRI2_SUBDIR) . $(VBE_SUBDIR) i2c dixmods \
+	  $(DRI2_SUBDIR)  $(WAYLAND_SUBDIR) . $(VBE_SUBDIR) i2c dixmods \
 	  fbdevhw shadowfb exa $(XF86UTILS_SUBDIR) doc man
 
 DIST_SUBDIRS = common ddc i2c x86emu int10 fbdevhw os-support \
                parser ramdac shadowfb vbe vgahw \
-               loader dixmods dri dri2 exa modes \
+               loader dixmods dri dri2 exa modes xwayland \
 	       utils doc man
 
 bin_PROGRAMS = Xorg
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 74d5ed3..5b5cbac 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -118,7 +118,8 @@ static ModuleDefault ModuleDefaults[] = {
     {.name = "fb",.toLoad = TRUE,.load_opt = NULL},
     {.name = "shadow",.toLoad = TRUE,.load_opt = NULL},
 #endif
-    {.name = NULL,.toLoad = FALSE,.load_opt = NULL}
+    {.name = "xwayland",.toLoad = FALSE,.load_opt=NULL},
+    {.name = NULL,.toLoad = FALSE,.load_opt=NULL}
 };
 
 /* Forward declarations */
@@ -260,6 +261,17 @@ xf86ModulelistFromConfig(pointer **optlist)
         return NULL;
     }
 
+    /*
+     * Set the xwayland module to autoload if requested.
+     */
+    if (xorgWayland) {
+        for (i=0 ; ModuleDefaults[i].name != NULL ; i++) {
+            if (strcmp(ModuleDefaults[i].name, "xwayland") == 0) {
+                ModuleDefaults[i].toLoad = TRUE;
+            }
+        }
+    }
+    
     if (xf86configptr->conf_modules) {
         /* Walk the disable list and let people know what we've parsed to
          * not be loaded 
@@ -863,6 +875,13 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
     }
     xf86Msg(from, "%sutomatically adding GPU devices\n",
             xf86Info.autoAddGPU ? "A" : "Not a");
+
+    /* FIXME: Do that at the right place (before xf86Msg). */
+    if (xorgWayland) {
+            xf86Info.autoAddDevices = FALSE;
+            xf86Info.autoEnableDevices = FALSE;
+    }
+
     /*
      * Set things up based on the config file information.  Some of these
      * settings may be overridden later when the command line options are
@@ -953,9 +972,10 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
     }
 #endif
 
-    /* if we're not hotplugging, force some input devices to exist */
-    xf86Info.forceInputDevices = !(xf86Info.autoAddDevices &&
-                                   xf86Info.autoEnableDevices);
+    if (xorgWayland) /* Don't force input devices */
+	xf86Info.forceInputDevices = FALSE;
+    else /* if we're not hotplugging, force some input devices to exist */
+	xf86Info.forceInputDevices = !(xf86Info.autoAddDevices && xf86Info.autoEnableDevices);
 
     /* when forcing input devices, we use kbd. otherwise evdev, so use the
      * evdev rules set. */
diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c
index 7df7a80..b41d2cc 100644
--- a/hw/xfree86/common/xf86Globals.c
+++ b/hw/xfree86/common/xf86Globals.c
@@ -204,3 +204,5 @@ Bool xf86VidModeAllowNonLocal = FALSE;
 #endif
 RootWinPropPtr *xf86RegisteredPropertiesTable = NULL;
 Bool xorgHWAccess = FALSE;
+Bool xorgWayland = FALSE;
+Bool xorgRootless = FALSE;
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 91ec4c8..98adaab 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -546,6 +546,13 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
 
             if (!(flags & HW_SKIP_CONSOLE))
                 xorgHWOpenConsole = TRUE;
+
+	    if (xorgWayland &&
+		(NEED_IO_ENABLED(flags) || !(flags & HW_SKIP_CONSOLE))) {
+
+		xf86DeleteDriver(i);
+		continue;
+	    }
         }
 
         if (xorgHWOpenConsole)
@@ -957,6 +964,9 @@ InitInput(int argc, char **argv)
 
     mieqInit();
 
+    if (xorgWayland)
+	return;
+
     /* Initialize all configured input devices */
     for (pInfo = xf86ConfigLayout.inputs; pInfo && *pInfo; pInfo++) {
         (*pInfo)->options =
@@ -1455,6 +1465,16 @@ ddxProcessArgument(int argc, char **argv, int i)
         return 1;
     }
 
+    if (!strcmp(argv[i], "-wayland")) {
+        xorgWayland = TRUE;
+        return 1;
+    }
+
+    if (!strcmp(argv[i], "-rootless")) {
+        xorgRootless = TRUE;
+        return 1;
+    }
+
     /* OS-specific processing */
     return xf86ProcessArgument(argc, argv, i);
 }
diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h
index 58cfe0a..3dd2697 100644
--- a/hw/xfree86/common/xf86Priv.h
+++ b/hw/xfree86/common/xf86Priv.h
@@ -91,6 +91,8 @@ extern _X_EXPORT int xf86NumScreens;
 extern _X_EXPORT const char *xf86VisualNames[];
 extern _X_EXPORT int xf86Verbose;       /* verbosity level */
 extern _X_EXPORT int xf86LogVerbose;    /* log file verbosity level */
+extern _X_EXPORT Bool xorgWayland;
+extern _X_EXPORT Bool xorgRootless;
 
 extern _X_EXPORT RootWinPropPtr *xf86RegisteredPropertiesTable;
 
diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index efdcd66..483d630 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -1332,13 +1332,16 @@ DRI2Connect(ClientPtr client, ScreenPtr pScreen,
 }
 
 static int
-DRI2AuthMagic (ScreenPtr pScreen, uint32_t magic)
+DRI2AuthMagic (ClientPtr client, ScreenPtr pScreen, uint32_t magic)
 {
     DRI2ScreenPtr ds = DRI2GetScreen(pScreen);
     if (ds == NULL)
         return -EINVAL;
 
-    return (*ds->LegacyAuthMagic) (ds->fd, magic);
+    if (ds->LegacyAuthMagic2)
+        return (*ds->LegacyAuthMagic2) (pScreen, magic);
+    else
+        return (*ds->LegacyAuthMagic) (ds->fd, magic);
 }
 
 Bool
diff --git a/hw/xfree86/dri2/dri2.h b/hw/xfree86/dri2/dri2.h
index 38b4f58..ed67d01 100644
--- a/hw/xfree86/dri2/dri2.h
+++ b/hw/xfree86/dri2/dri2.h
@@ -207,7 +207,7 @@ typedef int (*DRI2GetParamProcPtr) (ClientPtr client,
 /**
  * Version of the DRI2InfoRec structure defined in this header
  */
-#define DRI2INFOREC_VERSION 9
+#define DRI2INFOREC_VERSION 10
 
 typedef struct {
     unsigned int version;       /**< Version of this struct */
diff --git a/hw/xfree86/xwayland/Makefile.am b/hw/xfree86/xwayland/Makefile.am
new file mode 100644
index 0000000..b739145
--- /dev/null
+++ b/hw/xfree86/xwayland/Makefile.am
@@ -0,0 +1,44 @@
+AM_CPPFLAGS =					\
+	$(XORG_INCS)				\
+	-I$(srcdir)/../ddc			\
+	-I$(srcdir)/../ramdac			\
+	-I$(srcdir)/../i2c			\
+	-I$(srcdir)/../parser			\
+	-I$(srcdir)/../modes
+
+libxwayland_la_LTLIBRARIES = libxwayland.la
+libxwayland_la_CFLAGS = \
+	-DHAVE_XORG_CONFIG_H \
+	@DIX_CFLAGS@ @XORG_CFLAGS@ @LIBDRM_CFLAGS@ \
+	-I$(top_srcdir)/hw/xfree86/common \
+	-I$(top_srcdir)/hw/xfree86/os-support/bus
+
+libxwayland_la_LDFLAGS = -module -avoid-version @LIBDRM_LIBS@ -lwayland-client
+libxwayland_ladir = $(moduledir)/extensions
+libxwayland_la_SOURCES =			\
+	xwayland.c				\
+	xwayland-input.c			\
+	xwayland-output.c			\
+	xwayland-cursor.c			\
+	xwayland-window.c			\
+	xwayland-private.h			\
+	drm-client-protocol.h			\
+	drm-protocol.c				\
+	xserver-client-protocol.h		\
+	xserver-protocol.c
+
+if DRM
+libxwayland_la_SOURCES += xwayland-drm.c
+endif
+
+sdk_HEADERS = xwayland.h
+
+BUILT_SOURCES =					\
+	drm-client-protocol.h			\
+	drm-protocol.c				\
+	xserver-client-protocol.h		\
+	xserver-protocol.c
+
+CLEANFILES = $(BUILT_SOURCES)
+
+ at wayland_scanner_rules@
diff --git a/hw/xfree86/xwayland/drm.xml b/hw/xfree86/xwayland/drm.xml
new file mode 100644
index 0000000..89fd8f0
--- /dev/null
+++ b/hw/xfree86/xwayland/drm.xml
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="drm">
+
+  <copyright>
+    Copyright © 2008-2011 Kristian Høgsberg
+    Copyright © 2010-2011 Intel Corporation
+
+    Permission to use, copy, modify, distribute, and sell this
+    software and its documentation for any purpose is hereby granted
+    without fee, provided that\n the above copyright notice appear in
+    all copies and that both that copyright notice and this permission
+    notice appear in supporting documentation, and that the name of
+    the copyright holders not be used in advertising or publicity
+    pertaining to distribution of the software without specific,
+    written prior permission.  The copyright holders make no
+    representations about the suitability of this software for any
+    purpose.  It is provided "as is" without express or implied
+    warranty.
+
+    THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+    SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+    FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+    SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+    AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+    ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+    THIS SOFTWARE.
+  </copyright>
+
+  <!-- drm support. This object is created by the server and published
+       using the display's global event. -->
+  <interface name="wl_drm" version="1">
+    <enum name="error">
+      <entry name="authenticate_fail" value="0"/>
+      <entry name="invalid_format" value="1"/>
+      <entry name="invalid_name" value="2"/>
+    </enum>
+
+    <enum name="format">
+      <!-- The drm format codes match the #defines in drm_fourcc.h.
+           The formats actually supported by the compositor will be
+           reported by the format event. -->
+      <entry name="c8" value="0x20203843"/>
+      <entry name="rgb332" value="0x38424752"/>
+      <entry name="bgr233" value="0x38524742"/>
+      <entry name="xrgb4444" value="0x32315258"/>
+      <entry name="xbgr4444" value="0x32314258"/>
+      <entry name="rgbx4444" value="0x32315852"/>
+      <entry name="bgrx4444" value="0x32315842"/>
+      <entry name="argb4444" value="0x32315241"/>
+      <entry name="abgr4444" value="0x32314241"/>
+      <entry name="rgba4444" value="0x32314152"/>
+      <entry name="bgra4444" value="0x32314142"/>
+      <entry name="xrgb1555" value="0x35315258"/>
+      <entry name="xbgr1555" value="0x35314258"/>
+      <entry name="rgbx5551" value="0x35315852"/>
+      <entry name="bgrx5551" value="0x35315842"/>
+      <entry name="argb1555" value="0x35315241"/>
+      <entry name="abgr1555" value="0x35314241"/>
+      <entry name="rgba5551" value="0x35314152"/>
+      <entry name="bgra5551" value="0x35314142"/>
+      <entry name="rgb565" value="0x36314752"/>
+      <entry name="bgr565" value="0x36314742"/>
+      <entry name="rgb888" value="0x34324752"/>
+      <entry name="bgr888" value="0x34324742"/>
+      <entry name="xrgb8888" value="0x34325258"/>
+      <entry name="xbgr8888" value="0x34324258"/>
+      <entry name="rgbx8888" value="0x34325852"/>
+      <entry name="bgrx8888" value="0x34325842"/>
+      <entry name="argb8888" value="0x34325241"/>
+      <entry name="abgr8888" value="0x34324241"/>
+      <entry name="rgba8888" value="0x34324152"/>
+      <entry name="bgra8888" value="0x34324142"/>
+      <entry name="xrgb2101010" value="0x30335258"/>
+      <entry name="xbgr2101010" value="0x30334258"/>
+      <entry name="rgbx1010102" value="0x30335852"/>
+      <entry name="bgrx1010102" value="0x30335842"/>
+      <entry name="argb2101010" value="0x30335241"/>
+      <entry name="abgr2101010" value="0x30334241"/>
+      <entry name="rgba1010102" value="0x30334152"/>
+      <entry name="bgra1010102" value="0x30334142"/>
+      <entry name="yuyv" value="0x56595559"/>
+      <entry name="yvyu" value="0x55595659"/>
+      <entry name="uyvy" value="0x59565955"/>
+      <entry name="vyuy" value="0x59555956"/>
+      <entry name="ayuv" value="0x56555941"/>
+      <entry name="nv12" value="0x3231564e"/>
+      <entry name="nv21" value="0x3132564e"/>
+      <entry name="nv16" value="0x3631564e"/>
+      <entry name="nv61" value="0x3136564e"/>
+      <entry name="yuv410" value="0x39565559"/>
+      <entry name="yvu410" value="0x39555659"/>
+      <entry name="yuv411" value="0x31315559"/>
+      <entry name="yvu411" value="0x31315659"/>
+      <entry name="yuv420" value="0x32315559"/>
+      <entry name="yvu420" value="0x32315659"/>
+      <entry name="yuv422" value="0x36315559"/>
+      <entry name="yvu422" value="0x36315659"/>
+      <entry name="yuv444" value="0x34325559"/>
+      <entry name="yvu444" value="0x34325659"/>
+    </enum>
+
+    <!-- Call this request with the magic received from drmGetMagic().
+         It will be passed on to the drmAuthMagic() or
+         DRIAuthConnection() call.  This authentication must be
+         completed before create_buffer could be used. -->
+    <request name="authenticate">
+      <arg name="id" type="uint"/>
+    </request>
+
+    <!-- Create a wayland buffer for the named DRM buffer.  The DRM
+         surface must have a name using the flink ioctl -->
+    <request name="create_buffer">
+      <arg name="id" type="new_id" interface="wl_buffer"/>
+      <arg name="name" type="uint"/>
+      <arg name="width" type="int"/>
+      <arg name="height" type="int"/>
+      <arg name="stride" type="uint"/>
+      <arg name="format" type="uint"/>
+    </request>
+
+    <!-- Notification of the path of the drm device which is used by
+         the server.  The client should use this device for creating
+         local buffers.  Only buffers created from this device should
+         be be passed to the server using this drm object's
+         create_buffer request. -->
+    <event name="device">
+      <arg name="name" type="string"/>
+    </event>
+
+    <event name="format">
+      <arg name="format" type="uint"/>
+    </event>
+
+    <!-- Raised if the authenticate request succeeded -->
+    <event name="authenticated"/>
+  </interface>
+
+</protocol>
diff --git a/hw/xfree86/xwayland/xserver.xml b/hw/xfree86/xwayland/xserver.xml
new file mode 100644
index 0000000..9e25f5c
--- /dev/null
+++ b/hw/xfree86/xwayland/xserver.xml
@@ -0,0 +1,18 @@
+<protocol name="xserver">
+
+  <interface name="xserver" version="1">
+    <request name="set_window_id">
+      <arg name="surface" type="object" interface="wl_surface"/>
+      <arg name="id" type="uint"/>
+    </request>
+
+    <event name="client">
+      <arg name="fd" type="fd"/>
+    </event>
+
+    <event name="listen_socket">
+      <arg name="fd" type="fd"/>
+    </event>
+  </interface>
+
+</protocol>
diff --git a/hw/xfree86/xwayland/xwayland-cursor.c b/hw/xfree86/xwayland/xwayland-cursor.c
new file mode 100644
index 0000000..f8860bd
--- /dev/null
+++ b/hw/xfree86/xwayland/xwayland-cursor.c
@@ -0,0 +1,241 @@
+/*
+ * Copyright © 2011 Kristian Høgsberg
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of the
+ * copyright holders not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no
+ * representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include "xorg-config.h"
+#endif
+
+#include <unistd.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <wayland-client.h>
+
+#include <xorg-server.h>
+#include <cursorstr.h>
+#include <xf86Crtc.h>
+#include <mipointrst.h>
+
+#include "xwayland.h"
+#include "xwayland-private.h"
+#include "xserver-client-protocol.h"
+
+static DevPrivateKeyRec xwl_cursor_private_key;
+
+static void
+expand_source_and_mask(CursorPtr cursor, void *data)
+{
+    CARD32 *argb, *p, d, fg, bg;
+    CursorBitsPtr bits = cursor->bits;
+    int size;
+    int x, y, stride, i, bit;
+
+    size = bits->width * bits->height * 4;
+    argb = malloc(size);
+    if (argb == NULL)
+	return;
+
+    p = argb;
+    fg = ((cursor->foreRed & 0xff00) << 8) |
+	(cursor->foreGreen & 0xff00) | (cursor->foreGreen >> 8);
+    bg = ((cursor->backRed & 0xff00) << 8) |
+	(cursor->backGreen & 0xff00) | (cursor->backGreen >> 8);
+    stride = (bits->width / 8 + 3) & ~3;
+    for (y = 0; y < bits->height; y++)
+	for (x = 0; x < bits->width; x++) {
+	    i = y * stride + x / 8;
+	    bit = 1 << (x & 7);
+	    if (bits->source[i] & bit)
+		d = fg;
+	    else
+		d = bg;
+	    if (bits->mask[i] & bit)
+		d |= 0xff000000;
+	    else
+		d = 0x00000000;
+
+	    *p++ = d;
+	}
+
+    memcpy(data, argb, size);
+    free(argb);
+}
+
+static Bool
+xwl_realize_cursor(DeviceIntPtr device, ScreenPtr screen, CursorPtr cursor)
+{
+    struct xwl_screen *xwl_screen;
+    int size;
+    char filename[] = "/tmp/wayland-shm-XXXXXX";
+    int fd;
+    struct wl_shm_pool *pool;
+    struct wl_buffer *buffer;
+    void *data;
+
+    xwl_screen = xwl_screen_get(screen);
+    size = cursor->bits->width * cursor->bits->height * 4;
+
+    fd = mkstemp(filename);
+    if (fd < 0) {
+	ErrorF("open %s failed: %s", filename, strerror(errno));
+	return FALSE;
+    }
+    if (ftruncate(fd, size) < 0) {
+	ErrorF("ftruncate failed: %s", strerror(errno));
+	close(fd);
+	return FALSE;
+    }
+
+    data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+    unlink(filename);
+
+    if (data == MAP_FAILED) {
+	ErrorF("mmap failed: %s", strerror(errno));
+	close(fd);
+	return FALSE;
+    }
+
+    if (cursor->bits->argb)
+	memcpy(data, cursor->bits->argb, size);
+    else
+	expand_source_and_mask(cursor, data);
+    munmap(data, size);
+
+    pool = wl_shm_create_pool(xwl_screen->shm, fd, size);
+    close(fd);
+    buffer = wl_shm_pool_create_buffer(pool, 0,
+				  cursor->bits->width, cursor->bits->height,
+				  cursor->bits->width * 4,
+				  WL_SHM_FORMAT_ARGB8888);
+    wl_shm_pool_destroy(pool);
+
+    dixSetPrivate(&cursor->devPrivates, &xwl_cursor_private_key, buffer);
+
+    return TRUE;
+}
+
+static Bool
+xwl_unrealize_cursor(DeviceIntPtr device,
+			ScreenPtr screen, CursorPtr cursor)
+{
+    struct wl_buffer *buffer;
+
+    buffer = dixGetPrivate(&cursor->devPrivates, &xwl_cursor_private_key);
+    wl_buffer_destroy(buffer);
+
+    return TRUE;
+}
+
+void
+xwl_seat_set_cursor(struct xwl_seat *xwl_seat)
+{
+    struct wl_buffer *buffer;
+
+    if (!xwl_seat->x_cursor || !xwl_seat->wl_pointer)
+        return;
+
+    buffer = dixGetPrivate(&xwl_seat->x_cursor->devPrivates,
+                           &xwl_cursor_private_key);
+
+    wl_pointer_set_cursor(xwl_seat->wl_pointer,
+			  xwl_seat->pointer_enter_serial,
+			  xwl_seat->cursor,
+			  xwl_seat->x_cursor->bits->xhot,
+			  xwl_seat->x_cursor->bits->yhot);
+    wl_surface_attach(xwl_seat->cursor, buffer, 0, 0);
+    wl_surface_damage(xwl_seat->cursor, 0, 0,
+		      xwl_seat->x_cursor->bits->width,
+		      xwl_seat->x_cursor->bits->height);
+    wl_surface_commit(xwl_seat->cursor);
+}
+
+static void
+xwl_set_cursor(DeviceIntPtr device,
+	       ScreenPtr screen, CursorPtr cursor, int x, int y)
+{
+    struct xwl_screen *xwl_screen;
+    struct xwl_seat *xwl_seat;
+
+    xwl_screen = xwl_screen_get(screen);
+
+    if (!xwl_screen || xorg_list_is_empty(&xwl_screen->seat_list))
+	return;
+
+    xwl_seat = xorg_list_first_entry(&xwl_screen->seat_list,
+		                     struct xwl_seat, link);
+
+    xwl_seat->x_cursor = cursor;
+    xwl_seat_set_cursor(xwl_seat);
+}
+
+static void
+xwl_move_cursor(DeviceIntPtr device, ScreenPtr screen, int x, int y)
+{
+}
+
+static Bool
+xwl_device_cursor_initialize(DeviceIntPtr device, ScreenPtr screen)
+{
+    struct xwl_screen *xwl_screen;
+
+    xwl_screen = xwl_screen_get(screen);
+
+    return xwl_screen->sprite_funcs->DeviceCursorInitialize(device,
+							       screen);
+}
+
+static void
+xwl_device_cursor_cleanup(DeviceIntPtr device, ScreenPtr screen)
+{
+    struct xwl_screen *xwl_screen;
+
+    xwl_screen = xwl_screen_get(screen);
+
+    xwl_screen->sprite_funcs->DeviceCursorCleanup(device, screen);
+}
+
+static miPointerSpriteFuncRec xwl_pointer_sprite_funcs =
+{
+    xwl_realize_cursor,
+    xwl_unrealize_cursor,
+    xwl_set_cursor,
+    xwl_move_cursor,
+    xwl_device_cursor_initialize,
+    xwl_device_cursor_cleanup
+};
+
+int
+xwl_screen_init_cursor(struct xwl_screen *xwl_screen, ScreenPtr screen)
+{
+    miPointerScreenPtr pointer_priv;
+
+    if (!dixRegisterPrivateKey(&xwl_cursor_private_key, PRIVATE_CURSOR, 0))
+	return BadAlloc;
+
+    pointer_priv = dixLookupPrivate(&screen->devPrivates, miPointerScreenKey);
+    xwl_screen->sprite_funcs = pointer_priv->spriteFuncs;
+    pointer_priv->spriteFuncs = &xwl_pointer_sprite_funcs;
+
+    return Success;
+}
diff --git a/hw/xfree86/xwayland/xwayland-drm.c b/hw/xfree86/xwayland/xwayland-drm.c
new file mode 100644
index 0000000..1514ef5
--- /dev/null
+++ b/hw/xfree86/xwayland/xwayland-drm.c
@@ -0,0 +1,236 @@
+/*
+ * Copyright © 2011 Kristian Høgsberg
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of the
+ * copyright holders not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no
+ * representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include "xorg-config.h"
+#endif
+
+#include <unistd.h>
+#include <fcntl.h>
+
+#include <xf86drm.h>
+#include <wayland-util.h>
+#include <wayland-client.h>
+#include <drm-client-protocol.h>
+
+#include <xf86Xinput.h>
+#include <xf86Crtc.h>
+#include <xf86str.h>
+#include <windowstr.h>
+#include <input.h>
+#include <inputstr.h>
+#include <exevents.h>
+
+#include "xwayland.h"
+#include "xwayland-private.h"
+#include "../dri2/dri2.h"
+
+struct xwl_auth_req {
+    struct xorg_list link;
+
+    ClientPtr client;
+    struct xwl_screen *xwl_screen;
+    uint32_t magic;
+};
+
+static void
+drm_handle_device (void *data, struct wl_drm *drm, const char *device)
+{
+    struct xwl_screen *xwl_screen = data;
+
+    xwl_screen->device_name = strdup (device);
+}
+
+static void
+drm_handle_format(void *data, struct wl_drm *wl_drm, uint32_t format)
+{
+}
+
+static void
+drm_handle_authenticated (void *data, struct wl_drm *drm)
+{
+    struct xwl_screen *xwl_screen = data;
+    struct xwl_auth_req *req;
+
+    xwl_screen->authenticated = 1;
+
+    /* it does one authentication transaction at a time, so if there's an
+     * element in the list, we call DRI2SendAuthReply for that client, remove
+     * the head and free the struct. If there are still elements in the list,
+     * it means that we have one or more clients waiting to be authenticated
+     * and we send out a wl_drm authenticate request for the first client in
+     * the list */
+    if (xorg_list_is_empty(&xwl_screen->authenticate_client_list))
+	return;
+
+    req = xorg_list_first_entry(&xwl_screen->authenticate_client_list,
+	                        struct xwl_auth_req, link);
+    DRI2SendAuthReply(req->client, TRUE);
+    AttendClient(req->client);
+    xorg_list_del(&req->link);
+    free(req);
+
+    xorg_list_for_each_entry(req, &xwl_screen->authenticate_client_list,
+	                     link) {
+	wl_drm_authenticate (xwl_screen->drm, req->magic);
+	return;
+    }
+}
+
+static const struct wl_drm_listener xwl_drm_listener =
+{
+    drm_handle_device,
+    drm_handle_format,
+    drm_handle_authenticated
+};
+
+static void
+drm_handler(void *data, struct wl_registry *registry, uint32_t id,
+	    const char *interface, uint32_t version)
+{
+    struct xwl_screen *xwl_screen = data;
+
+    if (strcmp (interface, "wl_drm") == 0) {
+	xwl_screen->drm = wl_registry_bind(xwl_screen->registry, id,
+                                           &wl_drm_interface, 1);
+	wl_drm_add_listener(xwl_screen->drm, &xwl_drm_listener, xwl_screen);
+    }
+}
+
+static const struct wl_registry_listener drm_listener = {
+    drm_handler,
+};
+
+int
+xwl_drm_pre_init(struct xwl_screen *xwl_screen)
+{
+    uint32_t magic;
+
+    xwl_screen->drm_registry = wl_display_get_registry(xwl_screen->display);
+    wl_registry_add_listener(xwl_screen->drm_registry, &drm_listener,
+                             xwl_screen);
+
+    /* Ensure drm_handler has seen all the interfaces */
+    wl_display_roundtrip(xwl_screen->display);
+    /* Ensure the xwl_drm_listener has seen the drm device, if any */
+    wl_display_roundtrip(xwl_screen->display);
+
+    ErrorF("wayland_drm_screen_init, device name %s\n",
+	   xwl_screen->device_name);
+
+    xwl_screen->drm_fd = open(xwl_screen->device_name, O_RDWR);
+    if (xwl_screen->drm_fd < 0) {
+	ErrorF("failed to open the drm fd\n");
+	return BadAccess;
+    }
+
+    if (drmGetMagic(xwl_screen->drm_fd, &magic)) {
+	ErrorF("failed to get drm magic");
+	return BadAccess;
+    }
+
+    wl_drm_authenticate(xwl_screen->drm, magic);
+
+    wl_display_roundtrip(xwl_screen->display);
+
+    ErrorF("opened drm fd: %d\n", xwl_screen->drm_fd);
+
+    if (!xwl_screen->authenticated) {
+	ErrorF("Failed to auth drm fd\n");
+	return BadAccess;
+    }
+
+    return Success;
+}
+
+Bool xwl_drm_initialised(struct xwl_screen *xwl_screen)
+{
+    return xwl_screen->authenticated;
+}
+
+int xwl_screen_get_drm_fd(struct xwl_screen *xwl_screen)
+{
+    return xwl_screen->drm_fd;
+}
+
+int xwl_drm_authenticate(ClientPtr client, struct xwl_screen *xwl_screen,
+			    uint32_t magic)
+{
+    struct xwl_auth_req *req;
+
+    if (!xwl_screen->drm)
+	return BadAccess;
+
+    req = malloc (sizeof *req);
+    if (req == NULL)
+	return BadAlloc;
+
+    req->client = client;
+    req->xwl_screen = xwl_screen;
+    req->magic = magic;
+
+    if (xorg_list_is_empty(&xwl_screen->authenticate_client_list))
+	wl_drm_authenticate (xwl_screen->drm, magic);
+
+    xorg_list_append(&req->link, &xwl_screen->authenticate_client_list);
+
+    IgnoreClient(req->client);
+    xwl_screen->authenticated = 0;
+
+    return Success;
+}
+
+
+int
+xwl_create_window_buffer_drm(struct xwl_window *xwl_window,
+			     PixmapPtr pixmap, uint32_t name)
+{
+    VisualID visual;
+    WindowPtr window = xwl_window->window;
+    ScreenPtr screen = window->drawable.pScreen;
+    uint32_t format;
+    int i;
+
+    visual = wVisual(window);
+    for (i = 0; i < screen->numVisuals; i++)
+	if (screen->visuals[i].vid == visual)
+	    break;
+
+    if (screen->visuals[i].nplanes == 32)
+	format = WL_DRM_FORMAT_ARGB8888;
+    else
+	format = WL_DRM_FORMAT_XRGB8888;
+
+    xwl_window->buffer =
+      wl_drm_create_buffer(xwl_window->xwl_screen->drm,
+			   name,
+			   pixmap->drawable.width,
+			   pixmap->drawable.height,
+			   pixmap->devKind,
+			   format);
+
+    return xwl_window->buffer ? Success : BadDrawable;
+}
+
diff --git a/hw/xfree86/xwayland/xwayland-input.c b/hw/xfree86/xwayland/xwayland-input.c
new file mode 100644
index 0000000..2f8e0c7
--- /dev/null
+++ b/hw/xfree86/xwayland/xwayland-input.c
@@ -0,0 +1,610 @@
+/*
+ * Copyright © 2008 Kristian Høgsberg
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of the
+ * copyright holders not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no
+ * representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include "xorg-config.h"
+#endif
+
+#include <errno.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <linux/input.h>
+#include <wayland-util.h>
+#include <wayland-client.h>
+#include <X11/extensions/compositeproto.h>
+#include <xserver-properties.h>
+
+#include <compositeext.h>
+#include <selection.h>
+#include <extinit.h>
+#include <exevents.h>
+#include <input.h>
+#include <inpututils.h>
+#include <inputstr.h>
+#include <exevents.h>
+#include <xkbsrv.h>
+#include <xf86Xinput.h>
+#include <xf86Crtc.h>
+#include <xf86str.h>
+#include <windowstr.h>
+#include <xf86Priv.h>
+#include <mipointrst.h>
+#include <sys/mman.h>
+
+#include "xwayland.h"
+#include "xwayland-private.h"
+#include "xserver-client-protocol.h"
+
+static void
+xwl_pointer_control(DeviceIntPtr device, PtrCtrl *ctrl)
+{
+	/* Nothing to do, dix handles all settings */
+}
+
+static int
+xwl_pointer_proc(DeviceIntPtr device, int what)
+{
+#define NBUTTONS 10
+#define NAXES 2
+    BYTE map[NBUTTONS + 1];
+    int i = 0;
+    Atom btn_labels[NBUTTONS] = {0};
+    Atom axes_labels[NAXES] = {0};
+
+    switch (what) {
+    case DEVICE_INIT:
+	device->public.on = FALSE;
+
+        for (i = 1; i <= NBUTTONS; i++)
+            map[i] = i;
+
+        btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
+        btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
+        btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
+        btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
+        btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
+        btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
+        btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
+        /* don't know about the rest */
+
+        axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X);
+        axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y);
+
+        if (!InitValuatorClassDeviceStruct(device, 2, btn_labels,
+                                           GetMotionHistorySize(), Absolute))
+            return BadValue;
+
+        /* Valuators */
+        InitValuatorAxisStruct(device, 0, axes_labels[0],
+                               0, 0xFFFF, 10000, 0, 10000, Absolute);
+        InitValuatorAxisStruct(device, 1, axes_labels[1],
+                               0, 0xFFFF, 10000, 0, 10000, Absolute);
+
+        if (!InitPtrFeedbackClassDeviceStruct(device, xwl_pointer_control))
+            return BadValue;
+
+        if (!InitButtonClassDeviceStruct(device, 3, btn_labels, map))
+            return BadValue;
+
+        return Success;
+
+    case DEVICE_ON:
+	device->public.on = TRUE;
+        return Success;
+
+    case DEVICE_OFF:
+    case DEVICE_CLOSE:
+	device->public.on = FALSE;
+        return Success;
+    }
+
+    return BadMatch;
+
+#undef NBUTTONS
+#undef NAXES
+}
+
+static void
+xwl_keyboard_control(DeviceIntPtr device, KeybdCtrl *ctrl)
+{
+    /* FIXME: Set keyboard leds based on CAPSFLAG etc being set in
+     * ctrl->leds - needs private protocol. */
+}
+
+static int
+xwl_keyboard_proc(DeviceIntPtr device, int what)
+{
+    InputInfoPtr pInfo = device->public.devicePrivate;
+    struct xwl_seat *xwl_seat = pInfo->private;
+    int len;
+
+    switch (what) {
+    case DEVICE_INIT:
+	device->public.on = FALSE;
+	len = strnlen(xwl_seat->keymap, xwl_seat->keymap_size);
+        if (!InitKeyboardDeviceStructFromString(device, xwl_seat->keymap,
+						len,
+						NULL, xwl_keyboard_control))
+            return BadValue;
+
+        return Success;
+    case DEVICE_ON:
+	device->public.on = TRUE;
+        return Success;
+
+    case DEVICE_OFF:
+    case DEVICE_CLOSE:
+	device->public.on = FALSE;
+        return Success;
+    }
+
+    return BadMatch;
+}
+
+static void
+xwl_keyboard_uninit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
+{
+}
+
+static int
+xwl_keyboard_init(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
+{
+    pInfo->type_name = "xwayland-keyboard";
+    pInfo->device_control = xwl_keyboard_proc;
+    pInfo->read_input = NULL;
+    pInfo->control_proc = NULL;
+    pInfo->switch_mode = NULL;
+    pInfo->fd = -1;
+
+    return Success;
+}
+
+_X_EXPORT InputDriverRec xwl_keyboard_driver = {
+    1,
+    "xwayland-keyboard",
+    NULL,
+    xwl_keyboard_init,
+    xwl_keyboard_uninit,
+    NULL,
+};
+
+static void
+xwl_pointer_uninit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
+{
+}
+
+static int
+xwl_pointer_init(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
+{
+    pInfo->type_name = "xwayland-pointer";
+    pInfo->device_control = xwl_pointer_proc;
+    pInfo->read_input = NULL;
+    pInfo->control_proc = NULL;
+    pInfo->switch_mode = NULL;
+    pInfo->fd = -1;
+
+    return Success;
+}
+
+_X_EXPORT InputDriverRec xwl_pointer_driver = {
+    1,
+    "xwayland-pointer",
+    NULL,
+    xwl_pointer_init,
+    xwl_pointer_uninit,
+    NULL,
+};
+
+void
+xwl_input_teardown(pointer p)
+{
+}
+
+pointer
+xwl_input_setup(pointer module, pointer opts, int *errmaj, int *errmin)
+{
+    xf86AddInputDriver(&xwl_keyboard_driver, module, 0);
+    xf86AddInputDriver(&xwl_pointer_driver, module, 0);
+
+    return module;
+}
+
+static DeviceIntPtr
+device_added(struct xwl_seat *xwl_seat, const char *driver)
+{
+    DeviceIntPtr dev = NULL;
+    InputInfoPtr pInfo;
+    int rc;
+
+    pInfo = xf86AllocateInput();
+    if (!pInfo)
+        return NULL;
+
+    pInfo->driver = xstrdup(driver);
+
+    if (asprintf(&pInfo->name, "%s:%d", pInfo->driver, xwl_seat->id) == -1) {
+	free(pInfo);
+	return NULL;
+    }
+
+    pInfo->private = xwl_seat;
+
+    rc = xf86NewInputDevice(pInfo, &dev, 1);
+    if (rc != Success) {
+	free(pInfo);
+	return NULL;
+    }
+
+    LogMessage(X_INFO, "config/xwayland: Adding input device %s\n",
+	       pInfo->name);
+
+    return dev;
+}
+
+static void
+pointer_handle_enter(void *data, struct wl_pointer *pointer,
+		     uint32_t serial, struct wl_surface *surface,
+		     wl_fixed_t sx_w, wl_fixed_t sy_w)
+
+{
+    struct xwl_seat *xwl_seat = data;
+    DeviceIntPtr dev = xwl_seat->pointer;
+    int i;
+    int sx = wl_fixed_to_int(sx_w);
+    int sy = wl_fixed_to_int(sy_w);
+    ScreenPtr pScreen = xwl_seat->xwl_screen->screen;
+
+    xwl_seat->xwl_screen->serial = serial;
+    xwl_seat->pointer_enter_serial = serial;
+
+    xwl_seat->focus_window = wl_surface_get_user_data(surface);
+
+    (*pScreen->SetCursorPosition) (dev, pScreen, sx, sy, TRUE);
+
+    SetDeviceRedirectWindow(xwl_seat->pointer, xwl_seat->focus_window->window);
+
+    /* Ideally, X clients shouldn't see these button releases.  When
+     * the pointer leaves a window with buttons down, it means that
+     * the wayland compositor has grabbed the pointer.  The button
+     * release event is consumed by whatever grab in the compositor
+     * and won't be sent to clients (the X server is a client).
+     * However, we need to reset X's idea of which buttons are up and
+     * down, and they're all up (by definition) when the pointer
+     * enters a window.  We should figure out a way to swallow these
+     * events, perhaps using an X grab whenever the pointer is not in
+     * any X window, but for now just send the events. */
+    for (i = 0; i < dev->button->numButtons; i++)
+	if (BitIsOn(dev->button->down, i))
+		xf86PostButtonEvent(dev, TRUE, i, 0, 0, 0);
+
+    (*pScreen->DisplayCursor)(dev, pScreen, dev->spriteInfo->sprite->current);
+}
+
+static void
+pointer_handle_leave(void *data, struct wl_pointer *pointer,
+		     uint32_t serial, struct wl_surface *surface)
+{
+    struct xwl_seat *xwl_seat = data;
+    DeviceIntPtr dev = xwl_seat->pointer;
+    ScreenPtr pScreen = xwl_seat->xwl_screen->screen;
+
+    xwl_seat->xwl_screen->serial = serial;
+
+    xwl_seat->focus_window = NULL;
+    SetDeviceRedirectWindow(xwl_seat->pointer, PointerRootWin);
+    (*pScreen->DisplayCursor)(dev, pScreen, NullCursor);
+}
+
+static void
+pointer_handle_motion(void *data, struct wl_pointer *pointer,
+		      uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
+{
+    struct xwl_seat *xwl_seat = data;
+    int32_t dx, dy;
+    int sx = wl_fixed_to_int(sx_w);
+    int sy = wl_fixed_to_int(sy_w);
+    ValuatorMask mask;
+
+    if (!xwl_seat->focus_window)
+	return ;
+
+    dx = xwl_seat->focus_window->window->drawable.x;
+    dy = xwl_seat->focus_window->window->drawable.y;
+
+    valuator_mask_zero(&mask);
+    valuator_mask_set(&mask, 0, dx + sx);
+    valuator_mask_set(&mask, 1, dy + sy);
+
+    QueuePointerEvents(xwl_seat->pointer, MotionNotify, 0,
+		       POINTER_ABSOLUTE | POINTER_SCREEN, &mask);
+}
+
+static void
+pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
+		      uint32_t time, uint32_t button, uint32_t state)
+{
+    struct xwl_seat *xwl_seat = data;
+    int index;
+
+    xwl_seat->xwl_screen->serial = serial;
+
+    switch (button) {
+    case BTN_MIDDLE:
+	index = 2;
+	break;
+    case BTN_RIGHT:
+	index = 3;
+	break;
+    default:
+	index = button - BTN_LEFT + 1;
+	break;
+    }
+
+    xf86PostButtonEvent(xwl_seat->pointer, TRUE, index, state, 0, 0);
+}
+
+static void
+pointer_handle_axis(void *data, struct wl_pointer *pointer,
+		    uint32_t time, uint32_t axis, wl_fixed_t value)
+{
+    struct xwl_seat *xwl_seat = data;
+    int index, count;
+    int i, val;
+    const int divisor = 10;
+
+    if (time - xwl_seat->scroll_time > 2000) {
+	xwl_seat->vertical_scroll = 0;
+	xwl_seat->horizontal_scroll = 0;
+    }
+    xwl_seat->scroll_time = time;
+
+    /* FIXME: Need to do proper smooth scrolling here! */
+    switch (axis) {
+    case WL_POINTER_AXIS_VERTICAL_SCROLL:
+	xwl_seat->vertical_scroll += value / divisor;
+	val = wl_fixed_to_int(xwl_seat->vertical_scroll);
+	xwl_seat->vertical_scroll -= wl_fixed_from_int(val);
+
+	if (val <= -1)
+            index = 4;
+	else if (val >= 1)
+            index = 5;
+	else
+            return;
+	break;
+    case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
+	xwl_seat->horizontal_scroll += value / divisor;
+	val = wl_fixed_to_int(xwl_seat->horizontal_scroll);
+	xwl_seat->horizontal_scroll -= wl_fixed_from_int(val);
+
+	if (val <= -1)
+            index = 6;
+	else if (val >= 1)
+            index = 7;
+	else
+            return;
+	break;
+    default:
+	return;
+    }
+
+    count = abs(val);
+    for (i = 0; i < count; i++) {
+	xf86PostButtonEvent(xwl_seat->pointer, TRUE, index, 1, 0, 0);
+	xf86PostButtonEvent(xwl_seat->pointer, TRUE, index, 0, 0, 0);
+    }
+}
+
+static const struct wl_pointer_listener pointer_listener = {
+	pointer_handle_enter,
+	pointer_handle_leave,
+	pointer_handle_motion,
+	pointer_handle_button,
+	pointer_handle_axis,
+};
+
+static void
+keyboard_handle_key(void *data, struct wl_keyboard *keyboard, uint32_t serial,
+		    uint32_t time, uint32_t key, uint32_t state)
+{
+    struct xwl_seat *xwl_seat = data;
+    uint32_t *k, *end;
+
+    xwl_seat->xwl_screen->serial = serial;
+
+    end = xwl_seat->keys.data + xwl_seat->keys.size;
+    for (k = xwl_seat->keys.data; k < end; k++) {
+	if (*k == key)
+	    *k = *--end;
+    }
+    xwl_seat->keys.size = (void *) end - xwl_seat->keys.data;
+    if (state) {
+	k = wl_array_add(&xwl_seat->keys, sizeof *k);
+	*k = key;
+    }
+
+    xf86PostKeyboardEvent(xwl_seat->keyboard, key + 8, state);
+}
+
+static void
+keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
+		       uint32_t format, int fd, uint32_t size)
+{
+    struct xwl_seat *xwl_seat = data;
+
+    xwl_seat->keymap_size = size;
+    xwl_seat->keymap = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
+    if (xwl_seat->keymap == MAP_FAILED)
+	;	/* wah wah */
+
+    close(fd);
+}
+
+static void
+keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
+		      uint32_t serial,
+		      struct wl_surface *surface, struct wl_array *keys)
+{
+    struct xwl_seat *xwl_seat = data;
+    uint32_t *k;
+
+    xwl_seat->xwl_screen->serial = serial;
+
+    wl_array_copy(&xwl_seat->keys, keys);
+    wl_array_for_each(k, &xwl_seat->keys)
+	xf86PostKeyboardEvent(xwl_seat->keyboard, *k + 8, 1);
+}
+
+static void
+keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
+		      uint32_t serial, struct wl_surface *surface)
+{
+    struct xwl_seat *xwl_seat = data;
+    uint32_t *k;
+
+    xwl_seat->xwl_screen->serial = serial;
+
+    wl_array_for_each(k, &xwl_seat->keys)
+	xf86PostKeyboardEvent(xwl_seat->keyboard, *k + 8, 0);
+}
+
+static void
+keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
+			  uint32_t serial, uint32_t mods_depressed,
+			  uint32_t mods_latched, uint32_t mods_locked,
+			  uint32_t group)
+{
+    /* FIXME: Need more server XKB API here. */
+}
+
+static const struct wl_keyboard_listener keyboard_listener = {
+	keyboard_handle_keymap,
+	keyboard_handle_enter,
+	keyboard_handle_leave,
+	keyboard_handle_key,
+	keyboard_handle_modifiers,
+};
+
+static void
+add_devices(void *data, struct wl_callback *callback, uint32_t time)
+{
+    struct xwl_seat *xwl_seat = data;
+
+    wl_callback_destroy(callback);
+
+    if (xwl_seat->wl_pointer)
+	xwl_seat->pointer = device_added(xwl_seat, "xwayland-pointer");
+    if (xwl_seat->wl_keyboard)
+	xwl_seat->keyboard = device_added(xwl_seat, "xwayland-keyboard");
+}
+
+static const struct wl_callback_listener add_devices_listener = {
+	add_devices
+};
+
+static void
+seat_handle_capabilities(void *data, struct wl_seat *seat,
+			 enum wl_seat_capability caps)
+{
+	struct xwl_seat *xwl_seat = data;
+	struct wl_callback *callback;
+
+	if (caps & WL_SEAT_CAPABILITY_POINTER) {
+	    xwl_seat->wl_pointer = wl_seat_get_pointer(seat);
+	    wl_pointer_add_listener(xwl_seat->wl_pointer,
+				    &pointer_listener, xwl_seat);
+            xwl_seat_set_cursor(xwl_seat);
+	}
+
+	if (caps & WL_SEAT_CAPABILITY_KEYBOARD) {
+	    xwl_seat->wl_keyboard = wl_seat_get_keyboard(seat);
+	    wl_keyboard_add_listener(xwl_seat->wl_keyboard,
+				     &keyboard_listener, xwl_seat);
+
+	}
+        /* FIXME: Touch ... */
+
+	/* Add devices after we've received keymaps. */
+	if (caps) {
+	    callback = wl_display_sync(xwl_seat->xwl_screen->display);
+	    wl_callback_add_listener(callback,
+				     &add_devices_listener, xwl_seat);
+	}
+}
+
+static const struct wl_seat_listener seat_listener = {
+	seat_handle_capabilities,
+};
+
+static void
+create_input_device(struct xwl_screen *xwl_screen, uint32_t id)
+{
+    struct xwl_seat *xwl_seat;
+
+    xwl_seat = calloc(sizeof *xwl_seat, 1);
+    if (xwl_seat == NULL) {
+	ErrorF("create_input ENOMEM");
+	return ;
+    }
+
+    xwl_seat->xwl_screen = xwl_screen;
+    xorg_list_add(&xwl_seat->link, &xwl_screen->seat_list);
+
+    xwl_seat->seat =
+	wl_registry_bind(xwl_screen->registry, id, &wl_seat_interface, 1);
+    xwl_seat->id = id;
+
+    xwl_seat->cursor = wl_compositor_create_surface(xwl_screen->compositor);
+    wl_seat_add_listener(xwl_seat->seat, &seat_listener, xwl_seat);
+    wl_array_init(&xwl_seat->keys);
+}
+
+static void
+input_handler(void *data, struct wl_registry *registry, uint32_t id,
+	      const char *interface, uint32_t version)
+{
+    struct xwl_screen *xwl_screen = data;
+
+    if (strcmp (interface, "wl_seat") == 0) {
+        create_input_device(xwl_screen, id);
+    } else if (strcmp(interface, "xserver") == 0) {
+        xwl_screen->xorg_server =
+            wl_registry_bind(registry, id, &xserver_interface, 1);
+        xserver_add_listener(xwl_screen->xorg_server, &xwl_server_listener,
+                             xwl_screen);
+    }
+}
+
+static const struct wl_registry_listener input_listener = {
+    input_handler,
+};
+
+void
+xwl_input_init(struct xwl_screen *xwl_screen)
+{
+    xwl_screen->input_registry = wl_display_get_registry(xwl_screen->display);
+    wl_registry_add_listener(xwl_screen->input_registry, &input_listener,
+                             xwl_screen);
+}
diff --git a/hw/xfree86/xwayland/xwayland-output.c b/hw/xfree86/xwayland/xwayland-output.c
new file mode 100644
index 0000000..8f087f6
--- /dev/null
+++ b/hw/xfree86/xwayland/xwayland-output.c
@@ -0,0 +1,309 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of the
+ * copyright holders not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no
+ * representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include "xorg-config.h"
+#endif
+
+#include <unistd.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <wayland-client.h>
+
+#include <xorg-server.h>
+#include <cursorstr.h>
+#include <xf86Crtc.h>
+#include <mipointrst.h>
+
+#include "xwayland.h"
+#include "xwayland-private.h"
+#include "xserver-client-protocol.h"
+
+static void
+crtc_dpms(xf86CrtcPtr drmmode_crtc, int mode)
+{
+}
+
+static Bool
+crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
+		    Rotation rotation, int x, int y)
+{
+	return TRUE;
+}
+
+static void
+crtc_set_cursor_colors (xf86CrtcPtr crtc, int bg, int fg)
+{
+}
+
+static void
+crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
+{
+}
+
+static void
+crtc_show_cursor (xf86CrtcPtr crtc)
+{
+}
+
+static void
+crtc_hide_cursor (xf86CrtcPtr crtc)
+{
+}
+
+static void
+crtc_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
+{
+}
+
+static PixmapPtr
+crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
+{
+	return NULL;
+}
+
+static void *
+crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
+{
+	return NULL;
+}
+
+static void
+crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
+{
+}
+
+static const xf86CrtcFuncsRec crtc_funcs = {
+    .dpms                = crtc_dpms,
+    .set_mode_major      = crtc_set_mode_major,
+    .set_cursor_colors   = crtc_set_cursor_colors,
+    .set_cursor_position = crtc_set_cursor_position,
+    .show_cursor         = crtc_show_cursor,
+    .hide_cursor         = crtc_hide_cursor,
+    .load_cursor_argb    = crtc_load_cursor_argb,
+    .shadow_create       = crtc_shadow_create,
+    .shadow_allocate     = crtc_shadow_allocate,
+    .shadow_destroy      = crtc_shadow_destroy,
+    .destroy		 = NULL, /* XXX */
+};
+
+static void
+output_dpms(xf86OutputPtr output, int mode)
+{
+	return;
+}
+
+static xf86OutputStatus
+output_detect(xf86OutputPtr output)
+{
+	return XF86OutputStatusConnected;
+}
+
+static Bool
+output_mode_valid(xf86OutputPtr output, DisplayModePtr pModes)
+{
+	return MODE_OK;
+}
+
+static DisplayModePtr
+output_get_modes(xf86OutputPtr xf86output)
+{
+    struct xwl_output *output = xf86output->driver_private;
+    struct monitor_ranges *ranges;
+    DisplayModePtr modes;
+
+    modes = xf86CVTMode(output->width, output->height, 60, TRUE, FALSE);
+    output->xf86monitor.det_mon[0].type = DS_RANGES;
+    ranges = &output->xf86monitor.det_mon[0].section.ranges;
+    ranges->min_h = modes->HSync - 10;
+    ranges->max_h = modes->HSync + 10;
+    ranges->min_v = modes->VRefresh - 10;
+    ranges->max_v = modes->VRefresh + 10;
+    ranges->max_clock = modes->Clock + 100;
+    output->xf86monitor.det_mon[1].type = DT;
+    output->xf86monitor.det_mon[2].type = DT;
+    output->xf86monitor.det_mon[3].type = DT;
+    output->xf86monitor.no_sections = 0;
+
+    xf86output->MonInfo = &output->xf86monitor;
+
+    return modes;
+}
+
+static void
+output_destroy(xf86OutputPtr xf86output)
+{
+    struct xwl_output *output = xf86output->driver_private;
+
+    free(output);
+}
+
+static const xf86OutputFuncsRec output_funcs = {
+    .dpms	= output_dpms,
+    .detect	= output_detect,
+    .mode_valid	= output_mode_valid,
+    .get_modes	= output_get_modes,
+    .destroy	= output_destroy
+};
+
+struct xwl_output *
+xwl_output_create(struct xwl_screen *xwl_screen)
+{
+    struct xwl_output *xwl_output;
+    xf86OutputPtr xf86output;
+    xf86CrtcPtr xf86crtc;
+
+    xwl_output = calloc(sizeof *xwl_output, 1);
+    if (xwl_output == NULL) {
+	ErrorF("create_output ENOMEM");
+	return NULL;
+    }
+
+    xwl_output->xwl_screen = xwl_screen;
+
+    xf86output = xf86OutputCreate(xwl_screen->scrninfo,
+				  &output_funcs, "XWAYLAND-1");
+    xf86output->driver_private = xwl_output;
+    xf86output->possible_crtcs = 1;
+    xf86output->possible_clones = 1;
+
+    xf86crtc = xf86CrtcCreate(xwl_screen->scrninfo, &crtc_funcs);
+    xf86crtc->driver_private = xwl_output;
+
+    xwl_output->xf86output = xf86output;
+    xwl_output->xf86crtc = xf86crtc;
+
+    return xwl_output;
+}
+
+static Bool
+resize(ScrnInfoPtr scrn, int width, int height)
+{
+    if (scrn->virtualX == width && scrn->virtualY == height)
+	return TRUE;
+    /* We don't handle resize at all, we must match the compositor size */
+    return FALSE;
+}
+
+static const xf86CrtcConfigFuncsRec config_funcs = {
+    resize
+};
+
+static void
+display_handle_geometry(void *data, struct wl_output *wl_output, int x, int y,
+			int physical_width, int physical_height, int subpixel,
+			const char *make, const char *model, int transform)
+{
+    struct xwl_output *xwl_output = data;
+    struct xwl_screen *xwl_screen = xwl_output->xwl_screen;
+
+    xwl_output->xf86output->mm_width = physical_width;
+    xwl_output->xf86output->mm_height = physical_height;
+
+    switch (subpixel) {
+    case WL_OUTPUT_SUBPIXEL_UNKNOWN:
+	xwl_output->xf86output->subpixel_order = SubPixelUnknown;
+	break;
+    case WL_OUTPUT_SUBPIXEL_NONE:
+	xwl_output->xf86output->subpixel_order = SubPixelNone;
+	break;
+    case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB:
+	xwl_output->xf86output->subpixel_order = SubPixelHorizontalRGB;
+	break;
+    case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR:
+	xwl_output->xf86output->subpixel_order = SubPixelHorizontalBGR;
+	break;
+    case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB:
+	xwl_output->xf86output->subpixel_order = SubPixelVerticalRGB;
+	break;
+    case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR:
+	xwl_output->xf86output->subpixel_order = SubPixelVerticalBGR;
+	break;
+    }
+
+    xwl_output->x = x;
+    xwl_output->y = y;
+
+    xwl_screen->xwl_output = xwl_output;
+}
+
+static void
+display_handle_mode(void *data, struct wl_output *wl_output, uint32_t flags,
+		    int width, int height, int refresh)
+{
+    struct xwl_output *xwl_output = data;
+
+    if (flags & WL_OUTPUT_MODE_CURRENT) {
+	xwl_output->width = width;
+	xwl_output->height = height;
+    }
+}
+
+static const struct wl_output_listener output_listener = {
+    display_handle_geometry,
+    display_handle_mode
+};
+
+static void
+global_handler(void *data, struct wl_registry *registry, uint32_t id,
+	       const char *interface, uint32_t version)
+{
+    struct xwl_screen *xwl_screen = data;
+    struct xwl_output *xwl_output;
+
+    if (strcmp (interface, "wl_output") == 0) {
+	xwl_output = xwl_output_create(xwl_screen);
+	xwl_output->output = wl_registry_bind(registry, id,
+	                                      &wl_output_interface, 1);
+	wl_output_add_listener(xwl_output->output,
+			       &output_listener, xwl_output);
+    }
+}
+
+static const struct wl_registry_listener global_listener = {
+    global_handler,
+};
+
+void
+xwayland_screen_preinit_output(struct xwl_screen *xwl_screen, ScrnInfoPtr scrninfo)
+{
+    int ret;
+
+    xf86CrtcConfigInit(scrninfo, &config_funcs);
+
+    xf86CrtcSetSizeRange(scrninfo, 320, 200, 8192, 8192);
+
+    xwl_screen->output_registry = wl_display_get_registry(xwl_screen->display);
+    wl_registry_add_listener(xwl_screen->output_registry, &global_listener,
+                             xwl_screen);
+
+    while (!xwl_screen->xwl_output) {
+        ret = wl_display_roundtrip(xwl_screen->display);
+        if (ret == -1)
+            FatalError("failed to dispatch Wayland events: %s\n", strerror(errno));
+    }
+
+    xf86InitialConfiguration(scrninfo, TRUE);
+}
diff --git a/hw/xfree86/xwayland/xwayland-private.h b/hw/xfree86/xwayland/xwayland-private.h
new file mode 100644
index 0000000..e427316
--- /dev/null
+++ b/hw/xfree86/xwayland/xwayland-private.h
@@ -0,0 +1,132 @@
+/*
+ * Copyright © 2010 Kristian Høgsberg
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of the
+ * copyright holders not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no
+ * representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifndef _XWAYLAND_PRIVATE_H_
+#define _XWAYLAND_PRIVATE_H_
+
+struct xwl_window {
+    struct xwl_screen		*xwl_screen;
+    struct wl_surface		*surface;
+    struct wl_buffer		*buffer;
+    WindowPtr			 window;
+    DamagePtr			 damage;
+    struct xorg_list		 link;
+    struct xorg_list		 link_damage;
+};
+
+struct xwl_output;
+
+struct xwl_screen {
+    struct xwl_driver		*driver;
+    ScreenPtr			 screen;
+    ScrnInfoPtr			 scrninfo;
+    int				 drm_fd;
+    int				 wayland_fd;
+    struct xwl_output		*xwl_output;
+    struct wl_display		*display;
+    struct wl_registry          *registry;
+    struct wl_registry          *drm_registry;
+    struct wl_registry          *input_registry;
+    struct wl_registry          *output_registry;
+    struct wl_compositor	*compositor;
+    struct wl_drm		*drm;
+    struct wl_shm		*shm;
+    struct xserver		*xorg_server;
+    uint32_t			 mask;
+    uint32_t			 flags;
+    char			*device_name;
+    uint32_t			 authenticated;
+    struct xorg_list		 seat_list;
+    struct xorg_list		 damage_window_list;
+    struct xorg_list		 window_list;
+    struct xorg_list		 authenticate_client_list;
+    uint32_t			 serial;
+
+    CreateWindowProcPtr		 CreateWindow;
+    DestroyWindowProcPtr	 DestroyWindow;
+    RealizeWindowProcPtr	 RealizeWindow;
+    UnrealizeWindowProcPtr	 UnrealizeWindow;
+    SetWindowPixmapProcPtr	 SetWindowPixmap;
+    MoveWindowProcPtr		 MoveWindow;
+    miPointerSpriteFuncPtr	 sprite_funcs;
+};
+
+struct xwl_output {
+    struct wl_output		*output;
+    struct xwl_screen		*xwl_screen;
+    int32_t			 x, y, width, height;
+    xf86Monitor			 xf86monitor;
+    xf86OutputPtr		 xf86output;
+    xf86CrtcPtr			 xf86crtc;
+};
+
+
+#define MODIFIER_META 0x01
+
+struct xwl_seat {
+    DeviceIntPtr		 pointer;
+    DeviceIntPtr		 keyboard;
+    struct xwl_screen		*xwl_screen;
+    struct wl_seat		*seat;
+    struct wl_pointer		*wl_pointer;
+    struct wl_keyboard		*wl_keyboard;
+    struct wl_array		 keys;
+    struct wl_surface		*cursor;
+    struct xwl_window		*focus_window;
+    uint32_t			 id;
+    uint32_t			 pointer_enter_serial;
+    struct xorg_list		 link;
+    CursorPtr                    x_cursor;
+
+    wl_fixed_t			 horizontal_scroll;
+    wl_fixed_t			 vertical_scroll;
+    uint32_t			 scroll_time;
+
+    size_t			 keymap_size;
+    char			*keymap;
+
+};
+
+
+struct xwl_screen *xwl_screen_get(ScreenPtr screen);
+
+void xwayland_screen_preinit_output(struct xwl_screen *xwl_screen, ScrnInfoPtr scrninfo);
+
+int xwl_screen_init_cursor(struct xwl_screen *xwl_screen, ScreenPtr screen);
+int xwl_screen_init_window(struct xwl_screen *xwl_screen, ScreenPtr screen);
+
+struct xwl_output *xwl_output_create(struct xwl_screen *xwl_screen);
+
+void xwl_input_teardown(pointer p);
+pointer xwl_input_setup(pointer module, pointer opts, int *errmaj, int *errmin);
+void xwl_input_init(struct xwl_screen *screen);
+
+Bool xwl_drm_initialised(struct xwl_screen *screen);
+
+void xwl_seat_set_cursor(struct xwl_seat *xwl_seat);
+
+extern const struct xserver_listener xwl_server_listener;
+
+#endif /* _XWAYLAND_PRIVATE_H_ */
diff --git a/hw/xfree86/xwayland/xwayland-window.c b/hw/xfree86/xwayland/xwayland-window.c
new file mode 100644
index 0000000..d56e0d0
--- /dev/null
+++ b/hw/xfree86/xwayland/xwayland-window.c
@@ -0,0 +1,317 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of the
+ * copyright holders not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no
+ * representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include "xorg-config.h"
+#endif
+
+#include <unistd.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <wayland-client.h>
+#include <X11/extensions/compositeproto.h>
+
+#include <xorg-server.h>
+#include <xf86Crtc.h>
+#include <selection.h>
+#include <compositeext.h>
+#include <exevents.h>
+
+#include "xwayland.h"
+#include "xwayland-private.h"
+#include "xserver-client-protocol.h"
+
+static DevPrivateKeyRec xwl_window_private_key;
+
+static void
+free_pixmap(void *data, struct wl_callback *callback, uint32_t time)
+{
+    PixmapPtr pixmap = data;
+    ScreenPtr screen = pixmap->drawable.pScreen;
+
+    (*screen->DestroyPixmap)(pixmap);
+    wl_callback_destroy(callback);
+}
+
+static const struct wl_callback_listener free_pixmap_listener = {
+	free_pixmap,
+};
+
+static void
+xwl_window_attach(struct xwl_window *xwl_window, PixmapPtr pixmap)
+{
+    struct xwl_screen *xwl_screen = xwl_window->xwl_screen;
+    struct wl_callback *callback;
+
+    /* We can safely destroy the buffer because we only use one buffer
+     * per surface in xwayland model */
+    if (xwl_window->buffer)
+        wl_buffer_destroy(xwl_window->buffer);
+
+    xwl_screen->driver->create_window_buffer(xwl_window, pixmap);
+
+    if (!xwl_window->buffer) {
+        ErrorF("failed to create buffer\n");
+	return;
+    }
+
+    wl_surface_attach(xwl_window->surface, xwl_window->buffer, 0, 0);
+    wl_surface_damage(xwl_window->surface, 0, 0,
+		      pixmap->drawable.width,
+		      pixmap->drawable.height);
+    wl_surface_commit(xwl_window->surface);
+
+    callback = wl_display_sync(xwl_screen->display);
+    wl_callback_add_listener(callback, &free_pixmap_listener, pixmap);
+    pixmap->refcnt++;
+}
+
+static Bool
+xwl_create_window(WindowPtr window)
+{
+    ScreenPtr screen = window->drawable.pScreen;
+    struct xwl_screen *xwl_screen;
+    char buffer[32];
+    int len, rc;
+    Atom name;
+    Bool ret;
+
+    xwl_screen = xwl_screen_get(screen);
+
+    screen->CreateWindow = xwl_screen->CreateWindow;
+    ret = (*screen->CreateWindow)(window);
+    xwl_screen->CreateWindow = screen->CreateWindow;
+    screen->CreateWindow = xwl_create_window;
+
+    if (!(xwl_screen->flags & XWL_FLAGS_ROOTLESS) ||
+	window->parent != NULL)
+	return ret;
+
+    CompositeRedirectSubwindows(window, CompositeRedirectManual);
+
+    return ret;
+}
+
+static int
+xwl_destroy_window (WindowPtr window)
+{
+    ScreenPtr screen = window->drawable.pScreen;
+    struct xwl_screen *xwl_screen;
+    Bool ret;
+
+    if (window->parent == NULL)
+	CompositeUnRedirectSubwindows (window, CompositeRedirectManual);
+
+    xwl_screen = xwl_screen_get(screen);
+
+    screen->DestroyWindow = xwl_screen->DestroyWindow;
+    ret = (*screen->DestroyWindow)(window);
+    xwl_screen->DestroyWindow = screen->DestroyWindow;
+    screen->DestroyWindow = xwl_destroy_window;
+
+    return ret;
+}
+
+static void
+damage_report(DamagePtr pDamage, RegionPtr pRegion, void *data)
+{
+    struct xwl_window *xwl_window = data;
+    struct xwl_screen *xwl_screen = xwl_window->xwl_screen;
+
+    xorg_list_add(&xwl_window->link_damage, &xwl_screen->damage_window_list);
+}
+
+static void
+damage_destroy(DamagePtr pDamage, void *data)
+{
+}
+
+static Bool
+xwl_realize_window(WindowPtr window)
+{
+    ScreenPtr screen = window->drawable.pScreen;
+    struct xwl_screen *xwl_screen;
+    struct xwl_window *xwl_window;
+    Bool ret;
+
+    xwl_screen = xwl_screen_get(screen);
+
+    screen->RealizeWindow = xwl_screen->RealizeWindow;
+    ret = (*screen->RealizeWindow)(window);
+    xwl_screen->RealizeWindow = xwl_screen->RealizeWindow;
+    screen->RealizeWindow = xwl_realize_window;
+
+    if (xwl_screen->flags & XWL_FLAGS_ROOTLESS) {
+	if (window->redirectDraw != RedirectDrawManual)
+	    return ret;
+    } else {
+	if (window->parent)
+	    return ret;
+    }
+
+    xwl_window = calloc(sizeof *xwl_window, 1);
+    xwl_window->xwl_screen = xwl_screen;
+    xwl_window->window = window;
+    xwl_window->surface =
+	wl_compositor_create_surface(xwl_screen->compositor);
+    if (xwl_window->surface == NULL) {
+	ErrorF("wl_display_create_surface failed\n");
+	return FALSE;
+    }
+
+    if (xwl_screen->xorg_server)
+	xserver_set_window_id(xwl_screen->xorg_server,
+			      xwl_window->surface, window->drawable.id);
+
+    wl_surface_set_user_data(xwl_window->surface, xwl_window);
+    xwl_window_attach(xwl_window, (*screen->GetWindowPixmap)(window));
+
+    dixSetPrivate(&window->devPrivates,
+		  &xwl_window_private_key, xwl_window);
+
+    xwl_window->damage =
+	DamageCreate(damage_report, damage_destroy, DamageReportNonEmpty,
+		     FALSE, screen, xwl_window);
+    DamageRegister(&window->drawable, xwl_window->damage);
+    DamageSetReportAfterOp(xwl_window->damage, TRUE);
+
+    xorg_list_add(&xwl_window->link, &xwl_screen->window_list);
+    xorg_list_init(&xwl_window->link_damage);
+
+    return ret;
+}
+
+static Bool
+xwl_unrealize_window(WindowPtr window)
+{
+    ScreenPtr screen = window->drawable.pScreen;
+    struct xwl_screen *xwl_screen;
+    struct xwl_window *xwl_window;
+    struct xwl_seat *xwl_seat;
+    Bool ret;
+
+    xwl_screen = xwl_screen_get(screen);
+
+    xorg_list_for_each_entry(xwl_seat,
+			     &xwl_screen->seat_list, link) {
+	if (!xwl_seat->focus_window)
+	    continue ;
+	if (xwl_seat->focus_window->window == window) {
+	    xwl_seat->focus_window = NULL;
+	    SetDeviceRedirectWindow(xwl_seat->pointer, PointerRootWin);
+	}
+    }
+
+    screen->UnrealizeWindow = xwl_screen->UnrealizeWindow;
+    ret = (*screen->UnrealizeWindow)(window);
+    xwl_screen->UnrealizeWindow = screen->UnrealizeWindow;
+    screen->UnrealizeWindow = xwl_unrealize_window;
+
+    xwl_window =
+	dixLookupPrivate(&window->devPrivates, &xwl_window_private_key);
+    if (!xwl_window)
+	return ret;
+
+    if (xwl_window->buffer)
+	wl_buffer_destroy(xwl_window->buffer);
+    wl_surface_destroy(xwl_window->surface);
+    xorg_list_del(&xwl_window->link);
+    if (RegionNotEmpty(DamageRegion(xwl_window->damage)))
+	xorg_list_del(&xwl_window->link_damage);
+    DamageUnregister(&window->drawable, xwl_window->damage);
+    DamageDestroy(xwl_window->damage);
+    free(xwl_window);
+    dixSetPrivate(&window->devPrivates, &xwl_window_private_key, NULL);
+
+    return ret;
+}
+
+static void
+xwl_set_window_pixmap(WindowPtr window, PixmapPtr pixmap)
+{
+    ScreenPtr screen = window->drawable.pScreen;
+    struct xwl_screen *xwl_screen;
+    struct xwl_window *xwl_window;
+
+    xwl_screen = xwl_screen_get(screen);
+
+    screen->SetWindowPixmap = xwl_screen->SetWindowPixmap;
+    (*screen->SetWindowPixmap)(window, pixmap);
+    xwl_screen->SetWindowPixmap = screen->SetWindowPixmap;
+    screen->SetWindowPixmap = xwl_set_window_pixmap;
+
+    xwl_window =
+	dixLookupPrivate(&window->devPrivates, &xwl_window_private_key);
+    if (xwl_window)
+	xwl_window_attach(xwl_window, pixmap);
+}
+
+static void
+xwl_move_window(WindowPtr window, int x, int y,
+		   WindowPtr sibling, VTKind kind)
+{
+    ScreenPtr screen = window->drawable.pScreen;
+    struct xwl_screen *xwl_screen;
+    struct xwl_window *xwl_window;
+
+    xwl_screen = xwl_screen_get(screen);
+
+    screen->MoveWindow = xwl_screen->MoveWindow;
+    (*screen->MoveWindow)(window, x, y, sibling, kind);
+    xwl_screen->MoveWindow = screen->MoveWindow;
+    screen->MoveWindow = xwl_move_window;
+
+    xwl_window =
+	dixLookupPrivate(&window->devPrivates, &xwl_window_private_key);
+    if (xwl_window == NULL)
+	return;
+}
+
+int
+xwl_screen_init_window(struct xwl_screen *xwl_screen, ScreenPtr screen)
+{
+    if (!dixRegisterPrivateKey(&xwl_window_private_key, PRIVATE_WINDOW, 0))
+	return BadAlloc;
+
+    xwl_screen->CreateWindow = screen->CreateWindow;
+    screen->CreateWindow = xwl_create_window;
+
+    xwl_screen->DestroyWindow = screen->DestroyWindow;
+    screen->DestroyWindow = xwl_destroy_window;
+
+    xwl_screen->RealizeWindow = screen->RealizeWindow;
+    screen->RealizeWindow = xwl_realize_window;
+
+    xwl_screen->UnrealizeWindow = screen->UnrealizeWindow;
+    screen->UnrealizeWindow = xwl_unrealize_window;
+
+    xwl_screen->SetWindowPixmap = screen->SetWindowPixmap;
+    screen->SetWindowPixmap = xwl_set_window_pixmap;
+
+    xwl_screen->MoveWindow = screen->MoveWindow;
+    screen->MoveWindow = xwl_move_window;
+
+    return Success;
+}
diff --git a/hw/xfree86/xwayland/xwayland.c b/hw/xfree86/xwayland/xwayland.c
new file mode 100644
index 0000000..f59bfe4
--- /dev/null
+++ b/hw/xfree86/xwayland/xwayland.c
@@ -0,0 +1,392 @@
+/*
+ * Copyright © 2008-2011 Kristian Høgsberg
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of the
+ * copyright holders not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no
+ * representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include "xorg-config.h"
+#endif
+
+#include <stdint.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <wayland-util.h>
+#include <wayland-client.h>
+
+#include <xorg-server.h>
+#include <extinit.h>
+
+#include <xf86Xinput.h>
+#include <xf86Crtc.h>
+#include <xf86Priv.h>
+#include <os.h>
+#include <selection.h>
+
+#include "xwayland.h"
+#include "xwayland-private.h"
+#include "xserver-client-protocol.h"
+
+/*
+ * TODO:
+ *  - lose X kb focus when wayland surface loses it
+ *  - active grabs, grab owner crack
+ */
+
+static DevPrivateKeyRec xwl_screen_private_key;
+static Atom xdnd_atom;
+
+static void
+xserver_client(void *data, struct xserver *xserver, int fd)
+{
+    AddClientOnOpenFD(fd);
+}
+
+static void
+xserver_listen_socket(void *data, struct xserver *xserver, int fd)
+{
+    ListenOnOpenFD(fd, TRUE);
+}
+
+const struct xserver_listener xwl_server_listener = {
+    xserver_client,
+    xserver_listen_socket
+};
+
+static void
+xwl_input_delayed_init(void *data, struct wl_callback *callback, uint32_t time)
+{
+    struct xwl_screen *xwl_screen = data;
+
+    ErrorF("xwl_input_delayed_init\n");
+
+    wl_callback_destroy(callback);
+    xwl_input_init(xwl_screen);
+}
+
+static const struct wl_callback_listener delayed_init_listner = {
+	xwl_input_delayed_init
+};
+
+static void
+registry_global(void *data, struct wl_registry *registry, uint32_t id,
+	        const char *interface, uint32_t version)
+{
+    struct xwl_screen *xwl_screen = data;
+
+    if (strcmp (interface, "wl_compositor") == 0) {
+	xwl_screen->compositor =
+            wl_registry_bind(registry, id, &wl_compositor_interface, 1);
+    } else if (strcmp(interface, "wl_shm") == 0) {
+        xwl_screen->shm =
+            wl_registry_bind(registry, id, &wl_shm_interface, 1);
+    }
+}
+
+static const struct wl_registry_listener registry_listener = {
+    registry_global,
+};
+
+static void
+wakeup_handler(pointer data, int err, pointer read_mask)
+{
+    struct xwl_screen *xwl_screen = data;
+    int ret;
+
+    if (err < 0)
+        return;
+
+    if (!FD_ISSET(xwl_screen->wayland_fd, (fd_set *) read_mask))
+        return;
+
+    ret = wl_display_dispatch(xwl_screen->display);
+    if (ret == -1)
+        FatalError("failed to dispatch Wayland events: %s\n", strerror(errno));
+}
+
+static void
+block_handler(pointer data, struct timeval **tv, pointer read_mask)
+{
+    struct xwl_screen *xwl_screen = data;
+    int ret;
+
+    ret = wl_display_dispatch_pending(xwl_screen->display);
+    if (ret == -1)
+	FatalError("failed to dispatch Wayland events: %s\n", strerror(errno));
+
+    ret = wl_display_flush(xwl_screen->display);
+    if (ret == -1)
+        FatalError("failed to write to XWayland fd: %s\n", strerror(errno));
+}
+
+int
+xwl_screen_init(struct xwl_screen *xwl_screen, ScreenPtr screen)
+{
+    struct wl_callback *callback;
+
+    xwl_screen->screen = screen;
+
+    if (!dixRegisterPrivateKey(&xwl_screen_private_key, PRIVATE_SCREEN, 0))
+	return BadAlloc;
+
+    dixSetPrivate(&screen->devPrivates,
+		  &xwl_screen_private_key, xwl_screen);
+
+    xwl_screen_init_window(xwl_screen, screen);
+
+    xwl_screen_init_cursor(xwl_screen, screen);
+
+    AddGeneralSocket(xwl_screen->wayland_fd);
+    RegisterBlockAndWakeupHandlers(block_handler, wakeup_handler, xwl_screen);
+
+    callback = wl_display_sync(xwl_screen->display);
+    wl_callback_add_listener(callback, &delayed_init_listner, xwl_screen);
+
+    return Success;
+}
+
+struct xwl_screen *
+xwl_screen_get(ScreenPtr screen)
+{
+    return dixLookupPrivate(&screen->devPrivates, &xwl_screen_private_key);
+}
+
+static void
+xwayland_selection_callback(CallbackListPtr *callbacks,
+			    pointer data, pointer args)
+{
+    SelectionInfoRec *info = (SelectionInfoRec *) args;
+    Selection *selection = info->selection;
+
+    switch (info->kind) {
+    case SelectionSetOwner:
+	if (selection->selection == xdnd_atom) {
+	    if (selection->window != None)
+		ErrorF("client %p starts dnd\n", info->client);
+	    else
+		ErrorF("client %p stops dnd\n", info->client);
+	}
+	break;
+    case SelectionWindowDestroy:
+	ErrorF("selection window destroy\n");
+	break;
+    case SelectionClientClose:
+	ErrorF("selection client close\n");
+	break;
+    }
+}
+
+struct xwl_screen *
+xwl_screen_create(void)
+{
+    struct xwl_screen *xwl_screen;
+
+    xwl_screen = calloc(sizeof *xwl_screen, 1);
+    if (xwl_screen == NULL) {
+	ErrorF("calloc failed\n");
+	return NULL;
+    }
+
+    xwl_screen->display = wl_display_connect(NULL);
+    if (xwl_screen->display == NULL) {
+	ErrorF("wl_display_create failed\n");
+	return NULL;
+    }
+
+    return xwl_screen;
+}
+
+Bool
+xwl_screen_pre_init(ScrnInfoPtr scrninfo, struct xwl_screen *xwl_screen,
+		    uint32_t flags, struct xwl_driver *driver)
+{
+    int ret;
+
+    noScreenSaverExtension = TRUE;
+
+    xdnd_atom = MakeAtom("XdndSelection", 13, 1);
+    if (!AddCallback(&SelectionCallback,
+		     xwayland_selection_callback, xwl_screen)) {
+	return FALSE;
+    }
+
+    xorg_list_init(&xwl_screen->seat_list);
+    xorg_list_init(&xwl_screen->damage_window_list);
+    xorg_list_init(&xwl_screen->window_list);
+    xorg_list_init(&xwl_screen->authenticate_client_list);
+    xwl_screen->scrninfo = scrninfo;
+    xwl_screen->driver = driver;
+    xwl_screen->flags = flags;
+    xwl_screen->wayland_fd = wl_display_get_fd(xwl_screen->display);
+
+    if (xorgRootless)
+	xwl_screen->flags |= XWL_FLAGS_ROOTLESS;
+
+    /* Set up listener so we'll catch all events. */
+    xwl_screen->registry = wl_display_get_registry(xwl_screen->display);
+    wl_registry_add_listener(xwl_screen->registry, &registry_listener,
+                             xwl_screen);
+    ret = wl_display_roundtrip(xwl_screen->display);
+    if (ret == -1) {
+        xf86DrvMsg(scrninfo->scrnIndex, X_ERROR,
+                   "failed to dispatch Wayland events: %s\n", strerror(errno));
+        return FALSE;
+    }
+
+#ifdef WITH_LIBDRM
+    if (xwl_screen->driver->use_drm && !xwl_drm_initialised(xwl_screen))
+	if (xwl_drm_pre_init(xwl_screen) != Success)
+            return FALSE;
+#endif
+
+    xwayland_screen_preinit_output(xwl_screen, scrninfo);
+
+    return TRUE;
+}
+
+int
+xwl_create_window_buffer_shm(struct xwl_window *xwl_window,
+			     PixmapPtr pixmap, int fd)
+{
+    struct wl_shm_pool *pool;
+    int size, stride;
+
+    stride = pixmap->drawable.width * 4;
+
+    size = pixmap->drawable.width * pixmap->drawable.height * 4;
+    pool = wl_shm_create_pool(xwl_window->xwl_screen->shm, fd, size);
+    xwl_window->buffer =  wl_shm_pool_create_buffer(pool, 0,
+			   pixmap->drawable.width,
+			   pixmap->drawable.height,
+			   stride, WL_SHM_FORMAT_ARGB8888);
+    wl_shm_pool_destroy(pool);
+
+    return xwl_window->buffer ? Success : BadDrawable;
+}
+
+void xwl_screen_close(struct xwl_screen *xwl_screen)
+{
+    struct xwl_seat *xwl_seat, *itmp;
+    struct xwl_window *xwl_window, *wtmp;
+
+    if (xwl_screen->registry)
+        wl_registry_destroy(xwl_screen->registry);
+    xwl_screen->registry = NULL;
+
+    xorg_list_for_each_entry_safe(xwl_seat, itmp,
+				  &xwl_screen->seat_list, link) {
+	wl_seat_destroy(xwl_seat->seat);
+	free(xwl_seat);
+    }
+    xorg_list_for_each_entry_safe(xwl_window, wtmp,
+				  &xwl_screen->window_list, link) {
+	wl_buffer_destroy(xwl_window->buffer);
+	wl_surface_destroy(xwl_window->surface);
+	free(xwl_window);
+    }
+
+    xorg_list_init(&xwl_screen->seat_list);
+    xorg_list_init(&xwl_screen->damage_window_list);
+    xorg_list_init(&xwl_screen->window_list);
+    xorg_list_init(&xwl_screen->authenticate_client_list);
+
+    wl_display_roundtrip(xwl_screen->display);
+}
+
+void xwl_screen_destroy(struct xwl_screen *xwl_screen)
+{
+    if (xwl_screen->xwl_output) {
+	xf86OutputDestroy(xwl_screen->xwl_output->xf86output);
+	xf86CrtcDestroy(xwl_screen->xwl_output->xf86crtc);
+    }
+
+    free(xwl_screen->xwl_output);
+    free(xwl_screen);
+}
+
+/* DDX driver must call this after submitting the rendering */
+void xwl_screen_post_damage(struct xwl_screen *xwl_screen)
+{
+    struct xwl_window *xwl_window;
+    RegionPtr region;
+    BoxPtr box;
+    int count, i;
+
+    xorg_list_for_each_entry(xwl_window, &xwl_screen->damage_window_list,
+			     link_damage) {
+
+	region = DamageRegion(xwl_window->damage);
+	count = RegionNumRects(region);
+	for (i = 0; i < count; i++) {
+	    box = &RegionRects(region)[i];
+	    wl_surface_damage(xwl_window->surface,
+			      box->x1, box->y1,
+			      box->x2 - box->x1 + 1,
+			      box->y2 - box->y1 + 1);
+	}
+	wl_surface_attach(xwl_window->surface,
+			  xwl_window->buffer,
+			  0, 0);
+	wl_surface_commit(xwl_window->surface);
+	DamageEmpty(xwl_window->damage);
+    }
+
+    xorg_list_init(&xwl_screen->damage_window_list);
+}
+
+static pointer
+xwl_setup(pointer module, pointer opts, int *errmaj, int *errmin)
+{
+    return xwl_input_setup(module, opts, errmaj, errmin);
+}
+
+static void
+xwl_teardown(pointer p)
+{
+    xwl_input_teardown(p);
+}
+
+static XF86ModuleVersionInfo xwl_version_info = {
+    "xwayland",
+    MODULEVENDORSTRING,
+    MODINFOSTRING1,
+    MODINFOSTRING2,
+    XORG_VERSION_CURRENT,
+    1, 0, 0,
+    ABI_CLASS_EXTENSION,
+    ABI_EXTENSION_VERSION,
+    MOD_CLASS_NONE,
+    { 0, 0, 0, 0 }
+};
+
+_X_EXPORT const XF86ModuleData xwaylandModuleData = {
+    &xwl_version_info,
+    &xwl_setup,
+    &xwl_teardown
+};
+
+int
+xwl_version(void)
+{
+    return xwl_version_info.minorversion;
+}
diff --git a/hw/xfree86/xwayland/xwayland.h b/hw/xfree86/xwayland/xwayland.h
new file mode 100644
index 0000000..f268366
--- /dev/null
+++ b/hw/xfree86/xwayland/xwayland.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright © 2008 Kristian Høgsberg
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of the
+ * copyright holders not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no
+ * representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#ifndef _XWAYLAND_H_
+#define _XWAYLAND_H_
+
+#define XWL_VERSION 2
+
+struct xwl_window;
+struct xwl_screen;
+
+struct xwl_driver {
+    int version;
+    int use_drm;
+    int (*create_window_buffer)(struct xwl_window *xwl_window,
+                                PixmapPtr pixmap);
+};
+
+#define XWL_FLAGS_ROOTLESS 0x01
+
+extern _X_EXPORT int
+xwl_version(void);
+
+extern _X_EXPORT struct xwl_screen *
+xwl_screen_create(void);
+
+extern _X_EXPORT Bool
+xwl_screen_pre_init(ScrnInfoPtr scrninfo, struct xwl_screen *xwl_screen,
+		    uint32_t flags, struct xwl_driver *driver);
+
+extern _X_EXPORT int
+xwl_screen_init(struct xwl_screen *xwl_screen, ScreenPtr screen);
+
+extern _X_EXPORT int
+xwl_drm_pre_init(struct xwl_screen *xwl_screen);
+
+extern _X_EXPORT int
+xwl_screen_get_drm_fd(struct xwl_screen *xwl_screen);
+
+extern _X_EXPORT void
+xwl_screen_close(struct xwl_screen *xwl_screen);
+
+extern _X_EXPORT void
+xwl_screen_destroy(struct xwl_screen *xwl_screen);
+
+extern _X_EXPORT void
+xwl_screen_post_damage(struct xwl_screen *xwl_screen);
+
+extern _X_EXPORT int
+xwl_drm_authenticate(ClientPtr client, struct xwl_screen *xwl_screen,
+		     uint32_t magic);
+
+extern _X_EXPORT int
+xwl_create_window_buffer_drm(struct xwl_window *xwl_window,
+			     PixmapPtr pixmap, uint32_t name);
+
+extern _X_EXPORT int
+xwl_create_window_buffer_shm(struct xwl_window *xwl_window,
+			     PixmapPtr pixmap, int fd);
+
+#endif /* _XWAYLAND_H_ */
diff --git a/include/xorg-server.h.in b/include/xorg-server.h.in
index 81935be..2f9d27b 100644
--- a/include/xorg-server.h.in
+++ b/include/xorg-server.h.in
@@ -212,4 +212,7 @@
 #define _XSERVER64 1
 #endif
 
+/* Building Xorg server. */
+#undef XORG_WAYLAND
+
 #endif /* _XORG_SERVER_H_ */
commit 0292d60d029cd8299c9cbdc24ecd3bf76f076465
Author: Tiago Vignatti <tiago.vignatti at intel.com>
Date:   Wed Aug 21 21:23:09 2013 -0700

    dri2: Introduce a third version of the AuthMagic function
    
    This most recent version takes a client pointer to allow xwayland to
    asynchronously authenticate a client.

diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index 0b047f0..efdcd66 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -121,8 +121,9 @@ typedef struct _DRI2Screen {
     DRI2ScheduleSwapProcPtr ScheduleSwap;
     DRI2GetMSCProcPtr GetMSC;
     DRI2ScheduleWaitMSCProcPtr ScheduleWaitMSC;
-    DRI2AuthMagic2ProcPtr AuthMagic;
     DRI2AuthMagicProcPtr LegacyAuthMagic;
+    DRI2AuthMagic2ProcPtr LegacyAuthMagic2;
+    DRI2AuthMagic3ProcPtr AuthMagic;
     DRI2ReuseBufferNotifyProcPtr ReuseBufferNotify;
     DRI2SwapLimitValidateProcPtr SwapLimitValidate;
     DRI2GetParamProcPtr GetParam;
@@ -1352,7 +1353,7 @@ DRI2Authenticate(ClientPtr client, ScreenPtr pScreen, uint32_t magic)
         return FALSE;
 
     primescreen = GetScreenPrime(pScreen, dri2_client->prime_id);
-    if ((*ds->AuthMagic)(primescreen, magic))
+    if ((*ds->AuthMagic)(client, primescreen, magic))
         return FALSE;
     return TRUE;
 }
@@ -1457,8 +1458,11 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
         cur_minor = 1;
     }
 
+    if (info->version >= 10) {
+        ds->AuthMagic = info->AuthMagic3;
+    }
     if (info->version >= 8) {
-        ds->AuthMagic = info->AuthMagic2;
+        ds->LegacyAuthMagic2 = info->AuthMagic2;
     }
     if (info->version >= 5) {
         ds->LegacyAuthMagic = info->AuthMagic;
@@ -1497,7 +1501,7 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
          * If the driver doesn't provide an AuthMagic function
          * it relies on the old method (using libdrm) or fails
          */
-        if (!ds->LegacyAuthMagic)
+        if (!ds->LegacyAuthMagic2 && !ds->LegacyAuthMagic)
 #ifdef WITH_LIBDRM
             ds->LegacyAuthMagic = drmAuthMagic;
 #else
diff --git a/hw/xfree86/dri2/dri2.h b/hw/xfree86/dri2/dri2.h
index 1e7afdd..38b4f58 100644
--- a/hw/xfree86/dri2/dri2.h
+++ b/hw/xfree86/dri2/dri2.h
@@ -65,6 +65,8 @@ typedef void (*DRI2CopyRegionProcPtr) (DrawablePtr pDraw,
 typedef void (*DRI2WaitProcPtr) (WindowPtr pWin, unsigned int sequence);
 typedef int (*DRI2AuthMagicProcPtr) (int fd, uint32_t magic);
 typedef int (*DRI2AuthMagic2ProcPtr) (ScreenPtr pScreen, uint32_t magic);
+typedef int (*DRI2AuthMagic3ProcPtr) (ClientPtr client,
+                                      ScreenPtr pScreen, uint32_t magic);
 
 /**
  * Schedule a buffer swap
@@ -252,6 +254,9 @@ typedef struct {
     DRI2CreateBuffer2ProcPtr CreateBuffer2;
     DRI2DestroyBuffer2ProcPtr DestroyBuffer2;
     DRI2CopyRegion2ProcPtr CopyRegion2;
+
+    /* added in version 10 */
+    DRI2AuthMagic3ProcPtr AuthMagic3;
 } DRI2InfoRec, *DRI2InfoPtr;
 
 extern _X_EXPORT Bool DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info);
@@ -268,6 +273,8 @@ extern _X_EXPORT Bool DRI2Connect(ClientPtr client, ScreenPtr pScreen,
 
 extern _X_EXPORT Bool DRI2Authenticate(ClientPtr client, ScreenPtr pScreen, uint32_t magic);
 
+extern _X_EXPORT void DRI2SendAuthReply(ClientPtr client, Bool status);
+
 extern _X_EXPORT int DRI2CreateDrawable(ClientPtr client,
                                         DrawablePtr pDraw,
                                         XID id,
diff --git a/hw/xfree86/dri2/dri2ext.c b/hw/xfree86/dri2/dri2ext.c
index e1decec..4ab0186 100644
--- a/hw/xfree86/dri2/dri2ext.c
+++ b/hw/xfree86/dri2/dri2ext.c
@@ -136,11 +136,23 @@ ProcDRI2Connect(ClientPtr client)
     return Success;
 }
 
+void
+DRI2SendAuthReply(ClientPtr client, Bool status)
+{
+    xDRI2AuthenticateReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .authenticated = status
+    };
+
+    WriteToClient(client, sizeof(xDRI2AuthenticateReply), &rep);
+}
+
 static int
 ProcDRI2Authenticate(ClientPtr client)
 {
     REQUEST(xDRI2AuthenticateReq);
-    xDRI2AuthenticateReply rep;
     DrawablePtr pDraw;
     int status;
 
@@ -149,13 +161,12 @@ ProcDRI2Authenticate(ClientPtr client)
                        &pDraw, &status))
         return status;
 
-    rep = (xDRI2AuthenticateReply) {
-        .type = X_Reply,
-        .sequenceNumber = client->sequence,
-        .length = 0,
-        .authenticated = DRI2Authenticate(client, pDraw->pScreen, stuff->magic)
-    };
-    WriteToClient(client, sizeof(xDRI2AuthenticateReply), &rep);
+    status = DRI2Authenticate(client, pDraw->pScreen, stuff->magic);
+
+    /* if non-blocking authentication is in progress, then don't send a reply
+     * now but later in the implementation (e.g. drm_handle_authenticated) */
+    if (client->ignoreCount == 0)
+        DRI2SendAuthReply(client, status);
 
     return Success;
 }
commit c73891f8d4c2ef57eff977d186532c008815356a
Author: Kristian Høgsberg <krh at redhat.com>
Date:   Fri Sep 18 22:09:03 2009 -0400

    Add redirect window for input device feature

diff --git a/Xi/exevents.c b/Xi/exevents.c
index fd4b80c..f510a9e 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -2025,6 +2025,19 @@ DeliverTouchEvents(DeviceIntPtr dev, TouchPointInfoPtr ti,
     }
 }
 
+void
+SetDeviceRedirectWindow(DeviceIntPtr dev, WindowPtr window)
+{
+    SpritePtr pSprite = dev->spriteInfo->sprite;
+    DeviceIntPtr mouse;
+
+    mouse = IsMaster(dev) ? dev : GetMaster(dev, MASTER_POINTER);
+
+    pSprite->redirectWindow = window;
+
+    CheckMotion(NULL, mouse);
+}
+
 int
 InitProximityClassDeviceStruct(DeviceIntPtr dev)
 {
diff --git a/dix/events.c b/dix/events.c
index 086601a..702f98b 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2832,7 +2832,16 @@ XYToWindow(SpritePtr pSprite, int x, int y)
     BoxRec box;
 
     pSprite->spriteTraceGood = 1;       /* root window still there */
-    pWin = RootWindow(pSprite)->firstChild;
+    if (pSprite->redirectWindow == PointerRootWin) {
+        return RootWindow(pSprite);
+    }
+    else if (pSprite->redirectWindow) {
+        pWin = pSprite->redirectWindow;
+        pSprite->spriteTrace[pSprite->spriteTraceGood++] = pWin;
+        pWin = pWin->firstChild;
+    }
+    else
+        pWin = RootWindow(pSprite)->firstChild;
     while (pWin) {
         if ((pWin->mapped) &&
             (x >= pWin->drawable.x - wBorderWidth(pWin)) &&
diff --git a/include/exevents.h b/include/exevents.h
index 321fc42..ba93be3 100644
--- a/include/exevents.h
+++ b/include/exevents.h
@@ -162,6 +162,10 @@ extern void
  ProcessOtherEvent(InternalEvent * /* ev */ ,
                    DeviceIntPtr /* other */ );
 
+extern _X_EXPORT void
+  SetDeviceRedirectWindow(DeviceIntPtr /* dev */ ,
+                        WindowPtr /* window */ );
+
 extern int
  CheckGrabValues(ClientPtr /* client */ ,
                  GrabParameters * /* param */ );
diff --git a/include/inputstr.h b/include/inputstr.h
index dc36c5d..09471cf 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -246,6 +246,8 @@ typedef struct _SpriteRec {
     ScreenPtr pEnqueueScreen;
     ScreenPtr pDequeueScreen;
 
+    WindowPtr redirectWindow;
+
 } SpriteRec;
 
 typedef struct _KeyClassRec {
commit 15a7e62a9848f2089180c49b02887565d29bb896
Author: Kristian Høgsberg <krh at redhat.com>
Date:   Fri Sep 18 22:02:43 2009 -0400

    Export CompositeRedirectSubwindows and CompositeUnRedirectSubwindows

diff --git a/composite/compalloc.c b/composite/compalloc.c
index cc69c68..edee499 100644
--- a/composite/compalloc.c
+++ b/composite/compalloc.c
@@ -46,6 +46,7 @@
 #endif
 
 #include "compint.h"
+#include "compositeext.h"
 
 static void
 compScreenUpdate(ScreenPtr pScreen)
@@ -411,6 +412,11 @@ compRedirectSubwindows(ClientPtr pClient, WindowPtr pWin, int update)
     return Success;
 }
 
+int CompositeRedirectSubwindows (WindowPtr pWin, int update)
+{
+    return compRedirectSubwindows (serverClient, pWin, update);
+}
+
 /*
  * Free one of the per-client per-subwindows resources,
  * which frees one redirect per subwindow
@@ -482,6 +488,11 @@ compUnredirectSubwindows(ClientPtr pClient, WindowPtr pWin, int update)
     return BadValue;
 }
 
+int CompositeUnRedirectSubwindows (WindowPtr pWin, int update)
+{
+    return compUnredirectSubwindows (serverClient, pWin, update);
+}
+
 /*
  * Add redirection information for one subwindow (during reparent)
  */
diff --git a/composite/compositeext.h b/composite/compositeext.h
index 0b148f0..a072966 100644
--- a/composite/compositeext.h
+++ b/composite/compositeext.h
@@ -34,6 +34,10 @@
 extern _X_EXPORT Bool CompositeRegisterAlternateVisuals(ScreenPtr pScreen,
                                                         VisualID * vids,
                                                         int nVisuals);
+extern _X_EXPORT int CompositeRedirectSubwindows(WindowPtr pWin,
+						 int update);
+extern _X_EXPORT int CompositeUnRedirectSubwindows (WindowPtr pWin,
+						    int update);
 
 extern _X_EXPORT RESTYPE CompositeClientWindowType;
 
commit ea20333cb43fcc39715df40f5bbce6128ade30ec
Author: Kristian Høgsberg <krh at bitplanet.net>
Date:   Thu Jul 21 09:55:46 2011 -0700

    Export xf86NewInputDevice and xf86AllocateInput

diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 26c03c6..7669ee0 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -811,7 +811,7 @@ xf86InputDevicePostInit(DeviceIntPtr dev)
  *
  * @return Success or an error code
  */
-_X_INTERNAL int
+int
 xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL enable)
 {
     InputDriverPtr drv = NULL;
diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index 35c38a5..ff3d894 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -172,10 +172,9 @@ extern _X_EXPORT void xf86AddEnabledDevice(InputInfoPtr pInfo);
 extern _X_EXPORT void xf86RemoveEnabledDevice(InputInfoPtr pInfo);
 extern _X_EXPORT void xf86DisableDevice(DeviceIntPtr dev, Bool panic);
 extern _X_EXPORT void xf86EnableDevice(DeviceIntPtr dev);
-
-/* not exported */
-int xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL is_auto);
-InputInfoPtr xf86AllocateInput(void);
+extern _X_EXPORT int xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev,
+                                        BOOL is_auto);
+extern _X_EXPORT InputInfoPtr xf86AllocateInput(void);
 
 /* xf86Helper.c */
 extern _X_EXPORT void xf86AddInputDriver(InputDriverPtr driver, pointer module,
commit 1ff7e594dc81e939f9faee7488919415559f9055
Author: Kristian Høgsberg <krh at bitplanet.net>
Date:   Tue Jun 21 21:28:31 2011 -0400

    os: Add a function to create a client for an fd

diff --git a/include/opaque.h b/include/opaque.h
index b76ab6e..8ad9af0 100644
--- a/include/opaque.h
+++ b/include/opaque.h
@@ -74,5 +74,6 @@ extern _X_EXPORT Bool whiteRoot;
 extern _X_EXPORT Bool bgNoneRoot;
 
 extern _X_EXPORT Bool CoreDump;
+extern _X_EXPORT Bool NoListenAll;
 
 #endif                          /* OPAQUE_H */
diff --git a/include/os.h b/include/os.h
index c7108a5..32e5b96 100644
--- a/include/os.h
+++ b/include/os.h
@@ -160,8 +160,9 @@ extern _X_EXPORT void MakeClientGrabImpervious(ClientPtr /*client */ );
 
 extern _X_EXPORT void MakeClientGrabPervious(ClientPtr /*client */ );
 
-#ifdef XQUARTZ
-extern void ListenOnOpenFD(int /* fd */ , int /* noxauth */ );
+#if defined(XQUARTZ) || defined(XORG_WAYLAND)
+extern _X_EXPORT void ListenOnOpenFD(int /* fd */ , int /* noxauth */ );
+extern _X_EXPORT void AddClientOnOpenFD(int /* fd */ );
 #endif
 
 extern _X_EXPORT CARD32 GetTimeInMillis(void);
diff --git a/os/connection.c b/os/connection.c
index 6cd8bcf..499a4dd 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -64,6 +64,7 @@ SOFTWARE.
 #include <dix-config.h>
 #endif
 
+#include <xorg-server.h>
 #ifdef WIN32
 #include <X11/Xwinsock.h>
 #endif
@@ -138,6 +139,7 @@ fd_set OutputPending;           /* clients with reply/event data ready to go */
 int MaxClients = 0;
 Bool NewOutputPending;          /* not yet attempted to write some new output */
 Bool AnyClientsWriteBlocked;    /* true if some client blocked on write */
+Bool NoListenAll;               /* Don't establish any listening sockets */
 
 static Bool RunFromSmartParent; /* send SIGUSR1 to parent process */
 Bool RunFromSigStopParent;      /* send SIGSTOP to our own process; Upstart (or
@@ -406,7 +408,10 @@ CreateWellKnownSockets(void)
     /* display is initialized to "0" by main(). It is then set to the display
      * number if specified on the command line, or to NULL when the -displayfd
      * option is used. */
-    if (display) {
+    if (NoListenAll) {
+        ListenTransCount = 0;
+    }
+    else if (display) {
         if (TryCreateSocket(atoi(display), &partial) &&
             ListenTransCount >= 1)
             if (!PartialNetwork && partial)
@@ -440,9 +445,10 @@ CreateWellKnownSockets(void)
             DefineSelf (fd);
     }
 
-    if (!XFD_ANYSET(&WellKnownConnections))
+    if (!XFD_ANYSET(&WellKnownConnections) && !NoListenAll)
         FatalError
             ("Cannot establish any listening sockets - Make sure an X server isn't already running");
+
 #if !defined(WIN32)
     OsSignal(SIGPIPE, SIG_IGN);
     OsSignal(SIGHUP, AutoResetServer);
@@ -1253,7 +1259,7 @@ MakeClientGrabPervious(ClientPtr client)
     }
 }
 
-#ifdef XQUARTZ
+#if defined(XQUARTZ) || defined(XORG_WAYLAND)
 /* Add a fd (from launchd) to our listeners */
 void
 ListenOnOpenFD(int fd, int noxauth)
@@ -1309,4 +1315,24 @@ ListenOnOpenFD(int fd, int noxauth)
 #endif
 }
 
+/* based on TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status) */
+void
+AddClientOnOpenFD(int fd)
+{
+    XtransConnInfo ciptr;
+    CARD32 connect_time;
+
+    ciptr = _XSERVTransReopenCOTSServer(5, fd, "@anonymous");
+
+    _XSERVTransSetOption(ciptr, TRANS_NONBLOCKING, 1);
+    ciptr->flags |= TRANS_NOXAUTH;
+
+    connect_time = GetTimeInMillis();
+
+    if (!AllocNewConnection(ciptr, fd, connect_time)) {
+        fprintf(stderr, "failed to create client for wayland server\n");
+        return;
+    }
+}
+
 #endif
diff --git a/os/utils.c b/os/utils.c
index 60e828e..e56e4a4 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -780,7 +780,11 @@ ProcessCommandLine(int argc, char *argv[])
 #endif
         else if (strcmp(argv[i], "-nolisten") == 0) {
             if (++i < argc) {
-                if (_XSERVTransNoListen(argv[i]))
+                if (strcmp(argv[i], "all") == 0) {
+                    NoListenAll = TRUE;
+                    nolock = TRUE;
+                }
+                else if (_XSERVTransNoListen(argv[i]))
                     ErrorF("Failed to disable listen for %s transport",
                            argv[i]);
             }
commit 7602b3bf307642f81686cb917af51bb1f7c7098f
Author: Tiago Vignatti <tiago.vignatti at intel.com>
Date:   Thu Nov 22 20:22:56 2012 -0200

    configure: Track updated version of libxtrans
    
    XWayland fails to initialize in some systems complaining about realloc
    problems on libxtrans (when ListenOnOpenFD() is called). It got fixed in
    libxtrans version 1.2.7, more specifically:
    
        commit 6086f6c1d0e0a1c9e590879acb2319dea0eb6e96
        Author: Robert Bragg <robert at linux.intel.com>
        Date:   Mon Dec 12 00:30:43 2011 +0000
    
    Reported-by: nerdopolis, Prf_Jakob, spitzak among others at #wayland channel
    Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>

diff --git a/configure.ac b/configure.ac
index 5159420..2b6c7c4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -802,7 +802,7 @@ FIXESPROTO="fixesproto >= 5.0"
 DAMAGEPROTO="damageproto >= 1.1"
 XCMISCPROTO="xcmiscproto >= 1.2.0"
 BIGREQSPROTO="bigreqsproto >= 1.1.0"
-XTRANS="xtrans >= 1.2.2"
+XTRANS="xtrans >= 1.2.7"
 
 dnl List of libraries that require a specific version
 LIBAPPLEWM="applewm >= 1.4"
commit 74de0ec707730b888266965261e5b5d882328856
Author: Kristian Høgsberg <krh at bitplanet.net>
Date:   Tue Apr 9 17:45:08 2013 -0400

    xkb: Add XkbCompileKeymapFromString()
    
    This new function compiles a keymap from an in-memory string.  We use it
    to add a new keyooard device init function,
    InitKeyboardDeviceStructFromString(), which inits a keyboard device with
    a keymap specified as a string instead of a rmlvo set.
    
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/include/input.h b/include/input.h
index 1745e9a..9f09e65 100644
--- a/include/input.h
+++ b/include/input.h
@@ -385,6 +385,12 @@ extern _X_EXPORT Bool InitKeyboardDeviceStruct(DeviceIntPtr /*device */ ,
                                                KbdCtrlProcPtr /*controlProc */
                                                );
 
+extern _X_EXPORT Bool InitKeyboardDeviceStructFromString(DeviceIntPtr dev,
+							 const char *keymap,
+							 int keymap_length,
+							 BellProcPtr bell_func,
+							 KbdCtrlProcPtr ctrl_func);
+
 extern int ApplyPointerMapping(DeviceIntPtr /* pDev */ ,
                                CARD8 * /* map */ ,
                                int /* len */ ,
diff --git a/include/xkbsrv.h b/include/xkbsrv.h
index 346ebcc..bef98ef 100644
--- a/include/xkbsrv.h
+++ b/include/xkbsrv.h
@@ -861,4 +861,8 @@ extern _X_EXPORT XkbDescPtr XkbCompileKeymap(DeviceIntPtr /* dev */ ,
                                              XkbRMLVOSet *      /* rmlvo */
     );
 
+extern _X_EXPORT XkbDescPtr XkbCompileKeymapFromString(DeviceIntPtr dev,
+						       const char *keymap,
+						       int keymap_length);
+
 #endif                          /* _XKBSRV_H_ */
diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c
index 001ff46..7a7cf1e 100644
--- a/xkb/ddxLoad.c
+++ b/xkb/ddxLoad.c
@@ -262,6 +262,35 @@ XkbDDXOpenConfigFile(char *mapName, char *fileNameRtrn, int fileNameRtrnLen)
     return file;
 }
 
+static unsigned
+LoadXKM(unsigned want, unsigned need, XkbCompContextPtr ctx, XkbDescPtr *xkbRtrn)
+{
+    FILE *file;
+    char fileName[PATH_MAX];
+    unsigned missing;
+
+    file = XkbDDXOpenConfigFile(ctx->keymap, fileName, PATH_MAX);
+    if (file == NULL) {
+        LogMessage(X_ERROR, "Couldn't open compiled keymap file %s\n",
+                   fileName);
+        return 0;
+    }
+    missing = XkmReadFile(file, need, want, xkbRtrn);
+    if (*xkbRtrn == NULL) {
+        LogMessage(X_ERROR, "Error loading keymap %s\n", fileName);
+        fclose(file);
+        (void) unlink(fileName);
+        return 0;
+    }
+    else {
+        DebugF("Loaded XKB keymap %s, defined=0x%x\n", fileName,
+               (*xkbRtrn)->defined);
+    }
+    fclose(file);
+    (void) unlink(fileName);
+    return (need | want) & (~missing);
+}
+
 unsigned
 XkbDDXLoadKeymapByNames(DeviceIntPtr keybd,
                         XkbComponentNamesPtr names,
@@ -270,9 +299,6 @@ XkbDDXLoadKeymapByNames(DeviceIntPtr keybd,
                         XkbDescPtr *xkbRtrn, char *nameRtrn, int nameRtrnLen)
 {
     XkbDescPtr xkb;
-    FILE *file;
-    char fileName[PATH_MAX];
-    unsigned missing;
     XkbCompContextRec ctx;
 
     *xkbRtrn = NULL;
@@ -292,26 +318,30 @@ XkbDDXLoadKeymapByNames(DeviceIntPtr keybd,
         LogMessage(X_ERROR, "XKB: Couldn't compile keymap\n");
         return 0;
     }
-    file = XkbDDXOpenConfigFile(ctx.keymap, fileName, PATH_MAX);
-    if (file == NULL) {
-        LogMessage(X_ERROR, "Couldn't open compiled keymap file %s\n",
-                   fileName);
-        return 0;
-    }
-    missing = XkmReadFile(file, need, want, xkbRtrn);
-    if (*xkbRtrn == NULL) {
-        LogMessage(X_ERROR, "Error loading keymap %s\n", fileName);
-        fclose(file);
-        (void) unlink(fileName);
+
+    return LoadXKM(want, need, &ctx, xkbRtrn);
+}
+
+static unsigned
+XkbDDXLoadKeymapFromString(DeviceIntPtr keybd,
+			   const char *keymap, int keymap_length,
+			   unsigned want,
+			   unsigned need,
+			   XkbDescPtr *xkbRtrn)
+{
+    XkbCompContextRec ctx;
+
+    *xkbRtrn = NULL;
+
+    if (StartXkbComp(&ctx))
+	fwrite(keymap, keymap_length, 1, ctx.out);
+
+    if (!FinishXkbComp(&ctx)) {
+        LogMessage(X_ERROR, "XKB: Couldn't compile keymap\n");
         return 0;
     }
-    else {
-        DebugF("Loaded XKB keymap %s, defined=0x%x\n", fileName,
-               (*xkbRtrn)->defined);
-    }
-    fclose(file);
-    (void) unlink(fileName);
-    return (need | want) & (~missing);
+
+    return LoadXKM(want, need, &ctx, xkbRtrn);
 }
 
 Bool
@@ -407,6 +437,29 @@ XkbCompileKeymapForDevice(DeviceIntPtr dev, XkbRMLVOSet * rmlvo, int need)
     return xkb;
 }
 
+static XkbDescPtr
+KeymapOrDefaults(DeviceIntPtr dev, XkbDescPtr xkb)
+{
+    XkbRMLVOSet dflts;
+
+    if (xkb)
+	return xkb;
+
+    /* we didn't get what we really needed. And that will likely leave
+     * us with a keyboard that doesn't work. Use the defaults instead */
+    LogMessage(X_ERROR, "XKB: Failed to load keymap. Loading default "
+	       "keymap instead.\n");
+
+    XkbGetRulesDflts(&dflts);
+
+    xkb = XkbCompileKeymapForDevice(dev, &dflts, 0);
+
+    XkbFreeRMLVOSet(&dflts, FALSE);
+
+    return xkb;
+}
+
+
 XkbDescPtr
 XkbCompileKeymap(DeviceIntPtr dev, XkbRMLVOSet * rmlvo)
 {
@@ -424,20 +477,34 @@ XkbCompileKeymap(DeviceIntPtr dev, XkbRMLVOSet * rmlvo)
 
     xkb = XkbCompileKeymapForDevice(dev, rmlvo, need);
 
-    if (!xkb) {
-        XkbRMLVOSet dflts;
+    return KeymapOrDefaults(dev, xkb);
+}
 
-        /* we didn't get what we really needed. And that will likely leave
-         * us with a keyboard that doesn't work. Use the defaults instead */
-        LogMessage(X_ERROR, "XKB: Failed to load keymap. Loading default "
-                   "keymap instead.\n");
+XkbDescPtr
+XkbCompileKeymapFromString(DeviceIntPtr dev,
+			   const char *keymap, int keymap_length)
+{
+    XkbDescPtr xkb;
+    unsigned int need, provided;
 
-        XkbGetRulesDflts(&dflts);
+    if (!dev || !keymap) {
+        LogMessage(X_ERROR, "XKB: No device or keymap specified\n");
+        return NULL;
+    }
 
-        xkb = XkbCompileKeymapForDevice(dev, &dflts, 0);
+    /* These are the components we really really need */
+    need = XkmSymbolsMask | XkmCompatMapMask | XkmTypesMask |
+        XkmKeyNamesMask | XkmVirtualModsMask;
 
-        XkbFreeRMLVOSet(&dflts, FALSE);
+    provided =
+	XkbDDXLoadKeymapFromString(dev, keymap, keymap_length,
+				   XkmAllIndicesMask, need, &xkb);
+    if ((need & provided) != need) {
+	if (xkb) {
+	    XkbFreeKeyboard(xkb, 0, TRUE);
+	    xkb = NULL;
+	}
     }
 
-    return xkb;
+    return KeymapOrDefaults(dev, xkb);
 }
diff --git a/xkb/xkbInit.c b/xkb/xkbInit.c
index f72655f..f3f0d8f 100644
--- a/xkb/xkbInit.c
+++ b/xkb/xkbInit.c
@@ -490,9 +490,10 @@ XkbInitControls(DeviceIntPtr pXDev, XkbSrvInfoPtr xkbi)
     return Success;
 }
 
-_X_EXPORT Bool
-InitKeyboardDeviceStruct(DeviceIntPtr dev, XkbRMLVOSet * rmlvo,
-                         BellProcPtr bell_func, KbdCtrlProcPtr ctrl_func)
+static Bool
+InitKeyboardDeviceStructInternal(DeviceIntPtr dev, XkbRMLVOSet * rmlvo,
+				 const char *keymap, int keymap_length,
+				 BellProcPtr bell_func, KbdCtrlProcPtr ctrl_func)
 {
     int i;
     unsigned int check;
@@ -507,7 +508,7 @@ InitKeyboardDeviceStruct(DeviceIntPtr dev, XkbRMLVOSet * rmlvo,
     BUG_RETURN_VAL(dev->key != NULL, FALSE);
     BUG_RETURN_VAL(dev->kbdfeed != NULL, FALSE);
 
-    if (!rmlvo) {
+    if (!rmlvo && !keymap) {
         rmlvo = &rmlvo_dflts;
         XkbGetRulesDflts(rmlvo);
     }
@@ -535,19 +536,26 @@ InitKeyboardDeviceStruct(DeviceIntPtr dev, XkbRMLVOSet * rmlvo,
     }
     dev->key->xkbInfo = xkbi;
 
-    if (xkb_cached_map && !XkbCompareUsedRMLVO(rmlvo)) {
+    if (xkb_cached_map && (keymap || (rmlvo && !XkbCompareUsedRMLVO(rmlvo)))) {
         XkbFreeKeyboard(xkb_cached_map, XkbAllComponentsMask, TRUE);
         xkb_cached_map = NULL;
     }
 
     if (xkb_cached_map)
         LogMessageVerb(X_INFO, 4, "XKB: Reusing cached keymap\n");
-    else {
+    else if (rmlvo) {
         xkb_cached_map = XkbCompileKeymap(dev, rmlvo);
         if (!xkb_cached_map) {
             ErrorF("XKB: Failed to compile keymap\n");
             goto unwind_info;
         }
+    } else {
+	xkb_cached_map = XkbCompileKeymapFromString(dev,
+						    keymap, keymap_length);
+        if (!xkb_cached_map) {
+            ErrorF("XKB: Failed to compile keymap from string\n");
+            goto unwind_info;
+        }
     }
 
     xkb = XkbAllocKeyboard();
@@ -612,8 +620,10 @@ InitKeyboardDeviceStruct(DeviceIntPtr dev, XkbRMLVOSet * rmlvo,
 
     dev->kbdfeed->CtrlProc(dev, &dev->kbdfeed->ctrl);
 
-    XkbSetRulesDflts(rmlvo);
-    XkbSetRulesUsed(rmlvo);
+    if (rmlvo) {
+	XkbSetRulesDflts(rmlvo);
+	XkbSetRulesUsed(rmlvo);
+    }
     XkbFreeRMLVOSet(&rmlvo_dflts, FALSE);
 
     return TRUE;
@@ -632,6 +642,24 @@ InitKeyboardDeviceStruct(DeviceIntPtr dev, XkbRMLVOSet * rmlvo,
     return FALSE;
 }
 
+_X_EXPORT Bool
+InitKeyboardDeviceStruct(DeviceIntPtr dev, XkbRMLVOSet * rmlvo,
+                         BellProcPtr bell_func, KbdCtrlProcPtr ctrl_func)
+{
+    return InitKeyboardDeviceStructInternal(dev, rmlvo,
+					    NULL, 0, bell_func, ctrl_func);
+}
+
+_X_EXPORT Bool
+InitKeyboardDeviceStructFromString(DeviceIntPtr dev,
+				   const char *keymap, int keymap_length,
+				   BellProcPtr bell_func, KbdCtrlProcPtr ctrl_func)
+{
+    return InitKeyboardDeviceStructInternal(dev, NULL,
+					    keymap, keymap_length,
+					    bell_func, ctrl_func);
+}
+
 /***====================================================================***/
 
         /*
commit 267f91de56d97ba51f07ded06ca137520744e6de
Author: Kristian Høgsberg <krh at bitplanet.net>
Date:   Tue Apr 9 17:11:03 2013 -0400

    xkb: Split out code to start and finish xkbcomp
    
    Using the context struct from previous commit, we can now split out
    code to start xkbcomp and to finish and clean up after it.
    
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c
index 5da3a35..001ff46 100644
--- a/xkb/ddxLoad.c
+++ b/xkb/ddxLoad.c
@@ -99,10 +99,7 @@ typedef struct XkbCompContext {
 } XkbCompContextRec, *XkbCompContextPtr;
 
 static Bool
-XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
-                           XkbComponentNamesPtr names,
-                           unsigned want,
-                           unsigned need, XkbCompContextPtr ctx)
+StartXkbComp(XkbCompContextPtr ctx)
 {
     char xkm_output_dir[PATH_MAX];
 
@@ -168,14 +165,15 @@ XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
     ctx->out = fopen(ctx->tmpname, "w");
 #endif
 
+    return ctx->out != NULL;
+}
+
+static Bool
+FinishXkbComp(XkbCompContextPtr ctx)
+{
+    if (!ctx->buf)
+	return FALSE;
     if (ctx->out != NULL) {
-#ifdef DEBUG
-        if (xkbDebugFlags) {
-            ErrorF("[xkb] XkbDDXCompileKeymapByNames compiling keymap:\n");
-            XkbWriteXKBKeymapForNames(stderr, names, xkb, want, need);
-        }
-#endif
-        XkbWriteXKBKeymapForNames(ctx->out, names, xkb, want, need);
 #ifndef WIN32
         if (Pclose(ctx->out) == 0)
 #else
@@ -209,6 +207,25 @@ XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
     return FALSE;
 }
 
+static Bool
+XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
+                           XkbComponentNamesPtr names,
+                           unsigned want,
+                           unsigned need, XkbCompContextPtr ctx)
+{
+    if (StartXkbComp(ctx)) {
+#ifdef DEBUG
+        if (xkbDebugFlags) {
+            ErrorF("[xkb] XkbDDXCompileKeymapByNames compiling keymap:\n");
+            XkbWriteXKBKeymapForNames(stderr, names, xkb, want, need);
+        }
+#endif
+        XkbWriteXKBKeymapForNames(ctx->out, names, xkb, want, need);
+    }
+
+    return FinishXkbComp(ctx);
+}
+
 static FILE *
 XkbDDXOpenConfigFile(char *mapName, char *fileNameRtrn, int fileNameRtrnLen)
 {
commit 28159bfcaecf03ed0da285d75a12e9be38ae63dc
Author: Kristian Høgsberg <krh at bitplanet.net>
Date:   Tue Apr 9 16:54:55 2013 -0400

    xkb: Add struct XkbCompContext
    
    This commit adds a struct that contains most of the context for starting,
    running and cleaning up after xkbcomp.
    
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c
index d462957..5da3a35 100644
--- a/xkb/ddxLoad.c
+++ b/xkb/ddxLoad.c
@@ -90,14 +90,21 @@ OutputDirectory(char *outdir, size_t size)
     }
 }
 
+typedef struct XkbCompContext {
+    char keymap[PATH_MAX];
+    FILE *out;
+    char *buf;
+    char tmpname[PATH_MAX];
+    const char *xkmfile;
+} XkbCompContextRec, *XkbCompContextPtr;
+
 static Bool
 XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
                            XkbComponentNamesPtr names,
                            unsigned want,
-                           unsigned need, char *nameRtrn, int nameRtrnLen)
+                           unsigned need, XkbCompContextPtr ctx)
 {
-    FILE *out;
-    char *buf = NULL, keymap[PATH_MAX], xkm_output_dir[PATH_MAX];
+    char xkm_output_dir[PATH_MAX];
 
     const char *emptystring = "";
     char *xkbbasedirflag = NULL;
@@ -105,22 +112,19 @@ XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
     const char *xkbbindirsep = emptystring;
 
 #ifdef WIN32
-    /* WIN32 has no popen. The input must be stored in a file which is
-       used as input for xkbcomp. xkbcomp does not read from stdin. */
-    char tmpname[PATH_MAX];
-    const char *xkmfile = tmpname;
+    ctx->xkmfile = ctx->tmpname;
 #else
-    const char *xkmfile = "-";
+    ctx->xkmfile = "-";
 #endif
 
-    snprintf(keymap, sizeof(keymap), "server-%s", display);
+    snprintf(ctx->keymap, sizeof(ctx->keymap), "server-%s", display);
 
     OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir));
 
 #ifdef WIN32
-    strcpy(tmpname, Win32TempDir());
-    strcat(tmpname, "\\xkb_XXXXXX");
-    (void) mktemp(tmpname);
+    strcpy(ctx->tmpname, Win32TempDir());
+    strcat(ctx->tmpname, "\\xkb_XXXXXX");
+    (void) mktemp(ctx->tmpname);
 #endif
 
     if (XkbBaseDirectory != NULL) {
@@ -139,73 +143,69 @@ XkbDDXCompileKeymapByNames(XkbDescPtr xkb,
         }
     }
 
-    if (asprintf(&buf,
+    if (asprintf(&ctx->buf,
                  "\"%s%sxkbcomp\" -w %d %s -xkm \"%s\" "
                  "-em1 %s -emp %s -eml %s \"%s%s.xkm\"",
                  xkbbindir, xkbbindirsep,
                  ((xkbDebugFlags < 2) ? 1 :
                   ((xkbDebugFlags > 10) ? 10 : (int) xkbDebugFlags)),
-                 xkbbasedirflag ? xkbbasedirflag : "", xkmfile,
+                 xkbbasedirflag ? xkbbasedirflag : "", ctx->xkmfile,
                  PRE_ERROR_MSG, ERROR_PREFIX, POST_ERROR_MSG1,
-                 xkm_output_dir, keymap) == -1)
-        buf = NULL;
+                 xkm_output_dir, ctx->keymap) == -1)
+        ctx->buf = NULL;
 
     free(xkbbasedirflag);
 
-    if (!buf) {
+    if (!ctx->buf) {
         LogMessage(X_ERROR,
                    "XKB: Could not invoke xkbcomp: not enough memory\n");
         return FALSE;
     }
 
 #ifndef WIN32
-    out = Popen(buf, "w");
+    ctx->out = Popen(ctx->buf, "w");
 #else
-    out = fopen(tmpname, "w");
+    ctx->out = fopen(ctx->tmpname, "w");
 #endif
 
-    if (out != NULL) {
+    if (ctx->out != NULL) {
 #ifdef DEBUG
         if (xkbDebugFlags) {
             ErrorF("[xkb] XkbDDXCompileKeymapByNames compiling keymap:\n");
             XkbWriteXKBKeymapForNames(stderr, names, xkb, want, need);
         }
 #endif
-        XkbWriteXKBKeymapForNames(out, names, xkb, want, need);
+        XkbWriteXKBKeymapForNames(ctx->out, names, xkb, want, need);
 #ifndef WIN32
-        if (Pclose(out) == 0)
+        if (Pclose(ctx->out) == 0)
 #else
-        if (fclose(out) == 0 && System(buf) >= 0)
+        if (fclose(ctx->out) == 0 && System(ctx->buf) >= 0)
 #endif
         {
             if (xkbDebugFlags)
-                DebugF("[xkb] xkb executes: %s\n", buf);
-            if (nameRtrn) {
-                strlcpy(nameRtrn, keymap, nameRtrnLen);
-            }
-            free(buf);
+                DebugF("[xkb] xkb executes: %s\n", ctx->buf);
+            free(ctx->buf);
 #ifdef WIN32
-            unlink(tmpname);
+            unlink(ctx->tmpname);
 #endif
             return TRUE;
         }
         else
-            LogMessage(X_ERROR, "Error compiling keymap (%s)\n", keymap);
+            LogMessage(X_ERROR, "Error compiling keymap (%s)\n", ctx->keymap);
 #ifdef WIN32
         /* remove the temporary file */
-        unlink(tmpname);
+        unlink(ctx->tmpname);
 #endif
     }
     else {
 #ifndef WIN32
         LogMessage(X_ERROR, "XKB: Could not invoke xkbcomp\n");
 #else
-        LogMessage(X_ERROR, "Could not open file %s\n", tmpname);
+        LogMessage(X_ERROR, "Could not open file %s\n", ctx->tmpname);
 #endif
     }
-    if (nameRtrn)
-        nameRtrn[0] = '\0';
-    free(buf);
+    ctx->keymap[0] = '\0';
+    free(ctx->buf);
     return FALSE;
 }
 
@@ -256,6 +256,7 @@ XkbDDXLoadKeymapByNames(DeviceIntPtr keybd,
     FILE *file;
     char fileName[PATH_MAX];
     unsigned missing;
+    XkbCompContextRec ctx;
 
     *xkbRtrn = NULL;
     if ((keybd == NULL) || (keybd->key == NULL) ||
@@ -270,12 +271,11 @@ XkbDDXLoadKeymapByNames(DeviceIntPtr keybd,
                    keybd->name ? keybd->name : "(unnamed keyboard)");
         return 0;
     }
-    else if (!XkbDDXCompileKeymapByNames(xkb, names, want, need,
-                                         nameRtrn, nameRtrnLen)) {
+    else if (!XkbDDXCompileKeymapByNames(xkb, names, want, need, &ctx)) {
         LogMessage(X_ERROR, "XKB: Couldn't compile keymap\n");
         return 0;
     }
-    file = XkbDDXOpenConfigFile(nameRtrn, fileName, PATH_MAX);
+    file = XkbDDXOpenConfigFile(ctx.keymap, fileName, PATH_MAX);
     if (file == NULL) {
         LogMessage(X_ERROR, "Couldn't open compiled keymap file %s\n",
                    fileName);
commit 9ed2d6c1ef7e3590817d7ae8ea6cc6654fe0f97e
Author: Robert Bragg <robert at linux.intel.com>
Date:   Thu Jan 12 18:16:08 2012 +0000

    dbe: Cleanup in CloseScreen hook not ext CloseDown
    
    Instead of registering an extension CloseDownProc when adding the dbe
    extension this patch hooks into pScreen->CloseScreen so that the chain
    of pScreen->DestroyWindow hooks remains valid until all windows have
    been destroyed. Previously it was possible for DbeResetProc to be called
    before the root window had been destroyed and the unwrapping of
    pScreen->DestroyWindow would clobber the chain of callbacks.
    
    This is needed for xwayland to be able to know when the root window is
    destroyed so it can unredirect root sub-windows.

diff --git a/dbe/dbe.c b/dbe/dbe.c
index 9039d80..379feb1 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -292,8 +292,8 @@ ProcDbeAllocateBackBufferName(ClientPtr client)
 
             /* malloc/realloc a new array and initialize all elements to 0. */
             pDbeWindowPriv->IDs = (XID *) realloc(pIDs,
-                                                  (pDbeWindowPriv->
-                                                   maxAvailableIDs +
+                                                  (pDbeWindowPriv->maxAvailableIDs
+                                                   +
                                                    DBE_INCR_MAX_IDS) *
                                                   sizeof(XID));
             if (!pDbeWindowPriv->IDs) {
@@ -468,7 +468,7 @@ ProcDbeSwapBuffers(ClientPtr client)
         return BadAlloc;
 
     /* Get to the swap info appended to the end of the request. */
-    dbeSwapInfo = (xDbeSwapInfo *) &stuff[1];
+    dbeSwapInfo = (xDbeSwapInfo *) & stuff[1];
 
     /* Allocate array to record swap information. */
     swapInfo = (DbeSwapInfoPtr) malloc(nStuff * sizeof(DbeSwapInfoRec));
@@ -1298,7 +1298,7 @@ DbeWindowPrivDelete(pointer pDbeWinPriv, XID id)
 
 /******************************************************************************
  *
- * DBE DIX Procedure: DbeResetProc
+ * DBE DIX Procedure: DbeCloseScreen
  *
  * Description:
  *
@@ -1307,28 +1307,26 @@ DbeWindowPrivDelete(pointer pDbeWinPriv, XID id)
  *     other tasks related to shutting down the extension.
  *
  *****************************************************************************/
-static void
-DbeResetProc(ExtensionEntry * extEntry)
+static Bool
+DbeCloseScreen(ScreenPtr pScreen)
 {
-    int i;
-    ScreenPtr pScreen;
-    DbeScreenPrivPtr pDbeScreenPriv;
+    DbeScreenPrivPtr pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
 
-    for (i = 0; i < screenInfo.numScreens; i++) {
-        pScreen = screenInfo.screens[i];
-        pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
+    if (pDbeScreenPriv) {
+        /* Unwrap DestroyWindow, which was wrapped in DbeExtensionInit(). */
+        pScreen->DestroyWindow = pDbeScreenPriv->DestroyWindow;
 
-        if (pDbeScreenPriv) {
-            /* Unwrap DestroyWindow, which was wrapped in DbeExtensionInit(). */
-            pScreen->DestroyWindow = pDbeScreenPriv->DestroyWindow;
+        /* Unwrap CloseScreen, which was wrapped in DbeExtensionInit(). */
+        pScreen->CloseScreen = pDbeScreenPriv->CloseScreen;
 
-            if (pDbeScreenPriv->ResetProc)
-                (*pDbeScreenPriv->ResetProc) (pScreen);
+        if (pDbeScreenPriv->ResetProc)
+            (*pDbeScreenPriv->ResetProc) (pScreen);
 
-            free(pDbeScreenPriv);
-        }
+        free(pDbeScreenPriv);
     }
-}                               /* DbeResetProc() */
+
+    return (*pScreen->CloseScreen) (pScreen);
+}                               /* DbeCloseScreen */
 
 /******************************************************************************
  *
@@ -1498,6 +1496,9 @@ DbeExtensionInit(void)
 
                 pDbeScreenPriv->DestroyWindow = pScreen->DestroyWindow;
                 pScreen->DestroyWindow = DbeDestroyWindow;
+
+                pDbeScreenPriv->CloseScreen = pScreen->CloseScreen;
+                pScreen->CloseScreen = DbeCloseScreen;
             }
             else {
                 /* DDX initialization failed.  Stub the screen. */
@@ -1525,7 +1526,7 @@ DbeExtensionInit(void)
     /* Now add the extension. */
     extEntry = AddExtension(DBE_PROTOCOL_NAME, DbeNumberEvents,
                             DbeNumberErrors, ProcDbeDispatch, SProcDbeDispatch,
-                            DbeResetProc, StandardMinorOpcode);
+                            NULL, StandardMinorOpcode);
 
     dbeErrorBase = extEntry->errorBase;
     SetResourceTypeErrorValue(dbeWindowPrivResType,
diff --git a/dbe/dbestruct.h b/dbe/dbestruct.h
index f9d938a..4b88d25 100644
--- a/dbe/dbestruct.h
+++ b/dbe/dbestruct.h
@@ -162,6 +162,7 @@ typedef struct _DbeScreenPrivRec {
      */
     PositionWindowProcPtr PositionWindow;
     DestroyWindowProcPtr DestroyWindow;
+    CloseScreenProcPtr CloseScreen;
 
     /* Per-screen DIX routines */
     Bool (*SetupBackgroundPainter) (WindowPtr /*pWin */ ,
commit 6f89ae3e64c4dfeea508813e546c10ba1da3ea8e
Author: Thomas Klausner <wiz at NetBSD.org>
Date:   Wed Sep 4 20:06:07 2013 +0200

    Fix typo in configure warning.
    
    Signed-off-by: Thomas Klausner <wiz at NetBSD.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/configure.ac b/configure.ac
index d27ca23..5159420 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,7 +47,7 @@ XORG_WITH_XSLTPROC
 XORG_ENABLE_UNIT_TESTS
 XORG_LD_WRAP([optional])
 
-m4_ifndef([XORG_FONT_MACROS_VERSION], [m4_fatal([must install fontutil 1.1 or later before running autoconf/autogen])])
+m4_ifndef([XORG_FONT_MACROS_VERSION], [m4_fatal([must install font-util 1.1 or later before running autoconf/autogen])])
 XORG_FONT_MACROS_VERSION(1.1)
 
 dnl this gets generated by autoheader, and thus contains all the defines.  we
commit 47218a6e09549781fd61dbf5e0d3d5c81da64323
Author: Thomas Klausner <wiz at NetBSD.org>
Date:   Wed Sep 4 20:05:51 2013 +0200

    Fix bug in cursor handling.
    
    CreateCursor (Xlib call XCreatePixmapCursor) with a non-bitmap
    source pixmap and a None mask is supposed to error out with BadMatch,
    but didn't.
    
    From der Mouse <mouse at Rodents-Montreal.ORG>, changed following
    comments by Alan Coopersmith <alan.coopersmith at oracle.com>.
    
    Signed-off-by: Thomas Klausner <wiz at NetBSD.org>
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 51d0de2..71fda48 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -2864,18 +2864,25 @@ ProcCreateCursor(ClientPtr client)
         return rc;
     }
 
-    rc = dixLookupResourceByType((pointer *) &msk, stuff->mask, RT_PIXMAP,
-                                 client, DixReadAccess);
-    if (rc != Success) {
-        if (stuff->mask != None) {
+    if (src->drawable.depth != 1)
+        return (BadMatch);
+
+    /* Find and validate cursor mask pixmap, if one is provided */
+    if (stuff->mask != None) {
+        rc = dixLookupResourceByType((pointer *) &msk, stuff->mask, RT_PIXMAP,
+                                     client, DixReadAccess);
+        if (rc != Success) {
             client->errorValue = stuff->mask;
             return rc;
         }
+
+        if (src->drawable.width != msk->drawable.width
+            || src->drawable.height != msk->drawable.height
+            || src->drawable.depth != 1 || msk->drawable.depth != 1)
+            return BadMatch;
     }
-    else if (src->drawable.width != msk->drawable.width
-             || src->drawable.height != msk->drawable.height
-             || src->drawable.depth != 1 || msk->drawable.depth != 1)
-        return BadMatch;
+    else
+        msk = NULL;
 
     width = src->drawable.width;
     height = src->drawable.height;
commit 1110b71e360195aab040d835b54540ab558638c5
Author: Chris Clayton <chris2553 at googlemail.com>
Date:   Wed Sep 4 15:42:04 2013 +1000

    kdrive: fix build error on gcc 4.8 for out-of-bounds array access
    
    I'm getting a error building xorg-server-1.14.1.902 with thelatest snapshot
    of gcc-4.8:
    
    input.c:225:43: error: array subscript is above array bounds
    [-Werror=array-bounds]
    
    This is because kdNumInputFds can become equal to KD_MAX_INPUT_FDS in
    KdRegisterFd(). This means that in KdUnregisterFd(), kdInputFds[j + 1] can
    be beyond the end of the array.
    
    Signed-off-by: Chris Clayton <chris2553 at googlemail.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index f93830e..527c7a2 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -221,7 +221,7 @@ KdUnregisterFd(void *closure, int fd, Bool do_close)
             if (do_close)
                 close(kdInputFds[i].fd);
             kdNumInputFds--;
-            for (j = i; j < kdNumInputFds; j++)
+            for (j = i; j < (kdNumInputFds - 1); j++)
                 kdInputFds[j] = kdInputFds[j + 1];
             break;
         }
commit 94d4e29aedc69431fa9b299ca1b67947173d7a24
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Aug 26 15:51:46 2013 +1000

    Xi: allow for XIAllowEvent requests larger than XI < 2.2 size (#68554)
    
    XIAllowEvents changed length in XI 2.2 (for the touchid). A bug in libXi
    causes libXi to always use the new request length if the server supports
    2.2, regardless of the client's XIQueryVersion request.
    
    The server takes the client's XIQueryVersion request into account though,
    resulting in a BadLength error if a 2.[0,1] client calls XIAllowEvents on a
    XI 2.2+ server.
    
    Can't fix this in libXi, so work around this in the server.
    
    X.Org Bug 68554 <http://bugs.freedesktop.org/show_bug.cgi?id=68554>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/Xi/xiallowev.c b/Xi/xiallowev.c
index 62a0727..ebef233 100644
--- a/Xi/xiallowev.c
+++ b/Xi/xiallowev.c
@@ -81,7 +81,7 @@ ProcXIAllowEvents(ClientPtr client)
         have_xi22 = TRUE;
     }
     else {
-        REQUEST_SIZE_MATCH(xXIAllowEventsReq);
+        REQUEST_AT_LEAST_SIZE(xXIAllowEventsReq);
     }
 
     ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
commit 82939e02392cbb880313fe92957091ff89ce2f2b
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Aug 16 15:30:59 2013 +1000

    dix: check for grab type before checking XI2 mask
    
    if the grab type isn't XI2, grab->xi2mask is random. That random data may
    have the enter/leave mask set, leading to events sent to the client that the
    client can't handler.
    
    Source of these errors:
      _xgeWireToEvent: Unknown extension 131, this should never happen.
    
    Simplest reproducer:
       Start Xephyr, press button inside window, move out. As the pointer leaves
       the Xephyr window, the errors appear.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/events.c b/dix/events.c
index 4e6a175..086601a 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4653,7 +4653,7 @@ DeviceEnterLeaveEvent(DeviceIntPtr mouse,
 
     filter = GetEventFilter(mouse, (xEvent *) event);
 
-    if (grab) {
+    if (grab && grab->type == XI2) {
         Mask mask;
 
         mask = xi2mask_isset(grab->xi2mask, mouse, type);
commit 16894df1ffb6fe21bf723dd954578e8d934799ca
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Aug 16 10:55:09 2013 +1000

    Xi: replace loop with memset
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/Xi/grabdev.c b/Xi/grabdev.c
index 443ef56..9c6c429 100644
--- a/Xi/grabdev.c
+++ b/Xi/grabdev.c
@@ -175,10 +175,7 @@ CreateMaskFromList(ClientPtr client, XEventClass * list, int count,
     int device;
     DeviceIntPtr tdev;
 
-    for (i = 0; i < EMASKSIZE; i++) {
-        mask[i].mask = 0;
-        mask[i].dev = NULL;
-    }
+    memset(mask, 0, EMASKSIZE * sizeof(struct tmask));
 
     for (i = 0; i < count; i++, list++) {
         device = *list >> 8;
commit 8f2292b683f591052da2fe94fb3831a3c9a5aa61
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Aug 16 11:05:49 2013 +1000

    include: wrap EMASKSIZE in parentheses
    
    Otherwise things like EMASKSIZE * foo will yield interesting results.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/include/inputstr.h b/include/inputstr.h
index 2da72c1..dc36c5d 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -65,7 +65,7 @@ extern _X_EXPORT int CountBits(const uint8_t * mask, int len);
 #define SameClient(obj,client) \
 	(CLIENT_BITS((obj)->resource) == (client)->clientAsMask)
 
-#define EMASKSIZE	MAXDEVICES + 2
+#define EMASKSIZE	(MAXDEVICES + 2)
 
 /* This is the last XI2 event supported by the server. If you add
  * events to the protocol, the server will not support these events until
commit d803f296c616ccf55711cf0af9e7d3eae2edda16
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Aug 23 09:04:01 2013 +1000

    test: fix the gcc diagnostics pragma
    
    pop without push restores the commandline options. The proper way is to
    push, then ignore, then pop.
    
    And while we're at it, change the pop argument to a comment - pop ignores
    the argument, but be proper about it.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/test/signal-logging.c b/test/signal-logging.c
index f6bc85c..a03c5ac 100644
--- a/test/signal-logging.c
+++ b/test/signal-logging.c
@@ -150,6 +150,7 @@ number_formatting(void)
         assert(check_float_format_test(float_tests[i]));
 }
 
+#pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wformat-security"
 static void logging_format(void)
 {
@@ -378,7 +379,7 @@ static void logging_format(void)
 
 #undef read_log_msg
 }
-#pragma GCC diagnostic pop "-Wformat-security"
+#pragma GCC diagnostic pop /* "-Wformat-security" */
 
 int
 main(int argc, char **argv)
commit 05ea6307fa4f0bee3d3bf536396059f3906791a0
Author: Egbert Eich <eich at freedesktop.org>
Date:   Fri Aug 16 19:52:16 2013 +0200

    DIX/Xi: Pass correct client to CheckDeviceGrabAndHintWindow()
    
    If we have a client which has registered for a DeviceButton grab
    be sure to pass this to CheckDeviceGrabAndHintWindow(). Since the
    order of clients is arbitrary there is no guarantee that the last
    client in the list is the one that belongs to this class.
    
    Signed-off-by: Egbert Eich <eich at freedesktop.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/events.c b/dix/events.c
index ed3138d..4e6a175 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2105,6 +2105,7 @@ DeliverEventToInputClients(DeviceIntPtr dev, InputClients * inputclients,
 {
     int attempt;
     enum EventDeliveryState rc = EVENT_NOT_DELIVERED;
+    Bool have_device_button_grab_class_client = FALSE;
 
     for (; inputclients; inputclients = inputclients->next) {
         Mask mask;
@@ -2124,13 +2125,21 @@ DeliverEventToInputClients(DeviceIntPtr dev, InputClients * inputclients,
                                             events, count,
                                             mask, filter, grab))) {
             if (attempt > 0) {
-                rc = EVENT_DELIVERED;
-                *client_return = client;
-                *mask_return = mask;
-                /* Success overrides non-success, so if we've been
-                 * successful on one client, return that */
-            }
-            else if (rc == EVENT_NOT_DELIVERED)
+                /*
+                 * The order of clients is arbitrary therefore if one
+                 * client belongs to DeviceButtonGrabClass make sure to
+                 * catch it.
+                 */
+                if (!have_device_button_grab_class_client) {
+                    rc = EVENT_DELIVERED;
+                    *client_return = client;
+                    *mask_return = mask;
+                    /* Success overrides non-success, so if we've been
+                     * successful on one client, return that */
+                    if (mask & DeviceButtonGrabMask)
+                        have_device_button_grab_class_client = TRUE;
+                }
+            } else if (rc == EVENT_NOT_DELIVERED)
                 rc = EVENT_REJECTED;
         }
     }
commit e01a3f65d3e6d92f92ef2992b338cc9625bde082
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Aug 17 14:50:37 2013 +0200

    ephyr: Fix warning about XID vs unsigned long * by changing function args
    
    There's no reason to pass the data back out to the caller, since the
    caller was dropping it on the floor.  The original data is a CARD32,
    so no need to mess with weird unsigned longs.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrdri.c b/hw/kdrive/ephyr/ephyrdri.c
index 5055436..3a4a063 100644
--- a/hw/kdrive/ephyr/ephyrdri.c
+++ b/hw/kdrive/ephyr/ephyrdri.c
@@ -137,18 +137,19 @@ ephyrDRIGetClientDriverName(int a_screen,
 Bool
 ephyrDRICreateContext(int a_screen,
                       int a_visual_id,
-                      XID *a_returned_ctxt_id, drm_context_t * a_hw_ctxt)
+                      CARD32 ctxt_id, drm_context_t * a_hw_ctxt)
 {
     Display *dpy = hostx_get_display();
     Bool is_ok = FALSE;
     Visual v;
+    XID returned_ctxt_id = ctxt_id;
 
     EPHYR_LOG("enter. screen:%d, visual:%d\n", a_screen, a_visual_id);
     memset(&v, 0, sizeof(v));
     v.visualid = a_visual_id;
     is_ok = XF86DRICreateContext(dpy,
                                  DefaultScreen(dpy),
-                                 &v, a_returned_ctxt_id, a_hw_ctxt);
+                                 &v, &returned_ctxt_id, a_hw_ctxt);
     EPHYR_LOG("leave:%d\n", is_ok);
     return is_ok;
 }
diff --git a/hw/kdrive/ephyr/ephyrdri.h b/hw/kdrive/ephyr/ephyrdri.h
index d28910f..8f2d302 100644
--- a/hw/kdrive/ephyr/ephyrdri.h
+++ b/hw/kdrive/ephyr/ephyrdri.h
@@ -43,7 +43,7 @@ Bool ephyrDRIGetClientDriverName(int a_screen,
                                  char **a_client_driver_name);
 Bool ephyrDRICreateContext(int a_screen,
                            int a_visual_id,
-                           XID *a_returned_ctx_id, drm_context_t * a_hw_ctx);
+                           CARD32 ctx_id, drm_context_t * a_hw_ctx);
 Bool ephyrDRIDestroyContext(int a_screen, int a_context_id);
 Bool ephyrDRICreateDrawable(int a_screen,
                             int a_drawable, drm_drawable_t * a_hw_drawable);
diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index 4db40e3..617ffb1 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -716,7 +716,6 @@ ProcXF86DRICreateContext(register ClientPtr client)
     ScreenPtr pScreen;
     VisualPtr visual;
     int i = 0;
-    unsigned long context_id = 0;
 
     REQUEST(xXF86DRICreateContextReq);
     REQUEST_SIZE_MATCH(xXF86DRICreateContextReq);
@@ -739,10 +738,9 @@ ProcXF86DRICreateContext(register ClientPtr client)
         return BadValue;
     }
 
-    context_id = stuff->context;
     if (!ephyrDRICreateContext(stuff->screen,
                                stuff->visual,
-                               &context_id,
+                               stuff->context,
                                (drm_context_t *) &rep.hHWContext)) {
         return BadValue;
     }
commit f1cefe020bd21c07dfcc9f204e79939499abbd35
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Aug 17 14:38:08 2013 +0200

    ephyr: Drop is_ok logging.
    
    The only cases that lead to !is_ok are already EPHYR_LOG_ERROR, and it
    fixes set-but-unused compiler warnings.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index 144c6e1..4db40e3 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -189,7 +189,6 @@ static void
 ephyrDRIMoveWindow(WindowPtr a_win,
                    int a_x, int a_y, WindowPtr a_siblings, VTKind a_kind)
 {
-    Bool is_ok = FALSE;
     ScreenPtr screen = NULL;
     EphyrDRIScreenPrivPtr screen_priv = NULL;
     EphyrDRIWindowPrivPtr win_priv = NULL;
@@ -214,18 +213,16 @@ ephyrDRIMoveWindow(WindowPtr a_win,
     EPHYR_LOG("window: %p\n", a_win);
     if (!a_win->parent) {
         EPHYR_LOG("cannot move root window\n");
-        is_ok = TRUE;
-        goto out;
+        return;
     }
     win_priv = GET_EPHYR_DRI_WINDOW_PRIV(a_win);
     if (!win_priv) {
         EPHYR_LOG("not a DRI peered window\n");
-        is_ok = TRUE;
-        goto out;
+        return;
     }
     if (!findWindowPairFromLocal(a_win, &pair) || !pair) {
         EPHYR_LOG_ERROR("failed to get window pair\n");
-        goto out;
+        return;
     }
     /*compute position relative to parent window */
     x = a_win->drawable.x - a_win->parent->drawable.x;
@@ -237,11 +234,6 @@ ephyrDRIMoveWindow(WindowPtr a_win,
     geo.width = a_win->drawable.width;
     geo.height = a_win->drawable.height;
     hostx_set_window_geometry(pair->remote, &geo);
-    is_ok = TRUE;
-
- out:
-    EPHYR_LOG("leave. is_ok:%d\n", is_ok);
-    /*do cleanup here */
 }
 
 static Bool
@@ -297,7 +289,6 @@ ephyrDRIPositionWindow(WindowPtr a_win, int a_x, int a_y)
 static void
 ephyrDRIClipNotify(WindowPtr a_win, int a_x, int a_y)
 {
-    Bool is_ok = FALSE;
     ScreenPtr screen = NULL;
     EphyrDRIScreenPrivPtr screen_priv = NULL;
     EphyrDRIWindowPrivPtr win_priv = NULL;
@@ -323,7 +314,6 @@ ephyrDRIClipNotify(WindowPtr a_win, int a_x, int a_y)
     win_priv = GET_EPHYR_DRI_WINDOW_PRIV(a_win);
     if (!win_priv) {
         EPHYR_LOG("not a DRI peered window\n");
-        is_ok = TRUE;
         goto out;
     }
     if (!findWindowPairFromLocal(a_win, &pair) || !pair) {
@@ -343,9 +333,8 @@ ephyrDRIClipNotify(WindowPtr a_win, int a_x, int a_y)
      * push the clipping region of this window
      * to the peer window in the host
      */
-    is_ok = hostx_set_window_bounding_rectangles
+    hostx_set_window_bounding_rectangles
         (pair->remote, rects, RegionNumRects(&a_win->clipList));
-    is_ok = TRUE;
 
  out:
     free(rects);
commit 77c7a2014e3942b55c0b78308edf02eab33f2e60
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Aug 17 14:36:09 2013 +0200

    kdrive: Fix const cast warnings in arguments processing.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c
index adacac9..9a1dd7d 100644
--- a/hw/kdrive/ephyr/ephyrinit.c
+++ b/hw/kdrive/ephyr/ephyrinit.c
@@ -45,7 +45,7 @@ extern KdPointerDriver LinuxEvdevMouseDriver;
 extern KdKeyboardDriver LinuxEvdevKeyboardDriver;
 #endif
 
-void processScreenArg(char *screen_size, char *parent_id);
+void processScreenArg(const char *screen_size, char *parent_id);
 
 void
 InitCard(char *name)
@@ -134,7 +134,7 @@ ddxUseMsg(void)
 }
 
 void
-processScreenArg(char *screen_size, char *parent_id)
+processScreenArg(const char *screen_size, char *parent_id)
 {
     KdCardInfo *card;
 
diff --git a/hw/kdrive/ephyr/os.c b/hw/kdrive/ephyr/os.c
index a2a705d..56b52d1 100644
--- a/hw/kdrive/ephyr/os.c
+++ b/hw/kdrive/ephyr/os.c
@@ -28,7 +28,7 @@
 #endif
 #include "ephyr.h"
 
-extern void processScreenArg(char *screen_size, char *parent_id);
+extern void processScreenArg(const char *screen_size, char *parent_id);
 
 static int
 EphyrInit(void)
diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c
index 1899a27..f8949be 100644
--- a/hw/kdrive/src/kdrive.c
+++ b/hw/kdrive/src/kdrive.c
@@ -246,8 +246,8 @@ ddxGiveUp(enum ExitCode error)
 Bool kdDumbDriver;
 Bool kdSoftCursor;
 
-char *
-KdParseFindNext(char *cur, const char *delim, char *save, char *last)
+const char *
+KdParseFindNext(const char *cur, const char *delim, char *save, char *last)
 {
     while (*cur && !strchr(delim, *cur)) {
         *save++ = *cur++;
@@ -282,7 +282,7 @@ KdSubRotation(Rotation a, Rotation b)
 }
 
 void
-KdParseScreen(KdScreenInfo * screen, char *arg)
+KdParseScreen(KdScreenInfo * screen, const char *arg)
 {
     char delim;
     char save[1024];
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 96787b6..d5d0799 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -411,13 +411,14 @@ Rotation KdAddRotation(Rotation a, Rotation b);
 Rotation KdSubRotation(Rotation a, Rotation b);
 
 void
- KdParseScreen(KdScreenInfo * screen, char *arg);
+ KdParseScreen(KdScreenInfo * screen, const char *arg);
 
-KdPointerInfo *KdParsePointer(char *arg);
+KdPointerInfo *KdParsePointer(const char *arg);
 
-KdKeyboardInfo *KdParseKeyboard(char *arg);
+KdKeyboardInfo *KdParseKeyboard(const char *arg);
 
-char *KdParseFindNext(char *cur, const char *delim, char *save, char *last);
+const char *
+KdParseFindNext(const char *cur, const char *delim, char *save, char *last);
 
 void
  KdParseRgba(char *rgba);
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 3aad87a..f93830e 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -1086,7 +1086,7 @@ KdParseKbdOptions(KdKeyboardInfo * ki)
 }
 
 KdKeyboardInfo *
-KdParseKeyboard(char *arg)
+KdParseKeyboard(const char *arg)
 {
     char save[1024];
     char delim;
@@ -1178,7 +1178,7 @@ KdParsePointerOptions(KdPointerInfo * pi)
 }
 
 KdPointerInfo *
-KdParsePointer(char *arg)
+KdParsePointer(const char *arg)
 {
     char save[1024];
     char delim;
commit 7107937e473a3557c37d719cb100b2e9b09075dd
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Aug 17 13:11:17 2013 +0200

    kdrive: Fix const cast warnings in driver name handling.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/linux/mouse.c b/hw/kdrive/linux/mouse.c
index aaab0cd..2bfe7f2 100644
--- a/hw/kdrive/linux/mouse.c
+++ b/hw/kdrive/linux/mouse.c
@@ -193,7 +193,7 @@ MouseWriteBytes(int fd, unsigned char *c, int n, int timeout)
 #define MAX_VALID   4           /* number of valid packets before accepting */
 
 typedef struct _kmouseProt {
-    char *name;
+    const char *name;
     Bool (*Complete) (KdPointerInfo * pi, unsigned char *ev, int ne);
     int (*Valid) (KdPointerInfo * pi, unsigned char *ev, int ne);
     Bool (*Parse) (KdPointerInfo * pi, unsigned char *ev, int ne);
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 4829e1a..96787b6 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -174,7 +174,7 @@ typedef enum _kdPointerState {
 typedef struct _KdPointerInfo KdPointerInfo;
 
 typedef struct _KdPointerDriver {
-    char *name;
+    const char *name;
      Status(*Init) (KdPointerInfo *);
      Status(*Enable) (KdPointerInfo *);
     void (*Disable) (KdPointerInfo *);
@@ -243,7 +243,7 @@ typedef struct {
 typedef struct _KdKeyboardInfo KdKeyboardInfo;
 
 typedef struct _KdKeyboardDriver {
-    char *name;
+    const char *name;
     Bool (*Init) (KdKeyboardInfo *);
     Bool (*Enable) (KdKeyboardInfo *);
     void (*Leds) (KdKeyboardInfo *, int);
commit 56c405d46a86853771a0b808da4c8a9ef626960c
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Aug 17 13:07:23 2013 +0200

    kdrive: Fix a few easy cast warnings.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/linux/evdev.c b/hw/kdrive/linux/evdev.c
index 9982fad..63e8409 100644
--- a/hw/kdrive/linux/evdev.c
+++ b/hw/kdrive/linux/evdev.c
@@ -186,7 +186,7 @@ EvdevPtrRead(int evdevPort, void *closure)
     }
 }
 
-char *kdefaultEvdev[] = {
+const char *kdefaultEvdev[] = {
     "/dev/input/event0",
     "/dev/input/event1",
     "/dev/input/event2",
diff --git a/hw/kdrive/linux/linux.c b/hw/kdrive/linux/linux.c
index 498c239..00de2ae 100644
--- a/hw/kdrive/linux/linux.c
+++ b/hw/kdrive/linux/linux.c
@@ -63,7 +63,7 @@ LinuxVTRequest(int sig)
 
 /* Check before chowning -- this avoids touching the file system */
 static void
-LinuxCheckChown(char *file)
+LinuxCheckChown(const char *file)
 {
     struct stat st;
     __uid_t u;
diff --git a/hw/kdrive/linux/mouse.c b/hw/kdrive/linux/mouse.c
index f442447..aaab0cd 100644
--- a/hw/kdrive/linux/mouse.c
+++ b/hw/kdrive/linux/mouse.c
@@ -738,7 +738,7 @@ MouseInitProtocol(Kmouse * km)
 }
 
 static void
-MouseFirstProtocol(Kmouse * km, char *prot)
+MouseFirstProtocol(Kmouse * km, const char *prot)
 {
     if (prot) {
         for (km->i_prot = 0; km->i_prot < NUM_PROT; km->i_prot++)
@@ -887,7 +887,7 @@ MouseRead(int mousePort, void *closure)
 
 int MouseInputType;
 
-char *kdefaultMouse[] = {
+const char *kdefaultMouse[] = {
     "/dev/input/mice",
     "/dev/mouse",
     "/dev/psaux",
diff --git a/hw/kdrive/linux/ps2.c b/hw/kdrive/linux/ps2.c
index d1522a2..e5417a5 100644
--- a/hw/kdrive/linux/ps2.c
+++ b/hw/kdrive/linux/ps2.c
@@ -58,7 +58,7 @@ Ps2ReadBytes(int fd, char *buf, int len, int min)
     return tot;
 }
 
-char *Ps2Names[] = {
+const char *Ps2Names[] = {
     "/dev/psaux",
 /*    "/dev/mouse", */
     "/dev/input/mice",
commit a9c48a07eea50468fa47ab178cdd91edb0b5727f
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Aug 17 13:06:23 2013 +0200

    kdrive: Drop dead code.
    
    This is unused as of the introduction of a helper in
    e7150db5350bc2113ff4126019b489847a4dc217
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index c30f170..3aad87a 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -1675,13 +1675,6 @@ char *kdActionNames[] = {
 };
 #endif                          /* DEBUG */
 
-static void
-KdQueueEvent(DeviceIntPtr pDev, InternalEvent *ev)
-{
-    KdAssertSigioBlocked("KdQueueEvent");
-    mieqEnqueue(pDev, ev);
-}
-
 /* We return true if we're stealing the event. */
 static Bool
 KdRunMouseMachine(KdPointerInfo * pi, KdInputClass c, int type, int x, int y,
commit 873ae962bdb7559c952b5955ba262285701982a8
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Aug 17 13:01:57 2013 +0200

    ephyr: Fix dead code warning.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrhostglx.c b/hw/kdrive/ephyr/ephyrhostglx.c
index 6a4392f..5ecb02d 100644
--- a/hw/kdrive/ephyr/ephyrhostglx.c
+++ b/hw/kdrive/ephyr/ephyrhostglx.c
@@ -274,7 +274,6 @@ ephyrHostGLXGetVisualConfigsInternal(enum VisualConfRequestType a_type,
     xGLXGetVisualConfigsReply reply;
     char *server_glx_version = NULL, *server_glx_extensions = NULL;
     int j = 0,
-        screens = 0,
         major_opcode = 0,
         num_props = 0,
         num_visuals = 0, props_buf_size = 0, props_per_visual_size = 0;
@@ -282,7 +281,6 @@ ephyrHostGLXGetVisualConfigsInternal(enum VisualConfRequestType a_type,
 
     EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE);
 
-    screens = ScreenCount(dpy);
     if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) {
         EPHYR_LOG_ERROR("failed to get opcode\n");
         goto out;
commit 34af2eebe19e2f8afe35a5614d4d44fa4fd89d6b
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Aug 17 13:01:32 2013 +0200

    ephyr: Fix const-cast warnings for setting window title.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index f2b458d..5071289 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -215,7 +215,7 @@ hostx_set_screen_number(EphyrScreenInfo screen, int number)
 }
 
 void
-hostx_set_win_title(EphyrScreenInfo screen, char *extra_text)
+hostx_set_win_title(EphyrScreenInfo screen, const char *extra_text)
 {
     struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen);
 
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index 38b7b37..f47297c 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -171,7 +171,7 @@ void
  hostx_set_screen_number(EphyrScreenInfo screen, int number);
 
 void
- hostx_set_win_title(EphyrScreenInfo screen, char *extra_text);
+ hostx_set_win_title(EphyrScreenInfo screen, const char *extra_text);
 
 int
  hostx_get_depth(void);
commit 7edf5066db48434739ac64e0576fbb4fdf0f37f9
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Aug 17 12:54:33 2013 +0200

    ephyr: Fix const cast warnings in ephyrhostvideo.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/hw/kdrive/ephyr/ephyrhostvideo.c b/hw/kdrive/ephyr/ephyrhostvideo.c
index 05e9ad9..99f0f50 100644
--- a/hw/kdrive/ephyr/ephyrhostvideo.c
+++ b/hw/kdrive/ephyr/ephyrhostvideo.c
@@ -58,7 +58,7 @@
 #endif /*FALSE*/
 static XExtensionInfo _xv_info_data;
 static XExtensionInfo *xv_info = &_xv_info_data;
-static char *xv_extension_name = XvName;
+static const char *xv_extension_name = XvName;
 static char *xv_error_string(Display * dpy, int code, XExtCodes * codes,
                              char *buf, int n);
 static int xv_close_display(Display * dpy, XExtCodes * codes);
@@ -78,7 +78,7 @@ static XExtensionHooks xv_extension_hooks = {
     xv_error_string             /* error_string */
 };
 
-static char *xv_error_list[] = {
+static const char *xv_error_list[] = {
     "BadPort",                  /* XvBadPort     */
     "BadEncoding",              /* XvBadEncoding */
     "BadControl"                /* XvBadControl  */
@@ -311,7 +311,7 @@ char
 ephyrHostXVAdaptorGetType(const EphyrHostXVAdaptor * a_this)
 {
     EPHYR_RETURN_VAL_IF_FAIL(a_this, -1);
-    return ((XvAdaptorInfo *) a_this)->type;
+    return ((const XvAdaptorInfo *) a_this)->type;
 }
 
 const char *
@@ -319,7 +319,7 @@ ephyrHostXVAdaptorGetName(const EphyrHostXVAdaptor * a_this)
 {
     EPHYR_RETURN_VAL_IF_FAIL(a_this, NULL);
 
-    return ((XvAdaptorInfo *) a_this)->name;
+    return ((const XvAdaptorInfo *) a_this)->name;
 }
 
 EphyrHostVideoFormat *
@@ -333,16 +333,16 @@ ephyrHostXVAdaptorGetVideoFormats(const EphyrHostXVAdaptor * a_this,
 
     EPHYR_RETURN_VAL_IF_FAIL(a_this, NULL);
 
-    nb_formats = ((XvAdaptorInfo *) a_this)->num_formats;
+    nb_formats = ((const XvAdaptorInfo *) a_this)->num_formats;
     formats = calloc(nb_formats, sizeof(EphyrHostVideoFormat));
     for (i = 0; i < nb_formats; i++) {
         memset(&visual_info_template, 0, sizeof(visual_info_template));
         visual_info_template.visualid =
-            ((XvAdaptorInfo *) a_this)->formats[i].visual_id;
+            ((const XvAdaptorInfo *) a_this)->formats[i].visual_id;
         visual_info = XGetVisualInfo(hostx_get_display(),
                                      VisualIDMask,
                                      &visual_info_template, &nb_visual_info);
-        formats[i].depth = ((XvAdaptorInfo *) a_this)->formats[i].depth;
+        formats[i].depth = ((const XvAdaptorInfo *) a_this)->formats[i].depth;
         formats[i].visual_class = visual_info->class;
         XFree(visual_info);
     }
@@ -356,7 +356,7 @@ ephyrHostXVAdaptorGetNbPorts(const EphyrHostXVAdaptor * a_this)
 {
     EPHYR_RETURN_VAL_IF_FAIL(a_this, -1);
 
-    return ((XvAdaptorInfo *) a_this)->num_ports;
+    return ((const XvAdaptorInfo *) a_this)->num_ports;
 }
 
 int
@@ -364,7 +364,7 @@ ephyrHostXVAdaptorGetFirstPortID(const EphyrHostXVAdaptor * a_this)
 {
     EPHYR_RETURN_VAL_IF_FAIL(a_this, -1);
 
-    return ((XvAdaptorInfo *) a_this)->base_id;
+    return ((const XvAdaptorInfo *) a_this)->base_id;
 }
 
 Bool
@@ -372,8 +372,8 @@ ephyrHostXVAdaptorHasPutVideo(const EphyrHostXVAdaptor * a_this, Bool *a_result)
 {
     EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
 
-    if ((((XvAdaptorInfo *) a_this)->type & (XvVideoMask | XvInputMask)) ==
-        (XvVideoMask | XvInputMask))
+    if ((((const XvAdaptorInfo *) a_this)->type &
+         (XvVideoMask | XvInputMask)) == (XvVideoMask | XvInputMask))
         *a_result = TRUE;
     else
         *a_result = FALSE;
@@ -383,8 +383,8 @@ ephyrHostXVAdaptorHasPutVideo(const EphyrHostXVAdaptor * a_this, Bool *a_result)
 Bool
 ephyrHostXVAdaptorHasGetVideo(const EphyrHostXVAdaptor * a_this, Bool *a_result)
 {
-    if ((((XvAdaptorInfo *) a_this)->type & (XvVideoMask | XvOutputMask)) ==
-        (XvVideoMask | XvOutputMask))
+    if ((((const XvAdaptorInfo *) a_this)->type &
+         (XvVideoMask | XvOutputMask)) == (XvVideoMask | XvOutputMask))
         *a_result = TRUE;
     else
         *a_result = FALSE;
@@ -396,8 +396,8 @@ ephyrHostXVAdaptorHasPutStill(const EphyrHostXVAdaptor * a_this, Bool *a_result)
 {
     EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
 
-    if ((((XvAdaptorInfo *) a_this)->type & (XvStillMask | XvInputMask)) ==
-        (XvStillMask | XvInputMask))
+    if ((((const XvAdaptorInfo *) a_this)->type &
+         (XvStillMask | XvInputMask)) == (XvStillMask | XvInputMask))
         *a_result = TRUE;
     else
         *a_result = FALSE;
@@ -409,8 +409,8 @@ ephyrHostXVAdaptorHasGetStill(const EphyrHostXVAdaptor * a_this, Bool *a_result)
 {
     EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
 
-    if ((((XvAdaptorInfo *) a_this)->type & (XvStillMask | XvOutputMask)) ==
-        (XvStillMask | XvOutputMask))
+    if ((((const XvAdaptorInfo *) a_this)->type &
+         (XvStillMask | XvOutputMask)) == (XvStillMask | XvOutputMask))
         *a_result = TRUE;
     else
         *a_result = FALSE;
@@ -422,8 +422,8 @@ ephyrHostXVAdaptorHasPutImage(const EphyrHostXVAdaptor * a_this, Bool *a_result)
 {
     EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE);
 
-    if ((((XvAdaptorInfo *) a_this)->type & (XvImageMask | XvInputMask)) ==
-        (XvImageMask | XvInputMask))
+    if ((((const XvAdaptorInfo *) a_this)->type &
+         (XvImageMask | XvInputMask)) == (XvImageMask | XvInputMask))
         *a_result = TRUE;
     else
         *a_result = FALSE;


More information about the xorg-commit mailing list