2
* Copyright Ā© 2008 Bart Massey <bart@cs.pdx.edu>
3
* Copyright Ā© 2008 Ian Osgood <iano@quirkster.com>
4
* Copyright Ā© 2008 Jamey Sharp <jamey@minilop.net>
5
* Copyright Ā© 2008 Josh Triplett <josh@freedesktop.org>
7
* Permission is hereby granted, free of charge, to any person
8
* obtaining a copy of this software and associated documentation
9
* files (the "Software"), to deal in the Software without
10
* restriction, including without limitation the rights to use, copy,
11
* modify, merge, publish, distribute, sublicense, and/or sell copies
12
* of the Software, and to permit persons to whom the Software is
13
* furnished to do so, subject to the following conditions:
15
* The above copyright notice and this permission notice shall be
16
* included in all copies or substantial portions of the Software.
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
22
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
* Except as contained in this notice, the names of the authors or
27
* their institutions shall not be used in advertising or otherwise to
28
* promote the sale, use or other dealings in this Software without
29
* prior written authorization from the authors.
39
/* Connection related functions */
42
xcb_aux_get_depth (xcb_connection_t *c,
45
xcb_drawable_t drawable;
46
xcb_get_geometry_reply_t *geom;
49
drawable = screen->root;
50
geom = xcb_get_geometry_reply (c, xcb_get_geometry(c, drawable), 0);
61
xcb_aux_get_depth_of_visual (xcb_screen_t *screen,
64
xcb_depth_iterator_t i;
65
xcb_visualtype_iterator_t j;
66
for (i = xcb_screen_allowed_depths_iterator(screen);
67
i.rem; xcb_depth_next(&i))
68
for (j = xcb_depth_visuals_iterator(i.data);
69
j.rem; xcb_visualtype_next(&j))
70
if (j.data->visual_id == id)
76
xcb_aux_get_screen (xcb_connection_t *c,
79
xcb_screen_iterator_t i = xcb_setup_roots_iterator(xcb_get_setup(c));
80
for (; i.rem; --screen, xcb_screen_next(&i))
87
xcb_aux_get_visualtype (xcb_connection_t *c,
93
xcb_visualtype_iterator_t iter;
96
screen = xcb_aux_get_screen (c, scr);
97
if (!screen) return NULL;
99
depth = xcb_screen_allowed_depths_iterator(screen).data;
100
if (!depth) return NULL;
102
iter = xcb_depth_visuals_iterator(depth);
103
for (cur = 0 ; cur < iter.rem ; xcb_visualtype_next(&iter), ++cur)
104
if (vid == iter.data->visual_id)
111
xcb_aux_find_visual_by_id (xcb_screen_t *screen,
114
xcb_depth_iterator_t i;
115
xcb_visualtype_iterator_t j;
116
for (i = xcb_screen_allowed_depths_iterator(screen);
117
i.rem; xcb_depth_next(&i))
118
for (j = xcb_depth_visuals_iterator(i.data);
119
j.rem; xcb_visualtype_next(&j))
120
if (j.data->visual_id == id)
126
xcb_aux_find_visual_by_attrs (xcb_screen_t *screen,
130
xcb_depth_iterator_t i;
131
xcb_visualtype_iterator_t j;
132
for (i = xcb_screen_allowed_depths_iterator(screen);
133
i.rem; xcb_depth_next(&i)) {
134
if (depth != -1 && i.data->depth != depth)
136
for (j = xcb_depth_visuals_iterator(i.data);
137
j.rem; xcb_visualtype_next(&j))
138
if (class == -1 || j.data->_class == class)
145
xcb_aux_sync (xcb_connection_t *c)
147
free(xcb_get_input_focus_reply(c, xcb_get_input_focus(c), NULL));
150
/* structs instead of value lists */
151
/* TODO: generate the struct types and functions from protocol masks and descriptions */
153
/* This generic implementation of pack_list depends on:
154
a) structs packed to uint32_t size
155
b) structs consist of just uint32_t/int32_t fields in the same order as bitmask
159
pack_list( uint32_t mask, const uint32_t *src, uint32_t *dest )
161
for ( ; mask; mask >>= 1, src++)
167
xcb_aux_create_window (xcb_connection_t *c,
175
uint16_t border_width,
177
xcb_visualid_t visual,
179
const xcb_params_cw_t *params)
181
uint32_t value_list[16];
182
pack_list(mask, (const uint32_t *)params, value_list);
183
return xcb_create_window(c, depth, wid, parent,
184
x, y, width, height, border_width,
185
_class, visual, mask, value_list);
189
xcb_aux_create_window_checked (xcb_connection_t *c,
197
uint16_t border_width,
199
xcb_visualid_t visual,
201
const xcb_params_cw_t *params)
203
uint32_t value_list[16];
204
pack_list(mask, (const uint32_t *)params, value_list);
205
return xcb_create_window_checked(c, depth, wid, parent,
206
x, y, width, height, border_width,
207
_class, visual, mask, value_list);
211
xcb_aux_change_window_attributes_checked (xcb_connection_t *c,
214
const xcb_params_cw_t *params)
216
uint32_t value_list[16];
217
pack_list(mask, (const uint32_t *)params, value_list);
218
return xcb_change_window_attributes_checked( c, window, mask, value_list );
222
xcb_aux_change_window_attributes (xcb_connection_t *c,
225
const xcb_params_cw_t *params)
227
uint32_t value_list[16];
228
pack_list(mask, (const uint32_t *)params, value_list);
229
return xcb_change_window_attributes( c, window, mask, value_list );
233
xcb_aux_configure_window (xcb_connection_t *c,
236
const xcb_params_configure_window_t *params)
238
uint32_t value_list[8];
239
pack_list(mask, (const uint32_t *)params, value_list);
240
return xcb_configure_window( c, window, mask, value_list );
244
xcb_aux_create_gc (xcb_connection_t *c,
246
xcb_drawable_t drawable,
248
const xcb_params_gc_t *params)
250
uint32_t value_list[32];
251
pack_list(mask, (const uint32_t *)params, value_list);
252
return xcb_create_gc( c, gid, drawable, mask, value_list );
256
xcb_aux_create_gc_checked (xcb_connection_t *c,
258
xcb_drawable_t drawable,
260
const xcb_params_gc_t *params)
262
uint32_t value_list[32];
263
pack_list(mask, (const uint32_t *)params, value_list);
264
return xcb_create_gc_checked( c, gid, drawable, mask, value_list);
268
xcb_aux_change_gc (xcb_connection_t *c,
271
const xcb_params_gc_t *params)
273
uint32_t value_list[32];
274
pack_list(mask, (const uint32_t *)params, value_list);
275
return xcb_change_gc( c, gc, mask, value_list );
279
xcb_aux_change_gc_checked (xcb_connection_t *c,
282
const xcb_params_gc_t *params)
284
uint32_t value_list[32];
285
pack_list(mask, (const uint32_t *)params, value_list);
286
return xcb_change_gc_checked( c, gc, mask, value_list );
290
xcb_aux_change_keyboard_control (xcb_connection_t *c,
292
const xcb_params_keyboard_t *params)
294
uint32_t value_list[16];
295
pack_list(mask, (const uint32_t *)params, value_list);
296
return xcb_change_keyboard_control( c, mask, value_list );
299
/* Color related functions */
301
/* Return true if the given color name can be translated locally,
302
in which case load the components. Otherwise, a lookup_color request
303
will be needed, so return false. */
305
xcb_aux_parse_color(char *color_name,
306
uint16_t *red, uint16_t *green, uint16_t *blue)
309
if (!color_name || *color_name != '#')
312
* Excitingly weird RGB parsing code from Xlib.
314
n = strlen (color_name);
317
if (n != 3 && n != 6 && n != 9 && n != 12)
325
for (i = n; --i >= 0; ) {
326
char c = *color_name++;
328
if (c >= '0' && c <= '9')
330
else if (c >= 'A' && c <= 'F')
332
else if (c >= 'a' && c <= 'f')
336
} while (*color_name != '\0');
345
/* Drawing related functions */
347
/* Adapted from Xlib */
349
xcb_aux_set_line_attributes_checked (xcb_connection_t *dpy,
359
XCB_AUX_ADD_PARAM(&mask, &gv, line_width, linewidth);
360
XCB_AUX_ADD_PARAM(&mask, &gv, line_style, linestyle);
361
XCB_AUX_ADD_PARAM(&mask, &gv, cap_style, capstyle);
362
XCB_AUX_ADD_PARAM(&mask, &gv, join_style, joinstyle);
363
return xcb_aux_change_gc_checked(dpy, gc, mask, &gv);
366
/* Adapted from Xlib */
367
/* XXX It would be wiser for apps just to call
368
clear_area() directly. */
370
xcb_aux_clear_window(xcb_connection_t * dpy,
373
return xcb_clear_area(dpy, 0, w, 0, 0, 0, 0);