[PATCH 1/3] Add XESetEventCookieToWire()

carlosg at gnome.org carlosg at gnome.org
Fri Nov 26 14:59:27 PST 2010


From: Carlos Garnacho <carlosg at gnome.org>

This function allows extensions using XGE to register a function
to transform a XGenericEvent into their wire protocol equivalent.

This function is necessary as the normal handler is given an
&xEvent, so it can't handle events bigger than the xEvent struct
size.

Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
---
 include/X11/Xlibint.h |   22 ++++++++++++++++++++++
 src/InitExt.c         |   20 ++++++++++++++++++++
 src/XlibInt.c         |   14 ++++++++++++++
 3 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/include/X11/Xlibint.h b/include/X11/Xlibint.h
index 05d344c..e241cf8 100644
--- a/include/X11/Xlibint.h
+++ b/include/X11/Xlibint.h
@@ -196,6 +196,11 @@ struct _XDisplay
 		Display *	/* dpy */,
 		XGenericEventCookie *	/* in */,
 		XGenericEventCookie *   /* out*/);
+    /* vector for generic event to wire, index is (extension - 128) */
+    Bool (*generic_wire_vec[128])(
+        Display *	/* dpy */,
+        XGenericEventCookie *	/* Xlib event */,
+        xGenericEvent **	/* wire event */);
 	void *cookiejar;  /* cookie events returned but not claimed */
 };
 
@@ -1024,6 +1029,12 @@ extern Bool _XUnknownCopyEventCookie(
     XGenericEventCookie*	/* out */
 );
 
+extern Bool _XUnknownEventCookie(
+    Display*             /* dpy */,
+    XGenericEventCookie* /* re */,
+    xGenericEvent**      /* event */
+);
+
 extern Status _XUnknownNativeEvent(
     Display*	/* dpy */,
     XEvent*	/* re */,
@@ -1200,6 +1211,17 @@ extern Bool (*XESetCopyEventCookie(
     Display*, XGenericEventCookie*, XGenericEventCookie*
 );
 
+extern Bool (*XESetEventCookieToWire(
+    Display* /* display */,
+    int      /* extension */,
+    Bool (*) (
+        Display*             /* display */,
+        XGenericEventCookie* /* re */,
+        xGenericEvent**      /* event */
+    )        /* proc */
+))(
+    Display*, XGenericEventCookie*, xGenericEvent**
+);
 
 extern Status (*XESetEventToWire(
     Display*		/* display */,
diff --git a/src/InitExt.c b/src/InitExt.c
index cb9191d..8012d7b 100644
--- a/src/InitExt.c
+++ b/src/InitExt.c
@@ -293,6 +293,26 @@ CopyEventCookieType XESetCopyEventCookie(
 	return (CopyEventCookieType)oldproc;
 }
 
+typedef Bool (*EventCookieToWireType) (
+    Display*	/* display */,
+    XGenericEventCookie*	/* re */,
+    xGenericEvent**	/* event */
+);
+
+EventCookieToWireType XESetEventCookieToWire(
+    Display *dpy,       /* display */
+    int extension,      /* extension major opcode */
+    EventCookieToWireType proc /* routine to call for generic events */
+    )
+{
+	EventCookieToWireType oldproc;
+	if (proc == NULL) proc = (EventCookieToWireType)_XUnknownEventCookie;
+	LockDisplay (dpy);
+	oldproc = dpy->generic_wire_vec[extension & 0x7F];
+	dpy->generic_wire_vec[extension & 0x7F] = proc;
+	UnlockDisplay (dpy);
+	return (EventCookieToWireType)oldproc;
+}
 
 typedef Status (*EventToWireType) (
     Display*	/* display */,
diff --git a/src/XlibInt.c b/src/XlibInt.c
index 11a85ba..e094e7d 100644
--- a/src/XlibInt.c
+++ b/src/XlibInt.c
@@ -992,6 +992,20 @@ _XUnknownCopyEventCookie(
 	return(False);
 }
 
+Bool
+_XUnknownEventCookie(
+    Display *dpy,            /* pointer to display structure */
+    XGenericEventCookie *re, /* pointer to the event being converted to wire protocol */
+    xGenericEvent **event)   /* wire protocol event */
+{
+#ifdef notdef
+	fprintf(stderr,
+	    "Xlib: unhandled cookie event! extension number = %d, display = %x\n.",
+			re->extension, dpy);
+#endif
+    return(False);
+}
+
 /*ARGSUSED*/
 Status
 _XUnknownNativeEvent(
-- 
1.7.3.2



More information about the xorg-devel mailing list