--- drw.c | 41 +++++++++++++++++++++-------------------- drw.h | 24 ++++++++++-------------- 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/drw.c b/drw.c index 6c0859e..362484a 100644 --- a/drw.c +++ b/drw.c _AT_@ -171,35 +171,36 @@ drw_font_free(Fnt *font) { free(font); } -Clr * -drw_clr_create(Drw *drw, const char *clrname) { - Clr *clr; +Scm * +drw_scm_create(Drw *drw, const char *fgname, const char *bgname) { + Scm *scm; Colormap cmap; Visual *vis; - if(!drw) - return NULL; - clr = (Clr *)calloc(1, sizeof(Clr)); - if(!clr) + if (!drw || !(scm = (Scm *)calloc(1, sizeof(Scm)))) return NULL; + cmap = DefaultColormap(drw->dpy, drw->screen); vis = DefaultVisual(drw->dpy, drw->screen); - if(!XftColorAllocName(drw->dpy, vis, cmap, clrname, &clr->rgb)) - die("error, cannot allocate color '%s'\n", clrname); - clr->pix = clr->rgb.pixel; - return clr; + if (!XftColorAllocName(drw->dpy, vis, cmap, fgname, &scm->fg.rgb)) + die("error, cannot allocate color '%s'\n", fgname); + if (!XftColorAllocName(drw->dpy, vis, cmap, bgname, &scm->bg.rgb)) + die("error, cannot allocate color '%s'\n", bgname); + scm->fg.pix = scm->fg.rgb.pixel; + scm->bg.pix = scm->bg.rgb.pixel; + return scm; } void -drw_clr_free(Clr *clr) { - if(clr) - free(clr); +drw_scm_free(Scm *scm) { + if (scm) + free(scm); } void -drw_setscheme(Drw *drw, ClrScheme *scheme) { - if(drw && scheme) - drw->scheme = scheme; +drw_setscheme(Drw *drw, Scm *scm) { + if (drw && scm) + drw->scheme = scm; } void _AT_@ -208,7 +209,7 @@ drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int if(!drw || !drw->fontcount || !drw->scheme) return; - XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->bg->pix : drw->scheme->fg->pix); + XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->bg.pix : drw->scheme->fg.pix); dx = (drw->fonts[0]->ascent + drw->fonts[0]->descent + 2) / 4; if(filled) XFillRectangle(drw->dpy, drw->drawable, drw->gc, x+1, y+1, dx+1, dx+1); _AT_@ -242,7 +243,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex if (!drw || !drw->scheme) { return 0; } else if (render) { - XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->fg->pix : drw->scheme->bg->pix); + XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->fg.pix : drw->scheme->bg.pix); XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); } _AT_@ -297,7 +298,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex th = curfont->ascent + curfont->descent; ty = y + (h / 2) - (th / 2) + curfont->ascent; tx = x + (h / 2); - XftDrawStringUtf8(d, invert ? &drw->scheme->bg->rgb : &drw->scheme->fg->rgb, curfont->xfont, tx, ty, (XftChar8 *)buf, len); + XftDrawStringUtf8(d, invert ? &drw->scheme->bg.rgb : &drw->scheme->fg.rgb, curfont->xfont, tx, ty, (XftChar8 *)buf, len); } x += ew; diff --git a/drw.h b/drw.h index 28f7c61..ccd84d9 100644 --- a/drw.h +++ b/drw.h _AT_@ -2,11 +2,6 @@ #define DRW_FONT_CACHE_SIZE 32 typedef struct { - unsigned long pix; - XftColor rgb; -} Clr; - -typedef struct { Cursor cursor; } Cur; _AT_@ -20,10 +15,11 @@ typedef struct { } Fnt; typedef struct { - Clr *fg; - Clr *bg; - Clr *border; -} ClrScheme; + struct { + unsigned long pix; + XftColor rgb; + } fg, bg; +} Scm; typedef struct { unsigned int w, h; _AT_@ -32,7 +28,7 @@ typedef struct { Window root; Drawable drawable; GC gc; - ClrScheme *scheme; + Scm *scheme; size_t fontcount; Fnt *fonts[DRW_FONT_CACHE_SIZE]; } Drw; _AT_@ -48,9 +44,9 @@ void drw_load_fonts(Drw* drw, const char *fonts[], size_t fontcount); void drw_font_free(Fnt *font); void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h); -/* Colour abstraction */ -Clr *drw_clr_create(Drw *drw, const char *clrname); -void drw_clr_free(Clr *clr); +/* Colorscheme abstraction */ +Scm *drw_scm_create(Drw *drw, const char *fgname, const char *bgname); +void drw_scm_free(Scm *scm); /* Cursor abstraction */ Cur *drw_cur_create(Drw *drw, int shape); _AT_@ -58,7 +54,7 @@ void drw_cur_free(Drw *drw, Cur *cursor); /* Drawing context manipulation */ void drw_setfont(Drw *drw, Fnt *font); -void drw_setscheme(Drw *drw, ClrScheme *scheme); +void drw_setscheme(Drw *drw, Scm *scm); /* Drawing functions */ void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert); -- 2.0.5Received on Tue Apr 21 2015 - 23:37:48 CEST
This archive was generated by hypermail 2.3.0 : Tue Apr 21 2015 - 23:48:15 CEST