Index: xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmx.h
===================================================================
--- xorg-server-7.2.0.0-1.5.99.1.orig/hw/dmx/dmx.h
+++ xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmx.h
@@ -115,6 +115,11 @@ typedef struct _DMXRequest {
     void         *data;
 } DMXRequest;
 
+typedef struct _DMXEvent {
+    DMXSequence         base;
+    xcb_generic_event_t *event;
+} DMXEvent;
+
 typedef struct _DMXPropTrans {
     const char *name;
     const char *format;
@@ -298,6 +303,10 @@ typedef struct _DMXScreenInfo {
 
     DMXQueue ignore;
     DMXQueue request;
+    DMXQueue event;
+
+    unsigned int   repTimeout;
+    struct timeval repTimer;
 
 #ifdef GLXEXT
                                   /** Visual information for glxProxy */
@@ -438,6 +447,8 @@ extern Bool             dmxIgnoreBadFont
 extern Bool             dmxAddRemoveScreens;    /**< True if add and
 						 * remove screens support
 						 * is enabled */
+extern int              dmxDefaultResponseTimeout;
+
 #ifdef RANDR
 extern int             xRROutputsPerScreen;
 extern int             xRRCrtcsPerScreen;
Index: xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxatom.c
===================================================================
--- xorg-server-7.2.0.0-1.5.99.1.orig/hw/dmx/dmxatom.c
+++ xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxatom.c
@@ -161,11 +161,11 @@ dmxAtom (DMXScreenInfo *dmxScreen,
 	xcb_get_atom_name_reply_t *reply;
 	Atom                      atom;
 
-	reply = xcb_get_atom_name_reply
-	    (dmxScreen->connection,
-	     xcb_get_atom_name (dmxScreen->connection,
-				beAtom),
-	     NULL);
+	reply = (xcb_get_atom_name_reply_t *)
+	    dmxGetReply (dmxScreen,
+			 xcb_get_atom_name (dmxScreen->connection,
+					    beAtom).sequence,
+			 NULL);
 	if (!reply)
 	    return None;
 
@@ -203,17 +203,11 @@ dmxBEAtom (DMXScreenInfo *dmxScreen,
 	cookie.sequence = dmxBERequestAtom (dmxScreen, atom);
     
     if (cookie.sequence)
-    {
-	xcb_intern_atom_reply_t *reply;
-
-	reply = xcb_intern_atom_reply (dmxScreen->connection, cookie, NULL);
-
 	dmxInternAtomReply (screenInfo.screens[dmxScreen->index],
 			    cookie.sequence,
-			    (xcb_generic_reply_t *) reply,
+			    dmxGetReply (dmxScreen, cookie.sequence, NULL),
 			    NULL,
 			    (void *) atom);
-    }
 
     if (atom < dmxScreen->beAtomTableSize)
 	return dmxScreen->beAtomTable[atom].atom;
Index: xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxgcops.c
===================================================================
--- xorg-server-7.2.0.0-1.5.99.1.orig/hw/dmx/dmxgcops.c
+++ xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxgcops.c
@@ -658,13 +658,14 @@ void dmxGetImage(DrawablePtr pDrawable,
 	    if (!dmxScreen) continue;
 	}
 
-	reply = xcb_get_image_reply (dmxScreen->connection,
-				     xcb_get_image (dmxScreen->connection,
-						    format,
-						    draw,
-						    sx, sy, w, h,
-						    planeMask),
-				     NULL);
+	reply = (xcb_get_image_reply_t *)
+	    dmxGetReply (dmxScreen,
+			 xcb_get_image (dmxScreen->connection,
+					format,
+					draw,
+					sx, sy, w, h,
+					planeMask).sequence,
+			 NULL);
 
 	setup = xcb_get_setup (dmxScreen->connection);
 	if (reply && setup)
Index: xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxinit.c
===================================================================
--- xorg-server-7.2.0.0-1.5.99.1.orig/hw/dmx/dmxinit.c
+++ xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxinit.c
@@ -133,6 +133,8 @@ char            *dmxLaunchVT = NULL;
 
 int             dmxNumDetached = 4;
 
+int             dmxDefaultResponseTimeout = 5;
+
 #ifdef RANDR
 int             xRROutputsPerScreen = 1;
 int             xRRCrtcsPerScreen = 1;
@@ -326,6 +328,7 @@ dmxAddScreen(const char *name,
     dmxScreen->authData    = dmxMemDup (authData, authDataLen);
     dmxScreen->authDataLen = authDataLen;
     dmxScreen->virtualFb   = virtualFb;
+    dmxScreen->repTimeout  = dmxDefaultResponseTimeout;
     ++dmxNumScreens;
 
     return dmxScreen;
@@ -359,6 +362,13 @@ Bool dmxOpenDisplay(DMXScreenInfo *dmxSc
 	return FALSE;
     }
 
+    dmxLogOutput (dmxScreen,
+		  "Using %d second response timeout\n",
+		  dmxScreen->repTimeout);
+
+    dmxScreen->repTimer.tv_sec  = dmxScreen->repTimeout;
+    dmxScreen->repTimer.tv_usec = 0;
+
     dmxScreen->alive      = 1;
     dmxScreen->broken     = 0;
     dmxScreen->inDispatch = FALSE;
@@ -1259,6 +1269,9 @@ int ddxProcessArgument(int argc, char *a
     } else if (!strcmp(argv[i], "-noaddremovescreens")) {
 	dmxAddRemoveScreens = FALSE;
         retval = 1;
+    } else if (!strcmp(argv[i], "-timeout")) {
+	if (++i < argc) dmxDefaultResponseTimeout = atoi(argv[i]);
+        retval = 2;
 #ifdef PANORAMIX
     } else if (!strcmp (argv[i], "-xinerama")) {
 	dmxNoPanoramiXExtension = TRUE;
@@ -1374,6 +1387,7 @@ void ddxUseMsg(void)
 #endif
     ErrorF("-ignorebadfontpaths  Ignore bad font paths during initialization\n");
     ErrorF("-noaddremovescreens  Disable dynamic screen addition/removal\n");
+    ErrorF("-timeout secs        Specify default response timeout\n");
 #ifdef RANDR
     ErrorF("-outputs num         RANDR outputs for each back-end display\n");
     ErrorF("-crtcs num           RANDR crtcs for each back-end display\n");
Index: xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxinput.c
===================================================================
--- xorg-server-7.2.0.0-1.5.99.1.orig/hw/dmx/dmxinput.c
+++ xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxinput.c
@@ -35,6 +35,7 @@
 #include "dmxwindow.h"
 #include "dmxcursor.h"
 #include "dmxscrinit.h"
+#include "dmxsync.h"
 #include "dmxxlibio.h"
 
 #include "inputstr.h"
@@ -149,12 +150,13 @@ dmxUpdateKeyboardMapping (DeviceIntPtr p
     {
 	xcb_input_get_device_key_mapping_reply_t *reply;
 
-	reply = xcb_input_get_device_key_mapping_reply
-	    (dmxScreen->connection,
-	     xcb_input_get_device_key_mapping (dmxScreen->connection,
-					       pDevPriv->deviceId,
-					       first,
-					       count),
+	reply = (xcb_input_get_device_key_mapping_reply_t *)
+	    dmxGetReply (dmxScreen,
+			 xcb_input_get_device_key_mapping
+			 (dmxScreen->connection,
+			  pDevPriv->deviceId,
+			  first,
+			  count).sequence,
 	     NULL);
 
 	if (reply)
@@ -176,12 +178,12 @@ dmxUpdateKeyboardMapping (DeviceIntPtr p
     {
 	xcb_get_keyboard_mapping_reply_t *reply;
 
-	reply = xcb_get_keyboard_mapping_reply
-	    (dmxScreen->connection,
-	     xcb_get_keyboard_mapping (dmxScreen->connection,
-				       first,
-				       count),
-	     NULL);
+	reply = (xcb_get_keyboard_mapping_reply_t *)
+	    dmxGetReply (dmxScreen,
+			 xcb_get_keyboard_mapping (dmxScreen->connection,
+						   first,
+						   count).sequence,
+			 NULL);
 
 	if (reply)
 	{
Index: xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxscrinit.c
===================================================================
--- xorg-server-7.2.0.0-1.5.99.1.orig/hw/dmx/dmxscrinit.c
+++ xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxscrinit.c
@@ -237,9 +237,10 @@ dmxScreenGetSelectionOwner (ScreenPtr pS
 	xcb_atom_t                      a = dmxScreen->beSelectionAtom;
 	xcb_get_selection_owner_reply_t *reply;
 
-	reply = xcb_get_selection_owner_reply (c,
-					       xcb_get_selection_owner (c, a),
-					       NULL);
+	reply = (xcb_get_selection_owner_reply_t *)
+	    dmxGetReply (dmxScreen,
+			 xcb_get_selection_owner (c, a).sequence,
+			 NULL);
 	if (!reply)
 	    break;
 
@@ -812,38 +813,37 @@ dmxScreenEventCheckManageRoot (ScreenPtr
     return TRUE;
 }
 
-void
-dmxBEDispatch (ScreenPtr pScreen)
+static void
+dmxBEProcessEvents (ScreenPtr    pScreen,
+		    unsigned int sequence)
 {
-    DMXScreenInfo       *dmxScreen = &dmxScreens[pScreen->myNum];
-    xcb_generic_event_t *event;
-    xcb_generic_error_t *error;
-    void                *reply;
-
-    assert (dmxScreen->inDispatch == FALSE);
-    dmxScreen->inDispatch = TRUE;
+    DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
 
-    while ((event = xcb_poll_for_event (dmxScreen->connection)))
+    while (dmxScreen->event.head &&
+	   dmxScreen->event.head->sequence <= sequence)
     {
-	if (!dmxScreenEventCheckInput (pScreen, event)        &&
-	    !dmxScreenEventCheckSelection (pScreen, event)    &&
-	    !dmxScreenEventCheckDnD (pScreen, event)          &&
-	    !dmxScreenEventCheckOutputWindow (pScreen, event) &&
-	    !dmxScreenEventCheckManageRoot (pScreen, event)   &&
+	DMXEvent *head = (DMXEvent *) dmxScreen->event.head;
 
-#ifdef MITSHM
-	    !dmxScreenEventCheckShm (pScreen, event)          &&
-#endif
+	dmxScreen->event.head = head->base.next;
+	if (!dmxScreen->event.head)
+	    dmxScreen->event.tail = &dmxScreen->event.head;
+
+	if (!dmxScreenEventCheckInput (pScreen, head->event)        &&
+	    !dmxScreenEventCheckSelection (pScreen, head->event)    &&
+	    !dmxScreenEventCheckDnD (pScreen, head->event)          &&
+	    !dmxScreenEventCheckOutputWindow (pScreen, head->event) &&
+	    !dmxScreenEventCheckManageRoot (pScreen, head->event)   &&
 
 #ifdef RANDR
-	    !dmxScreenEventCheckRR (pScreen, event)           &&
+	    !dmxScreenEventCheckRR (pScreen, head->event)           &&
 #endif
 
-	    !dmxScreenEventCheckExpose (pScreen, event))
+	    !dmxScreenEventCheckExpose (pScreen, head->event))
 	{
-	    if (event->response_type == 0)
+	    if (head->event->response_type == 0)
 	    {
-		xcb_generic_error_t *error = (xcb_generic_error_t *) event;
+		xcb_generic_error_t *error = (xcb_generic_error_t *)
+		    head->event;
 
 		dmxLogOutput (dmxScreen, "unhandled error type %d\n",
 			      error->error_code);
@@ -851,12 +851,24 @@ dmxBEDispatch (ScreenPtr pScreen)
 	    else
 	    {
 		dmxLogOutput (dmxScreen, "unhandled event type %d\n",
-			      event->response_type);
+			      head->event->response_type);
 	    }
 	}
 
-	free (event);
+	free (head->event);
+	free (head);
     }
+}
+
+void
+dmxBEDispatch (ScreenPtr pScreen)
+{
+    DMXScreenInfo       *dmxScreen = &dmxScreens[pScreen->myNum];
+    xcb_generic_error_t *error;
+    void                *reply;
+
+    assert (dmxScreen->inDispatch == FALSE);
+    dmxScreen->inDispatch = TRUE;
 
     while (dmxScreen->request.head &&
 	   xcb_poll_for_reply (dmxScreen->connection,
@@ -870,20 +882,27 @@ dmxBEDispatch (ScreenPtr pScreen)
 	if (!dmxScreen->request.head)
 	    dmxScreen->request.tail = &dmxScreen->request.head;
 
+	/* process all events generated before reply */
+	dmxBEProcessEvents (pScreen, head->base.sequence);
+
 	(*head->reply) (pScreen,
 			head->base.sequence,
 			reply,
 			error,
 			head->data);
 
-        if (reply)
+	if (reply)
 	    free (reply);
-        if (error)
-            free (error);
+	if (error)
+	    free (error);
 
 	free (head);
     }
 
+    /* process remaining events */
+    while (dmxScreen->event.head)
+	dmxBEProcessEvents (pScreen, dmxScreen->event.head->sequence);
+
     if (!dmxScreen->scrnWin ||
 	xcb_connection_has_error (dmxScreen->connection))
     {
@@ -951,6 +970,9 @@ dmxScreenBlockHandler (pointer   blockDa
     ScreenPtr     pScreen = (ScreenPtr) blockData;
     DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
 
+    while (dmxScreen->event.head)
+	dmxBEDispatch (pScreen);
+
     if (dmxScreen->alive)
 	xcb_flush (dmxScreen->connection);
 
@@ -967,7 +989,14 @@ dmxScreenWakeupHandler (pointer blockDat
     DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
 
     if (dmxScreen->alive)
+    {
+	xcb_generic_event_t *event;
+
+	while ((event = xcb_poll_for_event (dmxScreen->connection)))
+	    dmxAddEvent (&dmxScreen->event, event);
+
 	dmxBEDispatch (pScreen);
+    }
 }
 
 static void
@@ -1028,6 +1057,9 @@ Bool dmxScreenInit(int idx, ScreenPtr pS
     dmxScreen->request.head = NULL;
     dmxScreen->request.tail = &dmxScreen->request.head;
 
+    dmxScreen->event.head = NULL;
+    dmxScreen->event.tail = &dmxScreen->event.head;
+
     dmxScreen->scrnEventMask = 0;
 
     dmxScreen->rootEventMask = ExposureMask | StructureNotifyMask |
@@ -1305,6 +1337,7 @@ void dmxBECloseScreen(ScreenPtr pScreen)
     }
 #endif
 
+    dmxClearQueue (&dmxScreen->event);
     dmxClearQueue (&dmxScreen->request);
     dmxClearQueue (&dmxScreen->ignore);
 }
@@ -1492,3 +1525,35 @@ dmxAddRequest (DMXQueue      *q,
     return TRUE;
 }
 
+Bool
+dmxAddEvent (DMXQueue            *q,
+	     xcb_generic_event_t *event)
+{
+    DMXEvent *e;
+
+    e = malloc (sizeof (DMXEvent));
+    if (!e)
+	return FALSE;
+
+    e->base.sequence = event->sequence;
+    e->base.next     = 0;
+    e->event         = event;
+
+    *(q->tail) = &e->base;
+    q->tail = &e->base.next;
+
+    return TRUE;
+}
+
+void
+dmxSaveStatusReply (ScreenPtr           pScreen,
+		    unsigned int        sequence,
+		    xcb_generic_reply_t *reply,
+		    xcb_generic_error_t *error,
+		    void                *data)
+{
+    if (reply)
+	*((int *) data) = 1;
+    else
+	*((int *) data) = -1;
+}
Index: xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxscrinit.h
===================================================================
--- xorg-server-7.2.0.0-1.5.99.1.orig/hw/dmx/dmxscrinit.h
+++ xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxscrinit.h
@@ -57,4 +57,13 @@ extern Bool dmxAddRequest (DMXQueue
 			   unsigned long sequence,
 			   void          *data);
 
+extern Bool dmxAddEvent (DMXQueue            *q,
+			 xcb_generic_event_t *event);
+
+extern void dmxSaveStatusReply (ScreenPtr           pScreen,
+				unsigned int        sequence,
+				xcb_generic_reply_t *reply,
+				xcb_generic_error_t *error,
+				void                *data);
+
 #endif /* DMXSCRINIT_H */
Index: xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxshm.c
===================================================================
--- xorg-server-7.2.0.0-1.5.99.1.orig/hw/dmx/dmxshm.c
+++ xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxshm.c
@@ -34,6 +34,7 @@
 #include "dmxpixmap.h"
 #include "dmxsync.h"
 #include "dmxlog.h"
+#include "dmxscrinit.h"
 #include "scrnintstr.h"
 #include "servermd.h"
 #include "shmint.h"
@@ -202,53 +203,20 @@ dmxBEDetachShmSeg (DMXScreenInfo    *dmx
     }
 }
 
-Bool
-dmxScreenEventCheckShm (ScreenPtr           pScreen,
-			xcb_generic_event_t *event)
+static void
+dmxScreenShmReply (ScreenPtr           pScreen,
+		   unsigned int        sequence,
+		   xcb_generic_reply_t *reply,
+		   xcb_generic_error_t *error,
+		   void                *data)
 {
-    DMXScreenInfo    *dmxScreen = &dmxScreens[pScreen->myNum];
-    dmxShmSegInfoPtr pShmInfo;
-    xcb_shm_seg_t    shmseg = 0;
-    unsigned int     sequence = 0;
-
-    if (!dmxScreen->beShm)
-	return FALSE;
-
-    if (event->response_type)
-    {
-	switch ((event->response_type & ~0x80) - dmxScreen->beShmEventBase) {
-	case XCB_SHM_COMPLETION: {
-	    /* XCB protocol description for XCB_SHM_COMPLETION is wrong */
-	    xShmCompletionEvent *xcompletion =
-		(xShmCompletionEvent *) event;
-
-	    shmseg = xcompletion->shmseg;
-	} break;
-	default:
-	    return FALSE;
-	}
-    }
-    else
-    {
-	sequence = ((xcb_generic_error_t *) event)->sequence;
-    }
+    dmxShmSegInfoPtr pShmInfo = (dmxShmSegInfoPtr) data;
 
-    for (pShmInfo = shmSegs; pShmInfo; pShmInfo = pShmInfo->next)
+    if (pShmInfo->cookie[pScreen->myNum].sequence)
     {
-	if (shmseg && shmseg != pShmInfo->shmseg[pScreen->myNum])
-	    continue;
-
-	if (!pShmInfo->cookie[pScreen->myNum].sequence)
-	    continue;
-
-	if (sequence && sequence != pShmInfo->cookie[pScreen->myNum].sequence)
-	    continue;
-	    
-	pShmInfo->pendingEvents--;
+	pShmInfo->pendingReplies--;
 	pShmInfo->cookie[pScreen->myNum].sequence = 0;
     }
-
-    return TRUE;
 }
 
 static int
@@ -304,10 +272,10 @@ dmxProcShmAttach (ClientPtr client)
 	if (!pShmInfo)
 	    return Success;
 
-	pShmInfo->refcnt        = 1;
-	pShmInfo->shmid         = stuff->shmid;
-	pShmInfo->readOnly      = stuff->readOnly;
-	pShmInfo->pendingEvents = 0;
+	pShmInfo->refcnt         = 1;
+	pShmInfo->shmid          = stuff->shmid;
+	pShmInfo->readOnly       = stuff->readOnly;
+	pShmInfo->pendingReplies = 0;
 
 	memset (pShmInfo->shmseg, 0, sizeof (pShmInfo->shmseg));
 	memset (pShmInfo->cookie, 0, sizeof (pShmInfo->cookie));
@@ -423,35 +391,27 @@ dmxProcShmGetImage (ClientPtr client)
     if (length)
     {
 	xcb_shm_get_image_cookie_t cookie;
-	xcb_shm_get_image_reply_t  *reply;
 	DMXScreenInfo		   *dmxScreen =
 	    &dmxScreens[pDraw->pScreen->myNum];
 
-	rc = BadValue;
 	cookie = xcb_shm_get_image (dmxScreen->connection, draw,
 				    stuff->x, stuff->y,
 				    stuff->width, stuff->height,
 				    stuff->planeMask, stuff->format,
 				    pShmInfo->shmseg[dmxScreen->index],
 				    stuff->offset);
+
+	rc = 0;
+	dmxAddRequest (&dmxScreen->request,
+		       dmxSaveStatusReply,
+		       cookie.sequence,
+		       (void *) &rc);
+
 	do {
 	    dmxDispatch ();
+	} while (rc == 0 && dmxScreen->alive && dmxWaitForResponse ());
 
-	    if (xcb_poll_for_reply (dmxScreen->connection,
-				    cookie.sequence,
-				    (void **) &reply,
-				    NULL))
-	    {
-		if (reply)
-		{
-		    rc = Success;
-		    free (reply);
-		}
-		break;
-	    }
-	} while (dmxWaitForResponse () && dmxScreen->alive);
-
-	if (rc != Success)
+	if (rc != 1)
 	    return (*dmxSaveProcVector[X_ShmGetImage]) (client);
     }
 
@@ -556,21 +516,28 @@ dmxProcShmPutImage (ClientPtr client)
 
 	if (dmxScreen->beDisplay && draw)
 	{
+	    xcb_shm_put_image (dmxScreen->connection,
+			       draw,
+			       XGContextFromGC (pGCPriv->gc),
+			       stuff->totalWidth, stuff->totalHeight,
+			       stuff->srcX, stuff->srcY,
+			       stuff->srcWidth, stuff->srcHeight,
+			       stuff->dstX, stuff->dstY,
+			       stuff->depth,
+			       stuff->format,
+			       FALSE,
+			       pShmInfo->shmseg[dmxScreen->index],
+			       stuff->offset);
+
 	    pShmInfo->cookie[dmxScreen->index] =
-		xcb_shm_put_image (dmxScreen->connection,
-				   draw,
-				   XGContextFromGC (pGCPriv->gc),
-				   stuff->totalWidth, stuff->totalHeight,
-				   stuff->srcX, stuff->srcY,
-				   stuff->srcWidth, stuff->srcHeight,
-				   stuff->dstX, stuff->dstY,
-				   stuff->depth,
-				   stuff->format,
-				   TRUE,
-				   pShmInfo->shmseg[dmxScreen->index],
-				   stuff->offset);
+		xcb_get_input_focus (dmxScreen->connection);
+
+	    dmxAddRequest (&dmxScreen->request,
+			   dmxScreenShmReply,
+			   pShmInfo->cookie[dmxScreen->index].sequence,
+			   (void *) pShmInfo);
 
-	    pShmInfo->pendingEvents++;
+	    pShmInfo->pendingReplies++;
 	}
     }
     else
@@ -595,7 +562,7 @@ dmxProcShmPutImage (ClientPtr client)
 	    /* wait for all back-end servers to complete */
 	    do {
 		dmxDispatch ();
-	    } while (pShmInfo->pendingEvents && dmxWaitForResponse ());
+	    } while (pShmInfo->pendingReplies && dmxWaitForResponse ());
 	}
     }
 
@@ -692,17 +659,17 @@ dmxBEShmScreenInit (ScreenPtr pScreen)
     }
     XLIB_EPILOGUE (dmxScreen);
 
-    reply =
-	xcb_shm_get_image_reply (dmxScreen->connection,
-				 xcb_shm_get_image (dmxScreen->connection,
-						    pixmap,
-						    0, 0,
-						    sizeof (key), 1,
-						    0xff,
-						    XCB_IMAGE_FORMAT_Z_PIXMAP,
-						    shmseg,
-						    0),
-				 NULL);
+    reply = (xcb_shm_get_image_reply_t *)
+	dmxGetReply (dmxScreen,
+		     xcb_shm_get_image (dmxScreen->connection,
+					pixmap,
+					0, 0,
+					sizeof (key), 1,
+					0xff,
+					XCB_IMAGE_FORMAT_Z_PIXMAP,
+					shmseg,
+					0).sequence,
+		     NULL);
 
     xcb_free_pixmap (dmxScreen->connection, pixmap);
     
Index: xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxshm.h
===================================================================
--- xorg-server-7.2.0.0-1.5.99.1.orig/hw/dmx/dmxshm.h
+++ xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxshm.h
@@ -32,13 +32,13 @@
 #include <xcb/shm.h>
 
 typedef struct _dmxShmSegInfo {
-    struct _dmxShmSegInfo *next;
-    uint32_t              shmid;
-    int                   refcnt;
-    uint8_t               readOnly;
-    uint32_t              pendingEvents;
-    xcb_shm_seg_t         shmseg[MAXSCREENS];
-    xcb_void_cookie_t     cookie[MAXSCREENS];
+    struct _dmxShmSegInfo        *next;
+    uint32_t                     shmid;
+    int                          refcnt;
+    uint8_t                      readOnly;
+    uint32_t                     pendingReplies;
+    xcb_shm_seg_t                shmseg[MAXSCREENS];
+    xcb_get_input_focus_cookie_t cookie[MAXSCREENS];
 } dmxShmSegInfoRec, *dmxShmSegInfoPtr;
 
 extern unsigned long DMX_SHMSEG;
@@ -50,9 +50,6 @@ extern void dmxBEAttachShmSeg (DMXScreen
 extern void dmxBEDetachShmSeg (DMXScreenInfo    *dmxScreen,
 			       dmxShmSegInfoPtr pShmInfo);
 
-extern Bool dmxScreenEventCheckShm (ScreenPtr           pScreen,
-				    xcb_generic_event_t *event);
-
 extern void dmxBEShmScreenInit (ScreenPtr pScreen);
 
 extern void dmxInitShm (void);
Index: xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxsync.c
===================================================================
--- xorg-server-7.2.0.0-1.5.99.1.orig/hw/dmx/dmxsync.c
+++ xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxsync.c
@@ -56,7 +56,7 @@
 #include "dmxlog.h"
 #include "dmxextension.h"
 #include "dmxscrinit.h"
-#include <sys/time.h>
+#include <X11/Xos.h> /* For sys/time.h */
 
 static int        dmxSyncInterval = 100; /* Default interval in milliseconds */
 static OsTimerPtr dmxSyncTimer = NULL;
@@ -64,8 +64,6 @@ static OsTimerPtr dmxActiveSyncTimer = N
 static int        dmxSyncPending = 0;
 static int        dmxSyncRequest = 0;
 
-#define DMX_SELECT_TIMEOUT_SECS 5
-
 /* dispatch all pending back-end server responses */
 void
 dmxDispatch (void)
@@ -73,23 +71,30 @@ dmxDispatch (void)
     int i;
 
     for (i = 0; i < dmxNumScreens; i++)
-	if (dmxScreens[i].alive)
-	    dmxBEDispatch (screenInfo.screens[i]);
+        if (dmxScreens[i].alive)
+            dmxBEDispatch (screenInfo.screens[i]);
 }
 
 /* non-blocking wait for back-end server response. returns 0 when no
-   more reponses can arrive */
+   more reponses can arrive. use -1 for any screen */
 int
-dmxWaitForResponse (void)
+dmxWaitForScreenResponse (int screen)
 {
-    fd_set rfds;
-    int    nfd = 0;
-    int    i, ret = 0;
+    fd_set         rfds;
+    int            nfd = 0;
+    int            i, ret = 0;
+    struct timeval timeout;
+
+    timeout.tv_sec  = 999999;
+    timeout.tv_usec = 0;
 
     FD_ZERO (&rfds);
-     
+
     for (i = 0; i < dmxNumScreens; i++)
     {
+	if (screen >= 0 && screen != i)
+	    continue;
+
 	if (dmxScreens[i].alive)
 	{
 	    xcb_flush (dmxScreens[i].connection);
@@ -105,29 +110,72 @@ dmxWaitForResponse (void)
 
 		if (dmxScreens[i].fd > nfd)
 		    nfd = dmxScreens[i].fd;
+
+		if (dmxScreens[i].request.head || screen == i)
+		{
+		    if (timercmp (&dmxScreens[i].repTimer, &timeout, < ))
+			timeout = dmxScreens[i].repTimer;
+		}
 	    }
 	}
     }
 
     if (ret == 0 && nfd)
     {
-	do {
-	    struct timeval timeout;
+	struct timeval left = timeout;
+
+       	do {
+	    struct timeval tv1, tv2, delta = left;
 
-	    timeout.tv_sec  = DMX_SELECT_TIMEOUT_SECS;
-	    timeout.tv_usec = 0;
+            gettimeofday (&tv1, NULL);
+	    ret = select (nfd + 1, &rfds, 0, 0, &delta);
+            gettimeofday (&tv2, NULL);
+
+            timersub (&tv2, &tv1, &delta);
+            if (timercmp (&left, &delta, < ))
+	    {
+		timerclear (&left);
+		break;
+	    }
+
+	    timersub (&left, &delta, &left);
 
-	    ret = select (nfd + 1, &rfds, 0, 0, &timeout);
 	} while (ret == -1 && errno == EINTR);
 
-	if (!ret)
+	timersub (&timeout, &left, &timeout);
+
+	for (i = 0; i < dmxNumScreens; i++)
 	{
-	    for (i = 0; i < dmxNumScreens; i++)
+	    if (screen >= 0 && screen != i)
+		continue;
+
+	    if (dmxScreens[i].alive)
 	    {
-		if (dmxScreens[i].alive && dmxScreens[i].request.head)
+		if (FD_ISSET (dmxScreens[i].fd, &rfds))
 		{
-		    xcb_disconnect (dmxScreens[i].connection);
-		    dmxScreens[i].alive = FALSE;
+		    xcb_connection_t    *c = dmxScreens[i].connection;
+		    xcb_generic_event_t *event;
+
+		    dmxScreens[i].repTimer.tv_sec  = dmxScreens[i].repTimeout;
+		    dmxScreens[i].repTimer.tv_usec = 0;
+
+		    while ((event = xcb_poll_for_event (c)))
+			dmxAddEvent (&dmxScreens[i].event, event);
+		}
+		else if (dmxScreens[i].request.head || screen == i)
+		{
+		    timersub (&dmxScreens[i].repTimer, &timeout,
+			      &dmxScreens[i].repTimer);
+
+		    if (!timerisset (&dmxScreens[i].repTimer))
+		    {
+			dmxLog (dmxWarning,
+				"More than %d seconds since last response "
+				"from screen %d\n",
+				dmxScreens[i].repTimeout, i);
+
+			close (dmxScreens[i].fd);
+		    }
 		}
 	    }
 	}
@@ -139,6 +187,47 @@ dmxWaitForResponse (void)
     return nfd;
 }
 
+int
+dmxWaitForResponse (void)
+{
+    return dmxWaitForScreenResponse (-1);
+}
+
+xcb_generic_reply_t *
+dmxGetReply (DMXScreenInfo       *dmxScreen,
+	     unsigned int        sequence,
+	     xcb_generic_error_t **e)
+{
+    xcb_generic_error_t *error = NULL;
+    void                *reply = NULL;
+
+    if (sequence)
+    {
+	do {
+	    if (xcb_poll_for_reply (dmxScreen->connection,
+				    sequence,
+				    &reply,
+				    &error))
+		break;
+	} while (dmxWaitForScreenResponse (dmxScreen->index));
+    }
+
+    if (error)
+    {
+	if (e)
+	    *e = error;
+	else
+	    free (error);
+    }
+    else
+    {
+	if (e)
+	    *e = NULL;
+    }
+
+    return reply;
+}
+
 static void dmxDoSync(DMXScreenInfo *dmxScreen)
 {
     dmxScreen->needsSync = FALSE;
@@ -250,12 +339,18 @@ void dmxSync(DMXScreenInfo *dmxScreen, B
         if (dmxScreen) {
 	    if (now && dmxScreen->inDispatch)
 	    {
+		xcb_generic_reply_t *reply;
+
 		dmxLog (dmxWarning,
 			"Immediate sync from within back-end dispatch\n");
-		free (xcb_get_input_focus_reply
-		      (dmxScreen->connection,
-		       xcb_get_input_focus (dmxScreen->connection),
-		       NULL));
+
+		reply = dmxGetReply (dmxScreen,
+				     xcb_get_input_focus
+				     (dmxScreen->connection).sequence,
+				     NULL);
+		if (reply)
+		    free (reply);
+
 		return;
 	    }
             dmxScreen->needsSync = TRUE;
Index: xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxsync.h
===================================================================
--- xorg-server-7.2.0.0-1.5.99.1.orig/hw/dmx/dmxsync.h
+++ xorg-server-7.2.0.0-1.5.99.1/hw/dmx/dmxsync.h
@@ -38,7 +38,11 @@
 #define _DMXSYNC_H_
 
 extern void dmxDispatch (void);
-extern int  dmxWaitForResponse (void);
+extern int dmxWaitForScreenResponse (int screen);
+extern int dmxWaitForResponse (void);
+extern xcb_generic_reply_t *dmxGetReply (DMXScreenInfo       *dmxScreen,
+					 unsigned int        sequence,
+					 xcb_generic_error_t **e);
 extern void dmxSyncActivate(const char *interval);
 extern void dmxSyncInit(void);
 extern void dmxSync(DMXScreenInfo *dmxScreen, Bool now);
