simplify drawsquare()
This commit is contained in:
parent
92e8fb4cfb
commit
9737185639
24
draw.c
24
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;
|
||||
|
||||
|
|
4
draw.h
4
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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue