2 * property.c - property handlers
4 * Copyright © 2008 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>
28 #include "common/atoms.h"
30 extern awesome_t globalconf
;
34 property_update_wm_transient_for(client_t
*c
, xcb_get_property_reply_t
*reply
)
40 if(!xcb_get_wm_transient_for_from_reply(&trans
, reply
))
45 if(!xcb_get_wm_transient_for_reply(globalconf
.connection
,
46 xcb_get_wm_transient_for_unchecked(globalconf
.connection
,
52 c
->type
= WINDOW_TYPE_DIALOG
;
53 c
->transient_for
= client_getbywin(trans
);
57 property_handle_wm_transient_for(void *data
,
58 xcb_connection_t
*connection
,
62 xcb_get_property_reply_t
*reply
)
64 client_t
*c
= client_getbywin(window
);
66 if(c
&& !client_isfloating(c
))
67 property_update_wm_transient_for(c
, reply
);
72 /** Update the size hints of a client.
73 * \param c The client.
76 property_update_wm_normal_hints(client_t
*c
, xcb_get_property_reply_t
*reply
)
80 if(!xcb_get_wm_size_hints_from_reply(&c
->size_hints
, reply
))
85 if(!xcb_get_wm_normal_hints_reply(globalconf
.connection
,
86 xcb_get_wm_normal_hints_unchecked(globalconf
.connection
,
88 &c
->size_hints
, NULL
))
92 if((c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
))
94 c
->basew
= c
->size_hints
.base_width
;
95 c
->baseh
= c
->size_hints
.base_height
;
97 else if((c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
))
99 c
->basew
= c
->size_hints
.min_width
;
100 c
->baseh
= c
->size_hints
.min_height
;
103 c
->basew
= c
->baseh
= 0;
105 if((c
->size_hints
.flags
& XCB_SIZE_HINT_P_RESIZE_INC
))
107 c
->incw
= c
->size_hints
.width_inc
;
108 c
->inch
= c
->size_hints
.height_inc
;
111 c
->incw
= c
->inch
= 0;
113 if((c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
))
115 c
->maxw
= c
->size_hints
.max_width
;
116 c
->maxh
= c
->size_hints
.max_height
;
119 c
->maxw
= c
->maxh
= 0;
121 if((c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
))
123 c
->minw
= c
->size_hints
.min_width
;
124 c
->minh
= c
->size_hints
.min_height
;
126 else if((c
->size_hints
.flags
& XCB_SIZE_HINT_BASE_SIZE
))
128 c
->minw
= c
->size_hints
.base_width
;
129 c
->minh
= c
->size_hints
.base_height
;
132 c
->minw
= c
->minh
= 0;
134 if((c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
))
136 c
->minax
= c
->size_hints
.min_aspect_num
;
137 c
->minay
= c
->size_hints
.min_aspect_den
;
138 c
->maxax
= c
->size_hints
.max_aspect_num
;
139 c
->maxay
= c
->size_hints
.max_aspect_den
;
142 c
->minax
= c
->maxax
= c
->minay
= c
->maxay
= 0;
144 c
->hassizehints
= !(!c
->basew
&& !c
->baseh
&& !c
->incw
&& !c
->inch
145 && !c
->maxw
&& !c
->maxh
&& !c
->minw
&& !c
->minh
146 && !c
->minax
&& !c
->maxax
&& !c
->minax
&& !c
->minay
);
150 property_handle_wm_normal_hints(void *data
,
151 xcb_connection_t
*connection
,
155 xcb_get_property_reply_t
*reply
)
157 client_t
*c
= client_getbywin(window
);
160 property_update_wm_normal_hints(c
, reply
);
165 /** Update the WM hints of a client.
166 * \param c The client.
169 property_update_wm_hints(client_t
*c
, xcb_get_property_reply_t
*reply
)
175 if(!xcb_get_wm_hints_from_reply(&wmh
, reply
))
180 if(!xcb_get_wm_hints_reply(globalconf
.connection
,
181 xcb_get_wm_hints_unchecked(globalconf
.connection
, c
->win
),
186 bool isurgent
= xcb_wm_hints_get_urgency(&wmh
);
187 if(isurgent
!= c
->isurgent
)
189 c
->isurgent
= isurgent
;
191 hooks_property(c
, "urgent");
193 if(wmh
.flags
& XCB_WM_HINT_STATE
&&
194 wmh
.initial_state
== XCB_WM_STATE_WITHDRAWN
)
195 client_setborder(c
, 0);
197 if(wmh
.flags
& XCB_WM_HINT_INPUT
)
198 c
->nofocus
= !wmh
.input
;
202 property_handle_wm_hints(void *data
,
203 xcb_connection_t
*connection
,
207 xcb_get_property_reply_t
*reply
)
209 client_t
*c
= client_getbywin(window
);
212 property_update_wm_hints(c
, reply
);
217 /** Update client name attribute with its new title.
218 * \param c The client.
219 * \param Return true if it has been updated.
222 property_update_wm_name(client_t
*c
)
227 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
, _NET_WM_NAME
, &name
, &len
))
228 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
, WM_NAME
, &name
, &len
))
233 if((utf8
= draw_iso2utf8(name
, len
)))
239 hooks_property(c
, "name");
242 /** Update client icon name attribute with its new title.
243 * \param c The client.
244 * \param Return true if it has been updated.
247 property_update_wm_icon_name(client_t
*c
)
252 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
, _NET_WM_ICON_NAME
, &name
, &len
))
253 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
, WM_ICON_NAME
, &name
, &len
))
256 p_delete(&c
->icon_name
);
258 if((utf8
= draw_iso2utf8(name
, len
)))
264 hooks_property(c
, "icon_name");
268 property_handle_wm_name(void *data
,
269 xcb_connection_t
*connection
,
273 xcb_get_property_reply_t
*reply
)
275 client_t
*c
= client_getbywin(window
);
278 property_update_wm_name(c
);
284 property_handle_wm_icon_name(void *data
,
285 xcb_connection_t
*connection
,
289 xcb_get_property_reply_t
*reply
)
291 client_t
*c
= client_getbywin(window
);
294 property_update_wm_icon_name(c
);
300 property_handle_net_wm_strut_partial(void *data
,
301 xcb_connection_t
*connection
,
305 xcb_get_property_reply_t
*reply
)
307 client_t
*c
= client_getbywin(window
);
310 ewmh_client_strut_update(c
, reply
);
316 property_handle_net_wm_icon(void *data
,
317 xcb_connection_t
*connection
,
321 xcb_get_property_reply_t
*reply
)
323 client_t
*c
= client_getbywin(window
);
328 image_unref(&c
->icon
);
329 icon
= ewmh_window_icon_from_reply(reply
);
330 c
->icon
= icon
? image_ref(&icon
) : NULL
;
333 hooks_property(c
, "icon");
339 /** The property notify event handler.
340 * \param data currently unused.
341 * \param connection The connection to the X server.
342 * \param ev The event.
345 property_handle_xembed_info(void *data
__attribute__ ((unused
)),
346 xcb_connection_t
*connection
,
350 xcb_get_property_reply_t
*reply
)
352 xembed_window_t
*emwin
= xembed_getbywin(globalconf
.embedded
, window
);
355 xembed_property_update(connection
, emwin
, reply
);
361 property_handle_xrootpmap_id(void *data
__attribute__ ((unused
)),
362 xcb_connection_t
*connection
,
366 xcb_get_property_reply_t
*reply
)
368 if(globalconf
.xinerama_is_active
)
369 for(int screen
= 0; screen
< globalconf
.nscreen
; screen
++)
371 wibox_array_t
*w
= &globalconf
.screens
[screen
].wiboxes
;
372 for(int i
= 0; i
< w
->len
; i
++)
373 w
->tab
[i
]->need_update
= true;
377 int screen
= xutil_root2screen(connection
, window
);
378 wibox_array_t
*w
= &globalconf
.screens
[screen
].wiboxes
;
379 for(int i
= 0; i
< w
->len
; i
++)
380 w
->tab
[i
]->need_update
= true;
386 void a_xcb_set_property_handlers(void)
389 xcb_property_handlers_init(&globalconf
.prophs
, &globalconf
.evenths
);
392 xcb_property_set_handler(&globalconf
.prophs
, _XEMBED_INFO
, UINT_MAX
,
393 property_handle_xembed_info
, NULL
);
396 xcb_property_set_handler(&globalconf
.prophs
, WM_TRANSIENT_FOR
, UINT_MAX
,
397 property_handle_wm_transient_for
, NULL
);
398 xcb_property_set_handler(&globalconf
.prophs
, WM_NORMAL_HINTS
, UINT_MAX
,
399 property_handle_wm_normal_hints
, NULL
);
400 xcb_property_set_handler(&globalconf
.prophs
, WM_HINTS
, UINT_MAX
,
401 property_handle_wm_hints
, NULL
);
402 xcb_property_set_handler(&globalconf
.prophs
, WM_NAME
, UINT_MAX
,
403 property_handle_wm_name
, NULL
);
404 xcb_property_set_handler(&globalconf
.prophs
, WM_ICON_NAME
, UINT_MAX
,
405 property_handle_wm_icon_name
, NULL
);
408 xcb_property_set_handler(&globalconf
.prophs
, _NET_WM_NAME
, UINT_MAX
,
409 property_handle_wm_name
, NULL
);
410 xcb_property_set_handler(&globalconf
.prophs
, _NET_WM_ICON_NAME
, UINT_MAX
,
411 property_handle_wm_icon_name
, NULL
);
412 xcb_property_set_handler(&globalconf
.prophs
, _NET_WM_STRUT_PARTIAL
, UINT_MAX
,
413 property_handle_net_wm_strut_partial
, NULL
);
414 xcb_property_set_handler(&globalconf
.prophs
, _NET_WM_ICON
, UINT_MAX
,
415 property_handle_net_wm_icon
, NULL
);
417 /* background change */
418 xcb_property_set_handler(&globalconf
.prophs
, _XROOTPMAP_ID
, 1,
419 property_handle_xrootpmap_id
, NULL
);
422 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80