2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
7 * window.c: Updates window attributes (X11 hints/properties).
13 * Updates the WM_CLASS (consisting of the class and instance) for the
17 void window_update_class(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
18 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
19 DLOG("WM_CLASS not set.\n");
24 /* We cannot use asprintf here since this property contains two
25 * null-terminated strings (for compatibility reasons). Instead, we
26 * use strdup() on both strings */
27 char *new_class = xcb_get_property_value(prop);
29 FREE(win->class_instance);
30 FREE(win->class_class);
32 win->class_instance = sstrdup(new_class);
33 if ((strlen(new_class) + 1) < xcb_get_property_value_length(prop))
34 win->class_class = sstrdup(new_class + strlen(new_class) + 1);
35 else win->class_class = NULL;
36 LOG("WM_CLASS changed to %s (instance), %s (class)\n",
37 win->class_instance, win->class_class);
50 * Updates the name by using _NET_WM_NAME (encoded in UTF-8) for the given
51 * window. Further updates using window_update_name_legacy will be ignored.
54 void window_update_name(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
55 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
56 DLOG("_NET_WM_NAME not specified, not changing\n");
61 /* Save the old pointer to make the update atomic */
63 if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
64 (char*)xcb_get_property_value(prop)) == -1) {
66 DLOG("Could not get window name\n");
70 /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */
72 xcb_char2b_t *ucs2_name = convert_utf8_to_ucs2(new_name, &len);
73 if (ucs2_name == NULL) {
74 LOG("Could not convert _NET_WM_NAME to UCS-2, ignoring new hint\n");
81 win->name_json = new_name;
82 win->name_x = (char*)ucs2_name;
84 win->name_x_changed = true;
85 LOG("_NET_WM_NAME changed to \"%s\"\n", win->name_json);
87 win->uses_net_wm_name = true;
100 * Updates the name by using WM_NAME (encoded in COMPOUND_TEXT). We do not
101 * touch what the client sends us but pass it to xcb_image_text_8. To get
102 * proper unicode rendering, the application has to use _NET_WM_NAME (see
103 * window_update_name()).
106 void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
107 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
108 DLOG("WM_NAME not set (_NET_WM_NAME is what you want anyways).\n");
113 /* ignore update when the window is known to already have a UTF-8 name */
114 if (win->uses_net_wm_name) {
120 if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
121 (char*)xcb_get_property_value(prop)) == -1) {
122 perror("asprintf()");
123 DLOG("Could not get legacy window name\n");
128 LOG("WM_NAME changed to \"%s\"\n", new_name);
129 LOG("Using legacy window title. Note that in order to get Unicode window "
130 "titles in i3, the application has to set _NET_WM_NAME (UTF-8)\n");
133 FREE(win->name_json);
134 win->name_x = new_name;
135 win->name_json = sstrdup(new_name);
136 win->name_len = strlen(new_name);
137 win->name_x_changed = true;
144 run_assignments(win);
150 * Updates the CLIENT_LEADER (logical parent window).
153 void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop) {
154 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
155 DLOG("CLIENT_LEADER not set.\n");
160 xcb_window_t *leader = xcb_get_property_value(prop);
161 if (leader == NULL) {
166 DLOG("Client leader changed to %08x\n", *leader);
168 win->leader = *leader;
174 * Updates the TRANSIENT_FOR (logical parent window).
177 void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop) {
178 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
179 DLOG("TRANSIENT_FOR not set.\n");
184 xcb_window_t transient_for;
185 if (!xcb_icccm_get_wm_transient_for_from_reply(&transient_for, prop)) {
190 DLOG("Transient for changed to %08x\n", transient_for);
192 win->transient_for = transient_for;
198 * Updates the _NET_WM_STRUT_PARTIAL (reserved pixels at the screen edges)
201 void window_update_strut_partial(i3Window *win, xcb_get_property_reply_t *prop) {
202 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
203 DLOG("_NET_WM_STRUT_PARTIAL not set.\n");
209 if (!(strut = xcb_get_property_value(prop))) {
214 DLOG("Reserved pixels changed to: left = %d, right = %d, top = %d, bottom = %d\n",
215 strut[0], strut[1], strut[2], strut[3]);
217 win->reserved = (struct reservedpx){ strut[0], strut[1], strut[2], strut[3] };
223 * Updates the WM_WINDOW_ROLE
226 void window_update_role(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
227 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
228 DLOG("WM_WINDOW_ROLE not set.\n");
234 if (asprintf(&new_role, "%.*s", xcb_get_property_value_length(prop),
235 (char*)xcb_get_property_value(prop)) == -1) {
236 perror("asprintf()");
237 DLOG("Could not get WM_WINDOW_ROLE\n");
242 win->role = new_role;
243 LOG("WM_WINDOW_ROLE changed to \"%s\"\n", win->role);
250 run_assignments(win);
256 * Updates the WM_HINTS (we only care about the input focus handling part).
259 void window_update_hints(i3Window *win, xcb_get_property_reply_t *prop) {
260 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
261 DLOG("WM_HINTS not set.\n");
266 xcb_icccm_wm_hints_t hints;
268 if (!xcb_icccm_get_wm_hints_from_reply(&hints, prop)) {
269 DLOG("Could not get WM_HINTS\n");
274 win->doesnt_accept_focus = !hints.input;
275 LOG("WM_HINTS.input changed to \"%d\"\n", hints.input);