diff -r f6c3491c41f1 config.def.h --- a/config.def.h Sun Nov 16 13:22:24 2008 +0000 +++ b/config.def.h Thu Dec 04 13:29:50 2008 -0500 @@ -1,13 +1,16 @@ /* See LICENSE file for copyright and license details. */ /* appearance */ +#define NUMCOLORS 4 +static const char colors[NUMCOLORS][ColLast][8] = { + // border foreground background + { "#cccccc", "#000000", "#cccccc" }, // normal + { "#0066ff", "#ffffff", "#0066ff" }, // selected + { "#0066ff", "#0066ff", "#ffffff" }, // urgent/warning + { "#ff0000", "#ffffff", "#ff0000" }, // error + // add more here +}; static const char font[] = "-*-terminus-medium-r-normal-*-14-*-*-*-*-*-*-*"; -static const char normbordercolor[] = "#cccccc"; -static const char normbgcolor[] = "#cccccc"; -static const char normfgcolor[] = "#000000"; -static const char selbordercolor[] = "#0066ff"; -static const char selbgcolor[] = "#0066ff"; -static const char selfgcolor[] = "#ffffff"; static unsigned int borderpx = 1; /* border pixel of windows */ static unsigned int snap = 32; /* snap pixel */ static Bool showbar = True; /* False means no bar */ @@ -49,7 +52,7 @@ #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } /* commands */ -static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL }; +static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", colors[0][ColBG], "-nf", colors[0][ColFG], "-sb", colors[1][ColBG], "-sf", colors[1][ColFG], NULL }; static const char *termcmd[] = { "uxterm", NULL }; static Key keys[] = { diff -r f6c3491c41f1 dwm.c --- a/dwm.c Sun Nov 16 13:22:24 2008 +0000 +++ b/dwm.c Thu Dec 04 13:29:50 2008 -0500 @@ -52,6 +52,7 @@ #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAXTAGLEN 16 +#define MAXCOLORS 8 #define MOUSEMASK (BUTTONMASK|PointerMotionMask) #define WIDTH(x) ((x)->w + 2 * (x)->bw) #define HEIGHT(x) ((x)->h + 2 * (x)->bw) @@ -97,8 +98,7 @@ typedef struct { int x, y, w, h; - unsigned long norm[ColLast]; - unsigned long sel[ColLast]; + unsigned long colors[MAXCOLORS][ColLast]; Drawable drawable; GC gc; struct { @@ -147,8 +147,9 @@ static void detachstack(Client *c); static void die(const char *errstr, ...); static void drawbar(void); -static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); -static void drawtext(const char *text, unsigned long col[ColLast], Bool invert); +static void drawcoloredtext(char *text); +static void drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]); +static void drawtext(const char *text, unsigned long col[ColLast], Bool pad); static void enternotify(XEvent *e); static void expose(XEvent *e); static void focus(Client *c); @@ -506,14 +507,14 @@ dc.x = 0; for(i = 0; i < LENGTH(tags); i++) { dc.w = TEXTW(tags[i]); - col = tagset[seltags] & 1 << i ? dc.sel : dc.norm; - drawtext(tags[i], col, urg & 1 << i); - drawsquare(sel && sel->tags & 1 << i, occ & 1 << i, urg & 1 << i, col); + col = dc.colors[ (tagset[seltags] & 1 << i ? 1 : (urg & 1 << i ? 2:0)) ]; + drawtext(tags[i], col, True); + drawsquare(sel && tagset[seltags] & 1 << i, occ & 1 << i, col); dc.x += dc.w; } if(blw > 0) { dc.w = blw; - drawtext(lt[sellt]->symbol, dc.norm, False); + drawtext(lt[sellt]->symbol, dc.colors[0], True); x = dc.x + dc.w; } else @@ -524,27 +525,57 @@ dc.x = x; dc.w = ww - x; } - drawtext(stext, dc.norm, False); + drawcoloredtext(stext); if((dc.w = dc.x - x) > bh) { dc.x = x; if(sel) { - drawtext(sel->name, dc.sel, False); - drawsquare(sel->isfixed, sel->isfloating, False, dc.sel); + drawtext(sel->name, dc.colors[1], True); + drawsquare(sel->isfixed, sel->isfloating, dc.colors[1]); } else - drawtext(NULL, dc.norm, False); + drawtext(NULL, dc.colors[0], True); } XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, ww, bh, 0, 0); XSync(dpy, False); } void -drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) { +drawcoloredtext(char *text) { + Bool first=True; + char *buf = text, *ptr = buf, c = 1; + unsigned long *col = dc.colors[0]; + int i, ox = dc.x; + + while( *ptr ) { + for( i = 0; *ptr <= MAXCOLORS && *ptr > NUMCOLORS; i++, ptr++); + if( !*ptr ) break; + c=*ptr; + *ptr=0; + if( i ) { + dc.w = ww - dc.x; + drawtext(buf, col, first); + dc.x += textnw(buf, i) + textnw(&c,1); + if( first ) dc.x+=(dc.font.ascent+dc.font.descent)/2; + first=False; + } else if(first) { + ox = dc.x += textnw(&c,1); + } + *ptr = c; + col = dc.colors[ c-1 ]; + buf = ++ptr; + } + if( !first ) dc.x-=(dc.font.ascent+dc.font.descent)/2; + drawtext(buf, col, True); + dc.x = ox; +} + +void +drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) { int x; XGCValues gcv; XRectangle r = { dc.x, dc.y, dc.w, dc.h }; - gcv.foreground = col[invert ? ColBG : ColFG]; + gcv.foreground = col[ ColFG ]; XChangeGC(dpy, dc.gc, GCForeground, &gcv); x = (dc.font.ascent + dc.font.descent + 2) / 4; r.x = dc.x + 1; @@ -560,18 +591,18 @@ } void -drawtext(const char *text, unsigned long col[ColLast], Bool invert) { +drawtext(const char *text, unsigned long col[ColLast], Bool pad) { char buf[256]; int i, x, y, h, len, olen; XRectangle r = { dc.x, dc.y, dc.w, dc.h }; - XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]); + XSetForeground(dpy, dc.gc, col[ ColBG ]); XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); if(!text) return; olen = strlen(text); - h = dc.font.ascent + dc.font.descent; - y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; + h = pad ? (dc.font.ascent + dc.font.descent) : 0; + y = dc.y + ((dc.h + dc.font.ascent - dc.font.descent) / 2); x = dc.x + (h / 2); /* shorten text if necessary */ for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--); @@ -580,7 +611,7 @@ memcpy(buf, text, len); if(len < olen) for(i = len; i && i > len - 3; buf[--i] = '.'); - XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); + XSetForeground(dpy, dc.gc, col[ ColFG ]); if(dc.font.set) XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); else @@ -614,13 +645,13 @@ for(c = stack; c && !ISVISIBLE(c); c = c->snext); if(sel && sel != c) { grabbuttons(sel, False); - XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]); + XSetWindowBorder(dpy, sel->win, dc.colors[0][ColBorder]); } if(c) { detachstack(c); attachstack(c); grabbuttons(c, True); - XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]); + XSetWindowBorder(dpy, c->win, dc.colors[1][ColBorder]); XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); } else @@ -881,7 +912,7 @@ wc.border_width = c->bw; XConfigureWindow(dpy, w, CWBorderWidth, &wc); - XSetWindowBorder(dpy, w, dc.norm[ColBorder]); + XSetWindowBorder(dpy, w, dc.colors[0][ColBorder]); configure(c); /* propagates border_width, if size doesn't change */ updatesizehints(c); XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); @@ -1332,12 +1363,11 @@ cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); /* init appearance */ - dc.norm[ColBorder] = getcolor(normbordercolor); - dc.norm[ColBG] = getcolor(normbgcolor); - dc.norm[ColFG] = getcolor(normfgcolor); - dc.sel[ColBorder] = getcolor(selbordercolor); - dc.sel[ColBG] = getcolor(selbgcolor); - dc.sel[ColFG] = getcolor(selfgcolor); + for(i=0; i