diff --git a/client.c b/client.c index bb552fb69..707539f62 100644 --- a/client.c +++ b/client.c @@ -188,7 +188,7 @@ client_updatetitle(client_t *c) return; p_delete(&c->name); - c->name = name; + a_iso2utf8(name, &c->name); /* call hook */ luaA_client_userdata_new(c); @@ -1178,7 +1178,7 @@ luaA_client_name_set(lua_State *L) client_t **c = luaA_checkudata(L, 1, "client"); const char *name = luaL_checkstring(L, 2); p_delete(&(*c)->name); - (*c)->name = a_strdup(name); + a_iso2utf8(name, &(*c)->name); return 0; } diff --git a/common/draw.c b/common/draw.c index a7e4e560f..40acd55e4 100644 --- a/common/draw.c +++ b/common/draw.c @@ -49,7 +49,7 @@ * \param iso the ISO string to convert * \return NULL if error, otherwise pointer to the new converted string */ -static char * +char * draw_iso2utf8(const char *iso) { iconv_t iso2utf8; @@ -304,11 +304,7 @@ draw_text(draw_context_t *ctx, font_t *font, if(!(len = a_strlen(text))) return; - /* try to convert it to UTF-8 */ - if((utf8 = draw_iso2utf8(text))) - len = a_strlen(utf8); - else - utf8 = a_strdup(text); + utf8 = a_strdup(text); p_clear(&parser_data, 1); parser_data.connection = ctx->connection; @@ -1033,10 +1029,7 @@ draw_text_extents(xcb_connection_t *conn, int phys_screen, font_t *font, const c return geom; /* try to convert it to UTF-8 */ - if((utf8 = draw_iso2utf8(text))) - len = a_strlen(utf8); - else - utf8 = a_strdup(text); + utf8 = a_strdup(text); p_clear(&parser_data, 1); parser_data.connection = conn; diff --git a/common/draw.h b/common/draw.h index 05a3e8c6b..ff3d3ca92 100644 --- a/common/draw.h +++ b/common/draw.h @@ -139,6 +139,21 @@ draw_context_delete(draw_context_t **ctx) font_t *draw_font_new(xcb_connection_t *, int, const char *); void draw_font_delete(font_t **); +char * draw_iso2utf8(const char *); + +static inline bool +a_iso2utf8(const char *str, char **res) +{ + char *utf8; + if((utf8 = draw_iso2utf8(str))) + { + *res = utf8; + return true; + } + *res = a_strdup(str); + return false; +} + void draw_text(draw_context_t *, font_t *, area_t, const char *); void draw_rectangle(draw_context_t *, area_t, float, bool, xcolor_t); void draw_rectangle_gradient(draw_context_t *, area_t, float, bool, area_t, xcolor_t *, xcolor_t *, xcolor_t *); diff --git a/tag.c b/tag.c index 5550f41b0..b97db0ad7 100644 --- a/tag.c +++ b/tag.c @@ -65,7 +65,7 @@ tag_new(const char *name, layout_t *layout, double mwfact, int nmaster, int ncol tag_t *tag; tag = p_new(tag_t, 1); - tag->name = a_strdup(name); + a_iso2utf8(name, &tag->name); tag->layout = layout; tag->mwfact = mwfact; @@ -473,7 +473,7 @@ luaA_tag_name_set(lua_State *L) tag_t **tag = luaA_checkudata(L, 1, "tag"); const char *name = luaL_checkstring(L, 2); p_delete(&(*tag)->name); - (*tag)->name = a_strdup(name); + a_iso2utf8(name, &(*tag)->name); return 0; } diff --git a/widgets/textbox.c b/widgets/textbox.c index da41cec04..5fe90781b 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -73,7 +73,7 @@ textbox_tell(widget_t *widget, const char *property, const char *new_value) if(!a_strcmp(property, "text")) { p_delete(&d->text); - d->text = a_strdup(new_value); + a_iso2utf8(new_value, &d->text); } else if(!a_strcmp(property, "width")) d->width = atoi(new_value);