Stop using libxcb-property
[awesome.git] / common / xutil.h
blobbce09e085787d63518b16181dbf94221536c74ef
1 /*
2 * common/xutil.h - X-related useful functions header
4 * Copyright © 2007-2009 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #ifndef AWESOME_COMMON_XUTIL_H
23 #define AWESOME_COMMON_XUTIL_H
25 #include <xcb/xcb.h>
26 #include <xcb/xcb_keysyms.h>
27 #include <xcb/xcb_aux.h>
28 #include <xcb/xcb_event.h>
29 #include <xcb/xcb_atom.h>
31 #include "common/array.h"
32 #include "common/atoms.h"
34 static inline char *
35 xutil_get_text_property_from_reply(xcb_get_property_reply_t *reply)
37 if(reply
38 && (reply->type == STRING
39 || reply->type == UTF8_STRING
40 || reply->type == COMPOUND_TEXT)
41 && reply->format == 8
42 && xcb_get_property_value_length(reply))
44 /* We need to copy it that way since the string may not be
45 * NULL-terminated */
46 int len = xcb_get_property_value_length(reply);
47 char *value = p_new(char, len + 1);
48 memcpy(value, xcb_get_property_value(reply), len);
49 value[len] = '\0';
50 return value;
52 return NULL;
55 void xutil_lock_mask_get(xcb_connection_t *, xcb_get_modifier_mapping_cookie_t,
56 xcb_key_symbols_t *,
57 uint16_t *, uint16_t *, uint16_t *, uint16_t *);
59 /** Set the same handler for all errors */
60 void xutil_error_handler_catch_all_set(xcb_event_handlers_t *,
61 xcb_generic_error_handler_t, void *);
63 uint16_t xutil_key_mask_fromstr(const char *, size_t);
64 void xutil_key_mask_tostr(uint16_t, const char **, size_t *);
66 /* Get the informations about the screen.
67 * \param c X connection.
68 * \param screen Screen number.
69 * \return Screen informations (must not be freed!).
71 static inline xcb_screen_t *
72 xutil_screen_get(xcb_connection_t *c, int screen)
74 xcb_screen_t *s;
76 if(xcb_connection_has_error(c))
77 fatal("X connection invalid");
79 s = xcb_aux_get_screen(c, screen);
81 assert(s);
83 return s;
86 int xutil_root2screen(xcb_connection_t *, xcb_window_t);
88 #endif
89 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80