2 * Copyright © 2008 Arnaud Fontaine <arnau@debian.org>
3 * Copyright © 2007-2008 Vincent Torri <vtorri@univ-evry.fr>
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
20 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * Except as contained in this notice, the names of the authors or
25 * their institutions shall not be used in advertising or otherwise to
26 * promote the sale, use or other dealings in this Software without
27 * prior written authorization from the authors.
34 #include "xcb_icccm.h"
37 xcb_get_property_cookie_t
38 xcb_get_text_property(xcb_connection_t *c,
42 return xcb_get_any_property(c, 0, window, property, UINT_MAX);
45 xcb_get_property_cookie_t
46 xcb_get_text_property_unchecked(xcb_connection_t *c,
50 return xcb_get_any_property_unchecked(c, 0, window, property, UINT_MAX);
54 xcb_get_text_property_reply(xcb_connection_t *c,
55 xcb_get_property_cookie_t cookie,
56 xcb_get_text_property_reply_t *prop,
57 xcb_generic_error_t **e)
59 xcb_get_property_reply_t *reply = xcb_get_property_reply(c, cookie, e);
65 prop->encoding = prop->_reply->type;
66 prop->format = prop->_reply->format;
67 prop->name_len = xcb_get_property_value_length(prop->_reply);
68 prop->name = xcb_get_property_value(prop->_reply);
74 xcb_get_text_property_reply_wipe(xcb_get_text_property_reply_t *prop)
82 xcb_set_wm_name_checked(xcb_connection_t *c, xcb_window_t window,
83 xcb_atom_t encoding, uint32_t name_len,
86 xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, window, WM_NAME,
87 encoding, 8, name_len, name);
91 xcb_set_wm_name(xcb_connection_t *c, xcb_window_t window, xcb_atom_t encoding,
92 uint32_t name_len, const char *name)
94 xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, WM_NAME, encoding, 8,
98 xcb_get_property_cookie_t
99 xcb_get_wm_name(xcb_connection_t *c,
102 return xcb_get_text_property(c, window, WM_NAME);
105 xcb_get_property_cookie_t
106 xcb_get_wm_name_unchecked(xcb_connection_t *c,
109 return xcb_get_text_property_unchecked(c, window, WM_NAME);
113 xcb_get_wm_name_reply(xcb_connection_t *c,
114 xcb_get_property_cookie_t cookie,
115 xcb_get_text_property_reply_t *prop,
116 xcb_generic_error_t **e)
118 return xcb_get_text_property_reply(c, cookie, prop, e);
122 xcb_watch_wm_name(xcb_property_handlers_t *prophs, uint32_t long_len,
123 xcb_generic_property_handler_t handler, void *data)
125 xcb_property_set_handler(prophs, WM_NAME, long_len, handler, data);
131 xcb_set_wm_icon_name_checked(xcb_connection_t *c, xcb_window_t window,
132 xcb_atom_t encoding, uint32_t name_len,
135 xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, window, WM_ICON_NAME,
136 encoding, 8, name_len, name);
140 xcb_set_wm_icon_name(xcb_connection_t *c, xcb_window_t window,
141 xcb_atom_t encoding, uint32_t name_len, const char *name)
143 xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, WM_ICON_NAME, encoding,
147 xcb_get_property_cookie_t
148 xcb_get_wm_icon_name(xcb_connection_t *c,
151 return xcb_get_text_property(c, window, WM_ICON_NAME);
154 xcb_get_property_cookie_t
155 xcb_get_wm_icon_name_unchecked(xcb_connection_t *c,
158 return xcb_get_text_property_unchecked(c, window, WM_ICON_NAME);
162 xcb_get_wm_icon_name_reply(xcb_connection_t *c,
163 xcb_get_property_cookie_t cookie,
164 xcb_get_text_property_reply_t *prop,
165 xcb_generic_error_t **e)
167 return xcb_get_text_property_reply(c, cookie, prop, e);
171 xcb_watch_wm_icon_name(xcb_property_handlers_t *prophs, uint32_t long_len,
172 xcb_generic_property_handler_t handler, void *data)
174 xcb_property_set_handler(prophs, WM_ICON_NAME, long_len, handler, data);
177 /* WM_CLIENT_MACHINE */
180 xcb_set_wm_client_machine_checked(xcb_connection_t *c, xcb_window_t window,
181 xcb_atom_t encoding, uint32_t name_len,
184 xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, window,
185 WM_CLIENT_MACHINE, encoding, 8, name_len, name);
189 xcb_set_wm_client_machine(xcb_connection_t *c, xcb_window_t window,
190 xcb_atom_t encoding, uint32_t name_len,
193 xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, WM_CLIENT_MACHINE,
194 encoding, 8, name_len, name);
197 xcb_get_property_cookie_t
198 xcb_get_wm_client_machine(xcb_connection_t *c,
201 return xcb_get_text_property(c, window, WM_CLIENT_MACHINE);
204 xcb_get_property_cookie_t
205 xcb_get_wm_client_machine_unchecked(xcb_connection_t *c,
208 return xcb_get_text_property_unchecked(c, window, WM_CLIENT_MACHINE);
212 xcb_get_wm_client_machine_reply(xcb_connection_t *c,
213 xcb_get_property_cookie_t cookie,
214 xcb_get_text_property_reply_t *prop,
215 xcb_generic_error_t **e)
217 return xcb_get_text_property_reply(c, cookie, prop, e);
221 xcb_watch_wm_client_machine(xcb_property_handlers_t *prophs, uint32_t long_len,
222 xcb_generic_property_handler_t handler, void *data)
224 xcb_property_set_handler(prophs, WM_CLIENT_MACHINE, long_len, handler, data);
229 xcb_get_property_cookie_t
230 xcb_get_wm_class(xcb_connection_t *c, xcb_window_t window)
232 return xcb_get_property(c, 0, window, WM_CLASS, STRING, 0L, 2048L);
235 xcb_get_property_cookie_t
236 xcb_get_wm_class_unchecked(xcb_connection_t *c, xcb_window_t window)
238 return xcb_get_property_unchecked(c, 0, window, WM_CLASS, STRING, 0L, 2048L);
242 xcb_get_wm_class_from_reply(xcb_get_wm_class_reply_t *prop,
243 xcb_get_property_reply_t *reply)
245 if(!reply || reply->type != STRING || reply->format != 8)
248 prop->_reply = reply;
249 prop->instance_name = (char *) xcb_get_property_value(prop->_reply);
251 int name_len = strlen(prop->instance_name);
252 if(name_len == xcb_get_property_value_length(prop->_reply))
255 prop->class_name = prop->instance_name + name_len + 1;
261 xcb_get_wm_class_reply(xcb_connection_t *c, xcb_get_property_cookie_t cookie,
262 xcb_get_wm_class_reply_t *prop, xcb_generic_error_t **e)
264 xcb_get_property_reply_t *reply = xcb_get_property_reply(c, cookie, e);
265 uint8_t ret = xcb_get_wm_class_from_reply(prop, reply);
266 /* if reply parsing failed, free the reply to avoid mem leak */
273 xcb_get_wm_class_reply_wipe(xcb_get_wm_class_reply_t *prop)
278 /* WM_TRANSIENT_FOR */
280 xcb_get_property_cookie_t
281 xcb_get_wm_transient_for(xcb_connection_t *c, xcb_window_t window)
283 return xcb_get_property(c, 0, window, WM_TRANSIENT_FOR, WINDOW, 0, 1);
286 xcb_get_property_cookie_t
287 xcb_get_wm_transient_for_unchecked(xcb_connection_t *c, xcb_window_t window)
289 return xcb_get_property_unchecked(c, 0, window, WM_TRANSIENT_FOR, WINDOW, 0, 1);
293 xcb_get_wm_transient_for_from_reply(xcb_window_t *prop,
294 xcb_get_property_reply_t *reply)
296 if(!reply || reply->type != WINDOW || reply->format != 32 || !reply->length)
299 *prop = *((xcb_window_t *) xcb_get_property_value(reply));
305 xcb_get_wm_transient_for_reply(xcb_connection_t *c,
306 xcb_get_property_cookie_t cookie,
308 xcb_generic_error_t **e)
310 xcb_get_property_reply_t *reply = xcb_get_property_reply(c, cookie, e);
311 uint8_t ret = xcb_get_wm_transient_for_from_reply(prop, reply);
319 xcb_size_hints_set_position(xcb_size_hints_t *hints, int user_specified,
320 int32_t x, int32_t y)
322 hints->flags &= ~(XCB_SIZE_HINT_US_POSITION | XCB_SIZE_HINT_P_POSITION);
324 hints->flags |= XCB_SIZE_HINT_US_POSITION;
326 hints->flags |= XCB_SIZE_HINT_P_POSITION;
332 xcb_size_hints_set_size(xcb_size_hints_t *hints, int user_specified,
333 int32_t width, int32_t height)
335 hints->flags &= ~(XCB_SIZE_HINT_US_SIZE | XCB_SIZE_HINT_P_SIZE);
337 hints->flags |= XCB_SIZE_HINT_US_SIZE;
339 hints->flags |= XCB_SIZE_HINT_P_SIZE;
340 hints->width = width;
341 hints->height = height;
345 xcb_size_hints_set_min_size(xcb_size_hints_t *hints, int32_t min_width,
348 hints->flags |= XCB_SIZE_HINT_P_MIN_SIZE;
349 hints->min_width = min_width;
350 hints->min_height = min_height;
354 xcb_size_hints_set_max_size(xcb_size_hints_t *hints, int32_t max_width,
357 hints->flags |= XCB_SIZE_HINT_P_MAX_SIZE;
358 hints->max_width = max_width;
359 hints->max_height = max_height;
363 xcb_size_hints_set_resize_inc(xcb_size_hints_t *hints, int32_t width_inc,
366 hints->flags |= XCB_SIZE_HINT_P_RESIZE_INC;
367 hints->width_inc = width_inc;
368 hints->height_inc = height_inc;
372 xcb_size_hints_set_aspect(xcb_size_hints_t *hints, int32_t min_aspect_num,
373 int32_t min_aspect_den, int32_t max_aspect_num,
374 int32_t max_aspect_den)
376 hints->flags |= XCB_SIZE_HINT_P_ASPECT;
377 hints->min_aspect_num = min_aspect_num;
378 hints->min_aspect_den = min_aspect_den;
379 hints->max_aspect_num = max_aspect_num;
380 hints->max_aspect_den = max_aspect_den;
384 xcb_size_hints_set_base_size(xcb_size_hints_t *hints, int32_t base_width,
387 hints->flags |= XCB_SIZE_HINT_BASE_SIZE;
388 hints->base_width = base_width;
389 hints->base_height = base_height;
393 xcb_size_hints_set_win_gravity(xcb_size_hints_t *hints, xcb_gravity_t win_gravity)
395 hints->flags |= XCB_SIZE_HINT_P_WIN_GRAVITY;
396 hints->win_gravity = win_gravity;
400 xcb_set_wm_size_hints_checked(xcb_connection_t *c, xcb_window_t window,
401 xcb_atom_t property, xcb_size_hints_t *hints)
403 xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, window, property,
404 WM_SIZE_HINTS, 32, sizeof(*hints) >> 2, hints);
408 xcb_set_wm_size_hints(xcb_connection_t *c, xcb_window_t window,
409 xcb_atom_t property, xcb_size_hints_t *hints)
411 xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, property,
412 WM_SIZE_HINTS, 32, sizeof(*hints) >> 2, hints);
415 xcb_get_property_cookie_t
416 xcb_get_wm_size_hints(xcb_connection_t *c, xcb_window_t window,
419 /* NumPropSizeElements = 18 (ICCCM version 1). */
420 return xcb_get_property(c, 0, window, property, WM_SIZE_HINTS, 0L, 18);
423 xcb_get_property_cookie_t
424 xcb_get_wm_size_hints_unchecked(xcb_connection_t *c, xcb_window_t window,
427 return xcb_get_property_unchecked(c, 0, window, property, WM_SIZE_HINTS,
432 xcb_get_wm_size_hints_from_reply(xcb_size_hints_t *hints, xcb_get_property_reply_t *reply)
439 int length = xcb_get_property_value_length(reply) / (reply->format / 8);
441 if (!(reply->type == WM_SIZE_HINTS &&
442 (reply->format == 8 || reply->format == 16 ||
443 reply->format == 32) &&
444 /* OldNumPropSizeElements = 15 (pre-ICCCM) */
448 memcpy(hints, (xcb_size_hints_t *) xcb_get_property_value (reply),
449 length * reply->format >> 3);
451 flags = (XCB_SIZE_HINT_US_POSITION | XCB_SIZE_HINT_US_SIZE |
452 XCB_SIZE_HINT_P_POSITION | XCB_SIZE_HINT_P_SIZE |
453 XCB_SIZE_HINT_P_MIN_SIZE | XCB_SIZE_HINT_P_MAX_SIZE |
454 XCB_SIZE_HINT_P_RESIZE_INC | XCB_SIZE_HINT_P_ASPECT);
456 /* NumPropSizeElements = 18 (ICCCM version 1) */
458 flags |= (XCB_SIZE_HINT_BASE_SIZE | XCB_SIZE_HINT_P_WIN_GRAVITY);
461 hints->base_width = 0;
462 hints->base_height = 0;
463 hints->win_gravity = 0;
465 /* get rid of unwanted bits */
466 hints->flags &= flags;
472 xcb_get_wm_size_hints_reply(xcb_connection_t *c, xcb_get_property_cookie_t cookie,
473 xcb_size_hints_t *hints, xcb_generic_error_t **e)
475 xcb_get_property_reply_t *reply = xcb_get_property_reply(c, cookie, e);
476 uint8_t ret = xcb_get_wm_size_hints_from_reply(hints, reply);
481 /* WM_NORMAL_HINTS */
484 xcb_set_wm_normal_hints_checked(xcb_connection_t *c, xcb_window_t window,
485 xcb_size_hints_t *hints)
487 xcb_set_wm_size_hints_checked(c, window, WM_NORMAL_HINTS, hints);
491 xcb_set_wm_normal_hints(xcb_connection_t *c, xcb_window_t window,
492 xcb_size_hints_t *hints)
494 xcb_set_wm_size_hints(c, window, WM_NORMAL_HINTS, hints);
497 xcb_get_property_cookie_t
498 xcb_get_wm_normal_hints(xcb_connection_t *c, xcb_window_t window)
500 return xcb_get_wm_size_hints(c, window, WM_NORMAL_HINTS);
503 xcb_get_property_cookie_t
504 xcb_get_wm_normal_hints_unchecked(xcb_connection_t *c, xcb_window_t window)
506 return xcb_get_wm_size_hints_unchecked(c, window, WM_NORMAL_HINTS);
510 xcb_get_wm_normal_hints_reply(xcb_connection_t *c,
511 xcb_get_property_cookie_t cookie,
512 xcb_size_hints_t *hints,
513 xcb_generic_error_t **e)
515 return xcb_get_wm_size_hints_reply(c, cookie, hints, e);
521 xcb_wm_hints_get_urgency(xcb_wm_hints_t *hints)
523 return (hints->flags & XCB_WM_HINT_X_URGENCY);
527 xcb_wm_hints_set_input(xcb_wm_hints_t *hints, uint8_t input)
529 hints->input = input;
530 hints->flags |= XCB_WM_HINT_INPUT;
534 xcb_wm_hints_set_iconic(xcb_wm_hints_t *hints)
536 hints->initial_state = XCB_WM_STATE_ICONIC;
537 hints->flags |= XCB_WM_HINT_STATE;
541 xcb_wm_hints_set_normal(xcb_wm_hints_t *hints)
543 hints->initial_state = XCB_WM_STATE_NORMAL;
544 hints->flags |= XCB_WM_HINT_STATE;
548 xcb_wm_hints_set_withdrawn(xcb_wm_hints_t *hints)
550 hints->initial_state = XCB_WM_STATE_WITHDRAWN;
551 hints->flags |= XCB_WM_HINT_STATE;
555 xcb_wm_hints_set_none(xcb_wm_hints_t *hints)
557 hints->flags &= ~XCB_WM_HINT_STATE;
561 xcb_wm_hints_set_icon_pixmap(xcb_wm_hints_t *hints, xcb_pixmap_t icon_pixmap)
563 hints->icon_pixmap = icon_pixmap;
564 hints->flags |= XCB_WM_HINT_ICON_PIXMAP;
568 xcb_wm_hints_set_icon_mask(xcb_wm_hints_t *hints, xcb_pixmap_t icon_mask)
570 hints->icon_mask = icon_mask;
571 hints->flags |= XCB_WM_HINT_ICON_MASK;
575 xcb_wm_hints_set_icon_window(xcb_wm_hints_t *hints, xcb_window_t icon_window)
577 hints->icon_window = icon_window;
578 hints->flags |= XCB_WM_HINT_ICON_WINDOW;
582 xcb_wm_hints_set_window_group(xcb_wm_hints_t *hints, xcb_window_t window_group)
584 hints->window_group = window_group;
585 hints->flags |= XCB_WM_HINT_WINDOW_GROUP;
589 xcb_wm_hints_set_urgency(xcb_wm_hints_t *hints)
591 hints->flags |= XCB_WM_HINT_X_URGENCY;
595 xcb_set_wm_hints_checked(xcb_connection_t *c, xcb_window_t window,
596 xcb_wm_hints_t *hints)
598 xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, window, WM_HINTS,
599 WM_HINTS, 32, sizeof(*hints) >> 2, hints);
603 xcb_set_wm_hints(xcb_connection_t *c, xcb_window_t window,
604 xcb_wm_hints_t *hints)
606 xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, WM_HINTS, WM_HINTS, 32,
607 sizeof(*hints) >> 2, hints);
610 xcb_get_property_cookie_t
611 xcb_get_wm_hints(xcb_connection_t *c,
614 return xcb_get_property(c, 0, window, WM_HINTS, WM_HINTS, 0L,
615 XCB_NUM_WM_HINTS_ELEMENTS);
618 xcb_get_property_cookie_t
619 xcb_get_wm_hints_unchecked(xcb_connection_t *c,
622 return xcb_get_property_unchecked(c, 0, window, WM_HINTS, WM_HINTS, 0L,
623 XCB_NUM_WM_HINTS_ELEMENTS);
627 xcb_get_wm_hints_from_reply(xcb_wm_hints_t *hints,
628 xcb_get_property_reply_t *reply)
633 int length = xcb_get_property_value_length(reply);
634 int num_elem = length / (reply->format / 8);
636 if (reply->type != WM_HINTS
637 || reply->format != 32
638 || num_elem < XCB_NUM_WM_HINTS_ELEMENTS - 1)
641 memcpy(hints, (xcb_size_hints_t *) xcb_get_property_value(reply), length);
643 if(num_elem < XCB_NUM_WM_HINTS_ELEMENTS)
644 hints->window_group = XCB_NONE;
650 xcb_get_wm_hints_reply(xcb_connection_t *c,
651 xcb_get_property_cookie_t cookie,
652 xcb_wm_hints_t *hints,
653 xcb_generic_error_t **e)
655 xcb_get_property_reply_t *reply = xcb_get_property_reply(c, cookie, e);
656 int ret = xcb_get_wm_hints_from_reply(hints, reply);
664 xcb_set_wm_protocols_checked(xcb_connection_t *c, xcb_atom_t wm_protocols,
665 xcb_window_t window, uint32_t list_len,
668 xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, window, wm_protocols,
669 ATOM, 32, list_len, list);
673 xcb_set_wm_protocols(xcb_connection_t *c, xcb_atom_t wm_protocols,
674 xcb_window_t window, uint32_t list_len, xcb_atom_t *list)
676 xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, wm_protocols, ATOM, 32,
680 xcb_get_property_cookie_t
681 xcb_get_wm_protocols(xcb_connection_t *c, xcb_window_t window,
682 xcb_atom_t wm_protocol_atom)
684 return xcb_get_property(c, 0, window, wm_protocol_atom, ATOM, 0, UINT_MAX);
687 xcb_get_property_cookie_t
688 xcb_get_wm_protocols_unchecked(xcb_connection_t *c,
690 xcb_atom_t wm_protocol_atom)
692 return xcb_get_property_unchecked(c, 0, window, wm_protocol_atom, ATOM, 0,
697 xcb_get_wm_protocols_from_reply(xcb_get_property_reply_t *reply, xcb_get_wm_protocols_reply_t *protocols)
699 if(!reply || reply->type != ATOM || reply->format != 32)
702 protocols->_reply = reply;
703 protocols->atoms_len = xcb_get_property_value_length(protocols->_reply) / (reply->format / 8);
704 protocols->atoms = (xcb_atom_t *) xcb_get_property_value(protocols->_reply);
710 xcb_get_wm_protocols_reply(xcb_connection_t *c,
711 xcb_get_property_cookie_t cookie,
712 xcb_get_wm_protocols_reply_t *protocols,
713 xcb_generic_error_t **e)
715 xcb_get_property_reply_t *reply = xcb_get_property_reply(c, cookie, e);
716 uint8_t ret = xcb_get_wm_protocols_from_reply(reply, protocols);
723 xcb_get_wm_protocols_reply_wipe(xcb_get_wm_protocols_reply_t *protocols)
725 free(protocols->_reply);