X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=draw.c;h=9743ec1d56cd467464defc810d70165e7fb5f2b5;hp=4c47c1a8c4c0501b9b542f633301c3715d06de94;hb=adaa28a6e600f636f5e86244ccef69e98419ba1a;hpb=dba23062bad40afb1a90f60b6897cf9e1ca5035b diff --git a/draw.c b/draw.c index 4c47c1a..9743ec1 100644 --- a/draw.c +++ b/draw.c @@ -2,13 +2,34 @@ * (C)opyright MMIV-MMVI Anselm R. Garbe * See LICENSE file for license details. */ +#include "dwm.h" #include #include - #include -#include "dwm.h" +/* static functions */ + +static void +drawborder(void) +{ + XPoint points[5]; + XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); + XSetForeground(dpy, dc.gc, dc.border); + 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); + XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious); +} + +/* extern functions */ void drawall() @@ -53,59 +74,6 @@ drawstatus() } void -drawtitle(Client *c) -{ - int i; - Bool istile = arrange == dotile; - - if(c == sel) { - drawstatus(); - XUnmapWindow(dpy, c->title); - XSetWindowBorder(dpy, c->win, dc.fg); - return; - } - - XSetWindowBorder(dpy, c->win, dc.bg); - XMapWindow(dpy, c->title); - - dc.x = dc.y = 0; - - dc.w = 0; - for(i = 0; i < TLast; i++) { - if(c->tags[i]) { - dc.x += dc.w; - dc.w = textw(c->tags[i]); - drawtext(c->tags[i], !istile, True); - } - } - dc.x += dc.w; - dc.w = textw(c->name); - drawtext(c->name, !istile, True); - XCopyArea(dpy, dc.drawable, c->title, dc.gc, - 0, 0, c->tw, c->th, 0, 0); - XFlush(dpy); -} - -static void -drawborder(void) -{ - XPoint points[5]; - XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); - XSetForeground(dpy, dc.gc, dc.border); - 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); - XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious); -} - -void drawtext(const char *text, Bool invert, Bool border) { int x, y, w, h; @@ -155,6 +123,40 @@ drawtext(const char *text, Bool invert, Bool border) } } +void +drawtitle(Client *c) +{ + int i; + Bool istile = arrange == dotile; + + if(c == sel) { + drawstatus(); + XUnmapWindow(dpy, c->title); + XSetWindowBorder(dpy, c->win, dc.fg); + return; + } + + XSetWindowBorder(dpy, c->win, dc.bg); + XMapWindow(dpy, c->title); + + dc.x = dc.y = 0; + + dc.w = 0; + for(i = 0; i < TLast; i++) { + if(c->tags[i]) { + dc.x += dc.w; + dc.w = textw(c->tags[i]); + drawtext(c->tags[i], !istile, True); + } + } + dc.x += dc.w; + dc.w = textw(c->name); + drawtext(c->name, !istile, True); + XCopyArea(dpy, dc.drawable, c->title, dc.gc, + 0, 0, c->tw, c->th, 0, 0); + XFlush(dpy); +} + unsigned long getcolor(const char *colstr) { @@ -165,23 +167,6 @@ getcolor(const char *colstr) return color.pixel; } -unsigned int -textnw(char *text, unsigned int len) -{ - XRectangle r; - if(dc.font.set) { - XmbTextExtents(dc.font.set, text, len, NULL, &r); - return r.width; - } - return XTextWidth(dc.font.xfont, text, len); -} - -unsigned int -textw(char *text) -{ - return textnw(text, strlen(text)) + dc.font.height; -} - void setfont(const char *fontstr) { @@ -232,3 +217,20 @@ setfont(const char *fontstr) } dc.font.height = dc.font.ascent + dc.font.descent; } + +unsigned int +textnw(char *text, unsigned int len) +{ + XRectangle r; + if(dc.font.set) { + XmbTextExtents(dc.font.set, text, len, NULL, &r); + return r.width; + } + return XTextWidth(dc.font.xfont, text, len); +} + +unsigned int +textw(char *text) +{ + return textnw(text, strlen(text)) + dc.font.height; +}