diff --git a/awesomerc.5.txt b/awesomerc.5.txt index 832ba045..1a9d7850 100644 --- a/awesomerc.5.txt +++ b/awesomerc.5.txt @@ -54,7 +54,6 @@ List of *awesome* markup elements and their attributes: - right: right margin in pixel - top: top margin in pixel * text - - align: text alignment - shadow: shadow color - shadow_offset: shadow color offset in pixel diff --git a/draw.c b/draw.c index 06313a4f..f0981503 100644 --- a/draw.c +++ b/draw.c @@ -205,9 +205,6 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem, for(; *names; names++, values++) switch(a_tokenize(*names, -1)) { - case A_TK_ALIGN: - data->align = draw_align_fromstr(*values, -1); - break; case A_TK_SHADOW: reqs[++reqs_nbr] = xcolor_init_unchecked(&data->shadow.color, *values, @@ -314,6 +311,7 @@ draw_context_init(draw_context_t *d, int phys_screen, * \param font The font to use. * \param elip Ellipsize mode. * \param wrap Wrap mode. + * \param align Text alignment. * \param area Area to draw to. * \param text Text to draw. * \param len Text to draw length. @@ -322,8 +320,8 @@ draw_context_init(draw_context_t *d, int phys_screen, */ void draw_text(draw_context_t *ctx, font_t *font, PangoEllipsizeMode ellip, PangoWrapMode wrap, - area_t area, const char *text, ssize_t len, draw_parser_data_t *pdata, - area_t *ext) + alignment_t align, area_t area, const char *text, ssize_t len, + draw_parser_data_t *pdata, area_t *ext) { int x, y; draw_parser_data_t parser_data; @@ -387,7 +385,7 @@ draw_text(draw_context_t *ctx, font_t *font, PangoEllipsizeMode ellip, PangoWrap /* only honors alignment if enough space */ if(ext->width < area.width) - switch(pdata->align) + switch(align) { case AlignCenter: x += (area.width - ext->width) / 2; diff --git a/draw.h b/draw.h index 82f97896..1be60f52 100644 --- a/draw.h +++ b/draw.h @@ -148,7 +148,6 @@ typedef struct PangoAttrList *attr_list; char *text; ssize_t len; - alignment_t align; struct { int left, right, top; @@ -169,7 +168,7 @@ typedef struct } shadow; } draw_parser_data_t; -void draw_text(draw_context_t *, font_t *, PangoEllipsizeMode, PangoWrapMode, area_t, const char *, ssize_t len, draw_parser_data_t *, area_t *); +void draw_text(draw_context_t *, font_t *, PangoEllipsizeMode, PangoWrapMode, alignment_t, area_t, const char *, ssize_t len, draw_parser_data_t *, area_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/widgets/textbox.c b/widgets/textbox.c index 6ae01679..8b68e678 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -45,6 +45,8 @@ typedef struct int width; xcolor_t color; } border; + /** Text alignment */ + alignment_t align; } textbox_data_t; static area_t @@ -86,7 +88,8 @@ textbox_draw(widget_t *widget, draw_context_t *ctx, area_t geometry, if(d->border.width > 0) draw_rectangle(ctx, geometry, d->border.width, false, &d->border.color); - draw_text(ctx, globalconf.font, d->ellip, d->wrap, geometry, d->text, d->len, &d->pdata, &d->extents); + draw_text(ctx, globalconf.font, d->ellip, d->wrap, d->align, + geometry, d->text, d->len, &d->pdata, &d->extents); } /** Delete a textbox widget. @@ -112,6 +115,7 @@ textbox_destructor(widget_t *w) * \lfield ellipsize The ellipsize mode: start, middle or end. * \lfield border_width The border width to draw around. * \lfield border_color The border color. + * \lfield align Text alignment, left, center or right. */ static int luaA_textbox_index(lua_State *L, awesome_token_t token) @@ -121,6 +125,9 @@ luaA_textbox_index(lua_State *L, awesome_token_t token) switch(token) { + case A_TK_ALIGN: + lua_pushstring(L, draw_align_tostr(d->align)); + return 1; case A_TK_BORDER_WIDTH: lua_pushnumber(L, d->border.width); return 1; @@ -181,6 +188,10 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token) switch(token) { + case A_TK_ALIGN: + if((buf = luaL_checklstring(L, 3, &len))) + d->align = draw_align_fromstr(buf, len); + break; case A_TK_BORDER_COLOR: if((buf = luaL_checklstring(L, 3, &len))) xcolor_init_reply(xcolor_init_unchecked(&d->border.color, buf, len));