From 1d6613349e7a6405b921314f6d07a5ba90702ad7 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 4 Jan 2008 19:17:20 +0100 Subject: [PATCH] typedef enum Alignment --- config.h | 2 +- draw.c | 14 ++++++++++---- draw.h | 10 ++++++++-- widget.c | 6 +++++- widgets/focustitle.c | 2 +- widgets/tasklist.c | 2 +- widgets/textbox.c | 2 +- 7 files changed, 27 insertions(+), 11 deletions(-) diff --git a/config.h b/config.h index 469034ce0..c1429ff12 100644 --- a/config.h +++ b/config.h @@ -103,7 +103,7 @@ struct Widget /** Statusbar */ Statusbar *statusbar; /** Alignement */ - int alignment; + Alignment alignment; /** Misc private data */ void *data; /** Location on status bar */ diff --git a/draw.c b/draw.c index 251a8e859..cf64daed8 100644 --- a/draw.c +++ b/draw.c @@ -121,12 +121,18 @@ draw_text(DrawCtx *ctx, buf[len - 3] = '.'; } - if(align == AlignLeft) + switch(align) + { + case AlignLeft: cairo_move_to(cr, x + padding, y + font->ascent + (ctx->height - font->height) / 2); - else if(align == AlignRight) + break; + case AlignRight: cairo_move_to(cr, x + (w - nw) + padding, y + font->ascent + (ctx->height - font->height) / 2); - else + break; + default: cairo_move_to(cr, x + ((w - nw) / 2) + padding, y + font->ascent + (ctx->height - font->height) / 2); + break; + } cairo_show_text(cr, buf); cairo_font_face_destroy(font_face); @@ -309,7 +315,7 @@ textwidth(XftFont *font, char *text) return MAX(te.x_advance, te.width); } -int +Alignment draw_get_align(const char *align) { if(!a_strncmp(align, "center", 6)) diff --git a/draw.h b/draw.h index 85b96cb97..7bb43775c 100644 --- a/draw.h +++ b/draw.h @@ -25,7 +25,13 @@ #include #include -enum { AlignLeft, AlignRight, AlignFlex, AlignCenter }; +typedef enum +{ + AlignLeft, + AlignRight, + AlignFlex, + AlignCenter +} Alignment; typedef struct { @@ -56,7 +62,7 @@ void draw_image_from_argb_data(DrawCtx *, int, int, int, int, int, unsigned char Area draw_get_image_size(const char *filename); Drawable draw_rotate(DrawCtx *, int, double, int, int); unsigned short textwidth(XftFont *, char *); -int draw_get_align(const char *); +Alignment draw_get_align(const char *); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/widget.c b/widget.c index c2d105ba0..16a3498d0 100644 --- a/widget.c +++ b/widget.c @@ -66,8 +66,12 @@ widget_calculate_alignments(Widget *widget) int widget_calculate_offset(int barwidth, int widgetwidth, int offset, int alignment) { - if (alignment == AlignLeft || alignment == AlignFlex) + switch(alignment) + { + case AlignLeft: + case AlignFlex: return offset; + } return barwidth - offset - widgetwidth; } diff --git a/widgets/focustitle.c b/widgets/focustitle.c index 576b55ef3..220c7697c 100644 --- a/widgets/focustitle.c +++ b/widgets/focustitle.c @@ -33,7 +33,7 @@ extern AwesomeConf globalconf; typedef struct { - int align; + Alignment align; XColor fg; XColor bg; } Data; diff --git a/widgets/tasklist.c b/widgets/tasklist.c index 10aa1f68c..149b0b38e 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -37,7 +37,7 @@ extern AwesomeConf globalconf; typedef struct { Bool show_icons; - int align; + Alignment align; XColor fg_sel; XColor bg_sel; XColor fg; diff --git a/widgets/textbox.c b/widgets/textbox.c index d8a3ab570..6276f9a1d 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -30,7 +30,7 @@ typedef struct { char *text; int width; - int align; + Alignment align; XColor fg; XColor bg; } Data;