simplify drawsquare()

This commit is contained in:
Julien Danjou 2007-09-20 20:11:33 +02:00
parent 92e8fb4cfb
commit 9737185639
3 changed files with 19 additions and 18 deletions

24
draw.c
View File

@ -32,7 +32,7 @@ drawtext(Display *disp, DC drawcontext, Drawable drawable, const char *text, uns
{ {
int x, y, w, h; int x, y, w, h;
static char buf[256]; static char buf[256];
unsigned int len, olen; size_t len, olen;
XRectangle r = { drawcontext.x, drawcontext.y, drawcontext.w, drawcontext.h }; XRectangle r = { drawcontext.x, drawcontext.y, drawcontext.w, drawcontext.h };
XSetForeground(disp, drawcontext.gc, col[ColBG]); XSetForeground(disp, drawcontext.gc, col[ColBG]);
@ -41,8 +41,8 @@ drawtext(Display *disp, DC drawcontext, Drawable drawable, const char *text, uns
return; return;
w = 0; w = 0;
olen = len = a_strlen(text); olen = len = a_strlen(text);
if(len >= sizeof buf) if(len >= sizeof(buf))
len = sizeof buf - 1; len = sizeof(buf) - 1;
memcpy(buf, text, len); memcpy(buf, text, len);
buf[len] = 0; buf[len] = 0;
h = drawcontext.font.ascent + drawcontext.font.descent; h = drawcontext.font.ascent + drawcontext.font.descent;
@ -70,7 +70,7 @@ drawtext(Display *disp, DC drawcontext, Drawable drawable, const char *text, uns
} }
void 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; int x;
XGCValues gcv; 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; x = (drawcontext.font.ascent + drawcontext.font.descent + 2) / 4;
r.x = drawcontext.x + 1; r.x = drawcontext.x + 1;
r.y = drawcontext.y + 1; r.y = drawcontext.y + 1;
r.width = r.height = x;
if(filled) if(filled)
{ {
r.width = r.height = x + 1; r.width++; r.height++;
XFillRectangles(disp, statusbar->drawable, drawcontext.gc, &r, 1); XFillRectangles(disp, drawable, drawcontext.gc, &r, 1);
}
else if(empty)
{
r.width = r.height = x;
XDrawRectangles(disp, statusbar->drawable, drawcontext.gc, &r, 1);
} }
else
XDrawRectangles(disp, drawable, drawcontext.gc, &r, 1);
} }
unsigned int int
textnw(XFontSet set, XFontStruct *xfont, const char *text, unsigned int len) textnw(XFontSet set, XFontStruct *xfont, const char *text, int len)
{ {
XRectangle r; XRectangle r;

4
draw.h
View File

@ -26,8 +26,8 @@
#define textw(set, xfont, text, height) (textnw(set, xfont, text, a_strlen(text)) + height) #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 *); 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 #endif

View File

@ -55,12 +55,14 @@ drawstatusbar(Display *disp, int screen, DC *drawcontext, awesome_config * aweso
if(awesomeconf->selected_tags[i]) if(awesomeconf->selected_tags[i])
{ {
drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i], drawcontext->sel); 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 else
{ {
drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, awesomeconf->tags[i], drawcontext->norm); 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; drawcontext->x += drawcontext->w;
} }
@ -81,7 +83,8 @@ drawstatusbar(Display *disp, int screen, DC *drawcontext, awesome_config * aweso
if(sel) if(sel)
{ {
drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, sel->name, drawcontext->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 else
drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, NULL, drawcontext->norm); drawtext(disp, *drawcontext, awesomeconf->statusbar.drawable, NULL, drawcontext->norm);