]> git.sur5r.net Git - i3/i3/commitdiff
i3/window: Port window names to i3String
authorQuentin Glidic <sardemff7+git@sardemff7.net>
Tue, 7 Aug 2012 19:23:06 +0000 (21:23 +0200)
committerQuentin Glidic <sardemff7+git@sardemff7.net>
Mon, 13 Aug 2012 09:30:08 +0000 (11:30 +0200)
include/data.h
src/ipc.c
src/match.c
src/tree.c
src/window.c
src/x.c

index a5ac943cead29eec8ea241e458c30e34395fa22b..6df3f6fc5a082b10080b068b91803ac330ad065f 100644 (file)
@@ -19,6 +19,7 @@
 #include <pcre.h>
 #include <sys/time.h>
 
+#include "libi3.h"
 #include "queue.h"
 
 /*
@@ -287,9 +288,8 @@ struct Window {
     char *class_class;
     char *class_instance;
 
-    /** The name of the window as it will be passed to X11 (in UCS2 if the
-     * application supports _NET_WM_NAME, in COMPOUND_TEXT otherwise). */
-    char *name_x;
+    /** The name of the window. */
+    i3String *name;
 
     /** The WM_WINDOW_ROLE of this window (for example, the pidgin buddy window
      * sets "buddy list"). Useful to match specific windows in assignments or
@@ -299,13 +299,6 @@ struct Window {
     /** Flag to force re-rendering the decoration upon changes */
     bool name_x_changed;
 
-    /** The name of the window as used in JSON (in UTF-8 if the application
-     * supports _NET_WM_NAME, in COMPOUND_TEXT otherwise) */
-    char *name_json;
-
-    /** The length of the name in glyphs (not bytes) */
-    size_t name_len;
-
     /** Whether the application used _NET_WM_NAME */
     bool uses_net_wm_name;
 
index 8db69259fcdf91cf711e6deb6ca9d649be5df510..1c6de798803bf2f0b729558aef819f523448077e 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -259,8 +259,8 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
     dump_rect(gen, "geometry", con->geometry);
 
     ystr("name");
-    if (con->window && con->window->name_json)
-        ystr(con->window->name_json);
+    if (con->window && con->window->name)
+        ystr(i3string_as_utf8(con->window->name));
     else
         ystr(con->name);
 
index 1014de848d358bb6a0e089cc76515331334774e0..350a2c11d0e115091e01ab7af96a31af55e29ebd 100644 (file)
@@ -113,9 +113,9 @@ bool match_matches_window(Match *match, i3Window *window) {
     }
 
     if (match->title != NULL) {
-        if (window->name_json != NULL &&
-            regex_matches(match->title, window->name_json)) {
-            LOG("title matches (%s)\n", window->name_json);
+        if (window->name != NULL &&
+            regex_matches(match->title, i3string_as_utf8(window->name))) {
+            LOG("title matches (%s)\n", i3string_as_utf8(window->name));
         } else {
             return false;
         }
index d2dc10ea470eda18ba6a670c3306b6d5e751c270..2c1c257e0235c569e869a20f8ca4d696b6b6899f 100644 (file)
@@ -247,8 +247,7 @@ bool tree_close(Con *con, kill_window_t kill_window, bool dont_kill_parent, bool
         }
         FREE(con->window->class_class);
         FREE(con->window->class_instance);
-        FREE(con->window->name_x);
-        FREE(con->window->name_json);
+        i3string_free(con->window->name);
         free(con->window);
     }
 
index 6ec63a8b43d60bb9717e0a8d92b82b6b7dd96127..b886c380880e865dd913340840420ab2e1cd0cbc 100644 (file)
@@ -60,31 +60,11 @@ void window_update_name(i3Window *win, xcb_get_property_reply_t *prop, bool befo
         return;
     }
 
-    /* Save the old pointer to make the update atomic */
-    char *new_name;
-    if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
-                 (char*)xcb_get_property_value(prop)) == -1) {
-        perror("asprintf()");
-        DLOG("Could not get window name\n");
-        free(prop);
-        return;
-    }
-    /* Convert it to UCS-2 here for not having to convert it later every time we want to pass it to X */
-    size_t len;
-    xcb_char2b_t *ucs2_name = convert_utf8_to_ucs2(new_name, &len);
-    if (ucs2_name == NULL) {
-        LOG("Could not convert _NET_WM_NAME to UCS-2, ignoring new hint\n");
-        FREE(new_name);
-        free(prop);
-        return;
-    }
-    FREE(win->name_x);
-    FREE(win->name_json);
-    win->name_json = new_name;
-    win->name_x = (char*)ucs2_name;
-    win->name_len = len;
+    i3string_free(win->name);
+    win->name = i3string_from_utf8_with_length(xcb_get_property_value(prop),
+                                               xcb_get_property_value_length(prop));
     win->name_x_changed = true;
-    LOG("_NET_WM_NAME changed to \"%s\"\n", win->name_json);
+    LOG("_NET_WM_NAME changed to \"%s\"\n", i3string_as_utf8(win->name));
 
     win->uses_net_wm_name = true;
 
@@ -118,24 +98,14 @@ void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop, bo
         return;
     }
 
-    char *new_name;
-    if (asprintf(&new_name, "%.*s", xcb_get_property_value_length(prop),
-                 (char*)xcb_get_property_value(prop)) == -1) {
-        perror("asprintf()");
-        DLOG("Could not get legacy window name\n");
-        free(prop);
-        return;
-    }
+    i3string_free(win->name);
+    win->name = i3string_from_utf8_with_length(xcb_get_property_value(prop),
+                                               xcb_get_property_value_length(prop));
 
-    LOG("WM_NAME changed to \"%s\"\n", new_name);
+    LOG("WM_NAME changed to \"%s\"\n", i3string_as_utf8(win->name));
     LOG("Using legacy window title. Note that in order to get Unicode window "
         "titles in i3, the application has to set _NET_WM_NAME (UTF-8)\n");
 
-    FREE(win->name_x);
-    FREE(win->name_json);
-    win->name_x = new_name;
-    win->name_json = sstrdup(new_name);
-    win->name_len = strlen(new_name);
     win->name_x_changed = true;
 
     if (before_mgmt) {
diff --git a/src/x.c b/src/x.c
index 84217a85f1101a6d8659ed77d6674ebbe2c5c1db..864949e5281fa56e78a0a9e15abc6974884e8fe3 100644 (file)
--- a/src/x.c
+++ b/src/x.c
@@ -481,7 +481,7 @@ void x_draw_decoration(Con *con) {
     int text_offset_y = (con->deco_rect.height - config.font.height) / 2;
 
     struct Window *win = con->window;
-    if (win == NULL || win->name_x == NULL) {
+    if (win == NULL || win->name == NULL) {
         /* this is a non-leaf container, we need to make up a good description */
         // TODO: use a good description instead of just "another container"
         draw_text("another container", strlen("another container"), false,
@@ -508,7 +508,7 @@ void x_draw_decoration(Con *con) {
     //DLOG("indent_level = %d, indent_mult = %d\n", indent_level, indent_mult);
     int indent_px = (indent_level * 5) * indent_mult;
 
-    draw_text(win->name_x, win->name_len, win->uses_net_wm_name,
+    draw_text((char *)i3string_as_ucs2(win->name), i3string_get_num_glyphs(win->name), true,
             parent->pixmap, parent->pm_gc,
             con->deco_rect.x + 2 + indent_px, con->deco_rect.y + text_offset_y,
             con->deco_rect.width - 2 - indent_px);