diff --git a/draw.c b/draw.c index bc13d6ff..687c89f6 100644 --- a/draw.c +++ b/draw.c @@ -66,6 +66,7 @@ draw_free_context(DrawCtx *ctx) * \param y y coord * \param w width * \param h height + * \param align alignment * \param padding padding to add before drawing the text * \param font font to use * \param text text to draw @@ -73,7 +74,13 @@ draw_free_context(DrawCtx *ctx) * \param bg background color */ void -draw_text(DrawCtx *ctx, int x, int y, int w, int h, int padding, XftFont *font, const char *text, XColor fg, XColor bg) +draw_text(DrawCtx *ctx, + int x, int y, + int w, int h, + int align, + int padding, + XftFont *font, const char *text, + XColor fg, XColor bg) { int nw = 0; static char buf[256]; @@ -114,7 +121,12 @@ draw_text(DrawCtx *ctx, int x, int y, int w, int h, int padding, XftFont *font, buf[len - 3] = '.'; } - cairo_move_to(cr, x + padding, y + font->ascent + (ctx->height - font->height) / 2); + if(align == AlignLeft) + cairo_move_to(cr, x + padding, y + font->ascent + (ctx->height - font->height) / 2); + else if(align == AlignRight) + cairo_move_to(cr, x + (w - nw) + padding, y + font->ascent + (ctx->height - font->height) / 2); + else + cairo_move_to(cr, x + ((w - nw) / 2) + padding, y + font->ascent + (ctx->height - font->height) / 2); cairo_show_text(cr, buf); cairo_font_face_destroy(font_face); diff --git a/draw.h b/draw.h index bcbedf39..ba9d7d8a 100644 --- a/draw.h +++ b/draw.h @@ -25,6 +25,8 @@ #include #include +enum { AlignLeft, AlignRight, AlignFlex, AlignCenter }; + typedef struct { /* Co-ords of upper left corner */ @@ -46,7 +48,7 @@ typedef struct DrawCtx *draw_get_context(int, int, int); void draw_free_context(DrawCtx *); -void draw_text(DrawCtx *, int, int, int, int, int, XftFont *, const char *, XColor fg, XColor bg); +void draw_text(DrawCtx *, int, int, int, int, int, int, XftFont *, const char *, XColor fg, XColor bg); void draw_rectangle(DrawCtx *, int, int, int, int, Bool, XColor); void draw_circle(DrawCtx *, int, int, int, Bool, XColor); void draw_image(DrawCtx *, int, int, int, const char *); diff --git a/widget.h b/widget.h index a0412c0a..f5f243bd 100644 --- a/widget.h +++ b/widget.h @@ -27,8 +27,6 @@ #include "config.h" -enum { AlignLeft, AlignRight, AlignFlex }; - typedef Widget *(WidgetConstructor)(Statusbar *, cfg_t *); int widget_calculate_offset(int, int, int, int); diff --git a/widgets/focustitle.c b/widgets/focustitle.c index 0fd69999..aad4aad3 100644 --- a/widgets/focustitle.c +++ b/widgets/focustitle.c @@ -51,8 +51,11 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used) if(sel) { - draw_text(ctx, widget->location, 0, vscreen.statusbar->width - used, - vscreen.statusbar->height, widget->font->height / 2, widget->font, sel->name, + draw_text(ctx, widget->location, 0, + vscreen.statusbar->width - used, + vscreen.statusbar->height, + AlignLeft, + widget->font->height / 2, widget->font, sel->name, d->fg, d->bg); if(sel->isfloating) draw_circle(ctx, widget->location, 0, diff --git a/widgets/taglist.c b/widgets/taglist.c index 74760523..cef344aa 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -93,6 +93,7 @@ taglist_draw(Widget *widget, draw_text(ctx, widget->location + widget->width, 0, w, vscreen.statusbar->height, + AlignCenter, vscreen.font->height / 2, vscreen.font, tag->name, diff --git a/widgets/tasklist.c b/widgets/tasklist.c index 63491f5d..292a1629 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -74,6 +74,7 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used) draw_text(ctx, widget->location + box_width * i, 0, box_width, vscreen.statusbar->height, + AlignLeft, widget->font->height / 2, widget->font, c->name, d->fg_sel, d->bg_sel); } @@ -81,6 +82,7 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used) draw_text(ctx, widget->location + box_width * i, 0, box_width, vscreen.statusbar->height, + AlignLeft, widget->font->height / 2, widget->font, c->name, d->fg, d->bg); if(sel->isfloating) diff --git a/widgets/textbox.c b/widgets/textbox.c index fac29f61..030a72cc 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -51,7 +51,7 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, widget->alignment); draw_text(ctx, widget->location, 0, widget->width, widget->statusbar->height, - 0, widget->font, d->text, d->fg, d->bg); + AlignCenter, 0, widget->font, d->text, d->fg, d->bg); return widget->width; }