X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=draw.c;h=688bd69d87ce8649a070a59723db26adf30ea3fd;hb=595e7976601fc77acf12015d3f5f6843e2cdd706;hp=6851a3409258a58a85b13a47beafb3063e75bb9d;hpb=b4e63454e5768d38682405d252a81b1149273c0b;p=dmenu.git diff --git a/draw.c b/draw.c index 6851a34..688bd69 100644 --- a/draw.c +++ b/draw.c @@ -1,37 +1,20 @@ /* See LICENSE file for copyright and license details. */ - -/* enums */ -enum { ColFG, ColBG, ColLast }; - -/* typedefs */ -typedef struct { - int x, y, w, h; - unsigned long norm[ColLast]; - unsigned long sel[ColLast]; - Drawable drawable; - GC gc; - struct { - XFontStruct *xfont; - XFontSet set; - int ascent; - int descent; - int height; - } font; -} DC; /* draw context */ - -/* forward declarations */ -static void dccleanup(void); -static void dcsetup(void); -static void drawtext(const char *text, unsigned long col[ColLast]); -static unsigned long getcolor(const char *colstr); -static void initfont(const char *fontstr); -static int textnw(const char *text, unsigned int len); -static int textw(const char *text); - -static DC dc; +#include +#include +#include +#include +#include +#include +#include +#include +#include "draw.h" + +/* macros */ +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) void -dccleanup(void) { +drawcleanup(void) { if(dc.font.set) XFreeFontSet(dpy, dc.font.set); else @@ -41,13 +24,12 @@ dccleanup(void) { } void -dcsetup() { +drawsetup(void) { /* style */ dc.norm[ColBG] = getcolor(normbgcolor); dc.norm[ColFG] = getcolor(normfgcolor); dc.sel[ColBG] = getcolor(selbgcolor); dc.sel[ColFG] = getcolor(selfgcolor); - initfont(font); /* pixmap */ dc.drawable = XCreatePixmap(dpy, parent, mw, mh, DefaultDepth(dpy, screen)); @@ -85,6 +67,16 @@ drawtext(const char *text, unsigned long col[ColLast]) { XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); } +void +eprint(const char *errstr, ...) { + va_list ap; + + va_start(ap, errstr); + vfprintf(stderr, errstr, ap); + va_end(ap); + exit(EXIT_FAILURE); +} + unsigned long getcolor(const char *colstr) { Colormap cmap = DefaultColormap(dpy, screen);