diff options
author | Arnaud Fontaine <arnau@debian.org> | 2008-08-25 00:10:49 +0200 |
---|---|---|
committer | Julien Danjou <julien@danjou.info> | 2008-09-15 11:39:09 +0200 |
commit | 0a17f077ce0e0db6842248f6395cdfad79e50c3c (patch) | |
tree | 56deb008b5d4d6f3c1c5fdf965f86adde606ad99 /icccm | |
parent | 36100f0efbc6f3ddc116a4dccb9a6a730a5c1bda (diff) |
[icccm] Add functions to get WM_CLASS property.
Diffstat (limited to 'icccm')
-rw-r--r-- | icccm/icccm.c | 43 | ||||
-rw-r--r-- | icccm/xcb_icccm.h | 55 |
2 files changed, 98 insertions, 0 deletions
diff --git a/icccm/icccm.c b/icccm/icccm.c index 4bac4f8..8183868 100644 --- a/icccm/icccm.c +++ b/icccm/icccm.c @@ -236,6 +236,49 @@ xcb_watch_wm_client_machine (xcb_property_handlers_t *prophs, xcb_set_property_handler(prophs, WM_CLIENT_MACHINE, long_len, handler, data); } +/* WM_CLASS */ + +xcb_get_property_cookie_t +xcb_get_wm_class(xcb_connection_t *c, xcb_window_t window) +{ + return xcb_get_property(c, 0, window, WM_CLASS, STRING, 0L, 2048L); +} + +xcb_get_property_cookie_t +xcb_get_wm_class_unchecked(xcb_connection_t *c, xcb_window_t window) +{ + return xcb_get_property_unchecked(c, 0, window, WM_CLASS, STRING, 0L, 2048L); +} + +uint8_t +xcb_get_wm_class_reply(xcb_connection_t *c, xcb_get_property_cookie_t cookie, + xcb_get_wm_class_reply_t *prop, xcb_generic_error_t **e) +{ + xcb_get_property_reply_t *reply = xcb_get_property_reply(c, cookie, e); + + if(!reply || reply->type != STRING || reply->format != 8) + { + free(reply); + return 0; + } + + prop->_reply = reply; + prop->name = (char *) xcb_get_property_value(prop->_reply); + + int name_len = strlen(prop->name); + if(name_len == xcb_get_property_value_length(prop->_reply)) + name_len--; + + prop->class = prop->name + name_len + 1; + + return 1; +} + +void xcb_get_wm_class_reply_wipe(xcb_get_wm_class_reply_t *prop) +{ + free(prop->_reply); +} + /* WM_TRANSIENT_FOR */ xcb_get_property_cookie_t diff --git a/icccm/xcb_icccm.h b/icccm/xcb_icccm.h index ac5df42..88eaa87 100644 --- a/icccm/xcb_icccm.h +++ b/icccm/xcb_icccm.h @@ -244,6 +244,61 @@ void xcb_watch_wm_client_machine (xcb_property_handlers_t *prophs, xcb_generic_property_handler_t handler, void *data); +/* WM_CLASS */ + +/** + * @brief WM_CLASS hint structure + */ +typedef struct { + /** Instance name */ + char *name; + /** Class of application */ + char *class; + /** Store reply to avoid memory allocation, should normally not be + used directly */ + xcb_get_property_reply_t *_reply; +} xcb_get_wm_class_reply_t; + +/** + * @brief Deliver a GetProperty request to the X server for WM_CLASS. + * @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_class(xcb_connection_t *c, + xcb_window_t window); + +/** + * @see xcb_get_wm_class() + */ +xcb_get_property_cookie_t xcb_get_wm_class_unchecked(xcb_connection_t *c, + xcb_window_t window); + +/** + * @brief Fill given structure with the WM_CLASS property of a window. + * @param c: The connection to the X server. + * @param cookie: Request cookie. + * @param prop: WM_CLASS 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_class_unchecked() is used. Otherwise, it stores the + * error if any. prop structure members should be freed by + * xcb_get_wm_class_reply_wipe(). + */ +uint8_t xcb_get_wm_class_reply(xcb_connection_t *c, + xcb_get_property_cookie_t cookie, + xcb_get_wm_class_reply_t *prop, + xcb_generic_error_t **e); + +/** + * @brief Wipe prop structure members previously allocated by + * xcb_get_wm_class_reply(). + * @param prop: prop structure whose members is going to be freed. + */ +void xcb_get_wm_class_reply_wipe(xcb_get_wm_class_reply_t *prop); + /* WM_TRANSIENT_FOR */ /** |