From adaa28a6e600f636f5e86244ccef69e98419ba1a Mon Sep 17 00:00:00 2001 From: Anselm R. Garbe Date: Sat, 15 Jul 2006 17:00:56 +0200 Subject: proceeded with cleaning up, sorting functions, etc --- draw.c | 146 +++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 74 insertions(+), 72 deletions(-) (limited to 'draw.c') 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() @@ -52,59 +73,6 @@ drawstatus() XFlush(dpy); } -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) { @@ -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; +} -- cgit v1.2.3