screen: move padding in Lua
[awesome.git] / ewmh.c
blob950f764e1b250e892ec6146660303e04d79c9bc6
1 /*
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>
23 #include <unistd.h>
25 #include <xcb/xcb.h>
26 #include <xcb/xcb_atom.h>
28 #include "ewmh.h"
29 #include "tag.h"
30 #include "screen.h"
31 #include "client.h"
32 #include "widget.h"
33 #include "wibox.h"
34 #include "common/atoms.h"
35 #include "common/buffer.h"
36 #include "common/xutil.h"
38 #define _NET_WM_STATE_REMOVE 0
39 #define _NET_WM_STATE_ADD 1
40 #define _NET_WM_STATE_TOGGLE 2
42 /** Update the desktop geometry.
43 * \param phys_screen The physical screen id.
45 static void
46 ewmh_update_desktop_geometry(int phys_screen)
48 area_t geom = screen_area_get(&globalconf.screens.tab[phys_screen],
49 NULL,
50 false);
51 uint32_t sizes[] = { geom.width, geom.height };
53 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
54 xutil_screen_get(globalconf.connection, phys_screen)->root,
55 _NET_DESKTOP_GEOMETRY, CARDINAL, 32, countof(sizes), sizes);
58 void
59 ewmh_init(int phys_screen)
61 xcb_window_t father;
62 xcb_screen_t *xscreen = xutil_screen_get(globalconf.connection, phys_screen);
63 xcb_atom_t atom[] =
65 _NET_SUPPORTED,
66 _NET_SUPPORTING_WM_CHECK,
67 _NET_STARTUP_ID,
68 _NET_CLIENT_LIST,
69 _NET_CLIENT_LIST_STACKING,
70 _NET_NUMBER_OF_DESKTOPS,
71 _NET_CURRENT_DESKTOP,
72 _NET_DESKTOP_NAMES,
73 _NET_ACTIVE_WINDOW,
74 _NET_WORKAREA,
75 _NET_DESKTOP_GEOMETRY,
76 _NET_CLOSE_WINDOW,
77 _NET_WM_NAME,
78 _NET_WM_STRUT_PARTIAL,
79 _NET_WM_ICON_NAME,
80 _NET_WM_VISIBLE_ICON_NAME,
81 _NET_WM_DESKTOP,
82 _NET_WM_WINDOW_TYPE,
83 _NET_WM_WINDOW_TYPE_DESKTOP,
84 _NET_WM_WINDOW_TYPE_DOCK,
85 _NET_WM_WINDOW_TYPE_TOOLBAR,
86 _NET_WM_WINDOW_TYPE_MENU,
87 _NET_WM_WINDOW_TYPE_UTILITY,
88 _NET_WM_WINDOW_TYPE_SPLASH,
89 _NET_WM_WINDOW_TYPE_DIALOG,
90 _NET_WM_WINDOW_TYPE_DROPDOWN_MENU,
91 _NET_WM_WINDOW_TYPE_POPUP_MENU,
92 _NET_WM_WINDOW_TYPE_TOOLTIP,
93 _NET_WM_WINDOW_TYPE_NOTIFICATION,
94 _NET_WM_WINDOW_TYPE_COMBO,
95 _NET_WM_WINDOW_TYPE_DND,
96 _NET_WM_WINDOW_TYPE_NORMAL,
97 _NET_WM_ICON,
98 _NET_WM_PID,
99 _NET_WM_STATE,
100 _NET_WM_STATE_STICKY,
101 _NET_WM_STATE_SKIP_TASKBAR,
102 _NET_WM_STATE_FULLSCREEN,
103 _NET_WM_STATE_MAXIMIZED_HORZ,
104 _NET_WM_STATE_MAXIMIZED_VERT,
105 _NET_WM_STATE_ABOVE,
106 _NET_WM_STATE_BELOW,
107 _NET_WM_STATE_MODAL,
108 _NET_WM_STATE_HIDDEN,
109 _NET_WM_STATE_DEMANDS_ATTENTION
111 int i;
113 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
114 xscreen->root, _NET_SUPPORTED, ATOM, 32,
115 countof(atom), atom);
117 /* create our own window */
118 father = xcb_generate_id(globalconf.connection);
119 xcb_create_window(globalconf.connection, xscreen->root_depth,
120 father, xscreen->root, -1, -1, 1, 1, 0,
121 XCB_COPY_FROM_PARENT, xscreen->root_visual, 0, NULL);
123 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
124 xscreen->root, _NET_SUPPORTING_WM_CHECK, WINDOW, 32,
125 1, &father);
127 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
128 father, _NET_SUPPORTING_WM_CHECK, WINDOW, 32,
129 1, &father);
131 /* set the window manager name */
132 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
133 father, _NET_WM_NAME, UTF8_STRING, 8, 7, "awesome");
135 /* set the window manager PID */
136 i = getpid();
137 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
138 father, _NET_WM_PID, CARDINAL, 32, 1, &i);
140 ewmh_update_desktop_geometry(phys_screen);
143 void
144 ewmh_update_net_client_list(int phys_screen)
146 xcb_window_t *wins = p_alloca(xcb_window_t, globalconf.clients.len);
148 int n = 0;
149 foreach(_c, globalconf.clients)
151 client_t *c = *_c;
152 if(c->phys_screen == phys_screen)
153 wins[n++] = c->win;
156 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
157 xutil_screen_get(globalconf.connection, phys_screen)->root,
158 _NET_CLIENT_LIST, WINDOW, 32, n, wins);
161 /** Set the client list in stacking order, bottom to top.
162 * \param phys_screen The physical screen id.
164 void
165 ewmh_update_net_client_list_stacking(int phys_screen)
167 int n = 0;
168 xcb_window_t *wins = p_alloca(xcb_window_t, globalconf.stack.len);
170 foreach(client, globalconf.stack)
171 if((*client)->phys_screen == phys_screen)
172 wins[n++] = (*client)->win;
174 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
175 xutil_screen_get(globalconf.connection, phys_screen)->root,
176 _NET_CLIENT_LIST_STACKING, WINDOW, 32, n, wins);
179 void
180 ewmh_update_net_numbers_of_desktop(int phys_screen)
182 uint32_t count = globalconf.screens.tab[phys_screen].tags.len;
184 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
185 xutil_screen_get(globalconf.connection, phys_screen)->root,
186 _NET_NUMBER_OF_DESKTOPS, CARDINAL, 32, 1, &count);
189 void
190 ewmh_update_net_current_desktop(int phys_screen)
192 tag_array_t *tags = &globalconf.screens.tab[phys_screen].tags;
193 uint32_t count = 0;
194 tag_t **curtags = tags_get_current( &globalconf.screens.tab[phys_screen]);
196 while(count < (uint32_t) tags->len && tags->tab[count] != curtags[0])
197 count++;
199 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
200 xutil_screen_get(globalconf.connection, phys_screen)->root,
201 _NET_CURRENT_DESKTOP, CARDINAL, 32, 1, &count);
203 p_delete(&curtags);
206 void
207 ewmh_update_net_desktop_names(int phys_screen)
209 tag_array_t *tags = &globalconf.screens.tab[phys_screen].tags;
210 buffer_t buf;
212 buffer_inita(&buf, BUFSIZ);
214 for(int i = 0; i < tags->len; i++)
216 buffer_adds(&buf, tags->tab[i]->name);
217 buffer_addc(&buf, '\0');
220 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
221 xutil_screen_get(globalconf.connection, phys_screen)->root,
222 _NET_DESKTOP_NAMES, UTF8_STRING, 8, buf.len, buf.s);
223 buffer_wipe(&buf);
226 /** Update the work area space for each physical screen and each desktop.
227 * \param phys_screen The physical screen id.
229 void
230 ewmh_update_workarea(int phys_screen)
232 tag_array_t *tags = &globalconf.screens.tab[phys_screen].tags;
233 uint32_t *area = p_alloca(uint32_t, tags->len * 4);
234 area_t geom = screen_area_get(&globalconf.screens.tab[phys_screen],
235 &globalconf.screens.tab[phys_screen].wiboxes,
236 true);
239 for(int i = 0; i < tags->len; i++)
241 area[4 * i + 0] = geom.x;
242 area[4 * i + 1] = geom.y;
243 area[4 * i + 2] = geom.width;
244 area[4 * i + 3] = geom.height;
247 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
248 xutil_screen_get(globalconf.connection, phys_screen)->root,
249 _NET_WORKAREA, CARDINAL, 32, tags->len * 4, area);
252 void
253 ewmh_update_net_active_window(int phys_screen)
255 xcb_window_t win;
257 if(globalconf.screen_focus->client_focus
258 && globalconf.screen_focus->client_focus->phys_screen == phys_screen)
259 win = globalconf.screen_focus->client_focus->win;
260 else
261 win = XCB_NONE;
263 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
264 xutil_screen_get(globalconf.connection, phys_screen)->root,
265 _NET_ACTIVE_WINDOW, WINDOW, 32, 1, &win);
268 static void
269 ewmh_process_state_atom(client_t *c, xcb_atom_t state, int set)
271 if(state == _NET_WM_STATE_STICKY)
273 if(set == _NET_WM_STATE_REMOVE)
274 client_setsticky(c, false);
275 else if(set == _NET_WM_STATE_ADD)
276 client_setsticky(c, true);
277 else if(set == _NET_WM_STATE_TOGGLE)
278 client_setsticky(c, !c->issticky);
280 else if(state == _NET_WM_STATE_SKIP_TASKBAR)
282 if(set == _NET_WM_STATE_REMOVE)
284 c->skiptb = false;
285 ewmh_client_update_hints(c);
287 else if(set == _NET_WM_STATE_ADD)
289 c->skiptb = true;
290 ewmh_client_update_hints(c);
292 else if(set == _NET_WM_STATE_TOGGLE)
294 c->skiptb = !c->skiptb;
295 ewmh_client_update_hints(c);
298 else if(state == _NET_WM_STATE_FULLSCREEN)
300 if(set == _NET_WM_STATE_REMOVE)
301 client_setfullscreen(c, false);
302 else if(set == _NET_WM_STATE_ADD)
303 client_setfullscreen(c, true);
304 else if(set == _NET_WM_STATE_TOGGLE)
305 client_setfullscreen(c, !c->isfullscreen);
307 else if(state == _NET_WM_STATE_MAXIMIZED_HORZ)
309 if(set == _NET_WM_STATE_REMOVE)
310 client_setmaxhoriz(c, false);
311 else if(set == _NET_WM_STATE_ADD)
312 client_setmaxhoriz(c, true);
313 else if(set == _NET_WM_STATE_TOGGLE)
314 client_setmaxhoriz(c, !c->ismaxhoriz);
316 else if(state == _NET_WM_STATE_MAXIMIZED_VERT)
318 if(set == _NET_WM_STATE_REMOVE)
319 client_setmaxvert(c, false);
320 else if(set == _NET_WM_STATE_ADD)
321 client_setmaxvert(c, true);
322 else if(set == _NET_WM_STATE_TOGGLE)
323 client_setmaxvert(c, !c->ismaxvert);
325 else if(state == _NET_WM_STATE_ABOVE)
327 if(set == _NET_WM_STATE_REMOVE)
328 client_setabove(c, false);
329 else if(set == _NET_WM_STATE_ADD)
330 client_setabove(c, true);
331 else if(set == _NET_WM_STATE_TOGGLE)
332 client_setabove(c, !c->isabove);
334 else if(state == _NET_WM_STATE_BELOW)
336 if(set == _NET_WM_STATE_REMOVE)
337 client_setbelow(c, false);
338 else if(set == _NET_WM_STATE_ADD)
339 client_setbelow(c, true);
340 else if(set == _NET_WM_STATE_TOGGLE)
341 client_setbelow(c, !c->isbelow);
343 else if(state == _NET_WM_STATE_MODAL)
345 if(set == _NET_WM_STATE_REMOVE)
346 client_setmodal(c, false);
347 else if(set == _NET_WM_STATE_ADD)
348 client_setmodal(c, true);
349 else if(set == _NET_WM_STATE_TOGGLE)
350 client_setmodal(c, !c->ismodal);
352 else if(state == _NET_WM_STATE_HIDDEN)
354 if(set == _NET_WM_STATE_REMOVE)
355 client_setminimized(c, false);
356 else if(set == _NET_WM_STATE_ADD)
357 client_setminimized(c, true);
358 else if(set == _NET_WM_STATE_TOGGLE)
359 client_setminimized(c, !c->isminimized);
361 else if(state == _NET_WM_STATE_DEMANDS_ATTENTION)
363 if(set == _NET_WM_STATE_REMOVE)
364 client_seturgent(c, false);
365 else if(set == _NET_WM_STATE_ADD)
366 client_seturgent(c, true);
367 else if(set == _NET_WM_STATE_TOGGLE)
368 client_seturgent(c, !c->isurgent);
373 ewmh_process_client_message(xcb_client_message_event_t *ev)
375 client_t *c;
376 int screen;
378 if(ev->type == _NET_CURRENT_DESKTOP)
379 for(screen = 0;
380 screen < xcb_setup_roots_length(xcb_get_setup(globalconf.connection));
381 screen++)
383 if(ev->window == xutil_screen_get(globalconf.connection, screen)->root)
384 tag_view_only_byindex(&globalconf.screens.tab[screen], ev->data.data32[0]);
386 else if(ev->type == _NET_CLOSE_WINDOW)
388 if((c = client_getbywin(ev->window)))
389 client_kill(c);
391 else if(ev->type == _NET_WM_DESKTOP)
393 if((c = client_getbywin(ev->window)))
395 tag_array_t *tags = &c->screen->tags;
397 if(ev->data.data32[0] == 0xffffffff)
398 c->issticky = true;
399 else
400 for(int i = 0; i < tags->len; i++)
401 if((int)ev->data.data32[0] == i)
403 tag_push(globalconf.L, tags->tab[i]);
404 tag_client(c);
406 else
407 untag_client(c, tags->tab[i]);
410 else if(ev->type == _NET_WM_STATE)
412 if((c = client_getbywin(ev->window)))
414 ewmh_process_state_atom(c, (xcb_atom_t) ev->data.data32[1], ev->data.data32[0]);
415 if(ev->data.data32[2])
416 ewmh_process_state_atom(c, (xcb_atom_t) ev->data.data32[2],
417 ev->data.data32[0]);
420 else if(ev->type == _NET_ACTIVE_WINDOW)
422 if((c = client_getbywin(ev->window)))
423 client_focus(c);
426 return 0;
429 /** Update client EWMH hints.
430 * \param c The client.
432 void
433 ewmh_client_update_hints(client_t *c)
435 xcb_atom_t state[10]; /* number of defined state atoms */
436 int i = 0;
438 if(c->ismodal)
439 state[i++] = _NET_WM_STATE_MODAL;
440 if(c->isfullscreen)
441 state[i++] = _NET_WM_STATE_FULLSCREEN;
442 if(c->ismaxvert)
443 state[i++] = _NET_WM_STATE_MAXIMIZED_VERT;
444 if(c->ismaxhoriz)
445 state[i++] = _NET_WM_STATE_MAXIMIZED_HORZ;
446 if(c->issticky)
447 state[i++] = _NET_WM_STATE_STICKY;
448 if(c->skiptb)
449 state[i++] = _NET_WM_STATE_SKIP_TASKBAR;
450 if(c->isabove)
451 state[i++] = _NET_WM_STATE_ABOVE;
452 if(c->isbelow)
453 state[i++] = _NET_WM_STATE_BELOW;
454 if(c->isminimized)
455 state[i++] = _NET_WM_STATE_HIDDEN;
456 if(c->isurgent)
457 state[i++] = _NET_WM_STATE_DEMANDS_ATTENTION;
459 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
460 c->win, _NET_WM_STATE, ATOM, 32, i, state);
463 /** Update the client active desktop.
464 * This is "wrong" since it can be on several tags, but EWMH has a strict view
465 * of desktop system so just take the first tag.
466 * \param c The client.
468 void
469 ewmh_client_update_desktop(client_t *c)
471 int i;
472 tag_array_t *tags = &c->screen->tags;
474 for(i = 0; i < tags->len; i++)
475 if(is_client_tagged(c, tags->tab[i]))
477 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
478 c->win, _NET_WM_DESKTOP, CARDINAL, 32, 1, &i);
479 return;
483 /** Update the client struts.
484 * \param c The client.
486 void
487 ewmh_update_client_strut(client_t *c)
489 uint32_t state[] =
491 c->strut.left,
492 c->strut.right,
493 c->strut.top,
494 c->strut.bottom,
495 c->strut.left_start_y,
496 c->strut.left_end_y,
497 c->strut.right_start_y,
498 c->strut.right_end_y,
499 c->strut.top_start_x,
500 c->strut.top_end_x,
501 c->strut.bottom_start_x,
502 c->strut.bottom_end_x
505 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
506 c->win, _NET_WM_STRUT_PARTIAL, CARDINAL, 32, countof(state), state);
509 void
510 ewmh_client_check_hints(client_t *c)
512 xcb_atom_t *state;
513 void *data = NULL;
514 int desktop;
515 xcb_get_property_cookie_t c0, c1, c2;
516 xcb_get_property_reply_t *reply;
518 /* Send the GetProperty requests which will be processed later */
519 c0 = xcb_get_property_unchecked(globalconf.connection, false, c->win,
520 _NET_WM_DESKTOP, XCB_GET_PROPERTY_TYPE_ANY, 0, 1);
522 c1 = xcb_get_property_unchecked(globalconf.connection, false, c->win,
523 _NET_WM_STATE, ATOM, 0, UINT32_MAX);
525 c2 = xcb_get_property_unchecked(globalconf.connection, false, c->win,
526 _NET_WM_WINDOW_TYPE, ATOM, 0, UINT32_MAX);
528 reply = xcb_get_property_reply(globalconf.connection, c0, NULL);
529 if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
531 tag_array_t *tags = &c->screen->tags;
533 desktop = *(uint32_t *) data;
534 if(desktop == -1)
535 c->issticky = true;
536 else
537 for(int i = 0; i < tags->len; i++)
538 if(desktop == i)
540 tag_push(globalconf.L, tags->tab[i]);
541 tag_client(c);
543 else
544 untag_client(c, tags->tab[i]);
547 p_delete(&reply);
549 reply = xcb_get_property_reply(globalconf.connection, c1, NULL);
550 if(reply && (data = xcb_get_property_value(reply)))
552 state = (xcb_atom_t *) data;
553 for(int i = 0; i < xcb_get_property_value_length(reply); i++)
554 ewmh_process_state_atom(c, state[i], _NET_WM_STATE_ADD);
557 p_delete(&reply);
559 reply = xcb_get_property_reply(globalconf.connection, c2, NULL);
560 if(reply && (data = xcb_get_property_value(reply)))
562 state = (xcb_atom_t *) data;
563 for(int i = 0; i < xcb_get_property_value_length(reply); i++)
564 if(state[i] == _NET_WM_WINDOW_TYPE_DESKTOP)
565 c->type = MAX(c->type, WINDOW_TYPE_DESKTOP);
566 else if(state[i] == _NET_WM_WINDOW_TYPE_DIALOG)
567 c->type = MAX(c->type, WINDOW_TYPE_DIALOG);
568 else if(state[i] == _NET_WM_WINDOW_TYPE_SPLASH)
569 c->type = MAX(c->type, WINDOW_TYPE_SPLASH);
570 else if(state[i] == _NET_WM_WINDOW_TYPE_DOCK)
571 c->type = MAX(c->type, WINDOW_TYPE_DOCK);
572 else if(state[i] == _NET_WM_WINDOW_TYPE_MENU)
573 c->type = MAX(c->type, WINDOW_TYPE_MENU);
574 else if(state[i] == _NET_WM_WINDOW_TYPE_TOOLBAR)
575 c->type = MAX(c->type, WINDOW_TYPE_TOOLBAR);
576 else if(state[i] == _NET_WM_WINDOW_TYPE_UTILITY)
577 c->type = MAX(c->type, WINDOW_TYPE_UTILITY);
579 if(c->type != WINDOW_TYPE_NORMAL
580 && c->type != WINDOW_TYPE_DESKTOP
581 && !c->transient_for)
582 client_setabove(c, true);
585 p_delete(&reply);
588 /** Process the WM strut of a client.
589 * \param c The client.
591 void
592 ewmh_process_client_strut(client_t *c, xcb_get_property_reply_t *strut_r)
594 void *data;
595 xcb_get_property_reply_t *mstrut_r = NULL;
597 if(!strut_r)
599 xcb_get_property_cookie_t strut_q = xcb_get_property_unchecked(globalconf.connection, false, c->win,
600 _NET_WM_STRUT_PARTIAL, CARDINAL, 0, 12);
601 strut_r = mstrut_r = xcb_get_property_reply(globalconf.connection, strut_q, NULL);
604 if(strut_r
605 && strut_r->value_len
606 && (data = xcb_get_property_value(strut_r)))
608 uint32_t *strut = data;
610 if(c->strut.left != strut[0]
611 || c->strut.right != strut[1]
612 || c->strut.top != strut[2]
613 || c->strut.bottom != strut[3]
614 || c->strut.left_start_y != strut[4]
615 || c->strut.left_end_y != strut[5]
616 || c->strut.right_start_y != strut[6]
617 || c->strut.right_end_y != strut[7]
618 || c->strut.top_start_x != strut[8]
619 || c->strut.top_end_x != strut[9]
620 || c->strut.bottom_start_x != strut[10]
621 || c->strut.bottom_end_x != strut[11])
623 c->strut.left = strut[0];
624 c->strut.right = strut[1];
625 c->strut.top = strut[2];
626 c->strut.bottom = strut[3];
627 c->strut.left_start_y = strut[4];
628 c->strut.left_end_y = strut[5];
629 c->strut.right_start_y = strut[6];
630 c->strut.right_end_y = strut[7];
631 c->strut.top_start_x = strut[8];
632 c->strut.top_end_x = strut[9];
633 c->strut.bottom_start_x = strut[10];
634 c->strut.bottom_end_x = strut[11];
636 client_need_arrange(c);
637 /* All the wiboxes (may) need to be repositioned. */
638 wibox_update_positions();
640 hook_property(client, c, "struts");
644 p_delete(&mstrut_r);
647 /** Send request to get NET_WM_ICON (EWMH)
648 * \param w The window.
649 * \return The cookie associated with the request.
651 xcb_get_property_cookie_t
652 ewmh_window_icon_get_unchecked(xcb_window_t w)
654 return xcb_get_property_unchecked(globalconf.connection, false, w,
655 _NET_WM_ICON, CARDINAL, 0, UINT32_MAX);
659 ewmh_window_icon_from_reply(xcb_get_property_reply_t *r)
661 uint32_t *data;
662 uint64_t len;
664 if(!r || r->type != CARDINAL || r->format != 32 || r->length < 2)
665 return 0;
667 data = (uint32_t *) xcb_get_property_value(r);
668 if (!data)
669 return 0;
671 /* Check that the property is as long as it should be, handling integer
672 * overflow. <uint32_t> times <another uint32_t casted to uint64_t> always
673 * fits into an uint64_t and thus this multiplication cannot overflow.
675 len = data[0] * (uint64_t) data[1];
676 if (!data[0] || !data[1] || len > r->length - 2)
677 return 0;
679 return image_new_from_argb32(data[0], data[1], data + 2);
682 /** Get NET_WM_ICON.
683 * \param cookie The cookie.
684 * \return The number of elements on stack.
687 ewmh_window_icon_get_reply(xcb_get_property_cookie_t cookie)
689 xcb_get_property_reply_t *r = xcb_get_property_reply(globalconf.connection, cookie, NULL);
690 int ret = ewmh_window_icon_from_reply(r);
691 p_delete(&r);
692 return ret;
695 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80