diff --git a/awesome-menu.c b/awesome-menu.c index 72bea2e79..91121361f 100644 --- a/awesome-menu.c +++ b/awesome-menu.c @@ -431,8 +431,7 @@ redraw(void) if(a_strlen(globalconf.prompt)) { - draw_text(globalconf.ctx, geometry, - MARGIN, globalconf.prompt, globalconf.styles.focus); + draw_text(globalconf.ctx, geometry, globalconf.prompt, globalconf.styles.focus); len = MARGIN * 2 + draw_text_extents(globalconf.connection, globalconf.default_screen, globalconf.styles.focus.font, globalconf.prompt).width; @@ -440,8 +439,7 @@ redraw(void) geometry.width -= len; } - draw_text(globalconf.ctx, geometry, - MARGIN, globalconf.text, globalconf.styles.normal); + draw_text(globalconf.ctx, geometry, globalconf.text, globalconf.styles.normal); len = MARGIN * 2 + MAX(draw_text_extents(globalconf.connection, globalconf.default_screen, globalconf.styles.normal.font, globalconf.text).width, @@ -463,7 +461,7 @@ redraw(void) else selected_item_is_drawn = true; } - draw_text(globalconf.ctx, geometry, MARGIN / 2, item->data, style); + draw_text(globalconf.ctx, geometry, item->data, style); geometry.x += len; geometry.width -= len; } @@ -485,7 +483,7 @@ redraw(void) if(geometry.x < prompt_len) break; - draw_text(globalconf.ctx, geometry, MARGIN / 2, item->data, style); + draw_text(globalconf.ctx, geometry, item->data, style); } if(item) diff --git a/awesome-message.c b/awesome-message.c index 95d0a1983..02d142e9f 100644 --- a/awesome-message.c +++ b/awesome-message.c @@ -211,7 +211,7 @@ main(int argc, char **argv) geometry.width, geometry.height, sw->drawable); geometry.x = geometry.y = 0; - draw_text(ctx, geometry, 0, argv[optind], globalconf.style); + draw_text(ctx, geometry, argv[optind], globalconf.style); if(icon_geometry.width > 0 && icon_geometry.height > 0) draw_image(ctx, 0, (geometry.height / 2) - (globalconf.style.font->height / 2), diff --git a/common/configopts.c b/common/configopts.c index fb7adce1b..c659c6ca6 100644 --- a/common/configopts.c +++ b/common/configopts.c @@ -280,11 +280,11 @@ cfg_opt_t widget_taglist_opts[] = /** Mouse bindings. */ CFG_SEC((char *) "mouse", mouse_taglist_opts, CFGF_MULTI), /** Markup title string for normal tags */ - CFG_STR((char *) "text_normal", (char *) "", CFGF_NONE), + CFG_STR((char *) "text_normal", (char *) " <text align=\"center\"/><bg color=\"#444444\"/><title/> ", CFGF_NONE), /** Markup title string for selected tags. */ - CFG_STR((char *) "text_focus", (char *) "<text align=\"center\"/><bg color=\"#535d6c\"/><title/>", CFGF_NONE), + CFG_STR((char *) "text_focus", (char *) " <text align=\"center\"/><bg color=\"#535d6c\"/><title/> ", CFGF_NONE), /** Markup title string for tags with urgent windows. */ - CFG_STR((char *) "text_urgent", (char *) "<text align=\"center\"/><bg color=\"#ff4500\"/><title/>", CFGF_NONE), + CFG_STR((char *) "text_urgent", (char *) " <text align=\"center\"/><bg color=\"#ff4500\"/><title/> ", CFGF_NONE), CFG_AWESOME_END() }; /** This section defines iconbox widget options. */ diff --git a/common/draw.c b/common/draw.c index b167a4dd6..88a67609e 100644 --- a/common/draw.c +++ b/common/draw.c @@ -221,6 +221,10 @@ typedef struct int phys_screen; char *text; alignment_t align; + struct + { + int left, right; + } margin; bool has_bg_color; xcolor_t bg_color; } draw_parser_data_t; @@ -229,14 +233,14 @@ static bool draw_text_markup_expand(draw_parser_data_t *data, const char *str, ssize_t slen) { - const char *elements[] = { "bg", "text", NULL }; + const char *elements[] = { "bg", "text", "margin", NULL }; markup_parser_data_t *p; int i; p = markup_parser_data_new(elements, NULL, countof(elements)); if(!markup_parse(p, str, slen)) - return false; + return a_strdup(str); /* bg */ if(p->attribute_names[0]) @@ -251,6 +255,16 @@ draw_text_markup_expand(draw_parser_data_t *data, if(!a_strcmp(p->attribute_names[1][i], "align")) data->align = draw_align_get_from_str(p->attribute_values[1][i]); + /* margin */ + if(p->attribute_names[2]) + for(i = 0; p->attribute_names[2][i]; i++) + { + if(!a_strcmp(p->attribute_names[2][i], "left")) + data->margin.left = atoi(p->attribute_values[2][i]); + else if(!a_strcmp(p->attribute_names[2][i], "right")) + data->margin.right = atoi(p->attribute_values[2][i]); + } + /* stole text */ data->text = p->text; p->text = NULL; @@ -263,16 +277,11 @@ draw_text_markup_expand(draw_parser_data_t *data, /** Draw text into a draw context * \param ctx DrawCtx to draw to * \param area area to draw to - * \param padding padding to add before drawing the text * \param text text to draw * \return area_t with width and height are set to what used */ void -draw_text(DrawCtx *ctx, - area_t area, - int padding, - const char *text, - style_t style) +draw_text(DrawCtx *ctx, area_t area, const char *text, style_t style) { int x, y; ssize_t len, olen; @@ -311,13 +320,16 @@ draw_text(DrawCtx *ctx, else draw_rectangle(ctx, area, 1.0, true, style.bg); - pango_layout_set_width(ctx->layout, pango_units_from_double(area.width - padding)); + pango_layout_set_width(ctx->layout, + pango_units_from_double(area.width + - (parser_data.margin.left + + parser_data.margin.right))); pango_layout_set_ellipsize(ctx->layout, PANGO_ELLIPSIZE_END); pango_layout_set_markup(ctx->layout, buf, len); pango_layout_set_font_description(ctx->layout, style.font->desc); pango_layout_get_pixel_extents(ctx->layout, NULL, &ext); - x = area.x + padding; + x = area.x + parser_data.margin.left; /* + 1 is added for rounding, so that in any case of doubt we rather draw * the text 1px lower than too high which usually results in a better type * face */ diff --git a/common/draw.h b/common/draw.h index 1a08486f7..19079b89c 100644 --- a/common/draw.h +++ b/common/draw.h @@ -125,7 +125,7 @@ void draw_context_delete(DrawCtx **); font_t *draw_font_new(xcb_connection_t *, int, char *); void draw_font_delete(font_t **); -void draw_text(DrawCtx *, area_t, int, const char *, style_t); +void draw_text(DrawCtx *, area_t, const char *, style_t); void draw_rectangle(DrawCtx *, area_t, float, bool, xcolor_t); void draw_rectangle_gradient(DrawCtx *, area_t, float, bool, area_t, xcolor_t *, xcolor_t *, xcolor_t *); diff --git a/common/markup.c b/common/markup.c index 495adce29..a666c9a6c 100644 --- a/common/markup.c +++ b/common/markup.c @@ -148,10 +148,7 @@ markup_parse_text(GMarkupParseContext *context __attribute__ ((unused)), len = a_strlen(p->text); rlen = len + 1 + text_len; p_realloc(&p->text, rlen); - if(len) - a_strncat(p->text, rlen, text, len); - else - a_strncpy(p->text, rlen, text, text_len); + a_strncat(p->text, rlen, text, text_len); } /** Create a markup_parser_data_t structure with elements list. @@ -169,6 +166,7 @@ markup_parser_data_new(const char **elements, const char **elements_sub, ssize_t p = p_new(markup_parser_data_t, 1); + p->text = p_new(char, 1); p->elements = elements; p->elements_sub = elements_sub; p->attribute_names = p_new(char **, nelem); diff --git a/mouse.c b/mouse.c index bd3cf0b19..3fd037dd7 100644 --- a/mouse.c +++ b/mouse.c @@ -145,7 +145,7 @@ mouse_resizebar_draw(DrawCtx *ctx, style_t style, simple_window_t *sw, area_t ge snprintf(size, sizeof(size), "<text align=\"center\"/>%dx%d+%d+%d", geometry.x, geometry.y, geometry.width, geometry.height); - draw_text(ctx, draw_geometry, style.font->height / 2, size, style); + draw_text(ctx, draw_geometry, size, style); 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/titlebar.c b/titlebar.c index 433a4d033..e3507cbf3 100644 --- a/titlebar.c +++ b/titlebar.c @@ -216,8 +216,7 @@ titlebar_draw(client_t *c) text = titlebar_text(c); geometry.x = geometry.y = 0; - draw_text(ctx, geometry, 0, - text, globalconf.screens[c->screen].styles.normal); + draw_text(ctx, geometry, text, globalconf.screens[c->screen].styles.normal); p_delete(&text); switch(c->titlebar.position) diff --git a/widgets/taglist.c b/widgets/taglist.c index 41ac5fab9..a742ed1c7 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -123,7 +123,6 @@ taglist_draw(widget_t *widget, *area = draw_text_extents(ctx->connection, ctx->default_screen, style.font, text[i]); area->x = widget->area.width; - area->width += style.font->height; area->height = widget->statusbar->height; area_list_append(&data->draw_area, area); widget->area.width += area->width; @@ -142,7 +141,7 @@ taglist_draw(widget_t *widget, tag && area; tag = tag->next, area = area->next, i++) { - draw_text(ctx, *area, 0, text[i], style); + draw_text(ctx, *area, text[i], style); if(tag_isoccupied(tag)) { diff --git a/widgets/tasklist.c b/widgets/tasklist.c index 84de43646..3cca03f37 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -169,7 +169,7 @@ tasklist_draw(widget_t *widget, DrawCtx *ctx, int offset, int used) if(i == n - 1) area.width += box_width_rest; - draw_text(ctx, area, style.font->height / 2, text, style); + draw_text(ctx, area, text, style); p_delete(&text); diff --git a/widgets/textbox.c b/widgets/textbox.c index 812bb0017..d45484092 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -56,7 +56,7 @@ textbox_draw(widget_t *widget, DrawCtx *ctx, int offset, int used) if(!widget->user_supplied_y) widget->area.y = 0; - draw_text(ctx, widget->area, 0, d->text, globalconf.screens[widget->statusbar->screen].styles.normal); + draw_text(ctx, widget->area, d->text, globalconf.screens[widget->statusbar->screen].styles.normal); return widget->area.width; }