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>
26 #include "objects/client.h"
28 #include "objects/drawin.h"
31 #include "common/atoms.h"
32 #include "common/xutil.h"
34 #define HANDLE_TEXT_PROPERTY(funcname, atom, setfunc) \
35 xcb_get_property_cookie_t \
36 property_get_##funcname(client_t *c) \
38 return xcb_get_property(globalconf.connection, \
42 XCB_GET_PROPERTY_TYPE_ANY, \
47 property_update_##funcname(client_t *c, xcb_get_property_cookie_t cookie) \
49 xcb_get_property_reply_t * reply = \
50 xcb_get_property_reply(globalconf.connection, cookie, NULL); \
51 luaA_object_push(globalconf.L, c); \
52 setfunc(globalconf.L, -1, xutil_get_text_property_from_reply(reply)); \
53 lua_pop(globalconf.L, 1); \
57 property_handle_##funcname(uint8_t state, \
58 xcb_window_t window) \
60 client_t *c = client_getbywin(window); \
62 property_update_##funcname(c, property_get_##funcname(c));\
67 HANDLE_TEXT_PROPERTY(wm_name
, XCB_ATOM_WM_NAME
, client_set_alt_name
)
68 HANDLE_TEXT_PROPERTY(net_wm_name
, _NET_WM_NAME
, client_set_name
)
69 HANDLE_TEXT_PROPERTY(wm_icon_name
, XCB_ATOM_WM_ICON_NAME
, client_set_alt_icon_name
)
70 HANDLE_TEXT_PROPERTY(net_wm_icon_name
, _NET_WM_ICON_NAME
, client_set_icon_name
)
71 HANDLE_TEXT_PROPERTY(wm_client_machine
, XCB_ATOM_WM_CLIENT_MACHINE
, client_set_machine
)
72 HANDLE_TEXT_PROPERTY(wm_window_role
, WM_WINDOW_ROLE
, client_set_role
)
74 #undef HANDLE_TEXT_PROPERTY
76 #define HANDLE_PROPERTY(name) \
78 property_handle_##name(uint8_t state, \
79 xcb_window_t window) \
81 client_t *c = client_getbywin(window); \
83 property_update_##name(c, property_get_##name(c));\
87 HANDLE_PROPERTY(wm_protocols
)
88 HANDLE_PROPERTY(wm_transient_for
)
89 HANDLE_PROPERTY(wm_client_leader
)
90 HANDLE_PROPERTY(wm_normal_hints
)
91 HANDLE_PROPERTY(wm_hints
)
92 HANDLE_PROPERTY(wm_class
)
93 HANDLE_PROPERTY(net_wm_icon
)
94 HANDLE_PROPERTY(net_wm_pid
)
96 #undef HANDLE_PROPERTY
98 xcb_get_property_cookie_t
99 property_get_wm_transient_for(client_t
*c
)
101 return xcb_icccm_get_wm_transient_for_unchecked(globalconf
.connection
, c
->window
);
105 property_update_wm_transient_for(client_t
*c
, xcb_get_property_cookie_t cookie
)
111 if(!xcb_icccm_get_wm_transient_for_reply(globalconf
.connection
,
116 tmp
= tc
= client_getbywin(trans
);
118 luaA_object_push(globalconf
.L
, c
);
119 client_set_type(globalconf
.L
, -1, WINDOW_TYPE_DIALOG
);
120 client_set_above(globalconf
.L
, -1, false);
122 /* Verify that there are no loops in the transient_for relation */
123 for(counter
= 0; tmp
!= NULL
&& counter
<= globalconf
.stack
.len
; counter
++)
124 tmp
= tmp
->transient_for
;
125 if (counter
<= globalconf
.stack
.len
)
126 client_set_transient_for(globalconf
.L
, -1, tc
);
128 lua_pop(globalconf
.L
, 1);
131 xcb_get_property_cookie_t
132 property_get_wm_client_leader(client_t
*c
)
134 return xcb_get_property_unchecked(globalconf
.connection
, false, c
->window
,
135 WM_CLIENT_LEADER
, XCB_ATOM_WINDOW
, 0, 32);
138 /** Update leader hint of a client.
139 * \param c The client.
140 * \param cookie Cookie returned by property_get_wm_client_leader.
143 property_update_wm_client_leader(client_t
*c
, xcb_get_property_cookie_t cookie
)
145 xcb_get_property_reply_t
*reply
;
148 reply
= xcb_get_property_reply(globalconf
.connection
, cookie
, NULL
);
150 if(reply
&& reply
->value_len
&& (data
= xcb_get_property_value(reply
)))
151 c
->leader_window
= *(xcb_window_t
*) data
;
156 xcb_get_property_cookie_t
157 property_get_wm_normal_hints(client_t
*c
)
159 return xcb_icccm_get_wm_normal_hints_unchecked(globalconf
.connection
, c
->window
);
162 /** Update the size hints of a client.
163 * \param c The client.
164 * \param cookie Cookie returned by property_get_wm_normal_hints.
167 property_update_wm_normal_hints(client_t
*c
, xcb_get_property_cookie_t cookie
)
169 xcb_icccm_get_wm_normal_hints_reply(globalconf
.connection
,
171 &c
->size_hints
, NULL
);
174 xcb_get_property_cookie_t
175 property_get_wm_hints(client_t
*c
)
177 return xcb_icccm_get_wm_hints_unchecked(globalconf
.connection
, c
->window
);
180 /** Update the WM hints of a client.
181 * \param c The client.
182 * \param cookie Cookie returned by property_get_wm_hints.
185 property_update_wm_hints(client_t
*c
, xcb_get_property_cookie_t cookie
)
187 xcb_icccm_wm_hints_t wmh
;
189 if(!xcb_icccm_get_wm_hints_reply(globalconf
.connection
,
194 luaA_object_push(globalconf
.L
, c
);
195 client_set_urgent(globalconf
.L
, -1, xcb_icccm_wm_hints_get_urgency(&wmh
));
197 if(wmh
.flags
& XCB_ICCCM_WM_HINT_INPUT
)
198 c
->nofocus
= !wmh
.input
;
200 if(wmh
.flags
& XCB_ICCCM_WM_HINT_WINDOW_GROUP
)
201 client_set_group_window(globalconf
.L
, -1, wmh
.window_group
);
203 lua_pop(globalconf
.L
, 1);
206 xcb_get_property_cookie_t
207 property_get_wm_class(client_t
*c
)
209 return xcb_icccm_get_wm_class_unchecked(globalconf
.connection
, c
->window
);
212 /** Update WM_CLASS of a client.
213 * \param c The client.
214 * \param cookie Cookie returned by property_get_wm_class.
217 property_update_wm_class(client_t
*c
, xcb_get_property_cookie_t cookie
)
219 xcb_icccm_get_wm_class_reply_t hint
;
221 if(!xcb_icccm_get_wm_class_reply(globalconf
.connection
,
226 luaA_object_push(globalconf
.L
, c
);
227 client_set_class_instance(globalconf
.L
, -1, hint
.class_name
, hint
.instance_name
);
228 lua_pop(globalconf
.L
, 1);
230 xcb_icccm_get_wm_class_reply_wipe(&hint
);
234 property_handle_net_wm_strut_partial(uint8_t state
,
237 client_t
*c
= client_getbywin(window
);
240 ewmh_process_client_strut(c
);
245 xcb_get_property_cookie_t
246 property_get_net_wm_icon(client_t
*c
)
248 return ewmh_window_icon_get_unchecked(c
->window
);
252 property_update_net_wm_icon(client_t
*c
, xcb_get_property_cookie_t cookie
)
254 cairo_surface_t
*surface
= ewmh_window_icon_get_reply(cookie
);
259 client_set_icon(c
, surface
);
260 cairo_surface_destroy(surface
);
263 xcb_get_property_cookie_t
264 property_get_net_wm_pid(client_t
*c
)
266 return xcb_get_property_unchecked(globalconf
.connection
, false, c
->window
, _NET_WM_PID
, XCB_ATOM_CARDINAL
, 0L, 1L);
270 property_update_net_wm_pid(client_t
*c
, xcb_get_property_cookie_t cookie
)
272 xcb_get_property_reply_t
*reply
;
274 reply
= xcb_get_property_reply(globalconf
.connection
, cookie
, NULL
);
276 if(reply
&& reply
->value_len
)
278 uint32_t *rdata
= xcb_get_property_value(reply
);
281 luaA_object_push(globalconf
.L
, c
);
282 client_set_pid(globalconf
.L
, -1, *rdata
);
283 lua_pop(globalconf
.L
, 1);
290 xcb_get_property_cookie_t
291 property_get_wm_protocols(client_t
*c
)
293 return xcb_icccm_get_wm_protocols_unchecked(globalconf
.connection
,
294 c
->window
, WM_PROTOCOLS
);
297 /** Update the list of supported protocols for a client.
298 * \param c The client.
299 * \param cookie Cookie from property_get_wm_protocols.
302 property_update_wm_protocols(client_t
*c
, xcb_get_property_cookie_t cookie
)
304 xcb_icccm_get_wm_protocols_reply_t protocols
;
306 /* If this fails for any reason, we still got the old value */
307 if(!xcb_icccm_get_wm_protocols_reply(globalconf
.connection
,
312 xcb_icccm_get_wm_protocols_reply_wipe(&c
->protocols
);
313 memcpy(&c
->protocols
, &protocols
, sizeof(protocols
));
316 /** The property notify event handler.
317 * \param state currently unused
318 * \param window The window to obtain update the property with.
319 * \param name The protocol atom, currently unused.
320 * \param reply (Optional) An existing reply.
323 property_handle_xembed_info(uint8_t state
,
326 xembed_window_t
*emwin
= xembed_getbywin(&globalconf
.embedded
, window
);
330 xcb_get_property_cookie_t cookie
=
331 xcb_get_property(globalconf
.connection
, 0, window
, _XEMBED_INFO
,
332 XCB_GET_PROPERTY_TYPE_ANY
, 0, 3);
333 xcb_get_property_reply_t
*propr
=
334 xcb_get_property_reply(globalconf
.connection
, cookie
, 0);
335 xembed_property_update(globalconf
.connection
, emwin
, propr
);
343 property_handle_net_wm_opacity(uint8_t state
,
346 drawin_t
*drawin
= drawin_getbywin(window
);
350 luaA_object_push(globalconf
.L
, drawin
);
351 window_set_opacity(globalconf
.L
, -1, xwindow_get_opacity(drawin
->window
));
352 lua_pop(globalconf
.L
, -1);
356 client_t
*c
= client_getbywin(window
);
359 luaA_object_push(globalconf
.L
, c
);
360 window_set_opacity(globalconf
.L
, -1, xwindow_get_opacity(c
->window
));
361 lua_pop(globalconf
.L
, 1);
369 property_handle_xrootpmap_id(uint8_t state
,
372 signal_object_emit(globalconf
.L
, &global_signals
, "wallpaper_changed", 0);
377 /** The property notify event handler.
378 * \param data Unused data.
379 * \param connection The connection to the X server.
380 * \param ev The event.
381 * \return Status code, 0 if everything's fine.
384 property_handle_propertynotify(xcb_property_notify_event_t
*ev
)
386 int (*handler
)(uint8_t state
,
387 xcb_window_t window
) = NULL
;
389 globalconf
.timestamp
= ev
->time
;
391 /* Find the correct event handler */
392 #define HANDLE(atom_, cb) \
393 if (ev->atom == atom_) \
400 HANDLE(_XEMBED_INFO
, property_handle_xembed_info
)
403 HANDLE(XCB_ATOM_WM_TRANSIENT_FOR
, property_handle_wm_transient_for
)
404 HANDLE(WM_CLIENT_LEADER
, property_handle_wm_client_leader
)
405 HANDLE(XCB_ATOM_WM_NORMAL_HINTS
, property_handle_wm_normal_hints
)
406 HANDLE(XCB_ATOM_WM_HINTS
, property_handle_wm_hints
)
407 HANDLE(XCB_ATOM_WM_NAME
, property_handle_wm_name
)
408 HANDLE(XCB_ATOM_WM_ICON_NAME
, property_handle_wm_icon_name
)
409 HANDLE(XCB_ATOM_WM_CLASS
, property_handle_wm_class
)
410 HANDLE(WM_PROTOCOLS
, property_handle_wm_protocols
)
411 HANDLE(XCB_ATOM_WM_CLIENT_MACHINE
, property_handle_wm_client_machine
)
412 HANDLE(WM_WINDOW_ROLE
, property_handle_wm_window_role
)
415 HANDLE(_NET_WM_NAME
, property_handle_net_wm_name
)
416 HANDLE(_NET_WM_ICON_NAME
, property_handle_net_wm_icon_name
)
417 HANDLE(_NET_WM_STRUT_PARTIAL
, property_handle_net_wm_strut_partial
)
418 HANDLE(_NET_WM_ICON
, property_handle_net_wm_icon
)
419 HANDLE(_NET_WM_PID
, property_handle_net_wm_pid
)
420 HANDLE(_NET_WM_WINDOW_OPACITY
, property_handle_net_wm_opacity
)
422 /* background change */
423 HANDLE(_XROOTPMAP_ID
, property_handle_xrootpmap_id
)
425 /* If nothing was found, return */
431 (*handler
)(ev
->state
, ev
->window
);
434 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80