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");
22 /* We cannot use asprintf here since this property contains two
23 * null-terminated strings (for compatibility reasons). Instead, we
24 * use strdup() on both strings */
25 char *new_class = xcb_get_property_value(prop);
27 FREE(win->class_instance);
28 FREE(win->class_class);
30 win->class_instance = sstrdup(new_class);
31 if ((strlen(new_class) + 1) < xcb_get_property_value_length(prop))
32 win->class_class = sstrdup(new_class + strlen(new_class) + 1);
33 else win->class_class = NULL;
34 LOG("WM_CLASS changed to %s (instance), %s (class)\n",
35 win->class_instance, win->class_class);
48 * Updates the name by using _NET_WM_NAME (encoded in UTF-8) for the given
49 * window. Further updates using window_update_name_legacy will be ignored.
52 void window_update_name(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
53 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
54 DLOG("_NET_WM_NAME not specified, not changing\n");
59 /* Save the old pointer to make the update atomic */
61 if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
62 (char*)xcb_get_property_value(prop)) == -1) {
64 DLOG("Could not get window name\n");
68 /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */
70 char *ucs2_name = convert_utf8_to_ucs2(new_name, &len);
71 if (ucs2_name == NULL) {
72 LOG("Could not convert _NET_WM_NAME to UCS-2, ignoring new hint\n");
79 win->name_json = new_name;
80 win->name_x = ucs2_name;
82 win->name_x_changed = true;
83 LOG("_NET_WM_NAME changed to \"%s\"\n", win->name_json);
85 win->uses_net_wm_name = true;
98 * Updates the name by using WM_NAME (encoded in COMPOUND_TEXT). We do not
99 * touch what the client sends us but pass it to xcb_image_text_8. To get
100 * proper unicode rendering, the application has to use _NET_WM_NAME (see
101 * window_update_name()).
104 void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
105 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
106 DLOG("prop == NULL\n");
111 /* ignore update when the window is known to already have a UTF-8 name */
112 if (win->uses_net_wm_name) {
118 if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
119 (char*)xcb_get_property_value(prop)) == -1) {
120 perror("asprintf()");
121 DLOG("Could not get legacy window name\n");
126 LOG("Using legacy window title. Note that in order to get Unicode window "
127 "titles in i3, the application has to set _NET_WM_NAME (UTF-8)\n");
130 FREE(win->name_json);
131 win->name_x = new_name;
132 win->name_json = sstrdup(new_name);
133 win->name_len = strlen(new_name);
134 win->name_x_changed = true;
141 run_assignments(win);
147 * Updates the CLIENT_LEADER (logical parent window).
150 void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop) {
151 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
152 DLOG("prop == NULL\n");
157 xcb_window_t *leader = xcb_get_property_value(prop);
158 if (leader == NULL) {
163 DLOG("Client leader changed to %08x\n", *leader);
165 win->leader = *leader;
171 * Updates the TRANSIENT_FOR (logical parent window).
174 void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop) {
175 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
176 DLOG("prop == NULL\n");
181 xcb_window_t transient_for;
182 if (!xcb_icccm_get_wm_transient_for_from_reply(&transient_for, prop)) {
187 DLOG("Transient for changed to %08x\n", transient_for);
189 win->transient_for = transient_for;
195 * Updates the _NET_WM_STRUT_PARTIAL (reserved pixels at the screen edges)
198 void window_update_strut_partial(i3Window *win, xcb_get_property_reply_t *prop) {
199 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
200 DLOG("prop == NULL\n");
206 if (!(strut = xcb_get_property_value(prop))) {
211 DLOG("Reserved pixels changed to: left = %d, right = %d, top = %d, bottom = %d\n",
212 strut[0], strut[1], strut[2], strut[3]);
214 win->reserved = (struct reservedpx){ strut[0], strut[1], strut[2], strut[3] };
220 * Updates the WM_WINDOW_ROLE
223 void window_update_role(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
224 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
225 DLOG("prop == NULL\n");
231 if (asprintf(&new_role, "%.*s", xcb_get_property_value_length(prop),
232 (char*)xcb_get_property_value(prop)) == -1) {
233 perror("asprintf()");
234 DLOG("Could not get WM_WINDOW_ROLE\n");
239 win->role = new_role;
240 LOG("WM_WINDOW_ROLE changed to \"%s\"\n", win->role);
247 run_assignments(win);