]> git.sur5r.net Git - i3/i3/commitdiff
Convert window title to UCS-2 when updating it, don’t update it if it didn’t change
authorMichael Stapelberg <michael+x200@stapelberg.de>
Mon, 9 Mar 2009 05:26:32 +0000 (06:26 +0100)
committerMichael Stapelberg <michael+x200@stapelberg.de>
Mon, 9 Mar 2009 05:26:32 +0000 (06:26 +0100)
include/data.h
src/handlers.c
src/layout.c

index c5dbf67e42f8357ddb0ef98df1a7539acae6961c..083d7fbd1ce9f515e23f0d6823a84f4c60984711 100644 (file)
@@ -215,6 +215,7 @@ struct Client {
 
         /* Name (= window title) */
         char *name;
+        int name_len;
 
         /* fullscreen is pretty obvious */
         bool fullscreen;
index 714ff211742c367b902a0558dbab7348cbe3e6cb..58e8c068af037261ff7a6401314e8cc37e23f4cf 100644 (file)
@@ -495,8 +495,24 @@ int handle_windowname_change(void *data, xcb_connection_t *conn, uint8_t state,
                 return 1;
 
         /* Save the old pointer to make the update atomic */
+        char *new_name;
+        int new_len;
+        asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop), (char*)xcb_get_property_value(prop));
+        /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */
+        char *ucs2_name = convert_utf8_to_ucs2(new_name, &new_len);
+        free(new_name);
+
+        /* Check if they are the same and don’t update if so */
+        if (new_len == client->name_len && strcmp(client->name, new_name) == 0) {
+                LOG("Name did not change, not updating\n");
+                free(ucs2_name);
+                return;
+        }
+
         char *old_name = client->name;
-        asprintf(&(client->name), "%.*s", xcb_get_property_value_length(prop), (char*)xcb_get_property_value(prop));
+        client->name = ucs2_name;
+        client->name_len = new_len;
+
         if (old_name != NULL)
                 free(old_name);
         LOG("rename to \"%s\".\n", client->name);
index 0aff86652945d3b0d414030d299adf460ca832f2..14120ef06ec6f91a7c5274a3e046be7533f3728f 100644 (file)
@@ -169,11 +169,8 @@ void decorate_window(xcb_connection_t *conn, Client *client, xcb_drawable_t draw
                 uint32_t values[] = { text_color, background_color, font->id };
                 xcb_change_gc(conn, gc, mask, values);
 
-                int real_strlen;
-                char *ucs2_label = convert_utf8_to_ucs2(client->name, &real_strlen);
-                xcb_image_text_16(conn, real_strlen, drawable, gc, 3 /* X */,
-                                  offset + font->height /* Y = baseline of font */, (xcb_char2b_t*)ucs2_label);
-                free(ucs2_label);
+                xcb_image_text_16(conn, client->name_len, drawable, gc, 3 /* X */,
+                                  offset + font->height /* Y = baseline of font */, (xcb_char2b_t*)client->name);
         }
 }