X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=draw.c;h=65a3d51823804b8e7cf510da8d699c6512a37303;hb=cff951c65086950eeef5723b65dc06cbe7cdfa19;hp=f73a7bdae522410bcb0bb71f69f1c09986c006ca;hpb=c976bc6c2cbc2f197806259b58a6c6ff2d154284;p=dwm.git diff --git a/draw.c b/draw.c index f73a7bd..65a3d51 100644 --- a/draw.c +++ b/draw.c @@ -10,8 +10,7 @@ /* static */ static unsigned int -textnw(const char *text, unsigned int len) -{ +textnw(const char *text, unsigned int len) { XRectangle r; if(dc.font.set) { @@ -22,29 +21,15 @@ textnw(const char *text, unsigned int len) } static void -drawtext(const char *text, Bool invert, Bool highlight) -{ +drawtext(const char *text, unsigned long col[ColLast], Bool highlight) { int x, y, w, h; static char buf[256]; unsigned int len, olen; XGCValues gcv; - XPoint points[5]; XRectangle r = { dc.x, dc.y, dc.w, dc.h }; - XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg); + XSetForeground(dpy, dc.gc, col[ColBG]); XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); - points[0].x = dc.x; - points[0].y = dc.y; - points[1].x = dc.w - 1; - points[1].y = 0; - points[2].x = 0; - points[2].y = dc.h - 1; - points[3].x = -(dc.w - 1); - points[3].y = 0; - points[4].x = 0; - points[4].y = -(dc.h - 1); - XSetForeground(dpy, dc.gc, dc.border); - XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious); if(!text) return; @@ -74,37 +59,28 @@ drawtext(const char *text, Bool invert, Bool highlight) if(w > dc.w) return; /* too long */ - gcv.foreground = invert ? dc.bg : dc.fg; - gcv.background = invert ? dc.fg : dc.bg; + gcv.foreground = col[ColFG]; if(dc.font.set) { - XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv); + XChangeGC(dpy, dc.gc, GCForeground, &gcv); XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); } else { gcv.font = dc.font.xfont->fid; - XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv); + XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv); XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); } if(highlight) { - points[0].x = dc.x + 1; - points[0].y = dc.y + 1; - points[1].x = dc.w - 3; - points[1].y = 0; - points[2].x = 0; - points[2].y = dc.h - 3; - points[3].x = -(dc.w - 3); - points[3].y = 0; - points[4].x = 0; - points[4].y = -(dc.h - 3); - XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious); + r.x = dc.x + 2; + r.y = dc.y + 2; + r.width = r.height = 3; + XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); } } /* extern */ void -drawall() -{ +drawall() { Client *c; for(c = clients; c; c = getnext(c->next)) @@ -113,24 +89,23 @@ drawall() } void -drawstatus() -{ +drawstatus() { int i, x; - Bool istile = arrange == dotile; dc.x = dc.y = 0; - dc.w = bw; - drawtext(NULL, !istile, False); - dc.w = 0; for(i = 0; i < ntags; i++) { - dc.x += dc.w; dc.w = textw(tags[i]); - if(istile) - drawtext(tags[i], seltag[i], sel && sel->tags[i]); + if(seltag[i]) + drawtext(tags[i], dc.sel, sel && sel->tags[i]); else - drawtext(tags[i], !seltag[i], sel && sel->tags[i]); + drawtext(tags[i], dc.norm, sel && sel->tags[i]); + dc.x += dc.w; } + + dc.w = bmw; + drawtext(arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, dc.status, False); + x = dc.x + dc.w; dc.w = textw(stext); dc.x = bx + bw - dc.w; @@ -138,41 +113,39 @@ drawstatus() dc.x = x; dc.w = bw - x; } - drawtext(stext, !istile, False); + drawtext(stext, dc.status, False); - if(sel && ((dc.w = dc.x - x) > bh)) { + if((dc.w = dc.x - x) > bh) { dc.x = x; - drawtext(sel->name, istile, False); + if(sel) + drawtext(sel->name, dc.sel, False); + else + drawtext(NULL, dc.norm, False); } XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0); XSync(dpy, False); } void -drawtitle(Client *c) -{ - int i; - Bool istile = arrange == dotile; - +drawtitle(Client *c) { if(c == sel && issel) { drawstatus(); XUnmapWindow(dpy, c->twin); - XSetWindowBorder(dpy, c->win, dc.fg); + XSetWindowBorder(dpy, c->win, dc.sel[ColBG]); return; } - XSetWindowBorder(dpy, c->win, dc.bg); + XSetWindowBorder(dpy, c->win, dc.norm[ColBG]); XMapWindow(dpy, c->twin); dc.x = dc.y = 0; dc.w = c->tw; - drawtext(c->name, !istile, False); + drawtext(c->name, dc.norm, False); XCopyArea(dpy, dc.drawable, c->twin, dc.gc, 0, 0, c->tw, c->th, 0, 0); XSync(dpy, False); } unsigned long -getcolor(const char *colstr) -{ +getcolor(const char *colstr) { Colormap cmap = DefaultColormap(dpy, screen); XColor color; @@ -181,8 +154,7 @@ getcolor(const char *colstr) } void -setfont(const char *fontstr) -{ +setfont(const char *fontstr) { char **missing, *def; int i, n; @@ -232,7 +204,6 @@ setfont(const char *fontstr) } unsigned int -textw(const char *text) -{ +textw(const char *text) { return textnw(text, strlen(text)) + dc.font.height; }