3 * vim:ts=4:sw=4:expandtab
5 * i3 - an improved dynamic tiling window manager
6 * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
8 * window.c: Updates window attributes (X11 hints/properties).
14 * Updates the WM_CLASS (consisting of the class and instance) for the
18 void window_update_class(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
19 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
20 DLOG("WM_CLASS not set.\n");
25 /* We cannot use asprintf here since this property contains two
26 * null-terminated strings (for compatibility reasons). Instead, we
27 * use strdup() on both strings */
28 char *new_class = xcb_get_property_value(prop);
30 FREE(win->class_instance);
31 FREE(win->class_class);
33 win->class_instance = sstrdup(new_class);
34 if ((strlen(new_class) + 1) < xcb_get_property_value_length(prop))
35 win->class_class = sstrdup(new_class + strlen(new_class) + 1);
36 else win->class_class = NULL;
37 LOG("WM_CLASS changed to %s (instance), %s (class)\n",
38 win->class_instance, win->class_class);
51 * Updates the name by using _NET_WM_NAME (encoded in UTF-8) for the given
52 * window. Further updates using window_update_name_legacy will be ignored.
55 void window_update_name(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
56 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
57 DLOG("_NET_WM_NAME not specified, not changing\n");
62 /* Save the old pointer to make the update atomic */
64 if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
65 (char*)xcb_get_property_value(prop)) == -1) {
67 DLOG("Could not get window name\n");
71 /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */
73 xcb_char2b_t *ucs2_name = convert_utf8_to_ucs2(new_name, &len);
74 if (ucs2_name == NULL) {
75 LOG("Could not convert _NET_WM_NAME to UCS-2, ignoring new hint\n");
82 win->name_json = new_name;
83 win->name_x = (char*)ucs2_name;
85 win->name_x_changed = true;
86 LOG("_NET_WM_NAME changed to \"%s\"\n", win->name_json);
88 win->uses_net_wm_name = true;
101 * Updates the name by using WM_NAME (encoded in COMPOUND_TEXT). We do not
102 * touch what the client sends us but pass it to xcb_image_text_8. To get
103 * proper unicode rendering, the application has to use _NET_WM_NAME (see
104 * window_update_name()).
107 void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
108 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
109 DLOG("WM_NAME not set (_NET_WM_NAME is what you want anyways).\n");
114 /* ignore update when the window is known to already have a UTF-8 name */
115 if (win->uses_net_wm_name) {
121 if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
122 (char*)xcb_get_property_value(prop)) == -1) {
123 perror("asprintf()");
124 DLOG("Could not get legacy window name\n");
129 LOG("WM_NAME changed to \"%s\"\n", new_name);
130 LOG("Using legacy window title. Note that in order to get Unicode window "
131 "titles in i3, the application has to set _NET_WM_NAME (UTF-8)\n");
134 FREE(win->name_json);
135 win->name_x = new_name;
136 win->name_json = sstrdup(new_name);
137 win->name_len = strlen(new_name);
138 win->name_x_changed = true;
145 run_assignments(win);
151 * Updates the CLIENT_LEADER (logical parent window).
154 void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop) {
155 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
156 DLOG("CLIENT_LEADER not set.\n");
161 xcb_window_t *leader = xcb_get_property_value(prop);
162 if (leader == NULL) {
167 DLOG("Client leader changed to %08x\n", *leader);
169 win->leader = *leader;
175 * Updates the TRANSIENT_FOR (logical parent window).
178 void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop) {
179 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
180 DLOG("TRANSIENT_FOR not set.\n");
185 xcb_window_t transient_for;
186 if (!xcb_icccm_get_wm_transient_for_from_reply(&transient_for, prop)) {
191 DLOG("Transient for changed to %08x\n", transient_for);
193 win->transient_for = transient_for;
199 * Updates the _NET_WM_STRUT_PARTIAL (reserved pixels at the screen edges)
202 void window_update_strut_partial(i3Window *win, xcb_get_property_reply_t *prop) {
203 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
204 DLOG("_NET_WM_STRUT_PARTIAL not set.\n");
210 if (!(strut = xcb_get_property_value(prop))) {
215 DLOG("Reserved pixels changed to: left = %d, right = %d, top = %d, bottom = %d\n",
216 strut[0], strut[1], strut[2], strut[3]);
218 win->reserved = (struct reservedpx){ strut[0], strut[1], strut[2], strut[3] };
224 * Updates the WM_WINDOW_ROLE
227 void window_update_role(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
228 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
229 DLOG("WM_WINDOW_ROLE not set.\n");
235 if (asprintf(&new_role, "%.*s", xcb_get_property_value_length(prop),
236 (char*)xcb_get_property_value(prop)) == -1) {
237 perror("asprintf()");
238 DLOG("Could not get WM_WINDOW_ROLE\n");
243 win->role = new_role;
244 LOG("WM_WINDOW_ROLE changed to \"%s\"\n", win->role);
251 run_assignments(win);
257 * Updates the WM_HINTS (we only care about the input focus handling part).
260 void window_update_hints(i3Window *win, xcb_get_property_reply_t *prop) {
261 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
262 DLOG("WM_HINTS not set.\n");
267 xcb_icccm_wm_hints_t hints;
269 if (!xcb_icccm_get_wm_hints_from_reply(&hints, prop)) {
270 DLOG("Could not get WM_HINTS\n");
275 win->doesnt_accept_focus = !hints.input;
276 LOG("WM_HINTS.input changed to \"%d\"\n", hints.input);