c36b847
From 7f8f9a36ef901f31279c385caf960a22daeb33fe Mon Sep 17 00:00:00 2001
c36b847
From: "Owen W. Taylor" <otaylor@fishsoup.net>
c36b847
Date: Fri, 9 May 2014 18:21:05 -0400
c36b847
Subject: [PATCH] Fix XNextRequest() after direct usage of XCB
c36b847
c36b847
When XCB owns the X socket, dpy->request is not updated, so
c36b847
NextRequest() and XNextRequest() return the wrong value. There's
c36b847
nothing we can do to fix NextRequest() while retaining ABI compat,
c36b847
but change XNextRequest() to grab the socket back from XCB,
c36b847
updating dpy->request.
c36b847
c36b847
Signed-off-by: Owen W. Taylor <otaylor@fishsoup.net>
c36b847
Reviewed-by: Uli Schlachter <psychon@znc.in>
c36b847
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
c36b847
---
c36b847
 src/Macros.c  | 14 +++++++++++++-
c36b847
 src/Xxcbint.h |  2 ++
c36b847
 src/xcb_io.c  | 11 +++++++++++
c36b847
 3 files changed, 26 insertions(+), 1 deletion(-)
c36b847
c36b847
diff --git a/src/Macros.c b/src/Macros.c
c36b847
index cfc083a..394a764 100644
c36b847
--- a/src/Macros.c
c36b847
+++ b/src/Macros.c
c36b847
@@ -30,6 +30,7 @@ in this Software without prior written authorization from The Open Group.
c36b847
 #include "Xlibint.h"
c36b847
 #define XUTIL_DEFINE_FUNCTIONS
c36b847
 #include "Xutil.h"
c36b847
+#include "Xxcbint.h"
c36b847
 
c36b847
 /*
c36b847
  * This file makes full definitions of routines for each macro.
c36b847
@@ -135,9 +136,20 @@ int XBitmapPad(Display *dpy) { return (BitmapPad(dpy)); }
c36b847
 
c36b847
 int XImageByteOrder(Display *dpy) { return (ImageByteOrder(dpy)); }
c36b847
 
c36b847
+/* XNextRequest() differs from the rest of the functions here because it is
c36b847
+ * no longer a macro wrapper - when libX11 is being used mixed together
c36b847
+ * with direct use of xcb, the next request field of the Display structure will
c36b847
+ * not be updated. We can't fix the NextRequest() macro in any easy way,
c36b847
+ * but we can at least make XNextRequest() do the right thing.
c36b847
+ */
c36b847
 unsigned long XNextRequest(Display *dpy)
c36b847
 {
c36b847
-    return (NextRequest(dpy));
c36b847
+    unsigned long next_request;
c36b847
+    LockDisplay(dpy);
c36b847
+    next_request = _XNextRequest(dpy);
c36b847
+    UnlockDisplay(dpy);
c36b847
+
c36b847
+    return next_request;
c36b847
 }
c36b847
 
c36b847
 unsigned long XLastKnownRequestProcessed(Display *dpy)
c36b847
diff --git a/src/Xxcbint.h b/src/Xxcbint.h
c36b847
index a8c9a67..bf41c23 100644
c36b847
--- a/src/Xxcbint.h
c36b847
+++ b/src/Xxcbint.h
c36b847
@@ -46,4 +46,6 @@ typedef struct _X11XCBPrivate {
c36b847
 int _XConnectXCB(Display *dpy, _Xconst char *display, int *screenp);
c36b847
 void _XFreeX11XCBStructure(Display *dpy);
c36b847
 
c36b847
+unsigned long _XNextRequest(Display *dpy);
c36b847
+
c36b847
 #endif /* XXCBINT_H */
c36b847
diff --git a/src/xcb_io.c b/src/xcb_io.c
c36b847
index 727c6c7..5987329 100644
c36b847
--- a/src/xcb_io.c
c36b847
+++ b/src/xcb_io.c
c36b847
@@ -774,3 +774,14 @@ void _XEatDataWords(Display *dpy, unsigned long n)
c36b847
 		dpy->xcb->reply_consumed = dpy->xcb->reply_length;
c36b847
 	_XFreeReplyData(dpy, False);
c36b847
 }
c36b847
+
c36b847
+unsigned long
c36b847
+_XNextRequest(Display *dpy)
c36b847
+{
c36b847
+    /* This will update dpy->request. The assumption is that the next thing
c36b847
+     * that the application will do is make a request so there's little
c36b847
+     * overhead.
c36b847
+     */
c36b847
+    require_socket(dpy);
c36b847
+    return NextRequest(dpy);
c36b847
+}
c36b847
-- 
c36b847
2.0.0
c36b847