2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
11 * Updates the WM_CLASS (consisting of the class and instance) for the
15 void window_update_class(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
16 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
17 DLOG("empty property, not updating\n");
21 /* We cannot use asprintf here since this property contains two
22 * null-terminated strings (for compatibility reasons). Instead, we
23 * use strdup() on both strings */
24 char *new_class = xcb_get_property_value(prop);
26 FREE(win->class_instance);
27 FREE(win->class_class);
29 win->class_instance = sstrdup(new_class);
30 if ((strlen(new_class) + 1) < xcb_get_property_value_length(prop))
31 win->class_class = sstrdup(new_class + strlen(new_class) + 1);
32 else win->class_class = NULL;
33 LOG("WM_CLASS changed to %s (instance), %s (class)\n",
34 win->class_instance, win->class_class);
43 * Updates the name by using _NET_WM_NAME (encoded in UTF-8) for the given
44 * window. Further updates using window_update_name_legacy will be ignored.
47 void window_update_name(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
48 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
49 DLOG("_NET_WM_NAME not specified, not changing\n");
53 /* Save the old pointer to make the update atomic */
55 if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
56 (char*)xcb_get_property_value(prop)) == -1) {
58 DLOG("Could not get window name\n");
61 /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */
63 char *ucs2_name = convert_utf8_to_ucs2(new_name, &len);
64 if (ucs2_name == NULL) {
65 LOG("Could not convert _NET_WM_NAME to UCS-2, ignoring new hint\n");
71 win->name_json = new_name;
72 win->name_x = ucs2_name;
74 win->name_x_changed = true;
75 LOG("_NET_WM_NAME changed to \"%s\"\n", win->name_json);
77 win->uses_net_wm_name = true;
86 * Updates the name by using WM_NAME (encoded in COMPOUND_TEXT). We do not
87 * touch what the client sends us but pass it to xcb_image_text_8. To get
88 * proper unicode rendering, the application has to use _NET_WM_NAME (see
89 * window_update_name()).
92 void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
93 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
94 DLOG("prop == NULL\n");
98 /* ignore update when the window is known to already have a UTF-8 name */
99 if (win->uses_net_wm_name)
103 if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
104 (char*)xcb_get_property_value(prop)) == -1) {
105 perror("asprintf()");
106 DLOG("Could not get legacy window name\n");
110 LOG("Using legacy window title. Note that in order to get Unicode window "
111 "titles in i3, the application has to set _NET_WM_NAME (UTF-8)\n");
114 FREE(win->name_json);
115 win->name_x = new_name;
116 win->name_json = sstrdup(new_name);
117 win->name_len = strlen(new_name);
118 win->name_x_changed = true;
123 run_assignments(win);
127 * Updates the CLIENT_LEADER (logical parent window).
130 void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop) {
131 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
132 DLOG("prop == NULL\n");
136 xcb_window_t *leader = xcb_get_property_value(prop);
140 DLOG("Client leader changed to %08x\n", *leader);
142 win->leader = *leader;
146 * Updates the TRANSIENT_FOR (logical parent window).
149 void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop) {
150 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
151 DLOG("prop == NULL\n");
155 xcb_window_t transient_for;
156 if (!xcb_icccm_get_wm_transient_for_from_reply(&transient_for, prop))
159 DLOG("Transient for changed to %08x\n", transient_for);
161 win->transient_for = transient_for;
165 * Updates the _NET_WM_STRUT_PARTIAL (reserved pixels at the screen edges)
168 void window_update_strut_partial(i3Window *win, xcb_get_property_reply_t *prop) {
169 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
170 DLOG("prop == NULL\n");
175 if (!(strut = xcb_get_property_value(prop)))
178 DLOG("Reserved pixels changed to: left = %d, right = %d, top = %d, bottom = %d\n",
179 strut[0], strut[1], strut[2], strut[3]);
181 win->reserved = (struct reservedpx){ strut[0], strut[1], strut[2], strut[3] };