diff --git a/common/draw.c b/common/draw.c index 8128c8308..c5378b97e 100644 --- a/common/draw.c +++ b/common/draw.c @@ -325,20 +325,17 @@ draw_text_markup_expand(draw_parser_data_t *data, * \param font The font to use. * \param area Area to draw to. * \param text Text to draw. + * \param len Text to draw length. * \param data Optional parser data. */ void draw_text(draw_context_t *ctx, font_t *font, - area_t area, const char *text, draw_parser_data_t *pdata) + area_t area, const char *text, ssize_t len, draw_parser_data_t *pdata) { int x, y; - ssize_t len = 0, olen; PangoRectangle ext; draw_parser_data_t parser_data; - if(!(len = a_strlen(text))) - return; - if(!pdata) { draw_parser_data_init(&parser_data); @@ -357,8 +354,6 @@ draw_text(draw_context_t *ctx, font_t *font, len = pdata->text.len; } - olen = len; - if(pdata->has_bg_color) draw_rectangle(ctx, area, 1.0, true, &pdata->bg_color); diff --git a/common/draw.h b/common/draw.h index c820a3370..478339fa9 100644 --- a/common/draw.h +++ b/common/draw.h @@ -199,7 +199,7 @@ typedef struct void draw_parser_data_init(draw_parser_data_t *); void draw_parser_data_wipe(draw_parser_data_t *); -void draw_text(draw_context_t *, font_t *, area_t, const char *, draw_parser_data_t *); +void draw_text(draw_context_t *, font_t *, area_t, const char *, ssize_t len, draw_parser_data_t *); void draw_rectangle(draw_context_t *, area_t, float, bool, const xcolor_t *); void draw_rectangle_gradient(draw_context_t *, area_t, float, bool, vector_t, const xcolor_t *, const xcolor_t *, const xcolor_t *); diff --git a/mouse.c b/mouse.c index 4f79f19a0..9da99bacf 100644 --- a/mouse.c +++ b/mouse.c @@ -241,11 +241,12 @@ mouse_infobox_draw(draw_context_t *ctx, { area_t draw_geometry = { 0, 0, ctx->width, ctx->height }; char size[64]; + size_t len; - snprintf(size, sizeof(size), "%dx%d+%d+%d", - geometry.width, geometry.height, geometry.x, geometry.y); + len = snprintf(size, sizeof(size), "%dx%d+%d+%d", + geometry.width, geometry.height, geometry.x, geometry.y); draw_rectangle(ctx, draw_geometry, 1.0, true, &globalconf.colors.bg); - draw_text(ctx, globalconf.font, draw_geometry, size, NULL); + draw_text(ctx, globalconf.font, draw_geometry, size, len, NULL); simplewindow_move(sw, geometry.x + ((2 * border + geometry.width) - sw->geometry.width) / 2, geometry.y + ((2 * border + geometry.height) - sw->geometry.height) / 2); diff --git a/widgets/taglist.c b/widgets/taglist.c index ea98743c8..d7e35bafd 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -93,10 +93,10 @@ taglist_draw(draw_context_t *ctx, int screen, widget_node_t *w, area_t area; taglist_drawn_area_t *tda; int prev_width = 0; - size_t len; tag_array_t *tags = &globalconf.screens[screen].tags; const char **text = p_alloca(const char *, tags->len); + size_t *len = p_alloca(size_t, tags->len); draw_parser_data_t *pdata = p_alloca(draw_parser_data_t, tags->len); w->area.width = w->area.y = 0; @@ -125,13 +125,13 @@ taglist_draw(draw_context_t *ctx, int screen, widget_node_t *w, luaA_dofunction(globalconf.L, data->label, 1, 1); if(lua_isstring(globalconf.L, -1)) - text[i] = lua_tolstring(globalconf.L, -1, &len); + text[i] = lua_tolstring(globalconf.L, -1, &len[i]); lua_pop(globalconf.L, 1); draw_parser_data_init(&pdata[i]); area = draw_text_extents(ctx->connection, ctx->phys_screen, - globalconf.font, text[i], len, &pdata[i]); + globalconf.font, text[i], len[i], &pdata[i]); if(pdata[i].bg_image) area.width = MAX(area.width, pdata[i].bg_resize ? w->area.height : pdata[i].bg_image->width); @@ -159,7 +159,7 @@ taglist_draw(draw_context_t *ctx, int screen, widget_node_t *w, r->x = w->area.x + prev_width; prev_width += r->width; - draw_text(ctx, globalconf.font, *r, text[i], &pdata[i]); + draw_text(ctx, globalconf.font, *r, text[i], len[i], &pdata[i]); draw_parser_data_wipe(&pdata[i]); } diff --git a/widgets/tasklist.c b/widgets/tasklist.c index 02b0bd05e..99edde0d2 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -214,7 +214,7 @@ tasklist_draw(draw_context_t *ctx, int screen, if(i == n - 1) area.width += box_width_rest; - draw_text(ctx, globalconf.font, area, text, NULL); + draw_text(ctx, globalconf.font, area, text, len, NULL); i++; } diff --git a/widgets/textbox.c b/widgets/textbox.c index 8eab4ffac..dcd574bd4 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -80,7 +80,7 @@ textbox_draw(draw_context_t *ctx, int screen __attribute__ ((unused)), w->widget->align); w->area.y = 0; - draw_text(ctx, globalconf.font, w->area, d->text, pdata_arg); + draw_text(ctx, globalconf.font, w->area, d->text, d->len, pdata_arg); if (pdata_arg) draw_parser_data_wipe(pdata_arg);