Only set client's urgent after startup
[awesome.git] / ewmh.c
blobdaf0d69230211409fc0fb3c0add5db0b759fc69a
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 "objects/tag.h"
30 #include "screen.h"
31 #include "objects/client.h"
32 #include "luaa.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.
44 static int
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 */
49 int i = 0;
51 if(c->modal)
52 state[i++] = _NET_WM_STATE_MODAL;
53 if(c->fullscreen)
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;
59 if(c->sticky)
60 state[i++] = _NET_WM_STATE_STICKY;
61 if(c->skip_taskbar)
62 state[i++] = _NET_WM_STATE_SKIP_TASKBAR;
63 if(c->above)
64 state[i++] = _NET_WM_STATE_ABOVE;
65 if(c->below)
66 state[i++] = _NET_WM_STATE_BELOW;
67 if(c->minimized)
68 state[i++] = _NET_WM_STATE_HIDDEN;
69 if(c->urgent)
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);
75 return 0;
78 static int
79 ewmh_update_net_active_window(lua_State *L)
81 xcb_window_t win;
83 if(globalconf.focus.client)
84 win = globalconf.focus.client->window;
85 else
86 win = XCB_NONE;
88 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
89 globalconf.screen->root,
90 _NET_ACTIVE_WINDOW, XCB_ATOM_WINDOW, 32, 1, &win);
92 return 0;
95 static int
96 ewmh_update_net_client_list(lua_State *L)
98 xcb_window_t *wins = p_alloca(xcb_window_t, globalconf.clients.len);
100 int n = 0;
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);
108 return 0;
111 void
112 ewmh_init(void)
114 xcb_window_t father;
115 xcb_screen_t *xscreen = globalconf.screen;
116 xcb_atom_t atom[] =
118 _NET_SUPPORTED,
119 _NET_SUPPORTING_WM_CHECK,
120 _NET_STARTUP_ID,
121 _NET_CLIENT_LIST,
122 _NET_CLIENT_LIST_STACKING,
123 _NET_NUMBER_OF_DESKTOPS,
124 _NET_CURRENT_DESKTOP,
125 _NET_DESKTOP_NAMES,
126 _NET_ACTIVE_WINDOW,
127 _NET_CLOSE_WINDOW,
128 _NET_WM_NAME,
129 _NET_WM_STRUT_PARTIAL,
130 _NET_WM_ICON_NAME,
131 _NET_WM_VISIBLE_ICON_NAME,
132 _NET_WM_DESKTOP,
133 _NET_WM_WINDOW_TYPE,
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,
148 _NET_WM_ICON,
149 _NET_WM_PID,
150 _NET_WM_STATE,
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,
156 _NET_WM_STATE_ABOVE,
157 _NET_WM_STATE_BELOW,
158 _NET_WM_STATE_MODAL,
159 _NET_WM_STATE_HIDDEN,
160 _NET_WM_STATE_DEMANDS_ATTENTION
162 int i;
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,
176 1, &father);
178 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
179 father, _NET_SUPPORTING_WM_CHECK, XCB_ATOM_WINDOW, 32,
180 1, &father);
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 */
187 i = getpid();
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.
210 void
211 ewmh_update_net_client_list_stacking(void)
213 int n = 0;
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);
224 void
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);
234 void
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);
244 void
245 ewmh_update_net_desktop_names(void)
247 buffer_t buf;
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);
260 buffer_wipe(&buf);
263 static void
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)
365 client_t *c;
367 if(ev->type == _NET_CURRENT_DESKTOP)
369 int idx = ev->data.data32[0];
370 if (idx >= 0 && idx < globalconf.tags.len)
372 luaA_object_push(globalconf.L, globalconf.tags.tab[idx]);
373 luaA_object_emit_signal(globalconf.L, -1, "request::select", 0);
374 lua_pop(globalconf.L, 1);
377 else if(ev->type == _NET_CLOSE_WINDOW)
379 if((c = client_getbywin(ev->window)))
380 client_kill(c);
382 else if(ev->type == _NET_WM_DESKTOP)
384 if((c = client_getbywin(ev->window)))
386 if(ev->data.data32[0] == 0xffffffff)
387 c->sticky = true;
388 else
389 for(int i = 0; i < globalconf.tags.len; i++)
390 if((int)ev->data.data32[0] == i)
392 luaA_object_push(globalconf.L, globalconf.tags.tab[i]);
393 tag_client(c);
395 else
396 untag_client(c, globalconf.tags.tab[i]);
399 else if(ev->type == _NET_WM_STATE)
401 if((c = client_getbywin(ev->window)))
403 ewmh_process_state_atom(c, (xcb_atom_t) ev->data.data32[1], ev->data.data32[0]);
404 if(ev->data.data32[2])
405 ewmh_process_state_atom(c, (xcb_atom_t) ev->data.data32[2],
406 ev->data.data32[0]);
409 else if(ev->type == _NET_ACTIVE_WINDOW)
411 if((c = client_getbywin(ev->window))) {
412 luaA_object_push(globalconf.L, c);
413 luaA_object_emit_signal(globalconf.L, -1, "request::activate", 0);
414 lua_pop(globalconf.L, 1);
418 return 0;
421 /** Update the client active desktop.
422 * This is "wrong" since it can be on several tags, but EWMH has a strict view
423 * of desktop system so just take the first tag.
424 * \param c The client.
426 void
427 ewmh_client_update_desktop(client_t *c)
429 int i;
431 for(i = 0; i < globalconf.tags.len; i++)
432 if(is_client_tagged(c, globalconf.tags.tab[i]))
434 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
435 c->window, _NET_WM_DESKTOP, XCB_ATOM_CARDINAL, 32, 1, &i);
436 return;
438 /* It doesn't have any tags, remove the property */
439 xcb_delete_property(globalconf.connection, c->window, _NET_WM_DESKTOP);
442 /** Update the client struts.
443 * \param window The window to update the struts for.
444 * \param strut The strut type to update the window with.
446 void
447 ewmh_update_strut(xcb_window_t window, strut_t *strut)
449 if(window)
451 const uint32_t state[] =
453 strut->left,
454 strut->right,
455 strut->top,
456 strut->bottom,
457 strut->left_start_y,
458 strut->left_end_y,
459 strut->right_start_y,
460 strut->right_end_y,
461 strut->top_start_x,
462 strut->top_end_x,
463 strut->bottom_start_x,
464 strut->bottom_end_x
467 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
468 window, _NET_WM_STRUT_PARTIAL, XCB_ATOM_CARDINAL, 32, countof(state), state);
472 /** Update the window type.
473 * \param window The window to update.
474 * \param type The new type to set.
476 void
477 ewmh_update_window_type(xcb_window_t window, uint32_t type)
479 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
480 window, _NET_WM_WINDOW_TYPE, XCB_ATOM_ATOM, 32, 1, &type);
483 void
484 ewmh_client_check_hints(client_t *c)
486 xcb_atom_t *state;
487 void *data = NULL;
488 int desktop;
489 xcb_get_property_cookie_t c0, c1, c2;
490 xcb_get_property_reply_t *reply;
492 /* Send the GetProperty requests which will be processed later */
493 c0 = xcb_get_property_unchecked(globalconf.connection, false, c->window,
494 _NET_WM_DESKTOP, XCB_GET_PROPERTY_TYPE_ANY, 0, 1);
496 c1 = xcb_get_property_unchecked(globalconf.connection, false, c->window,
497 _NET_WM_STATE, XCB_ATOM_ATOM, 0, UINT32_MAX);
499 c2 = xcb_get_property_unchecked(globalconf.connection, false, c->window,
500 _NET_WM_WINDOW_TYPE, XCB_ATOM_ATOM, 0, UINT32_MAX);
502 reply = xcb_get_property_reply(globalconf.connection, c0, NULL);
503 if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
505 desktop = *(uint32_t *) data;
506 if(desktop == -1)
507 c->sticky = true;
508 else if (desktop >= 0 && desktop < globalconf.tags.len)
509 for(int i = 0; i < globalconf.tags.len; i++)
510 if(desktop == i)
512 luaA_object_push(globalconf.L, globalconf.tags.tab[i]);
513 tag_client(c);
515 else
516 untag_client(c, globalconf.tags.tab[i]);
517 else
518 /* Value out of bounds, just give it the first tag */
519 if (globalconf.tags.len > 0)
521 luaA_object_push(globalconf.L, globalconf.tags.tab[0]);
522 tag_client(c);
526 p_delete(&reply);
528 reply = xcb_get_property_reply(globalconf.connection, c1, NULL);
529 if(reply && (data = xcb_get_property_value(reply)))
531 state = (xcb_atom_t *) data;
532 for(int i = 0; i < xcb_get_property_value_length(reply) / ssizeof(xcb_atom_t); i++)
533 ewmh_process_state_atom(c, state[i], _NET_WM_STATE_ADD);
536 p_delete(&reply);
538 reply = xcb_get_property_reply(globalconf.connection, c2, NULL);
539 if(reply && (data = xcb_get_property_value(reply)))
541 state = (xcb_atom_t *) data;
542 for(int i = 0; i < xcb_get_property_value_length(reply) / ssizeof(xcb_atom_t); i++)
543 if(state[i] == _NET_WM_WINDOW_TYPE_DESKTOP)
544 c->type = MAX(c->type, WINDOW_TYPE_DESKTOP);
545 else if(state[i] == _NET_WM_WINDOW_TYPE_DIALOG)
546 c->type = MAX(c->type, WINDOW_TYPE_DIALOG);
547 else if(state[i] == _NET_WM_WINDOW_TYPE_SPLASH)
548 c->type = MAX(c->type, WINDOW_TYPE_SPLASH);
549 else if(state[i] == _NET_WM_WINDOW_TYPE_DOCK)
550 c->type = MAX(c->type, WINDOW_TYPE_DOCK);
551 else if(state[i] == _NET_WM_WINDOW_TYPE_MENU)
552 c->type = MAX(c->type, WINDOW_TYPE_MENU);
553 else if(state[i] == _NET_WM_WINDOW_TYPE_TOOLBAR)
554 c->type = MAX(c->type, WINDOW_TYPE_TOOLBAR);
555 else if(state[i] == _NET_WM_WINDOW_TYPE_UTILITY)
556 c->type = MAX(c->type, WINDOW_TYPE_UTILITY);
559 p_delete(&reply);
562 /** Process the WM strut of a client.
563 * \param c The client.
564 * \param strut_r (Optional) An existing reply.
566 void
567 ewmh_process_client_strut(client_t *c)
569 void *data;
570 xcb_get_property_reply_t *strut_r;
572 xcb_get_property_cookie_t strut_q = xcb_get_property_unchecked(globalconf.connection, false, c->window,
573 _NET_WM_STRUT_PARTIAL, XCB_ATOM_CARDINAL, 0, 12);
574 strut_r = xcb_get_property_reply(globalconf.connection, strut_q, NULL);
576 if(strut_r
577 && strut_r->value_len
578 && (data = xcb_get_property_value(strut_r)))
580 uint32_t *strut = data;
582 if(c->strut.left != strut[0]
583 || c->strut.right != strut[1]
584 || c->strut.top != strut[2]
585 || c->strut.bottom != strut[3]
586 || c->strut.left_start_y != strut[4]
587 || c->strut.left_end_y != strut[5]
588 || c->strut.right_start_y != strut[6]
589 || c->strut.right_end_y != strut[7]
590 || c->strut.top_start_x != strut[8]
591 || c->strut.top_end_x != strut[9]
592 || c->strut.bottom_start_x != strut[10]
593 || c->strut.bottom_end_x != strut[11])
595 c->strut.left = strut[0];
596 c->strut.right = strut[1];
597 c->strut.top = strut[2];
598 c->strut.bottom = strut[3];
599 c->strut.left_start_y = strut[4];
600 c->strut.left_end_y = strut[5];
601 c->strut.right_start_y = strut[6];
602 c->strut.right_end_y = strut[7];
603 c->strut.top_start_x = strut[8];
604 c->strut.top_end_x = strut[9];
605 c->strut.bottom_start_x = strut[10];
606 c->strut.bottom_end_x = strut[11];
608 luaA_object_push(globalconf.L, c);
609 luaA_object_emit_signal(globalconf.L, -1, "property::struts", 0);
610 lua_pop(globalconf.L, 1);
614 p_delete(&strut_r);
617 /** Send request to get NET_WM_ICON (EWMH)
618 * \param w The window.
619 * \return The cookie associated with the request.
621 xcb_get_property_cookie_t
622 ewmh_window_icon_get_unchecked(xcb_window_t w)
624 return xcb_get_property_unchecked(globalconf.connection, false, w,
625 _NET_WM_ICON, XCB_ATOM_CARDINAL, 0, UINT32_MAX);
628 static cairo_surface_t *
629 ewmh_window_icon_from_reply(xcb_get_property_reply_t *r)
631 uint32_t *data;
632 uint64_t len;
634 if(!r || r->type != XCB_ATOM_CARDINAL || r->format != 32 || r->length < 2)
635 return 0;
637 data = (uint32_t *) xcb_get_property_value(r);
638 if (!data)
639 return 0;
641 /* Check that the property is as long as it should be, handling integer
642 * overflow. <uint32_t> times <another uint32_t casted to uint64_t> always
643 * fits into an uint64_t and thus this multiplication cannot overflow.
645 len = data[0] * (uint64_t) data[1];
646 if (!data[0] || !data[1] || len > r->length - 2)
647 return 0;
649 return draw_surface_from_data(data[0], data[1], data + 2);
652 /** Get NET_WM_ICON.
653 * \param cookie The cookie.
654 * \return The number of elements on stack.
656 cairo_surface_t *
657 ewmh_window_icon_get_reply(xcb_get_property_cookie_t cookie)
659 xcb_get_property_reply_t *r = xcb_get_property_reply(globalconf.connection, cookie, NULL);
660 cairo_surface_t *surface = ewmh_window_icon_from_reply(r);
661 p_delete(&r);
662 return surface;
665 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80