summaryrefslogtreecommitdiff
path: root/src/InitExt.c
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2009-06-26 11:27:43 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2009-07-12 16:09:57 +1000
commit554f755e5545f63d3c8f299297927238da155773 (patch)
tree047773e3676995a5003edbba0b6941844d2967a5 /src/InitExt.c
parentd7675cb8fa7155e7aff1459636a117a97aa1bf28 (diff)
downloadxorg-lib-libX11-554f755e5545f63d3c8f299297927238da155773.tar.gz
Add generic event cookie handling to libX11.
Generic events require more bytes than Xlib provides in the standard XEvent. Memory allocated by the extension and stored as pointers inside the event is prone to leak by simple 'while (1) { XNextEvent(...); }' loops. This patch adds cookie handling for generic events. Extensions may register a cookie handler in addition to the normal event vectors. If an extension has registered a cookie handler, _all_ generic events for this extensions must be handled through cookies. Otherwise, the default event handler is used. The cookie handler must return an XGenericEventCookie with a pointer to the data.The rest of the event (type, serialNumber, etc.) are to be filled as normal. When a client retrieves such a cookie event, the data is stored in an internal queue (the 'cookiejar'). This data is freed on the next call to XNextEvent(). New extension interfaces: XESetWireToEventCookie(display, extension_number, cookie_handler) Where cookie_handler must set cookie->data. The data pointer is of arbitray size and type but must be a single memory block. This memory block represents the actual extension's event. New client interfaces: XGetEventData(display, *cookie); XFreeEventData(display, *cookie); If the client needs the actual event data, it must call XGetEventData() with the cookie. This returns the data pointer (and removes it from the cookie jar) and the client is then responsible for freeing the event with XFreeEventData(). It is safe to call either function with a non-cookie event. Events unclaimed or not handled by the XGetEventData() are cleaned up automatically. Example client code: XEvent event; XGenericEventCookie *cookie = &ev; XNextEvent(display, &event); if (XGetEventData(display, cookie)) { XIEvent *xievent = cookie->data; ... } else if (cookie->type == GenericEvent) { /* handle generic event */ } else { /* handle extension/core event */ } XFreeEventData(display, cookie); Cookies are not multi-threading safe. Clients that use XGetEventData() must lock between XNextEvent and XGetEventData to avoid other threads freeing cookies. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src/InitExt.c')
-rw-r--r--src/InitExt.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/InitExt.c b/src/InitExt.c
index 92fc44af..0e6c94ee 100644
--- a/src/InitExt.c
+++ b/src/InitExt.c
@@ -253,6 +253,49 @@ WireToEventType XESetWireToEvent(
return (WireToEventType)oldproc;
}
+typedef Bool (*WireToEventCookieType) (
+ Display* /* display */,
+ XGenericEventCookie* /* re */,
+ xEvent* /* event */
+);
+
+WireToEventCookieType XESetWireToEventCookie(
+ Display *dpy, /* display */
+ int extension, /* extension major opcode */
+ WireToEventCookieType proc /* routine to call for generic events */
+ )
+{
+ WireToEventCookieType oldproc;
+ if (proc == NULL) proc = (WireToEventCookieType)_XUnknownWireEventCookie;
+ LockDisplay (dpy);
+ oldproc = dpy->generic_event_vec[extension & 0x7F];
+ dpy->generic_event_vec[extension & 0x7F] = proc;
+ UnlockDisplay (dpy);
+ return (WireToEventCookieType)oldproc;
+}
+
+typedef Bool (*CopyEventCookieType) (
+ Display* /* display */,
+ XGenericEventCookie* /* in */,
+ XGenericEventCookie* /* out */
+);
+
+CopyEventCookieType XESetCopyEventCookie(
+ Display *dpy, /* display */
+ int extension, /* extension major opcode */
+ CopyEventCookieType proc /* routine to copy generic events */
+ )
+{
+ CopyEventCookieType oldproc;
+ if (proc == NULL) proc = (CopyEventCookieType)_XUnknownCopyEventCookie;
+ LockDisplay (dpy);
+ oldproc = dpy->generic_event_copy_vec[extension & 0x7F];
+ dpy->generic_event_copy_vec[extension & 0x7F] = proc;
+ UnlockDisplay (dpy);
+ return (CopyEventCookieType)oldproc;
+}
+
+
typedef Status (*EventToWireType) (
Display* /* display */,
XEvent* /* re */,