2 #define I3__FILE__ "window.c"
4 * vim:ts=4:sw=4:expandtab
6 * i3 - an improved dynamic tiling window manager
7 * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
9 * window.c: Updates window attributes (X11 hints/properties).
15 * Updates the WM_CLASS (consisting of the class and instance) for the
19 void window_update_class(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
20 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
21 DLOG("WM_CLASS not set.\n");
26 /* We cannot use asprintf here since this property contains two
27 * null-terminated strings (for compatibility reasons). Instead, we
28 * use strdup() on both strings */
29 char *new_class = xcb_get_property_value(prop);
31 FREE(win->class_instance);
32 FREE(win->class_class);
34 win->class_instance = sstrdup(new_class);
35 if ((strlen(new_class) + 1) < (size_t)xcb_get_property_value_length(prop))
36 win->class_class = sstrdup(new_class + strlen(new_class) + 1);
38 win->class_class = NULL;
39 LOG("WM_CLASS changed to %s (instance), %s (class)\n",
40 win->class_instance, win->class_class);
53 * Updates the name by using _NET_WM_NAME (encoded in UTF-8) for the given
54 * window. Further updates using window_update_name_legacy will be ignored.
57 void window_update_name(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
58 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
59 DLOG("_NET_WM_NAME not specified, not changing\n");
64 i3string_free(win->name);
65 win->name = i3string_from_utf8_with_length(xcb_get_property_value(prop),
66 xcb_get_property_value_length(prop));
67 win->name_x_changed = true;
68 LOG("_NET_WM_NAME changed to \"%s\"\n", i3string_as_utf8(win->name));
70 win->uses_net_wm_name = true;
83 * Updates the name by using WM_NAME (encoded in COMPOUND_TEXT). We do not
84 * touch what the client sends us but pass it to xcb_image_text_8. To get
85 * proper unicode rendering, the application has to use _NET_WM_NAME (see
86 * window_update_name()).
89 void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
90 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
91 DLOG("WM_NAME not set (_NET_WM_NAME is what you want anyways).\n");
96 /* ignore update when the window is known to already have a UTF-8 name */
97 if (win->uses_net_wm_name) {
102 i3string_free(win->name);
103 win->name = i3string_from_utf8_with_length(xcb_get_property_value(prop),
104 xcb_get_property_value_length(prop));
106 LOG("WM_NAME changed to \"%s\"\n", i3string_as_utf8(win->name));
107 LOG("Using legacy window title. Note that in order to get Unicode window "
108 "titles in i3, the application has to set _NET_WM_NAME (UTF-8)\n");
110 win->name_x_changed = true;
117 run_assignments(win);
123 * Updates the CLIENT_LEADER (logical parent window).
126 void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop) {
127 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
128 DLOG("CLIENT_LEADER not set.\n");
133 xcb_window_t *leader = xcb_get_property_value(prop);
134 if (leader == NULL) {
139 DLOG("Client leader changed to %08x\n", *leader);
141 win->leader = *leader;
147 * Updates the TRANSIENT_FOR (logical parent window).
150 void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop) {
151 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
152 DLOG("TRANSIENT_FOR not set.\n");
157 xcb_window_t transient_for;
158 if (!xcb_icccm_get_wm_transient_for_from_reply(&transient_for, prop)) {
163 DLOG("Transient for changed to %08x\n", transient_for);
165 win->transient_for = transient_for;
171 * Updates the _NET_WM_STRUT_PARTIAL (reserved pixels at the screen edges)
174 void window_update_strut_partial(i3Window *win, xcb_get_property_reply_t *prop) {
175 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
176 DLOG("_NET_WM_STRUT_PARTIAL not set.\n");
182 if (!(strut = xcb_get_property_value(prop))) {
187 DLOG("Reserved pixels changed to: left = %d, right = %d, top = %d, bottom = %d\n",
188 strut[0], strut[1], strut[2], strut[3]);
190 win->reserved = (struct reservedpx) {strut[0], strut[1], strut[2], strut[3]};
196 * Updates the WM_WINDOW_ROLE
199 void window_update_role(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
200 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
201 DLOG("WM_WINDOW_ROLE not set.\n");
207 if (asprintf(&new_role, "%.*s", xcb_get_property_value_length(prop),
208 (char *)xcb_get_property_value(prop)) == -1) {
209 perror("asprintf()");
210 DLOG("Could not get WM_WINDOW_ROLE\n");
215 win->role = new_role;
216 LOG("WM_WINDOW_ROLE changed to \"%s\"\n", win->role);
223 run_assignments(win);
229 * Updates the WM_HINTS (we only care about the input focus handling part).
232 void window_update_hints(i3Window *win, xcb_get_property_reply_t *prop, bool *urgency_hint) {
233 if (urgency_hint != NULL)
234 *urgency_hint = false;
236 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
237 DLOG("WM_HINTS not set.\n");
242 xcb_icccm_wm_hints_t hints;
244 if (!xcb_icccm_get_wm_hints_from_reply(&hints, prop)) {
245 DLOG("Could not get WM_HINTS\n");
250 win->doesnt_accept_focus = !hints.input;
251 LOG("WM_HINTS.input changed to \"%d\"\n", hints.input);
253 if (urgency_hint != NULL)
254 *urgency_hint = (xcb_icccm_wm_hints_get_urgency(&hints) != 0);
260 * Updates the MOTIF_WM_HINTS. The container's border style should be set to
261 * `motif_border_style' if border style is not BS_NORMAL.
263 * i3 only uses this hint when it specifies a window should have no
264 * title bar, or no decorations at all, which is how most window managers
267 * The EWMH spec intended to replace Motif hints with _NET_WM_WINDOW_TYPE, but
268 * it is still in use by popular widget toolkits such as GTK+ and Java AWT.
271 void window_update_motif_hints(i3Window *win, xcb_get_property_reply_t *prop, border_style_t *motif_border_style) {
272 /* This implementation simply mirrors Gnome's Metacity. Official
273 * documentation of this hint is nowhere to be found.
274 * For more information see:
275 * https://people.gnome.org/~tthurman/docs/metacity/xprops_8h-source.html
276 * http://stackoverflow.com/questions/13787553/detect-if-a-x11-window-has-decorations
278 #define MWM_HINTS_DECORATIONS (1 << 1)
279 #define MWM_DECOR_ALL (1 << 0)
280 #define MWM_DECOR_BORDER (1 << 1)
281 #define MWM_DECOR_TITLE (1 << 3)
283 if (motif_border_style != NULL)
284 *motif_border_style = BS_NORMAL;
286 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
291 /* The property consists of an array of 5 uint64_t's. The first value is a bit
292 * mask of what properties the hint will specify. We are only interested in
293 * MWM_HINTS_DECORATIONS because it indicates that the second value of the
294 * array tells us which decorations the window should have, each flag being
295 * a particular decoration. */
296 uint64_t *motif_hints = (uint64_t *)xcb_get_property_value(prop);
298 if (motif_border_style != NULL && motif_hints[0] & MWM_HINTS_DECORATIONS) {
299 if (motif_hints[1] & MWM_DECOR_ALL || motif_hints[1] & MWM_DECOR_TITLE)
300 *motif_border_style = BS_NORMAL;
301 else if (motif_hints[1] & MWM_DECOR_BORDER)
302 *motif_border_style = BS_PIXEL;
304 *motif_border_style = BS_NONE;
309 #undef MWM_HINTS_DECORATIONS
311 #undef MWM_DECOR_BORDER
312 #undef MWM_DECOR_TITLE