From 9737185639f7450fdf78331a9e835ceb241bab3a Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 20 Sep 2007 20:11:33 +0200 Subject: [PATCH] simplify drawsquare() --- draw.c | 24 +++++++++++------------- draw.h | 4 ++-- statusbar.c | 9 ++++++--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/draw.c b/draw.c index 8ca910e6..67142486 100644 --- a/draw.c +++ b/draw.c @@ -32,7 +32,7 @@ drawtext(Display *disp, DC drawcontext, Drawable drawable, const char *text, uns { int x, y, w, h; static char buf[256]; - unsigned int len, olen; + size_t len, olen; XRectangle r = { drawcontext.x, drawcontext.y, drawcontext.w, drawcontext.h }; XSetForeground(disp, drawcontext.gc, col[ColBG]); @@ -41,8 +41,8 @@ drawtext(Display *disp, DC drawcontext, Drawable drawable, const char *text, uns return; w = 0; olen = len = a_strlen(text); - if(len >= sizeof buf) - len = sizeof buf - 1; + if(len >= sizeof(buf)) + len = sizeof(buf) - 1; memcpy(buf, text, len); buf[len] = 0; h = drawcontext.font.ascent + drawcontext.font.descent; @@ -70,7 +70,7 @@ drawtext(Display *disp, DC drawcontext, Drawable drawable, const char *text, uns } void -drawsquare(Display *disp, DC drawcontext, Bool filled, Bool empty, unsigned long col, Statusbar *statusbar) +drawsquare(Display *disp, DC drawcontext, Drawable drawable, Bool filled, unsigned long col) { int x; XGCValues gcv; @@ -81,20 +81,18 @@ drawsquare(Display *disp, DC drawcontext, Bool filled, Bool empty, unsigned long x = (drawcontext.font.ascent + drawcontext.font.descent + 2) / 4; r.x = drawcontext.x + 1; r.y = drawcontext.y + 1; + r.width = r.height = x; if(filled) { - r.width = r.height = x + 1; - XFillRectangles(disp, statusbar->drawable, drawcontext.gc, &r, 1); - } - else if(empty) - { - r.width = r.height = x; - XDrawRectangles(disp, statusbar->drawable, drawcontext.gc, &r, 1); + r.width++; r.height++; + XFillRectangles(disp, drawable, drawcontext.gc, &r, 1); } + else + XDrawRectangles(disp, drawable, drawcontext.gc, &r, 1); } -unsigned int -textnw(XFontSet set, XFontStruct *xfont, const char *text, unsigned int len) +int +textnw(XFontSet set, XFontStruct *xfont, const char *text, int len) { XRectangle r; diff --git a/draw.h b/draw.h index 66b05526..b36d9d7f 100644 --- a/draw.h +++ b/draw.h @@ -26,8 +26,8 @@ #define textw(set, xfont, text, height) (textnw(set, xfont, text, a_strlen(text)) + height) -void drawsquare(Display *, DC, Bool, Bool, unsigned long, Statusbar *); +void drawsquare(Display *, DC, Drawable, Bool, unsigned long); void drawtext(Display *, DC, Drawable, const char *, unsigned long *); -unsigned int textnw(XFontSet, XFontStruct *, const char *, unsigned int); +int textnw(XFontSet, XFontStruct *, const char *, int); #endif diff --git a/statusbar.c b/statusbar.c index 009ad494..cc92a442 100644 --- a/statusbar.c +++ b/statusbar.c @@ -55,12 +55,14 @@ drawstatusbar(Display *disp, int screen, DC *drawcontext, awesome_config * aweso if(awesomeconf->selected_tags[i]) { drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i], drawcontext->sel); - drawsquare(disp, *drawcontext, sel && sel->tags[i], isoccupied(i, screen), drawcontext->sel[ColFG], &awesomeconf->statusbar); + if(isoccupied(i, screen)) + drawsquare(disp, *drawcontext, awesomeconf->statusbar.drawable, sel && sel->tags[i], drawcontext->sel[ColFG]); } else { drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i], drawcontext->norm); - drawsquare(disp, *drawcontext, sel && sel->tags[i], isoccupied(i, screen), drawcontext->norm[ColFG], &awesomeconf->statusbar); + if(isoccupied(i, screen)) + drawsquare(disp, *drawcontext, awesomeconf->statusbar.drawable, sel && sel->tags[i], drawcontext->norm[ColFG]); } drawcontext->x += drawcontext->w; } @@ -81,7 +83,8 @@ drawstatusbar(Display *disp, int screen, DC *drawcontext, awesome_config * aweso if(sel) { drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, sel->name, drawcontext->sel); - drawsquare(disp, *drawcontext, sel->ismax, sel->isfloating, drawcontext->sel[ColFG], &awesomeconf->statusbar); + if(sel->isfloating) + drawsquare(disp, *drawcontext, awesomeconf->statusbar.drawable, sel->ismax, drawcontext->sel[ColFG]); } else drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, NULL, drawcontext->norm);