2 * ewmh.c - EWMH support functions
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 #include <sys/types.h>
26 #include <xcb/xcb_atom.h>
29 #include "objects/tag.h"
31 #include "objects/client.h"
33 #include "common/atoms.h"
34 #include "common/buffer.h"
35 #include "common/xutil.h"
37 #define _NET_WM_STATE_REMOVE 0
38 #define _NET_WM_STATE_ADD 1
39 #define _NET_WM_STATE_TOGGLE 2
41 /** Update client EWMH hints.
42 * \param c The client.
45 ewmh_client_update_hints(lua_State
*L
)
47 client_t
*c
= luaA_checkudata(L
, 1, &client_class
);
48 xcb_atom_t state
[10]; /* number of defined state atoms */
52 state
[i
++] = _NET_WM_STATE_MODAL
;
54 state
[i
++] = _NET_WM_STATE_FULLSCREEN
;
55 if(c
->maximized_vertical
)
56 state
[i
++] = _NET_WM_STATE_MAXIMIZED_VERT
;
57 if(c
->maximized_horizontal
)
58 state
[i
++] = _NET_WM_STATE_MAXIMIZED_HORZ
;
60 state
[i
++] = _NET_WM_STATE_STICKY
;
62 state
[i
++] = _NET_WM_STATE_SKIP_TASKBAR
;
64 state
[i
++] = _NET_WM_STATE_ABOVE
;
66 state
[i
++] = _NET_WM_STATE_BELOW
;
68 state
[i
++] = _NET_WM_STATE_HIDDEN
;
70 state
[i
++] = _NET_WM_STATE_DEMANDS_ATTENTION
;
72 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
,
73 c
->window
, _NET_WM_STATE
, XCB_ATOM_ATOM
, 32, i
, state
);
79 ewmh_update_net_active_window(lua_State
*L
)
83 if(globalconf
.focus
.client
)
84 win
= globalconf
.focus
.client
->window
;
88 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
,
89 globalconf
.screen
->root
,
90 _NET_ACTIVE_WINDOW
, XCB_ATOM_WINDOW
, 32, 1, &win
);
96 ewmh_update_net_client_list(lua_State
*L
)
98 xcb_window_t
*wins
= p_alloca(xcb_window_t
, globalconf
.clients
.len
);
101 foreach(client
, globalconf
.clients
)
102 wins
[n
++] = (*client
)->window
;
104 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
,
105 globalconf
.screen
->root
,
106 _NET_CLIENT_LIST
, XCB_ATOM_WINDOW
, 32, n
, wins
);
115 xcb_screen_t
*xscreen
= globalconf
.screen
;
119 _NET_SUPPORTING_WM_CHECK
,
122 _NET_CLIENT_LIST_STACKING
,
123 _NET_NUMBER_OF_DESKTOPS
,
124 _NET_CURRENT_DESKTOP
,
129 _NET_WM_STRUT_PARTIAL
,
131 _NET_WM_VISIBLE_ICON_NAME
,
134 _NET_WM_WINDOW_TYPE_DESKTOP
,
135 _NET_WM_WINDOW_TYPE_DOCK
,
136 _NET_WM_WINDOW_TYPE_TOOLBAR
,
137 _NET_WM_WINDOW_TYPE_MENU
,
138 _NET_WM_WINDOW_TYPE_UTILITY
,
139 _NET_WM_WINDOW_TYPE_SPLASH
,
140 _NET_WM_WINDOW_TYPE_DIALOG
,
141 _NET_WM_WINDOW_TYPE_DROPDOWN_MENU
,
142 _NET_WM_WINDOW_TYPE_POPUP_MENU
,
143 _NET_WM_WINDOW_TYPE_TOOLTIP
,
144 _NET_WM_WINDOW_TYPE_NOTIFICATION
,
145 _NET_WM_WINDOW_TYPE_COMBO
,
146 _NET_WM_WINDOW_TYPE_DND
,
147 _NET_WM_WINDOW_TYPE_NORMAL
,
151 _NET_WM_STATE_STICKY
,
152 _NET_WM_STATE_SKIP_TASKBAR
,
153 _NET_WM_STATE_FULLSCREEN
,
154 _NET_WM_STATE_MAXIMIZED_HORZ
,
155 _NET_WM_STATE_MAXIMIZED_VERT
,
159 _NET_WM_STATE_HIDDEN
,
160 _NET_WM_STATE_DEMANDS_ATTENTION
164 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
,
165 xscreen
->root
, _NET_SUPPORTED
, XCB_ATOM_ATOM
, 32,
166 countof(atom
), atom
);
168 /* create our own window */
169 father
= xcb_generate_id(globalconf
.connection
);
170 xcb_create_window(globalconf
.connection
, xscreen
->root_depth
,
171 father
, xscreen
->root
, -1, -1, 1, 1, 0,
172 XCB_COPY_FROM_PARENT
, xscreen
->root_visual
, 0, NULL
);
174 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
,
175 xscreen
->root
, _NET_SUPPORTING_WM_CHECK
, XCB_ATOM_WINDOW
, 32,
178 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
,
179 father
, _NET_SUPPORTING_WM_CHECK
, XCB_ATOM_WINDOW
, 32,
182 /* set the window manager name */
183 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
,
184 father
, _NET_WM_NAME
, UTF8_STRING
, 8, 7, "awesome");
186 /* set the window manager PID */
188 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
,
189 father
, _NET_WM_PID
, XCB_ATOM_CARDINAL
, 32, 1, &i
);
192 luaA_class_connect_signal(globalconf
.L
, &client_class
, "focus", ewmh_update_net_active_window
);
193 luaA_class_connect_signal(globalconf
.L
, &client_class
, "unfocus", ewmh_update_net_active_window
);
194 luaA_class_connect_signal(globalconf
.L
, &client_class
, "manage", ewmh_update_net_client_list
);
195 luaA_class_connect_signal(globalconf
.L
, &client_class
, "unmanage", ewmh_update_net_client_list
);
196 luaA_class_connect_signal(globalconf
.L
, &client_class
, "property::modal" , ewmh_client_update_hints
);
197 luaA_class_connect_signal(globalconf
.L
, &client_class
, "property::fullscreen" , ewmh_client_update_hints
);
198 luaA_class_connect_signal(globalconf
.L
, &client_class
, "property::maximized_horizontal" , ewmh_client_update_hints
);
199 luaA_class_connect_signal(globalconf
.L
, &client_class
, "property::maximized_vertical" , ewmh_client_update_hints
);
200 luaA_class_connect_signal(globalconf
.L
, &client_class
, "property::sticky" , ewmh_client_update_hints
);
201 luaA_class_connect_signal(globalconf
.L
, &client_class
, "property::skip_taskbar" , ewmh_client_update_hints
);
202 luaA_class_connect_signal(globalconf
.L
, &client_class
, "property::above" , ewmh_client_update_hints
);
203 luaA_class_connect_signal(globalconf
.L
, &client_class
, "property::below" , ewmh_client_update_hints
);
204 luaA_class_connect_signal(globalconf
.L
, &client_class
, "property::minimized" , ewmh_client_update_hints
);
205 luaA_class_connect_signal(globalconf
.L
, &client_class
, "property::urgent" , ewmh_client_update_hints
);
208 /** Set the client list in stacking order, bottom to top.
211 ewmh_update_net_client_list_stacking(void)
214 xcb_window_t
*wins
= p_alloca(xcb_window_t
, globalconf
.stack
.len
);
216 foreach(client
, globalconf
.stack
)
217 wins
[n
++] = (*client
)->window
;
219 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
,
220 globalconf
.screen
->root
,
221 _NET_CLIENT_LIST_STACKING
, XCB_ATOM_WINDOW
, 32, n
, wins
);
225 ewmh_update_net_numbers_of_desktop(void)
227 uint32_t count
= globalconf
.tags
.len
;
229 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
,
230 globalconf
.screen
->root
,
231 _NET_NUMBER_OF_DESKTOPS
, XCB_ATOM_CARDINAL
, 32, 1, &count
);
235 ewmh_update_net_current_desktop(void)
237 uint32_t idx
= tags_get_first_selected_index();
239 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
,
240 globalconf
.screen
->root
,
241 _NET_CURRENT_DESKTOP
, XCB_ATOM_CARDINAL
, 32, 1, &idx
);
245 ewmh_update_net_desktop_names(void)
249 buffer_inita(&buf
, BUFSIZ
);
251 foreach(tag
, globalconf
.tags
)
253 buffer_adds(&buf
, tag_get_name(*tag
));
254 buffer_addc(&buf
, '\0');
257 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
,
258 globalconf
.screen
->root
,
259 _NET_DESKTOP_NAMES
, UTF8_STRING
, 8, buf
.len
, buf
.s
);
264 ewmh_process_state_atom(client_t
*c
, xcb_atom_t state
, int set
)
266 luaA_object_push(globalconf
.L
, c
);
268 if(state
== _NET_WM_STATE_STICKY
)
270 if(set
== _NET_WM_STATE_REMOVE
)
271 client_set_sticky(globalconf
.L
, -1, false);
272 else if(set
== _NET_WM_STATE_ADD
)
273 client_set_sticky(globalconf
.L
, -1, true);
274 else if(set
== _NET_WM_STATE_TOGGLE
)
275 client_set_sticky(globalconf
.L
, -1, !c
->sticky
);
277 else if(state
== _NET_WM_STATE_SKIP_TASKBAR
)
279 if(set
== _NET_WM_STATE_REMOVE
)
280 client_set_skip_taskbar(globalconf
.L
, -1, false);
281 else if(set
== _NET_WM_STATE_ADD
)
282 client_set_skip_taskbar(globalconf
.L
, -1, true);
283 else if(set
== _NET_WM_STATE_TOGGLE
)
284 client_set_skip_taskbar(globalconf
.L
, -1, !c
->skip_taskbar
);
286 else if(state
== _NET_WM_STATE_FULLSCREEN
)
288 if(set
== _NET_WM_STATE_REMOVE
)
289 client_set_fullscreen(globalconf
.L
, -1, false);
290 else if(set
== _NET_WM_STATE_ADD
)
291 client_set_fullscreen(globalconf
.L
, -1, true);
292 else if(set
== _NET_WM_STATE_TOGGLE
)
293 client_set_fullscreen(globalconf
.L
, -1, !c
->fullscreen
);
295 else if(state
== _NET_WM_STATE_MAXIMIZED_HORZ
)
297 if(set
== _NET_WM_STATE_REMOVE
)
298 client_set_maximized_horizontal(globalconf
.L
, -1, false);
299 else if(set
== _NET_WM_STATE_ADD
)
300 client_set_maximized_horizontal(globalconf
.L
, -1, true);
301 else if(set
== _NET_WM_STATE_TOGGLE
)
302 client_set_maximized_horizontal(globalconf
.L
, -1, !c
->maximized_horizontal
);
304 else if(state
== _NET_WM_STATE_MAXIMIZED_VERT
)
306 if(set
== _NET_WM_STATE_REMOVE
)
307 client_set_maximized_vertical(globalconf
.L
, -1, false);
308 else if(set
== _NET_WM_STATE_ADD
)
309 client_set_maximized_vertical(globalconf
.L
, -1, true);
310 else if(set
== _NET_WM_STATE_TOGGLE
)
311 client_set_maximized_vertical(globalconf
.L
, -1, !c
->maximized_vertical
);
313 else if(state
== _NET_WM_STATE_ABOVE
)
315 if(set
== _NET_WM_STATE_REMOVE
)
316 client_set_above(globalconf
.L
, -1, false);
317 else if(set
== _NET_WM_STATE_ADD
)
318 client_set_above(globalconf
.L
, -1, true);
319 else if(set
== _NET_WM_STATE_TOGGLE
)
320 client_set_above(globalconf
.L
, -1, !c
->above
);
322 else if(state
== _NET_WM_STATE_BELOW
)
324 if(set
== _NET_WM_STATE_REMOVE
)
325 client_set_below(globalconf
.L
, -1, false);
326 else if(set
== _NET_WM_STATE_ADD
)
327 client_set_below(globalconf
.L
, -1, true);
328 else if(set
== _NET_WM_STATE_TOGGLE
)
329 client_set_below(globalconf
.L
, -1, !c
->below
);
331 else if(state
== _NET_WM_STATE_MODAL
)
333 if(set
== _NET_WM_STATE_REMOVE
)
334 client_set_modal(globalconf
.L
, -1, false);
335 else if(set
== _NET_WM_STATE_ADD
)
336 client_set_modal(globalconf
.L
, -1, true);
337 else if(set
== _NET_WM_STATE_TOGGLE
)
338 client_set_modal(globalconf
.L
, -1, !c
->modal
);
340 else if(state
== _NET_WM_STATE_HIDDEN
)
342 if(set
== _NET_WM_STATE_REMOVE
)
343 client_set_minimized(globalconf
.L
, -1, false);
344 else if(set
== _NET_WM_STATE_ADD
)
345 client_set_minimized(globalconf
.L
, -1, true);
346 else if(set
== _NET_WM_STATE_TOGGLE
)
347 client_set_minimized(globalconf
.L
, -1, !c
->minimized
);
349 else if(state
== _NET_WM_STATE_DEMANDS_ATTENTION
)
351 if(set
== _NET_WM_STATE_REMOVE
)
352 client_set_urgent(globalconf
.L
, -1, false);
353 else if(set
== _NET_WM_STATE_ADD
)
354 client_set_urgent(globalconf
.L
, -1, true);
355 else if(set
== _NET_WM_STATE_TOGGLE
)
356 client_set_urgent(globalconf
.L
, -1, !c
->urgent
);
359 lua_pop(globalconf
.L
, 1);
363 ewmh_process_client_message(xcb_client_message_event_t
*ev
)
367 if(ev
->type
== _NET_CURRENT_DESKTOP
)
368 tag_view_only_byindex(ev
->data
.data32
[0]);
369 else if(ev
->type
== _NET_CLOSE_WINDOW
)
371 if((c
= client_getbywin(ev
->window
)))
374 else if(ev
->type
== _NET_WM_DESKTOP
)
376 if((c
= client_getbywin(ev
->window
)))
378 if(ev
->data
.data32
[0] == 0xffffffff)
381 for(int i
= 0; i
< globalconf
.tags
.len
; i
++)
382 if((int)ev
->data
.data32
[0] == i
)
384 luaA_object_push(globalconf
.L
, globalconf
.tags
.tab
[i
]);
388 untag_client(c
, globalconf
.tags
.tab
[i
]);
391 else if(ev
->type
== _NET_WM_STATE
)
393 if((c
= client_getbywin(ev
->window
)))
395 ewmh_process_state_atom(c
, (xcb_atom_t
) ev
->data
.data32
[1], ev
->data
.data32
[0]);
396 if(ev
->data
.data32
[2])
397 ewmh_process_state_atom(c
, (xcb_atom_t
) ev
->data
.data32
[2],
401 else if(ev
->type
== _NET_ACTIVE_WINDOW
)
403 if((c
= client_getbywin(ev
->window
))) {
404 luaA_object_push(globalconf
.L
, c
);
405 luaA_object_emit_signal(globalconf
.L
, -1, "request::activate", 0);
406 lua_pop(globalconf
.L
, 1);
413 /** Update the client active desktop.
414 * This is "wrong" since it can be on several tags, but EWMH has a strict view
415 * of desktop system so just take the first tag.
416 * \param c The client.
419 ewmh_client_update_desktop(client_t
*c
)
423 for(i
= 0; i
< globalconf
.tags
.len
; i
++)
424 if(is_client_tagged(c
, globalconf
.tags
.tab
[i
]))
426 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
,
427 c
->window
, _NET_WM_DESKTOP
, XCB_ATOM_CARDINAL
, 32, 1, &i
);
430 /* It doesn't have any tags, remove the property */
431 xcb_delete_property(globalconf
.connection
, c
->window
, _NET_WM_DESKTOP
);
434 /** Update the client struts.
435 * \param window The window to update the struts for.
436 * \param strut The strut type to update the window with.
439 ewmh_update_strut(xcb_window_t window
, strut_t
*strut
)
443 const uint32_t state
[] =
451 strut
->right_start_y
,
455 strut
->bottom_start_x
,
459 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
,
460 window
, _NET_WM_STRUT_PARTIAL
, XCB_ATOM_CARDINAL
, 32, countof(state
), state
);
464 /** Update the window type.
465 * \param window The window to update.
466 * \param type The new type to set.
469 ewmh_update_window_type(xcb_window_t window
, uint32_t type
)
471 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
,
472 window
, _NET_WM_WINDOW_TYPE
, XCB_ATOM_ATOM
, 32, 1, &type
);
476 ewmh_client_check_hints(client_t
*c
)
481 xcb_get_property_cookie_t c0
, c1
, c2
;
482 xcb_get_property_reply_t
*reply
;
484 /* Send the GetProperty requests which will be processed later */
485 c0
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->window
,
486 _NET_WM_DESKTOP
, XCB_GET_PROPERTY_TYPE_ANY
, 0, 1);
488 c1
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->window
,
489 _NET_WM_STATE
, XCB_ATOM_ATOM
, 0, UINT32_MAX
);
491 c2
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->window
,
492 _NET_WM_WINDOW_TYPE
, XCB_ATOM_ATOM
, 0, UINT32_MAX
);
494 reply
= xcb_get_property_reply(globalconf
.connection
, c0
, NULL
);
495 if(reply
&& reply
->value_len
&& (data
= xcb_get_property_value(reply
)))
497 desktop
= *(uint32_t *) data
;
500 else if (desktop
>= 0 && desktop
< globalconf
.tags
.len
)
501 for(int i
= 0; i
< globalconf
.tags
.len
; i
++)
504 luaA_object_push(globalconf
.L
, globalconf
.tags
.tab
[i
]);
508 untag_client(c
, globalconf
.tags
.tab
[i
]);
510 /* Value out of bounds, just give it the first tag */
511 if (globalconf
.tags
.len
> 0)
513 luaA_object_push(globalconf
.L
, globalconf
.tags
.tab
[0]);
520 reply
= xcb_get_property_reply(globalconf
.connection
, c1
, NULL
);
521 if(reply
&& (data
= xcb_get_property_value(reply
)))
523 state
= (xcb_atom_t
*) data
;
524 for(int i
= 0; i
< xcb_get_property_value_length(reply
) / ssizeof(xcb_atom_t
); i
++)
525 ewmh_process_state_atom(c
, state
[i
], _NET_WM_STATE_ADD
);
530 reply
= xcb_get_property_reply(globalconf
.connection
, c2
, NULL
);
531 if(reply
&& (data
= xcb_get_property_value(reply
)))
533 state
= (xcb_atom_t
*) data
;
534 for(int i
= 0; i
< xcb_get_property_value_length(reply
) / ssizeof(xcb_atom_t
); i
++)
535 if(state
[i
] == _NET_WM_WINDOW_TYPE_DESKTOP
)
536 c
->type
= MAX(c
->type
, WINDOW_TYPE_DESKTOP
);
537 else if(state
[i
] == _NET_WM_WINDOW_TYPE_DIALOG
)
538 c
->type
= MAX(c
->type
, WINDOW_TYPE_DIALOG
);
539 else if(state
[i
] == _NET_WM_WINDOW_TYPE_SPLASH
)
540 c
->type
= MAX(c
->type
, WINDOW_TYPE_SPLASH
);
541 else if(state
[i
] == _NET_WM_WINDOW_TYPE_DOCK
)
542 c
->type
= MAX(c
->type
, WINDOW_TYPE_DOCK
);
543 else if(state
[i
] == _NET_WM_WINDOW_TYPE_MENU
)
544 c
->type
= MAX(c
->type
, WINDOW_TYPE_MENU
);
545 else if(state
[i
] == _NET_WM_WINDOW_TYPE_TOOLBAR
)
546 c
->type
= MAX(c
->type
, WINDOW_TYPE_TOOLBAR
);
547 else if(state
[i
] == _NET_WM_WINDOW_TYPE_UTILITY
)
548 c
->type
= MAX(c
->type
, WINDOW_TYPE_UTILITY
);
554 /** Process the WM strut of a client.
555 * \param c The client.
556 * \param strut_r (Optional) An existing reply.
559 ewmh_process_client_strut(client_t
*c
)
562 xcb_get_property_reply_t
*strut_r
;
564 xcb_get_property_cookie_t strut_q
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->window
,
565 _NET_WM_STRUT_PARTIAL
, XCB_ATOM_CARDINAL
, 0, 12);
566 strut_r
= xcb_get_property_reply(globalconf
.connection
, strut_q
, NULL
);
569 && strut_r
->value_len
570 && (data
= xcb_get_property_value(strut_r
)))
572 uint32_t *strut
= data
;
574 if(c
->strut
.left
!= strut
[0]
575 || c
->strut
.right
!= strut
[1]
576 || c
->strut
.top
!= strut
[2]
577 || c
->strut
.bottom
!= strut
[3]
578 || c
->strut
.left_start_y
!= strut
[4]
579 || c
->strut
.left_end_y
!= strut
[5]
580 || c
->strut
.right_start_y
!= strut
[6]
581 || c
->strut
.right_end_y
!= strut
[7]
582 || c
->strut
.top_start_x
!= strut
[8]
583 || c
->strut
.top_end_x
!= strut
[9]
584 || c
->strut
.bottom_start_x
!= strut
[10]
585 || c
->strut
.bottom_end_x
!= strut
[11])
587 c
->strut
.left
= strut
[0];
588 c
->strut
.right
= strut
[1];
589 c
->strut
.top
= strut
[2];
590 c
->strut
.bottom
= strut
[3];
591 c
->strut
.left_start_y
= strut
[4];
592 c
->strut
.left_end_y
= strut
[5];
593 c
->strut
.right_start_y
= strut
[6];
594 c
->strut
.right_end_y
= strut
[7];
595 c
->strut
.top_start_x
= strut
[8];
596 c
->strut
.top_end_x
= strut
[9];
597 c
->strut
.bottom_start_x
= strut
[10];
598 c
->strut
.bottom_end_x
= strut
[11];
600 luaA_object_push(globalconf
.L
, c
);
601 luaA_object_emit_signal(globalconf
.L
, -1, "property::struts", 0);
602 lua_pop(globalconf
.L
, 1);
609 /** Send request to get NET_WM_ICON (EWMH)
610 * \param w The window.
611 * \return The cookie associated with the request.
613 xcb_get_property_cookie_t
614 ewmh_window_icon_get_unchecked(xcb_window_t w
)
616 return xcb_get_property_unchecked(globalconf
.connection
, false, w
,
617 _NET_WM_ICON
, XCB_ATOM_CARDINAL
, 0, UINT32_MAX
);
620 static cairo_surface_t
*
621 ewmh_window_icon_from_reply(xcb_get_property_reply_t
*r
)
626 if(!r
|| r
->type
!= XCB_ATOM_CARDINAL
|| r
->format
!= 32 || r
->length
< 2)
629 data
= (uint32_t *) xcb_get_property_value(r
);
633 /* Check that the property is as long as it should be, handling integer
634 * overflow. <uint32_t> times <another uint32_t casted to uint64_t> always
635 * fits into an uint64_t and thus this multiplication cannot overflow.
637 len
= data
[0] * (uint64_t) data
[1];
638 if (!data
[0] || !data
[1] || len
> r
->length
- 2)
641 return draw_surface_from_data(data
[0], data
[1], data
+ 2);
645 * \param cookie The cookie.
646 * \return The number of elements on stack.
649 ewmh_window_icon_get_reply(xcb_get_property_cookie_t cookie
)
651 xcb_get_property_reply_t
*r
= xcb_get_property_reply(globalconf
.connection
, cookie
, NULL
);
652 cairo_surface_t
*surface
= ewmh_window_icon_from_reply(r
);
657 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80