summaryrefslogtreecommitdiff
path: root/icccm
diff options
context:
space:
mode:
authorArnaud Fontaine <arnau@debian.org>2008-08-25 00:08:32 +0200
committerArnaud Fontaine <arnau@debian.org>2010-11-14 20:21:26 +0900
commit1ee450563cb29d8b427998e45074ea16219b3c26 (patch)
tree5eb8160281bce402f42776f288639c3d50bc3299 /icccm
parent17b943d08f15f24f34f07187a8075b2ee7f2aadc (diff)
[icccm] Make xcb_get_wm_protocols() asynchronous and document the
code.
Diffstat (limited to 'icccm')
-rw-r--r--icccm/icccm.c82
-rw-r--r--icccm/xcb_icccm.h58
2 files changed, 96 insertions, 44 deletions
diff --git a/icccm/icccm.c b/icccm/icccm.c
index f2aa775..e4c8027 100644
--- a/icccm/icccm.c
+++ b/icccm/icccm.c
@@ -617,44 +617,46 @@ xcb_set_wm_protocols (xcb_connection_t *c,
xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, WM_PROTOCOLS, ATOM, 32, list_len, list);
}
-int
-xcb_get_wm_protocols (xcb_connection_t *c,
- xcb_window_t window,
- uint32_t *list_len,
- xcb_atom_t **list)
-{
- xcb_get_property_cookie_t cookie;
- xcb_get_property_reply_t *rep;
- xcb_atom_t property;
-
- property = intern_atom_fast_reply(c,
- intern_atom_fast(c,
- 0,
- strlen("WM_PROTOCOLS"),
- "WM_PROTOCOLS"),
- NULL);
- cookie = xcb_get_property(c, 0, window,
- property, ATOM, 0, 1000000L);
- rep = xcb_get_property_reply(c, cookie, 0);
- if (!rep)
- return 0;
- if ((rep->type == ATOM) ||
- (rep->format == 32))
- {
- int length;
-
- length = xcb_get_property_value_length(rep);
- *list_len = length;
- *list = (xcb_atom_t *)malloc(sizeof(xcb_atom_t) * length);
- if (!(*list))
- {
- free(rep);
- return 0;
- }
- memcpy(*list, xcb_get_property_value(rep), length * rep->format >> 3);
- free(rep);
- return 1;
- }
- free(rep);
- return 0;
+xcb_get_property_cookie_t
+xcb_get_wm_protocols(xcb_connection_t *c,
+ xcb_window_t window,
+ xcb_atom_t wm_protocol_atom)
+{
+ return xcb_get_property(c, 0, window, wm_protocol_atom, ATOM, 0, UINT_MAX);
+}
+
+xcb_get_property_cookie_t
+xcb_get_wm_protocols_unchecked(xcb_connection_t *c,
+ xcb_window_t window,
+ xcb_atom_t wm_protocol_atom)
+{
+ return xcb_get_property_unchecked(c, 0, window, wm_protocol_atom, ATOM, 0,
+ UINT_MAX);
+}
+
+uint8_t
+xcb_get_wm_protocols_reply(xcb_connection_t *c,
+ xcb_get_property_cookie_t cookie,
+ xcb_get_wm_protocols_reply_t *protocols,
+ xcb_generic_error_t **e)
+{
+ xcb_get_property_reply_t *reply = xcb_get_property_reply(c, cookie, e);
+
+ if(!reply || reply->type != ATOM || reply->format != 32)
+ {
+ free(reply);
+ return 0;
+ }
+
+ protocols->_reply = reply;
+ protocols->atoms_len = xcb_get_property_value_length(protocols->_reply);
+ protocols->atoms = (xcb_atom_t *) xcb_get_property_value(protocols->_reply);
+
+ return 1;
+}
+
+void
+xcb_get_wm_protocols_reply_wipe(xcb_get_wm_protocols_reply_t *protocols)
+{
+ free(protocols->_reply);
}
diff --git a/icccm/xcb_icccm.h b/icccm/xcb_icccm.h
index efee687..75a7fc8 100644
--- a/icccm/xcb_icccm.h
+++ b/icccm/xcb_icccm.h
@@ -525,10 +525,60 @@ void xcb_set_wm_protocols (xcb_connection_t *c,
uint32_t list_len,
xcb_atom_t *list);
-int xcb_get_wm_protocols (xcb_connection_t *c,
- xcb_window_t window,
- uint32_t *list_len,
- xcb_atom_t **list);
+/**
+ * @brief WM_PROTOCOLS structure.
+ */
+typedef struct {
+ /** Length of the atoms list */
+ uint32_t atoms_len;
+ /** Atoms list */
+ xcb_atom_t *atoms;
+ /** Store reply to avoid memory allocation, should normally not be
+ used directly */
+ xcb_get_property_reply_t *_reply;
+} xcb_get_wm_protocols_reply_t;
+
+/**
+ * @brief Send request to get WM_PROTOCOLS property of a given window.
+ * @param c: The connection to the X server.
+ * @param window: Window X identifier.
+ * @return The request cookie.
+ */
+xcb_get_property_cookie_t xcb_get_wm_protocols(xcb_connection_t *c,
+ xcb_window_t window,
+ xcb_atom_t wm_protocol_atom);
+
+/**
+ * @see xcb_get_wm_protocols()
+ */
+xcb_get_property_cookie_t xcb_get_wm_protocols_unchecked(xcb_connection_t *c,
+ xcb_window_t window,
+ xcb_atom_t wm_protocol_atom);
+
+/**
+ * @brief Fill the given structure with the WM_PROTOCOLS property of a window.
+ * @param c: The connection to the X server.
+ * @param cookie: Request cookie.
+ * @param protocols: WM_PROTOCOLS property value.
+ * @param e: Error if any.
+ * @return Return 1 on success, 0 otherwise.
+ *
+ * The parameter e supplied to this function must be NULL if
+ * xcb_get_wm_protocols_unchecked() is used. Otherwise, it stores the
+ * error if any. protocols structure members should be freed by
+ * xcb_get_wm_protocols_reply_wipe().
+ */
+uint8_t xcb_get_wm_protocols_reply(xcb_connection_t *c,
+ xcb_get_property_cookie_t cookie,
+ xcb_get_wm_protocols_reply_t *protocols,
+ xcb_generic_error_t **e);
+
+/**
+ * @brief Wipe protocols structure members previously allocated by
+ * xcb_get_wm_protocols_reply().
+ * @param protocols: protocols structure whose members is going to be freed.
+ */
+void xcb_get_wm_protocols_reply_wipe(xcb_get_wm_protocols_reply_t *protocols);
#ifdef __cplusplus
}