2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009-2010 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) {
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 = strdup(new_class);
30 if ((strlen(new_class) + 1) < xcb_get_property_value_length(prop))
31 win->class_class = strdup(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);
38 * Updates the name by using _NET_WM_NAME (encoded in UTF-8) for the given
39 * window. Further updates using window_update_name_legacy will be ignored.
42 void window_update_name(i3Window *win, xcb_get_property_reply_t *prop) {
43 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
44 DLOG("_NET_WM_NAME not specified, not changing\n");
48 /* Save the old pointer to make the update atomic */
50 if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
51 (char*)xcb_get_property_value(prop)) == -1) {
53 DLOG("Could not get window name\n");
55 /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */
58 win->name_json = new_name;
59 win->name_x = convert_utf8_to_ucs2(win->name_json, &win->name_len);
60 LOG("_NET_WM_NAME changed to \"%s\"\n", win->name_json);
62 win->uses_net_wm_name = true;
66 * Updates the name by using WM_NAME (encoded in COMPOUND_TEXT). We do not
67 * touch what the client sends us but pass it to xcb_image_text_8. To get
68 * proper unicode rendering, the application has to use _NET_WM_NAME (see
69 * window_update_name()).
72 void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop) {
73 if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
74 DLOG("prop == NULL\n");
78 /* ignore update when the window is known to already have a UTF-8 name */
79 if (win->uses_net_wm_name)
83 if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
84 (char*)xcb_get_property_value(prop)) == -1) {
86 DLOG("Could not get legacy window name\n");
90 LOG("Using legacy window title. Note that in order to get Unicode window "
91 "titles in i3, the application has to set _NET_WM_NAME (UTF-8)\n");
95 win->name_x = new_name;
96 win->name_json = strdup(new_name);
97 win->name_len = strlen(new_name);