2 * property.c - property handlers
4 * Copyright © 2008-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 <xcb/xcb_atom.h>
31 #include "common/atoms.h"
32 #include "common/xutil.h"
35 #define HANDLE_TEXT_PROPERTY(funcname, atom, setfunc) \
37 property_update_##funcname(client_t *c, xcb_get_property_reply_t *reply) \
39 bool no_reply = !reply; \
41 reply = xcb_get_property_reply(globalconf.connection, \
42 xcb_get_any_property(globalconf.connection, \
47 luaA_object_push(globalconf.L, c); \
48 setfunc(globalconf.L, -1, xutil_get_text_property_from_reply(reply)); \
49 lua_pop(globalconf.L, 1); \
54 property_handle_##funcname(void *data, \
55 xcb_connection_t *connection, \
57 xcb_window_t window, \
59 xcb_get_property_reply_t *reply) \
61 client_t *c = client_getbywin(window); \
63 property_update_##funcname(c, reply); \
68 HANDLE_TEXT_PROPERTY(wm_name
, WM_NAME
, client_set_name
)
69 HANDLE_TEXT_PROPERTY(wm_icon_name
, WM_ICON_NAME
, client_set_icon_name
)
70 HANDLE_TEXT_PROPERTY(wm_client_machine
, WM_CLIENT_MACHINE
, client_set_machine
)
71 HANDLE_TEXT_PROPERTY(wm_window_role
, WM_WINDOW_ROLE
, client_set_role
)
73 #undef HANDLE_TEXT_PROPERTY
75 #define HANDLE_PROPERTY(name) \
77 property_handle_##name(void *data, \
78 xcb_connection_t *connection, \
80 xcb_window_t window, \
82 xcb_get_property_reply_t *reply) \
84 client_t *c = client_getbywin(window); \
86 property_update_##name(c, reply); \
90 HANDLE_PROPERTY(wm_protocols
)
91 HANDLE_PROPERTY(wm_transient_for
)
92 HANDLE_PROPERTY(wm_client_leader
)
93 HANDLE_PROPERTY(wm_normal_hints
)
94 HANDLE_PROPERTY(wm_hints
)
95 HANDLE_PROPERTY(wm_class
)
96 HANDLE_PROPERTY(net_wm_icon
)
97 HANDLE_PROPERTY(net_wm_pid
)
99 #undef HANDLE_PROPERTY
102 property_update_wm_transient_for(client_t
*c
, xcb_get_property_reply_t
*reply
)
108 if(!xcb_get_wm_transient_for_from_reply(&trans
, reply
))
113 if(!xcb_get_wm_transient_for_reply(globalconf
.connection
,
114 xcb_get_wm_transient_for_unchecked(globalconf
.connection
,
120 luaA_object_push(globalconf
.L
, c
);
121 client_set_type(globalconf
.L
, -1, WINDOW_TYPE_DIALOG
);
122 client_set_above(globalconf
.L
, -1, false);
123 client_set_transient_for(globalconf
.L
, -1, client_getbywin(trans
));
124 lua_pop(globalconf
.L
, 1);
127 /** Update leader hint of a client.
128 * \param c The client.
129 * \param reply (Optional) An existing reply.
132 property_update_wm_client_leader(client_t
*c
, xcb_get_property_reply_t
*reply
)
134 xcb_get_property_cookie_t client_leader_q
;
136 bool no_reply
= !reply
;
140 client_leader_q
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->window
,
141 WM_CLIENT_LEADER
, WINDOW
, 0, 32);
143 reply
= xcb_get_property_reply(globalconf
.connection
, client_leader_q
, NULL
);
146 if(reply
&& reply
->value_len
&& (data
= xcb_get_property_value(reply
)))
147 c
->leader_window
= *(xcb_window_t
*) data
;
149 /* Only free when we created a reply ourselves. */
154 /** Update the size hints of a client.
155 * \param c The client.
156 * \param reply (Optional) An existing reply.
159 property_update_wm_normal_hints(client_t
*c
, xcb_get_property_reply_t
*reply
)
163 if(!xcb_get_wm_size_hints_from_reply(&c
->size_hints
, reply
))
168 if(!xcb_get_wm_normal_hints_reply(globalconf
.connection
,
169 xcb_get_wm_normal_hints_unchecked(globalconf
.connection
,
171 &c
->size_hints
, NULL
))
176 /** Update the WM hints of a client.
177 * \param c The client.
178 * \param reply (Optional) An existing reply.
181 property_update_wm_hints(client_t
*c
, xcb_get_property_reply_t
*reply
)
187 if(!xcb_get_wm_hints_from_reply(&wmh
, reply
))
192 if(!xcb_get_wm_hints_reply(globalconf
.connection
,
193 xcb_get_wm_hints_unchecked(globalconf
.connection
, c
->window
),
198 luaA_object_push(globalconf
.L
, c
);
199 client_set_urgent(globalconf
.L
, -1, xcb_wm_hints_get_urgency(&wmh
));
200 if(wmh
.flags
& XCB_WM_HINT_STATE
&&
201 wmh
.initial_state
== XCB_WM_STATE_WITHDRAWN
)
202 client_set_border_width(globalconf
.L
, -1, 0);
204 if(wmh
.flags
& XCB_WM_HINT_INPUT
)
205 c
->nofocus
= !wmh
.input
;
207 if(wmh
.flags
& XCB_WM_HINT_WINDOW_GROUP
)
208 client_set_group_window(globalconf
.L
, -1, wmh
.window_group
);
211 /** Update WM_CLASS of a client.
212 * \param c The client.
213 * \param reply The reply to get property request, or NULL if none.
216 property_update_wm_class(client_t
*c
, xcb_get_property_reply_t
*reply
)
218 xcb_get_wm_class_reply_t hint
;
222 if(!xcb_get_wm_class_from_reply(&hint
, reply
))
227 if(!xcb_get_wm_class_reply(globalconf
.connection
,
228 xcb_get_wm_class_unchecked(globalconf
.connection
, c
->window
),
233 luaA_object_push(globalconf
.L
, c
);
234 client_set_class_instance(globalconf
.L
, -1, hint
.instance_name
, hint
.class_name
);
235 lua_pop(globalconf
.L
, 1);
237 /* only delete reply if we get it ourselves */
239 xcb_get_wm_class_reply_wipe(&hint
);
243 property_handle_net_wm_strut_partial(void *data
,
244 xcb_connection_t
*connection
,
248 xcb_get_property_reply_t
*reply
)
250 client_t
*c
= client_getbywin(window
);
253 ewmh_process_client_strut(c
, reply
);
259 property_update_net_wm_icon(client_t
*c
,
260 xcb_get_property_reply_t
*reply
)
262 luaA_object_push(globalconf
.L
, c
);
266 if(ewmh_window_icon_from_reply(reply
))
267 client_set_icon(globalconf
.L
, -2, -1);
269 else if(ewmh_window_icon_get_reply(ewmh_window_icon_get_unchecked(c
->window
)))
270 client_set_icon(globalconf
.L
, -2, -1);
273 lua_pop(globalconf
.L
, 1);
277 property_update_net_wm_pid(client_t
*c
,
278 xcb_get_property_reply_t
*reply
)
280 bool no_reply
= !reply
;
284 xcb_get_property_cookie_t prop_c
=
285 xcb_get_property_unchecked(globalconf
.connection
, false, c
->window
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
286 reply
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
289 if(reply
&& reply
->value_len
)
291 uint32_t *rdata
= xcb_get_property_value(reply
);
294 luaA_object_push(globalconf
.L
, c
);
295 client_set_pid(globalconf
.L
, -1, *rdata
);
296 lua_pop(globalconf
.L
, 1);
304 /** Update the list of supported protocols for a client.
305 * \param c The client.
308 property_update_wm_protocols(client_t
*c
, xcb_get_property_reply_t
*reply
)
310 xcb_get_wm_protocols_reply_t protocols
;
314 if(!xcb_get_wm_protocols_from_reply(reply
, &protocols
))
319 /* If this fails for any reason, we still got the old value */
320 if(!xcb_get_wm_protocols_reply(globalconf
.connection
,
321 xcb_get_wm_protocols_unchecked(globalconf
.connection
,
322 c
->window
, WM_PROTOCOLS
),
327 xcb_get_wm_protocols_reply_wipe(&c
->protocols
);
328 memcpy(&c
->protocols
, &protocols
, sizeof(protocols
));
331 /** The property notify event handler.
332 * \param data currently unused.
333 * \param connection The connection to the X server.
334 * \param state currently unused
335 * \param window The window to obtain update the property with.
336 * \param name The protocol atom, currently unused.
337 * \param reply (Optional) An existing reply.
340 property_handle_xembed_info(void *data
__attribute__ ((unused
)),
341 xcb_connection_t
*connection
,
345 xcb_get_property_reply_t
*reply
)
347 xembed_window_t
*emwin
= xembed_getbywin(&globalconf
.embedded
, window
);
350 xembed_property_update(connection
, emwin
, reply
);
356 property_handle_xrootpmap_id(void *data
__attribute__ ((unused
)),
357 xcb_connection_t
*connection
,
361 xcb_get_property_reply_t
*reply
)
363 if(globalconf
.xinerama_is_active
)
364 foreach(w
, globalconf
.wiboxes
)
365 (*w
)->need_update
= true;
368 int screen
= xutil_root2screen(connection
, window
);
369 foreach(w
, globalconf
.wiboxes
)
370 if(screen
== screen_array_indexof(&globalconf
.screens
, (*w
)->screen
))
371 (*w
)->need_update
= true;
378 property_handle_net_wm_opacity(void *data
__attribute__ ((unused
)),
379 xcb_connection_t
*connection
,
383 xcb_get_property_reply_t
*reply
)
385 wibox_t
*wibox
= wibox_getbywin(window
);
389 luaA_object_push(globalconf
.L
, wibox
);
390 wibox_set_opacity(globalconf
.L
, -1, window_opacity_get_from_reply(reply
));
391 lua_pop(globalconf
.L
, -1);
395 client_t
*c
= client_getbywin(window
);
398 luaA_object_push(globalconf
.L
, c
);
399 client_set_opacity(globalconf
.L
, -1, window_opacity_get_from_reply(reply
));
400 lua_pop(globalconf
.L
, 1);
407 void a_xcb_set_property_handlers(void)
410 xcb_property_handlers_init(&globalconf
.prophs
, &globalconf
.evenths
);
413 xcb_property_set_handler(&globalconf
.prophs
, _XEMBED_INFO
, UINT_MAX
,
414 property_handle_xembed_info
, NULL
);
417 xcb_property_set_handler(&globalconf
.prophs
, WM_TRANSIENT_FOR
, UINT_MAX
,
418 property_handle_wm_transient_for
, NULL
);
419 xcb_property_set_handler(&globalconf
.prophs
, WM_CLIENT_LEADER
, UINT_MAX
,
420 property_handle_wm_client_leader
, NULL
);
421 xcb_property_set_handler(&globalconf
.prophs
, WM_NORMAL_HINTS
, UINT_MAX
,
422 property_handle_wm_normal_hints
, NULL
);
423 xcb_property_set_handler(&globalconf
.prophs
, WM_HINTS
, UINT_MAX
,
424 property_handle_wm_hints
, NULL
);
425 xcb_property_set_handler(&globalconf
.prophs
, WM_NAME
, UINT_MAX
,
426 property_handle_wm_name
, NULL
);
427 xcb_property_set_handler(&globalconf
.prophs
, WM_ICON_NAME
, UINT_MAX
,
428 property_handle_wm_icon_name
, NULL
);
429 xcb_property_set_handler(&globalconf
.prophs
, WM_CLASS
, UINT_MAX
,
430 property_handle_wm_class
, NULL
);
431 xcb_property_set_handler(&globalconf
.prophs
, WM_PROTOCOLS
, UINT_MAX
,
432 property_handle_wm_protocols
, NULL
);
433 xcb_property_set_handler(&globalconf
.prophs
, WM_CLIENT_MACHINE
, UINT_MAX
,
434 property_handle_wm_client_machine
, NULL
);
435 xcb_property_set_handler(&globalconf
.prophs
, WM_WINDOW_ROLE
, UINT_MAX
,
436 property_handle_wm_window_role
, NULL
);
439 xcb_property_set_handler(&globalconf
.prophs
, _NET_WM_NAME
, UINT_MAX
,
440 property_handle_wm_name
, NULL
);
441 xcb_property_set_handler(&globalconf
.prophs
, _NET_WM_ICON_NAME
, UINT_MAX
,
442 property_handle_wm_icon_name
, NULL
);
443 xcb_property_set_handler(&globalconf
.prophs
, _NET_WM_STRUT_PARTIAL
, UINT_MAX
,
444 property_handle_net_wm_strut_partial
, NULL
);
445 xcb_property_set_handler(&globalconf
.prophs
, _NET_WM_ICON
, UINT_MAX
,
446 property_handle_net_wm_icon
, NULL
);
447 xcb_property_set_handler(&globalconf
.prophs
, _NET_WM_PID
, UINT_MAX
,
448 property_handle_net_wm_pid
, NULL
);
449 xcb_property_set_handler(&globalconf
.prophs
, _NET_WM_WINDOW_OPACITY
, 1,
450 property_handle_net_wm_opacity
, NULL
);
452 /* background change */
453 xcb_property_set_handler(&globalconf
.prophs
, _XROOTPMAP_ID
, 1,
454 property_handle_xrootpmap_id
, NULL
);
457 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80