diff options
author | Jamey Sharp <jamey@minilop.net> | 2010-06-24 10:48:35 -0700 |
---|---|---|
committer | Jamey Sharp <jamey@minilop.net> | 2010-06-24 17:22:18 -0700 |
commit | 38a5dc83a861d041f78257cf554d4ae4c75aece2 (patch) | |
tree | 807efa6652dd9f2734f658ed96c67f0eeb187c94 | |
parent | 3b979557a99dab0361cca419ca53024063af65c3 (diff) |
Delete callback-based APIs for events, properties, and replies.
They are poorly designed and not terribly useful. I wrote the original
versions of these libraries for demonstration purposes and would like to
actively discourage anyone from actually using them.
After deleting the callback-based APIs, there was nothing interesting
left in property or reply, so those libraries are deleted outright. The
event library is no longer particularly related to event handling, but
that's a problem for another commit.
The icccm library had some simple hooks for integrating with the
property library, which are precisely as useful as the property library
itself, so I deleted them too. (Arnaud suggested this in
<sa5ocib84hf.fsf@Orfeo.duckcorp.org>.)
Since the icccm and event libraries have changed interfaces, this commit
bumps their SONAME versions.
Signed-off-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Mikhail Gusarov <dottedmag@dottedmag.net>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Acked-by: Julien Cristau <jcristau@debian.org>
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | README | 3 | ||||
-rw-r--r-- | configure.ac | 10 | ||||
-rw-r--r-- | event/Makefile.am | 2 | ||||
-rw-r--r-- | event/event.c | 86 | ||||
-rw-r--r-- | event/xcb_event.h | 112 | ||||
-rw-r--r-- | icccm/Makefile.am | 7 | ||||
-rw-r--r-- | icccm/icccm.c | 27 | ||||
-rw-r--r-- | icccm/xcb-icccm.pc.in | 2 | ||||
-rw-r--r-- | icccm/xcb_icccm.h | 35 | ||||
-rw-r--r-- | property/Makefile.am | 17 | ||||
-rw-r--r-- | property/property.c | 147 | ||||
-rw-r--r-- | property/xcb-property.pc.in | 11 | ||||
-rw-r--r-- | property/xcb_property.h | 161 | ||||
-rw-r--r-- | reply/.gitignore | 1 | ||||
-rw-r--r-- | reply/Makefile.am | 25 | ||||
-rw-r--r-- | reply/reply.c | 146 | ||||
-rw-r--r-- | reply/test_reply.c | 86 | ||||
-rw-r--r-- | reply/xcb-reply.pc.in | 11 | ||||
-rw-r--r-- | reply/xcb_reply.h | 122 |
20 files changed, 9 insertions, 1004 deletions
diff --git a/Makefile.am b/Makefile.am index 5a98062..f9be2b6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ MAINTAINERCLEANFILES = Makefile.in -SUBDIRS = atom aux event property icccm image keysyms reply renderutil +SUBDIRS = atom aux event icccm image keysyms renderutil EXTRA_DIST=xcb-util-common.h @@ -13,10 +13,9 @@ These libraries are currently included, roughly ordered by maturity: render-util: Convenience functions for the Render extension. aux: Convenient access to connection setup and some core requests. atom: Standard core X atom constants and atom caching. -property: Callback X property-change handling. icccm: Both client and window-manager helpers for ICCCM. keysyms: Standard X key constants and conversion to/from keycodes. -event: Callback X event handling. +event: Some utilities that have little to do with events any more. image: Port of Xlib's XImage and XShmImage functions. If you find any of these libraries useful, please let us know what diff --git a/configure.ac b/configure.ac index e8b48f6..d843da6 100644 --- a/configure.ac +++ b/configure.ac @@ -80,31 +80,21 @@ XCB_AUX_CFLAGS='-I$(top_srcdir)/aux' XCB_AUX_LIBS='$(top_builddir)/aux/libxcb-aux.la' XCB_ATOM_CFLAGS='-I$(top_srcdir)/atom -I$(top_builddir)/atom' XCB_ATOM_LIBS='$(top_builddir)/atom/libxcb-atom.la' -XCB_EVENT_CFLAGS='-I$(top_srcdir)/event' -XCB_EVENT_LIBS='$(top_builddir)/event/libxcb-event.la' -XCB_PROPERTY_CFLAGS='-I$(top_srcdir)/property' -XCB_PROPERTY_LIBS='$(top_builddir)/property/libxcb-property.la' XCB_ICCCM_CFLAGS='-I$(top_srcdir)/icccm' XCB_ICCCM_LIBS='$(top_builddir)/icccm/libxcb-icccm.la' AC_SUBST(XCB_AUX_CFLAGS) AC_SUBST(XCB_AUX_LIBS) AC_SUBST(XCB_ATOM_CFLAGS) AC_SUBST(XCB_ATOM_LIBS) -AC_SUBST(XCB_EVENT_CFLAGS) -AC_SUBST(XCB_EVENT_LIBS) -AC_SUBST(XCB_PROPERTY_CFLAGS) -AC_SUBST(XCB_PROPERTY_LIBS) AC_SUBST(XCB_ICCCM_CFLAGS) AC_SUBST(XCB_ICCCM_LIBS) AC_OUTPUT([Makefile aux/Makefile aux/xcb-aux.pc - reply/Makefile reply/xcb-reply.pc image/Makefile image/xcb-image.pc atom/Makefile atom/xcb-atom.pc event/Makefile event/xcb-event.pc keysyms/Makefile keysyms/xcb-keysyms.pc - property/Makefile property/xcb-property.pc icccm/Makefile icccm/xcb-icccm.pc renderutil/Makefile renderutil/xcb-renderutil.pc xcb_util_intro diff --git a/event/Makefile.am b/event/Makefile.am index 5a7d819..cec6381 100644 --- a/event/Makefile.am +++ b/event/Makefile.am @@ -10,7 +10,7 @@ AM_CFLAGS = $(CWARNFLAGS) libxcb_event_la_SOURCES = event.c libxcb_event_la_CPPFLAGS = $(XCB_CFLAGS) libxcb_event_la_LIBADD = $(XCB_LIBS) -libxcb_event_la_LDFLAGS = -version-info 1:0:0 +libxcb_event_la_LDFLAGS = -version-info 2:0:0 pkgconfig_DATA = xcb-event.pc diff --git a/event/event.c b/event/event.c index 7faac1c..f770612 100644 --- a/event/event.c +++ b/event/event.c @@ -33,92 +33,6 @@ #include "xcb_event.h" #include "../xcb-util-common.h" -void -xcb_event_handlers_init(xcb_connection_t *c, xcb_event_handlers_t *evenths) -{ - memset(evenths, 0, sizeof(xcb_event_handlers_t)); - evenths->c = c; -} - -xcb_connection_t * -xcb_event_get_xcb_connection(xcb_event_handlers_t *evenths) -{ - return evenths->c; -} - -static xcb_event_handler_t * -get_event_handler(xcb_event_handlers_t *evenths, int event) -{ - assert(event < 256); - event &= XCB_EVENT_RESPONSE_TYPE_MASK; - assert(event >= 2); - return &evenths->event[event - 2]; -} - -static xcb_event_handler_t * -get_error_handler(xcb_event_handlers_t *evenths, int error) -{ - assert(error >= 0 && error < 256); - return &evenths->error[error]; -} - -int -xcb_event_handle(xcb_event_handlers_t *evenths, xcb_generic_event_t *event) -{ - xcb_event_handler_t *eventh = 0; - assert(event->response_type != 1); - - if(event->response_type == 0) - eventh = get_error_handler(evenths, ((xcb_generic_error_t *) event)->error_code); - else - eventh = get_event_handler(evenths, event->response_type); - - if(eventh->handler) - return eventh->handler(eventh->data, evenths->c, event); - return 0; -} - -void -xcb_event_wait_for_event_loop(xcb_event_handlers_t *evenths) -{ - xcb_generic_event_t *event; - while((event = xcb_wait_for_event(evenths->c))) - { - xcb_event_handle(evenths, event); - free(event); - } -} - -void -xcb_event_poll_for_event_loop(xcb_event_handlers_t *evenths) -{ - xcb_generic_event_t *event; - while ((event = xcb_poll_for_event(evenths->c))) - { - xcb_event_handle(evenths, event); - free(event); - } -} - -static void -set_handler(xcb_generic_event_handler_t handler, void *data, xcb_event_handler_t *place) -{ - xcb_event_handler_t eventh = { handler, data }; - *place = eventh; -} - -void -xcb_event_set_handler(xcb_event_handlers_t *evenths, int event, xcb_generic_event_handler_t handler, void *data) -{ - set_handler(handler, data, get_event_handler(evenths, event)); -} - -void -xcb_event_set_error_handler(xcb_event_handlers_t *evenths, int error, xcb_generic_error_handler_t handler, void *data) -{ - set_handler((xcb_generic_event_handler_t) handler, data, get_error_handler(evenths, error)); -} - static const char *labelError[] = { "Success", diff --git a/event/xcb_event.h b/event/xcb_event.h index 8978cca..ee911fc 100644 --- a/event/xcb_event.h +++ b/event/xcb_event.h @@ -56,118 +56,6 @@ extern "C" { #define XCB_EVENT_RESPONSE_TYPE(e) (e->response_type & XCB_EVENT_RESPONSE_TYPE_MASK) #define XCB_EVENT_SENT(e) (e->response_type & ~XCB_EVENT_RESPONSE_TYPE_MASK) -typedef int (*xcb_generic_event_handler_t)(void *data, xcb_connection_t *c, xcb_generic_event_t *event); -typedef int (*xcb_generic_error_handler_t)(void *data, xcb_connection_t *c, xcb_generic_error_t *error); - -typedef struct xcb_event_handler xcb_event_handler_t; -struct xcb_event_handler -{ - xcb_generic_event_handler_t handler; - void *data; -}; - -typedef struct xcb_event_handlers xcb_event_handlers_t; -struct xcb_event_handlers -{ - xcb_event_handler_t event[126]; - xcb_event_handler_t error[256]; - xcb_connection_t *c; -}; - -/** - * @brief Initialize event handlers data structure. - * @param c The connection to the X server. - * @param evenths A pointer to the event handler data structure to initialize. - */ -void xcb_event_handlers_init(xcb_connection_t *c, xcb_event_handlers_t *evenths); - -/** - * @brief Get X connection used in event handlers. - * @param evenths The event handlers. - * @return The connection to the X server. - */ -xcb_connection_t *xcb_event_get_xcb_connection(xcb_event_handlers_t *evenths); - -/** - * @brief Wait for event and handle it with event handler. - * @param evenths The event handlers. - */ -void xcb_event_wait_for_event_loop(xcb_event_handlers_t *evenths); - -/** - * @brief Poll for event and handle it with event handler. - * @param evenths The event handlers. - */ -void xcb_event_poll_for_event_loop(xcb_event_handlers_t *evenths); - -/** - * @brief Handle an event using event handlers from event handlers data - * structure. - * @param evenths The event handlers. - * @param event The event to handle. - * @return The return value of the handler, or 0 if no handler exists for this - * event. - */ -int xcb_event_handle(xcb_event_handlers_t *evenths, xcb_generic_event_t *event); - -/** - * @brief Set an event handler for an event type. - * @param evenths The event handlers data structure. - * @param event The event type. - * @param handler The callback function to call for this event type. - * @param data Optional data pointer to pass to handler callback function. - */ -void xcb_event_set_handler(xcb_event_handlers_t *evenths, int event, xcb_generic_event_handler_t handler, void *data); - -/** - * @brief Set an error handler for an error type. - * @param evenths The error handlers data structure. - * @param error The error type. - * @param handler The callback function to call for this error type. - * @param data Optional data pointer to pass to handler callback function. - */ -void xcb_event_set_error_handler(xcb_event_handlers_t *evenths, int error, xcb_generic_error_handler_t handler, void *data); - -#define XCB_EVENT_MAKE_EVENT_HANDLER(lkind, ukind) \ -static inline void xcb_event_set_##lkind##_handler(xcb_event_handlers_t *evenths, int (*handler)(void *, xcb_connection_t *, xcb_##lkind##_event_t *), void *data) \ -{ \ - xcb_event_set_handler(evenths, XCB_##ukind, (xcb_generic_event_handler_t) handler, data); \ -} - -XCB_EVENT_MAKE_EVENT_HANDLER(key_press, KEY_PRESS) -XCB_EVENT_MAKE_EVENT_HANDLER(key_release, KEY_RELEASE) -XCB_EVENT_MAKE_EVENT_HANDLER(button_press, BUTTON_PRESS) -XCB_EVENT_MAKE_EVENT_HANDLER(button_release, BUTTON_RELEASE) -XCB_EVENT_MAKE_EVENT_HANDLER(motion_notify, MOTION_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(enter_notify, ENTER_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(leave_notify, LEAVE_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(focus_in, FOCUS_IN) -XCB_EVENT_MAKE_EVENT_HANDLER(focus_out, FOCUS_OUT) -XCB_EVENT_MAKE_EVENT_HANDLER(keymap_notify, KEYMAP_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(expose, EXPOSE) -XCB_EVENT_MAKE_EVENT_HANDLER(graphics_exposure, GRAPHICS_EXPOSURE) -XCB_EVENT_MAKE_EVENT_HANDLER(no_exposure, NO_EXPOSURE) -XCB_EVENT_MAKE_EVENT_HANDLER(visibility_notify, VISIBILITY_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(create_notify, CREATE_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(destroy_notify, DESTROY_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(unmap_notify, UNMAP_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(map_notify, MAP_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(map_request, MAP_REQUEST) -XCB_EVENT_MAKE_EVENT_HANDLER(reparent_notify, REPARENT_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(configure_notify, CONFIGURE_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(configure_request, CONFIGURE_REQUEST) -XCB_EVENT_MAKE_EVENT_HANDLER(gravity_notify, GRAVITY_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(resize_request, RESIZE_REQUEST) -XCB_EVENT_MAKE_EVENT_HANDLER(circulate_notify, CIRCULATE_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(circulate_request, CIRCULATE_REQUEST) -XCB_EVENT_MAKE_EVENT_HANDLER(property_notify, PROPERTY_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(selection_clear, SELECTION_CLEAR) -XCB_EVENT_MAKE_EVENT_HANDLER(selection_request, SELECTION_REQUEST) -XCB_EVENT_MAKE_EVENT_HANDLER(selection_notify, SELECTION_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(colormap_notify, COLORMAP_NOTIFY) -XCB_EVENT_MAKE_EVENT_HANDLER(client_message, CLIENT_MESSAGE) -XCB_EVENT_MAKE_EVENT_HANDLER(mapping_notify, MAPPING_NOTIFY) - /** * @brief Convert an event response type to a label. * @param type The event type. diff --git a/icccm/Makefile.am b/icccm/Makefile.am index bd955f0..2e7f8ca 100644 --- a/icccm/Makefile.am +++ b/icccm/Makefile.am @@ -8,10 +8,9 @@ xcbinclude_HEADERS = xcb_icccm.h AM_CFLAGS = $(CWARNFLAGS) libxcb_icccm_la_SOURCES = icccm.c -libxcb_icccm_la_CPPFLAGS = $(XCB_CFLAGS) $(XPROTO_CFLAGS) $(XCB_EVENT_CFLAGS) \ - $(XCB_PROPERTY_CFLAGS) -libxcb_icccm_la_LIBADD = $(XCB_LIBS) $(XPROTO_LIBS) $(XCB_PROPERTY_LIBS) -libxcb_icccm_la_LDFLAGS = -version-info 2:0:0 +libxcb_icccm_la_CPPFLAGS = $(XCB_CFLAGS) $(XPROTO_CFLAGS) +libxcb_icccm_la_LIBADD = $(XCB_LIBS) $(XPROTO_LIBS) +libxcb_icccm_la_LDFLAGS = -version-info 3:0:0 pkgconfig_DATA = xcb-icccm.pc diff --git a/icccm/icccm.c b/icccm/icccm.c index 4bb2c00..260a557 100644 --- a/icccm/icccm.c +++ b/icccm/icccm.c @@ -40,7 +40,7 @@ xcb_get_text_property(xcb_connection_t *c, xcb_window_t window, xcb_atom_t property) { - return xcb_get_any_property(c, 0, window, property, UINT_MAX); + return xcb_get_property(c, 0, window, property, XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX); } xcb_get_property_cookie_t @@ -48,7 +48,7 @@ xcb_get_text_property_unchecked(xcb_connection_t *c, xcb_window_t window, xcb_atom_t property) { - return xcb_get_any_property_unchecked(c, 0, window, property, UINT_MAX); + return xcb_get_property_unchecked(c, 0, window, property, XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX); } uint8_t @@ -123,13 +123,6 @@ xcb_get_wm_name_reply(xcb_connection_t *c, return xcb_get_text_property_reply(c, cookie, prop, e); } -uint8_t -xcb_watch_wm_name(xcb_property_handlers_t *prophs, uint32_t long_len, - xcb_generic_property_handler_t handler, void *data) -{ - return xcb_property_set_handler(prophs, XCB_ATOM_WM_NAME, long_len, handler, data); -} - /* WM_ICON_NAME */ xcb_void_cookie_t @@ -175,14 +168,6 @@ xcb_get_wm_icon_name_reply(xcb_connection_t *c, return xcb_get_text_property_reply(c, cookie, prop, e); } -uint8_t -xcb_watch_wm_icon_name(xcb_property_handlers_t *prophs, uint32_t long_len, - xcb_generic_property_handler_t handler, void *data) -{ - return xcb_property_set_handler(prophs, XCB_ATOM_WM_ICON_NAME, long_len, handler, - data); -} - /* WM_COLORMAP_WINDOWS */ xcb_void_cookie_t @@ -306,14 +291,6 @@ xcb_get_wm_client_machine_reply(xcb_connection_t *c, return xcb_get_text_property_reply(c, cookie, prop, e); } -uint8_t -xcb_watch_wm_client_machine(xcb_property_handlers_t *prophs, uint32_t long_len, - xcb_generic_property_handler_t handler, void *data) -{ - return xcb_property_set_handler(prophs, XCB_ATOM_WM_CLIENT_MACHINE, long_len, handler, - data); -} - /* WM_CLASS */ xcb_void_cookie_t diff --git a/icccm/xcb-icccm.pc.in b/icccm/xcb-icccm.pc.in index d21d019..b8c626e 100644 --- a/icccm/xcb-icccm.pc.in +++ b/icccm/xcb-icccm.pc.in @@ -6,6 +6,6 @@ includedir=@includedir@ Name: XCB ICCCM library Description: XCB ICCCM binding Version: @PACKAGE_VERSION@ -Requires: xcb xcb-property +Requires: xcb Libs: -L${libdir} -lxcb-icccm @LIBS@ Cflags: -I${includedir} diff --git a/icccm/xcb_icccm.h b/icccm/xcb_icccm.h index f05ced0..1617b84 100644 --- a/icccm/xcb_icccm.h +++ b/icccm/xcb_icccm.h @@ -40,7 +40,6 @@ */ #include <xcb/xcb.h> -#include "xcb_property.h" #ifdef __cplusplus extern "C" { @@ -166,16 +165,6 @@ uint8_t xcb_get_wm_name_reply(xcb_connection_t *c, xcb_get_text_property_reply_t *prop, xcb_generic_error_t **e); -/** - * @brief Set a callback on WM_NAME property changes. - * @param prophs Property handlers. - * @param long_len Length of data. - * @param handler The callback. - * @param data data given to the callback. - */ -uint8_t xcb_watch_wm_name(xcb_property_handlers_t *prophs, uint32_t long_len, - xcb_generic_property_handler_t handler, void *data); - /* WM_ICON_NAME */ /** @@ -233,18 +222,6 @@ uint8_t xcb_get_wm_icon_name_reply(xcb_connection_t *c, xcb_get_text_property_reply_t *prop, xcb_generic_error_t **e); -/** - * @brief Set a callback on WM_ICON_NAME property changes. - * @param prophs Property handlers. - * @param long_len Length of data. - * @param handler The callback. - * @param data data given to the callback. - */ -uint8_t xcb_watch_wm_icon_name(xcb_property_handlers_t *prophs, - uint32_t long_len, - xcb_generic_property_handler_t handler, - void *data); - /* WM_COLORMAP_WINDOWS */ /** @@ -394,18 +371,6 @@ uint8_t xcb_get_wm_client_machine_reply(xcb_connection_t *c, xcb_get_text_property_reply_t *prop, xcb_generic_error_t **e); -/** - * @brief Set a callback on WM_CLIENT_MACHINE property changes. - * @param prophs Property handlers. - * @param long_len Length of data. - * @param handler The callback. - * @param data data given to the callback. - */ -uint8_t xcb_watch_wm_client_machine(xcb_property_handlers_t *prophs, - uint32_t long_len, - xcb_generic_property_handler_t handler, - void *data); - /* WM_CLASS */ /** diff --git a/property/Makefile.am b/property/Makefile.am deleted file mode 100644 index 3fb56de..0000000 --- a/property/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ - -MAINTAINERCLEANFILES = Makefile.in - -lib_LTLIBRARIES = libxcb-property.la - -xcbinclude_HEADERS = xcb_property.h - -AM_CFLAGS = $(CWARNFLAGS) - -libxcb_property_la_SOURCES = property.c -libxcb_property_la_CPPFLAGS = $(XCB_CFLAGS) $(XCB_EVENT_CFLAGS) -libxcb_property_la_LIBADD = $(XCB_LIBS) $(XCB_EVENT_LIBS) -libxcb_property_la_LDFLAGS = -version-info 1:0:0 - -pkgconfig_DATA = xcb-property.pc - -EXTRA_DIST = xcb-property.pc.in diff --git a/property/property.c b/property/property.c deleted file mode 100644 index 161481e..0000000 --- a/property/property.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright © 2008 Julien Danjou <julien@danjou.info> - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the names of the authors or - * their institutions shall not be used in advertising or otherwise to - * promote the sale, use or other dealings in this Software without - * prior written authorization from the authors. - */ - -#include <stdlib.h> -#include <string.h> - -#include "xcb_property.h" - -xcb_get_property_cookie_t -xcb_get_any_property(xcb_connection_t *c, uint8_t del, xcb_window_t window, xcb_atom_t name, uint32_t long_len) -{ - static const xcb_atom_t type = XCB_GET_PROPERTY_TYPE_ANY; - - return xcb_get_property(c, del, window, name, type, 0, long_len); -} - -xcb_get_property_cookie_t -xcb_get_any_property_unchecked(xcb_connection_t *c, - uint8_t del, - xcb_window_t window, - xcb_atom_t name, - uint32_t long_len) -{ - return xcb_get_property_unchecked(c, del, window, name, XCB_GET_PROPERTY_TYPE_ANY, 0, long_len); -} - -static int -call_handler(xcb_connection_t *c, uint8_t state, xcb_window_t window, xcb_atom_t atom, xcb_property_handler_t *h) -{ - xcb_get_property_reply_t *propr = 0; - int ret; - - if(state != XCB_PROPERTY_DELETE) - { - xcb_get_property_cookie_t cookie = xcb_get_any_property(c, 0, window, atom, h->long_len); - propr = xcb_get_property_reply(c, cookie, 0); - } - ret = h->handler(h->data, c, state, window, atom, propr); - free(propr); - return ret; -} - -int -xcb_property_changed(xcb_property_handlers_t *prophs, uint8_t state, xcb_window_t window, xcb_atom_t atom) -{ - xcb_connection_t *c = xcb_event_get_xcb_connection(xcb_property_get_event_handlers(prophs)); - xcb_property_handler_node_t *cur; - - for(cur = prophs->head; cur; cur = cur->next) - if(cur->name == atom) - return call_handler(c, state, window, atom, &cur->h); - - if(prophs->def.handler) - return call_handler(c, state, window, atom, &prophs->def); - - return 0; -} - -static int -handle_property_notify_event(void *data, xcb_connection_t *c, xcb_property_notify_event_t *e) -{ - xcb_property_handlers_t *prophs = data; - uint8_t state = e->state; - xcb_window_t window = e->window; - xcb_atom_t atom = e->atom; - - return xcb_property_changed(prophs, state, window, atom); -} - -void -xcb_property_handlers_init(xcb_property_handlers_t *prophs, xcb_event_handlers_t *evenths) -{ - memset(prophs, 0, sizeof(prophs)); - prophs->evenths = evenths; - xcb_event_set_property_notify_handler(evenths, handle_property_notify_event, prophs); -} - -void -xcb_property_handlers_wipe(xcb_property_handlers_t *prophs) -{ - xcb_property_handler_node_t *node, *next; - - for(node = prophs->head; node; node = next) - { - next = node->next; - free(node); - } -} - -xcb_event_handlers_t * -xcb_property_get_event_handlers(xcb_property_handlers_t *prophs) -{ - return prophs->evenths; -} - -static inline void -set_prop_handler(xcb_property_handler_t *cur, uint32_t long_len, xcb_generic_property_handler_t handler, void *data) -{ - cur->long_len = long_len; - cur->handler = handler; - cur->data = data; -} - -uint8_t -xcb_property_set_handler(xcb_property_handlers_t *prophs, xcb_atom_t name, uint32_t long_len, xcb_generic_property_handler_t handler, void *data) -{ - xcb_property_handler_node_t *cur = malloc(sizeof(xcb_property_handler_node_t)); - if(!cur) - return 0; - cur->next = prophs->head; - cur->name = name; - set_prop_handler(&cur->h, long_len, handler, data); - prophs->head = cur; - return 1; -} - -uint8_t -xcb_property_set_default_handler(xcb_property_handlers_t *prophs, uint32_t long_len, xcb_generic_property_handler_t handler, void *data) -{ - set_prop_handler(&prophs->def, long_len, handler, data); - return 1; -} diff --git a/property/xcb-property.pc.in b/property/xcb-property.pc.in deleted file mode 100644 index 94cd0f7..0000000 --- a/property/xcb-property.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: XCB Property library -Description: XCB property convenience library -Version: @PACKAGE_VERSION@ -Requires: xcb xcb-event -Libs: -L${libdir} -lxcb-property @LIBS@ -Cflags: -I${includedir} diff --git a/property/xcb_property.h b/property/xcb_property.h deleted file mode 100644 index 30ffc14..0000000 --- a/property/xcb_property.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (C) 2008 Julien Danjou <julien@danjou.info> - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the names of the authors or - * their institutions shall not be used in advertising or otherwise to - * promote the sale, use or other dealings in this Software without - * prior written authorization from the authors. - */ - -/** - * @defgroup xcb__property_t XCB Property Functions - * - * These functions ease the handling of X properties received. - * - * @{ - */ - -#ifndef __XCB_PROPERTY_H__ -#define __XCB_PROPERTY_H__ - -#include "xcb_event.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct xcb_property_handlers xcb_property_handlers_t; -typedef int (*xcb_generic_property_handler_t)(void *data, xcb_connection_t *c, uint8_t state, xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *property); - -typedef struct { - uint32_t long_len; - xcb_generic_property_handler_t handler; - void *data; -} xcb_property_handler_t; - -typedef struct xcb_property_handler_node xcb_property_handler_node_t; -struct xcb_property_handler_node { - xcb_property_handler_node_t *next; - xcb_atom_t name; - xcb_property_handler_t h; -}; - -struct xcb_property_handlers { - xcb_property_handler_node_t *head; - xcb_property_handler_t def; - xcb_event_handlers_t *evenths; -}; - -/** - * @brief Get any property from a window, from any format. - * @param c The connection to the X server. - * @param del Boolean value that determines whether the property is deleted. - * @param window The window to get property from. - * @param name The property atom name. - * @param long_len The maximum length of the property. - * @return A cookie. - */ -xcb_get_property_cookie_t xcb_get_any_property(xcb_connection_t *c, - uint8_t del, - xcb_window_t window, - xcb_atom_t name, - uint32_t long_len); - -/** - * @see xcb_get_any_property - */ -xcb_get_property_cookie_t xcb_get_any_property_unchecked(xcb_connection_t *c, - uint8_t del, - xcb_window_t window, - xcb_atom_t name, - uint32_t long_len); -/** - * @brief Initialize a property handlers structure. - * @param prophs The property handlers data structure pointer. - * @param evenths The event handlers. - */ -void xcb_property_handlers_init(xcb_property_handlers_t *prophs, xcb_event_handlers_t *evenths); - -/** - * @brief Wipe a property handler structure. - * @param prophs The property handlers data structure pointer. - */ -void xcb_property_handlers_wipe(xcb_property_handlers_t *prophs); - -/** - * @brief Get a event handlers from a property handlers data structure. - * @param prophs The property handlers. - * @return The event handlers data structure which was set if any, NULL - * otherwise. - */ -xcb_event_handlers_t *xcb_property_get_event_handlers(xcb_property_handlers_t *prophs); - -/** - * @brief Set a property handler for an event. - * @param prophs The property handlers. - * @param name The property atom name. - * @param long_len The maximum length of the property value that will be - * handled. - * @param handler The handler callback function. - * @param data Optional data that will be passed as argument of the handler - * callback function. Can be NULL safely if you do not need it. - * @return Return 1 on success, 0 otherwise. - */ -uint8_t xcb_property_set_handler(xcb_property_handlers_t *prophs, - xcb_atom_t name, - uint32_t long_len, - xcb_generic_property_handler_t handler, - void *data); - -/** - * @brief Set the default property handler. - * If a property does not have its own handler function, this one will be - * used. - * @param prophs The property handlers. - * @param name The property atom name. - * @param long_len The maximum length of the property value that will be - * handled. - * @param handler The handler callback function. - * @param data Optional data that will be passed as argument of the handler - * callback function. Can be NULL safely if you do not need it. - * @return Return 1 on success, 0 otherwise. - */ -uint8_t xcb_property_set_default_handler(xcb_property_handlers_t *prophs, uint32_t long_len, xcb_generic_property_handler_t handler, void *data); - -/** - * @brief Notify that a property has changed and call handler function callback as needed. - * @param prophs The property handlers. - * @param state The property state. - * @param window The window. - * @param atom The property atom name. - */ -int xcb_property_changed(xcb_property_handlers_t *prophs, uint8_t state, xcb_window_t window, xcb_atom_t atom); - -#ifdef __cplusplus -} -#endif - -/** - * @} - */ - -#endif /* __XCB_PROPERTY_H__ */ diff --git a/reply/.gitignore b/reply/.gitignore deleted file mode 100644 index 957705d..0000000 --- a/reply/.gitignore +++ /dev/null @@ -1 +0,0 @@ -test_reply diff --git a/reply/Makefile.am b/reply/Makefile.am deleted file mode 100644 index aa49773..0000000 --- a/reply/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ - -MAINTAINERCLEANFILES = Makefile.in - -lib_LTLIBRARIES = libxcb-reply.la - -xcbinclude_HEADERS = xcb_reply.h - -AM_CFLAGS = $(CWARNFLAGS) - -XCB_REPLY_LIBS = libxcb-reply.la - -libxcb_reply_la_SOURCES = reply.c -libxcb_reply_la_CPPFLAGS = $(XCB_CFLAGS) -libxcb_reply_la_LIBADD = $(XCB_LIBS) -lpthread -libxcb_reply_la_LDFLAGS = -version-info 1:0:0 - -pkgconfig_DATA = xcb-reply.pc - -EXTRA_DIST=xcb-reply.pc.in - -noinst_PROGRAMS = test_reply - -test_reply_CPPFLAGS = $(XCB_CFLAGS) -test_reply_LDADD = $(XCB_LIBS) $(XCB_REPLY_LIBS) -test_reply_SOURCES = test_reply.c diff --git a/reply/reply.c b/reply/reply.c deleted file mode 100644 index 0cc75c6..0000000 --- a/reply/reply.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright © 2008 Julien Danjou <julien@danjou.info> - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the names of the authors or - * their institutions shall not be used in advertising or otherwise to - * promote the sale, use or other dealings in this Software without - * prior written authorization from the authors. - */ - -#include <stdlib.h> -#include <xcb/xcbext.h> - -#include "xcb_reply.h" - -void -xcb_reply_handlers_init(xcb_connection_t *c, xcb_reply_handlers_t *r) -{ - static const pthread_mutex_t proto_lock = PTHREAD_MUTEX_INITIALIZER; - static const pthread_cond_t proto_cond = PTHREAD_COND_INITIALIZER; - r->lock = proto_lock; - r->cond = proto_cond; - r->c = c; - r->head = NULL; -} - -xcb_connection_t * -xcb_reply_get_xcb_connection(xcb_reply_handlers_t *h) -{ - return h->c; -} - -static void -insert_handler(xcb_reply_handlers_t *h, struct xcb_reply_node *cur) -{ - struct xcb_reply_node **prev = &h->head; - while(*prev && (*prev)->request < cur->request) - prev = &(*prev)->next; - cur->next = *prev; - *prev = cur; -} - -static void -remove_handler(xcb_reply_handlers_t *h, struct xcb_reply_node *cur) -{ - struct xcb_reply_node **prev = &h->head; - while(*prev && (*prev)->request < cur->request) - prev = &(*prev)->next; - if(!(*prev) || (*prev)->request != cur->request) - return; - *prev = cur->next; - free(cur); -} - -static int -process_replies(xcb_reply_handlers_t *h, int block) -{ - int handled = 0; - pthread_mutex_lock(&h->lock); - pthread_cleanup_push((void (*)(void *)) pthread_mutex_unlock, &h->lock); - while(1) - { - struct xcb_reply_node *cur = h->head; - xcb_generic_error_t *error; - void *reply; - pthread_mutex_unlock(&h->lock); - pthread_cleanup_push((void (*)(void *)) pthread_mutex_lock, &h->lock); - if(block) - reply = xcb_wait_for_reply(h->c, cur->request, &error); - else if(!xcb_poll_for_reply(h->c, cur->request, &reply, &error)) - return handled; - if(reply || error) - { - cur->handler(cur->data, h->c, reply, error); - cur->handled = 1; - free(reply); - free(error); - } - handled |= cur->handled; - pthread_cleanup_pop(1); - if(!reply) - remove_handler(h, cur); - if(!h->head) - { - if(block) - pthread_cond_wait(&h->cond, &h->lock); - else - break; - } - } - pthread_cleanup_pop(1); - return handled; -} - -static void * -reply_thread(void *h) -{ - process_replies(h, 1); - return 0; -} - -void -xcb_reply_start_thread(xcb_reply_handlers_t *h) -{ - pthread_create(&h->thread, 0, reply_thread, h); -} - -void -xcb_reply_stop_thread(xcb_reply_handlers_t *h) -{ - pthread_cancel(h->thread); - pthread_join(h->thread, 0); -} - -void -xcb_reply_add_handler(xcb_reply_handlers_t *h, unsigned int request, xcb_generic_reply_handler_t handler, void *data) -{ - struct xcb_reply_node *cur = malloc(sizeof(struct xcb_reply_node)); - cur->request = request; - cur->handler = handler; - cur->data = data; - cur->handled = 0; - - pthread_mutex_lock(&h->lock); - insert_handler(h, cur); - pthread_cond_broadcast(&h->cond); - pthread_mutex_unlock(&h->lock); -} diff --git a/reply/test_reply.c b/reply/test_reply.c deleted file mode 100644 index 0805c41..0000000 --- a/reply/test_reply.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright © 2008 Ian Osgood <iano@quirkster.com> - * Copyright © 2008 Jamey Sharp <jamey@minilop.net> - * Copyright © 2008 Josh Triplett <josh@freedesktop.org> - * Copyright © 2008 Julien Danjou <julien@danjou.info> - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the names of the authors or - * their institutions shall not be used in advertising or otherwise to - * promote the sale, use or other dealings in this Software without - * prior written authorization from the authors. - */ - -#include "xcb_reply.h" - -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; - -void fontinfo_handler(void *data, xcb_connection_t *c, xcb_generic_reply_t *rg, xcb_generic_error_t *eg) -{ - xcb_list_fonts_with_info_reply_t *rep = (xcb_list_fonts_with_info_reply_t *) rg; - if(rep) - { - int len = xcb_list_fonts_with_info_name_length(rep); - if(len) - printf("(+%u) Font \"%.*s\"\n", - (unsigned int) rep->replies_hint, - len, xcb_list_fonts_with_info_name(rep)); - else - { - pthread_mutex_lock(&lock); - pthread_cond_broadcast(&cond); - pthread_mutex_unlock(&lock); - printf("End of font list.\n"); - } - } - if(eg) - printf("Error from ListFontsWithInfo: %d\n", eg->error_code); -} - -int main(int argc, char **argv) -{ - int count = 10; - char *pattern = "*"; - xcb_connection_t *c = xcb_connect(NULL, NULL); - xcb_reply_handlers_t h; - xcb_reply_handlers_init(c, &h); - - if(argc > 1) - count = atoi(argv[1]); - if(argc > 2) - pattern = argv[2]; - - xcb_reply_add_handler(&h, xcb_list_fonts_with_info(c, count, strlen(pattern), pattern).sequence, fontinfo_handler, 0); - pthread_mutex_lock(&lock); - xcb_reply_start_thread(&h); - pthread_cond_wait(&cond, &lock); - xcb_reply_stop_thread(&h); - pthread_mutex_unlock(&lock); - - xcb_disconnect(c); - exit(0); -} diff --git a/reply/xcb-reply.pc.in b/reply/xcb-reply.pc.in deleted file mode 100644 index 3299a5f..0000000 --- a/reply/xcb-reply.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: XCB Reply library -Description: XCB reply convenience library -Version: @PACKAGE_VERSION@ -Requires: xcb -Libs: -L${libdir} -lxcb-reply @LIBS@ -Cflags: -I${includedir} diff --git a/reply/xcb_reply.h b/reply/xcb_reply.h deleted file mode 100644 index 71d07ac..0000000 --- a/reply/xcb_reply.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2008 Julien Danjou <julien@danjou.info> - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the names of the authors or - * their institutions shall not be used in advertising or otherwise to - * promote the sale, use or other dealings in this Software without - * prior written authorization from the authors. - */ - -/** - * @defgroup xcb__reply_t XCB Reply Functions - * - * These functions ease the usage of asynchronous possibility of XCB about - * the reply retrieve of sent requests. - * - * @{ - */ - -#ifndef __XCB_REPLY_H__ -#define __XCB_REPLY_H__ - -#include <xcb/xcb.h> -#include <pthread.h> - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void (*xcb_generic_reply_handler_t)(void *data, xcb_connection_t *c, xcb_generic_reply_t *reply, xcb_generic_error_t *error); - -struct xcb_reply_node -{ - struct xcb_reply_node *next; - unsigned int request; - xcb_generic_reply_handler_t handler; - void *data; - char handled; -}; - -struct xcb_reply_handlers -{ - pthread_mutex_t lock; - pthread_cond_t cond; - struct xcb_reply_node *head; - xcb_connection_t *c; - pthread_t thread; -}; - -typedef struct xcb_reply_handlers xcb_reply_handlers_t; - -/** - * @brief Initialize a reply handlers structure. - * @param c The connection to the X server. - * @param h The reply handlers. - */ -void xcb_reply_handlers_init(xcb_connection_t *c, xcb_reply_handlers_t *h); - -/** - * @brief Get the connection to the X server used in reply handlers. - * @param h The reply handlers data structure. - * @return The connection to the X server. - */ -xcb_connection_t *xcb_reply_get_xcb_connection(xcb_reply_handlers_t *h); - -/** - * @brief Poll for reply using reply handlers. - * @param h The reply handlers data structure. - * @return The value return by the handler callback function, or 0 if no - * handler was found. - */ -int xcb_reply_poll_for_reply(xcb_reply_handlers_t *h); - -/** - * @brief Start reply handling thread. - * This thread will run forever until it is stop with xcb_reply_stop_thread. - * @param h The reply handlers. - */ -void xcb_reply_start_thread(xcb_reply_handlers_t *h); - -/** - * @brief Stop reply handling thread. - * @param h The reply handlers. - */ -void xcb_reply_stop_thread(xcb_reply_handlers_t *h); - -/** - * @brief Add a reply handler. - * @param h The reply handlers data structure to fill. - * @param request The request identifier. - * @param handler The handler to call for this request. - * @param data Optional data passed to the callback function handling request. - */ -void xcb_reply_add_handler(xcb_reply_handlers_t *h, unsigned int request, xcb_generic_reply_handler_t handler, void *data); - -#ifdef __cplusplus -} -#endif - -/** - * @} - */ - -#endif /* __XCB_REPLY_H__ */ |