2 * common/xutil.h - X-related useful functions header
4 * Copyright © 2007-2008 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
26 #include <xcb/xcb_keysyms.h>
27 #include <xcb/xcb_aux.h>
28 #include <xcb/xcb_event.h>
30 /* XCB doesn't provide keysyms definition */
31 #include <X11/keysym.h>
35 #define XUTIL_MASK_CLEAN(mask) (mask & ~(globalconf.numlockmask | XCB_MOD_MASK_LOCK))
37 /* See http://tronche.com/gui/x/xlib/appendix/b/ for values */
38 #define XUTIL_CURSOR_FLEUR 52
39 #define XUTIL_CURSOR_LEFT_PTR 68
40 #define XUTIL_CURSOR_SIZING 120
41 #define XUTIL_CURSOR_BOTTOM_LEFT_CORNER 12
42 #define XUTIL_CURSOR_BOTTOM_RIGHT_CORNER 14
43 #define XUTIL_CURSOR_TOP_LEFT_CORNER 134
44 #define XUTIL_CURSOR_TOP_RIGHT_CORNER 136
45 #define XUTIL_CURSOR_DOUBLE_ARROW_HORIZ 108
46 #define XUTIL_CURSOR_DOUBLE_ARROW_VERT 116
50 /* Everything's okay */
51 #define XUTIL_SUCCESS 0
52 /* Bad request code */
53 #define XUTIL_BAD_REQUEST 1
54 /* Int parameter out of range */
55 #define XUTIL_BAD_VALUE 2
56 /* Parameter not a Window */
57 #define XUTIL_BAD_WINDOW 3
58 /* Parameter not a Pixmap */
59 #define XUTIL_BAD_PIXMAP 4
60 /* Parameter not an Atom */
61 #define XUTIL_BAD_ATOM 5
62 /* Parameter not a Cursor */
63 #define XUTIL_BAD_CURSOR 6
64 /* Parameter not a Font */
65 #define XUTIL_BAD_FONT 7
66 /* Parameter mismatch */
67 #define XUTIL_BAD_MATCH 8
68 /* Parameter not a Pixmap or Window */
69 #define XUTIL_BAD_DRAWABLE 9
70 /* Depending on context:
71 - key/button already grabbed
72 - attempt to free an illegal
74 - attempt to store into a read-only
76 - attempt to modify the access control
77 list from other than the local host.
79 #define XUTIL_BAD_ACCESS 10
80 /* Insufficient resources */
81 #define XUTIL_BAD_ALLOC 11
82 /* No such colormap */
83 #define XUTIL_BAD_COLOR 12
84 /* Parameter not a GC */
85 #define XUTIL_BAD_GC 13
86 /* Choice not in range or already used */
87 #define XUTIL_BAD_ID_CHOICE 14
88 /* Font or color name doesn't exist */
89 #define XUTIL_BAD_NAME 15
90 /* Request length incorrect */
91 #define XUTIL_BAD_LENGTH 16
92 /* Server is defective */
93 #define XUTIL_BAD_IMPLEMENTATION 17
95 bool xutil_text_prop_get(xcb_connection_t
*, xcb_window_t
, xcb_atom_t
, char **, ssize_t
*);
97 void xutil_lock_mask_get(xcb_connection_t
*, xcb_get_modifier_mapping_cookie_t
,
98 xcb_key_symbols_t
*, unsigned int *, unsigned int *,
101 /** Set the same handler for all errors */
102 void xutil_error_handler_catch_all_set(xcb_event_handlers_t
*,
103 xcb_generic_error_handler_t
, void *);
107 uint8_t request_code
;
112 bool xutil_error_init(const xcb_generic_error_t
*, xutil_error_t
*);
113 xcb_keysym_t
xutil_key_mask_fromstr(const char *, size_t);
114 unsigned int xutil_button_fromint(int);
115 xcb_cursor_t
xutil_cursor_new(xcb_connection_t
*, unsigned int);
118 xutil_error_wipe(xutil_error_t
*err
)
120 p_delete(&err
->error_label
);
121 p_delete(&err
->request_label
);
124 /* Get the informations about the screen.
125 * \param c X connection.
126 * \param screen Screen number.
127 * \return Screen informations (must not be freed!).
129 static inline xcb_screen_t
*
130 xutil_screen_get(xcb_connection_t
*c
, int screen
)
134 if(xcb_connection_has_error(c
))
135 fatal("X connection invalid");
137 s
= xcb_aux_get_screen(c
, screen
);
144 int xutil_root2screen(xcb_connection_t
*, xcb_window_t
);
147 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80