From b6c705a1a4eed6a885d6bbed8246b53d48e60819 Mon Sep 17 00:00:00 2001 From: Quentin Glidic Date: Tue, 7 Aug 2012 21:23:06 +0200 Subject: [PATCH] i3/window: Port window names to i3String --- include/data.h | 13 +++---------- src/ipc.c | 4 ++-- src/match.c | 6 +++--- src/tree.c | 3 +-- src/window.c | 46 ++++++++-------------------------------------- src/x.c | 4 ++-- 6 files changed, 19 insertions(+), 57 deletions(-) diff --git a/include/data.h b/include/data.h index a5ac943c..6df3f6fc 100644 --- a/include/data.h +++ b/include/data.h @@ -19,6 +19,7 @@ #include #include +#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; diff --git a/src/ipc.c b/src/ipc.c index 8db69259..1c6de798 100644 --- 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); diff --git a/src/match.c b/src/match.c index 1014de84..350a2c11 100644 --- a/src/match.c +++ b/src/match.c @@ -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; } diff --git a/src/tree.c b/src/tree.c index d2dc10ea..2c1c257e 100644 --- a/src/tree.c +++ b/src/tree.c @@ -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); } diff --git a/src/window.c b/src/window.c index 6ec63a8b..b886c380 100644 --- a/src/window.c +++ b/src/window.c @@ -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 84217a85..864949e5 100644 --- 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);