dwm-statuscolors-5.9.diff (8926B)
1 diff -up dwm-5.9/config.def.h dwm-5.9-colors/config.def.h 2 --- dwm-5.9/config.def.h 2011-07-10 16:24:25.000000000 -0400 3 +++ dwm-5.9-colors/config.def.h 2011-08-18 02:02:47.033830823 -0400 4 @@ -1,13 +1,16 @@ 5 /* See LICENSE file for copyright and license details. */ 6 7 /* appearance */ 8 +#define NUMCOLORS 4 // need at least 3 9 +static const char colors[NUMCOLORS][ColLast][8] = { 10 + // border foreground background 11 + { "#cccccc", "#000000", "#cccccc" }, // 0 = normal 12 + { "#0066ff", "#ffffff", "#0066ff" }, // 1 = selected 13 + { "#0066ff", "#0066ff", "#ffffff" }, // 2 = urgent/warning 14 + { "#ff0000", "#ffffff", "#ff0000" }, // 3 = error 15 + // add more here 16 +}; 17 static const char font[] = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*"; 18 -static const char normbordercolor[] = "#cccccc"; 19 -static const char normbgcolor[] = "#cccccc"; 20 -static const char normfgcolor[] = "#000000"; 21 -static const char selbordercolor[] = "#0066ff"; 22 -static const char selbgcolor[] = "#0066ff"; 23 -static const char selfgcolor[] = "#ffffff"; 24 static const unsigned int borderpx = 1; /* border pixel of windows */ 25 static const unsigned int snap = 32; /* snap pixel */ 26 static const Bool showbar = True; /* False means no bar */ 27 @@ -45,7 +48,7 @@ static const Layout layouts[] = { 28 #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } 29 30 /* commands */ 31 -static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL }; 32 +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 }; 33 static const char *termcmd[] = { "uxterm", NULL }; 34 35 static Key keys[] = { 36 Only in dwm-5.9: config.h 37 Only in dwm-5.9: dwm 38 diff -up dwm-5.9/dwm.c dwm-5.9-colors/dwm.c 39 --- dwm-5.9/dwm.c 2011-07-10 16:24:25.000000000 -0400 40 +++ dwm-5.9-colors/dwm.c 2011-08-18 02:07:20.788935100 -0400 41 @@ -48,6 +48,7 @@ 42 #define LENGTH(X) (sizeof X / sizeof X[0]) 43 #define MAX(A, B) ((A) > (B) ? (A) : (B)) 44 #define MIN(A, B) ((A) < (B) ? (A) : (B)) 45 +#define MAXCOLORS 8 46 #define MOUSEMASK (BUTTONMASK|PointerMotionMask) 47 #define WIDTH(X) ((X)->w + 2 * (X)->bw) 48 #define HEIGHT(X) ((X)->h + 2 * (X)->bw) 49 @@ -97,9 +98,8 @@ struct Client { 50 51 typedef struct { 52 int x, y, w, h; 53 - unsigned long norm[ColLast]; 54 - unsigned long sel[ColLast]; 55 - Drawable drawable; 56 + unsigned long colors[MAXCOLORS][ColLast]; 57 + Drawable drawable; 58 GC gc; 59 struct { 60 int ascent; 61 @@ -175,8 +175,9 @@ static void die(const char *errstr, ...) 62 static Monitor *dirtomon(int dir); 63 static void drawbar(Monitor *m); 64 static void drawbars(void); 65 -static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); 66 -static void drawtext(const char *text, unsigned long col[ColLast], Bool invert); 67 +static void drawcoloredtext(char *text); 68 +static void drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]); 69 +static void drawtext(const char *text, unsigned long col[ColLast], Bool pad); 70 static void enternotify(XEvent *e); 71 static void expose(XEvent *e); 72 static void focus(Client *c); 73 @@ -736,14 +737,13 @@ drawbar(Monitor *m) { 74 dc.x = 0; 75 for(i = 0; i < LENGTH(tags); i++) { 76 dc.w = TEXTW(tags[i]); 77 - col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm; 78 - drawtext(tags[i], col, urg & 1 << i); 79 - drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i, 80 - occ & 1 << i, urg & 1 << i, col); 81 + col = dc.colors[ (m->tagset[m->seltags] & 1 << i ? 1:(urg & 1 << i ? 2:0))]; 82 + drawtext(tags[i], col, True); 83 + drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i, occ & 1 << i, col); 84 dc.x += dc.w; 85 } 86 dc.w = blw = TEXTW(m->ltsymbol); 87 - drawtext(m->ltsymbol, dc.norm, False); 88 + drawtext(m->ltsymbol, dc.colors[0], True); 89 dc.x += dc.w; 90 x = dc.x; 91 if(m == selmon) { /* status is only drawn on selected monitor */ 92 @@ -753,19 +753,19 @@ drawbar(Monitor *m) { 93 dc.x = x; 94 dc.w = m->ww - x; 95 } 96 - drawtext(stext, dc.norm, False); 97 + drawcoloredtext(stext); 98 } 99 else 100 dc.x = m->ww; 101 if((dc.w = dc.x - x) > bh) { 102 dc.x = x; 103 if(m->sel) { 104 - col = m == selmon ? dc.sel : dc.norm; 105 - drawtext(m->sel->name, col, False); 106 - drawsquare(m->sel->isfixed, m->sel->isfloating, False, col); 107 + col = m == selmon ? dc.colors[1] : dc.colors[0]; 108 + drawtext(m->sel->name, col, True); 109 + drawsquare(m->sel->isfixed, m->sel->isfloating, col); 110 } 111 else 112 - drawtext(NULL, dc.norm, False); 113 + drawtext(NULL, dc.colors[0], False); 114 } 115 XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0); 116 XSync(dpy, False); 117 @@ -780,10 +780,39 @@ drawbars(void) { 118 } 119 120 void 121 -drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) { 122 - int x; 123 +drawcoloredtext(char *text) { 124 + Bool first=True; 125 + char *buf = text, *ptr = buf, c = 1; 126 + unsigned long *col = dc.colors[0]; 127 + int i, ox = dc.x; 128 + 129 + while( *ptr ) { 130 + for( i = 0; *ptr < 0 || *ptr > NUMCOLORS; i++, ptr++); 131 + if( !*ptr ) break; 132 + c=*ptr; 133 + *ptr=0; 134 + if( i ) { 135 + dc.w = selmon->ww - dc.x; 136 + drawtext(buf, col, first); 137 + dc.x += textnw(buf, i) + textnw(&c,1); 138 + if( first ) dc.x += ( dc.font.ascent + dc.font.descent ) / 2; 139 + first = False; 140 + } else if( first ) { 141 + ox = dc.x += textnw(&c,1); 142 + } 143 + *ptr = c; 144 + col = dc.colors[ c-1 ]; 145 + buf = ++ptr; 146 + } 147 + if( !first ) dc.x-=(dc.font.ascent+dc.font.descent)/2; 148 + drawtext(buf, col, True); 149 + dc.x = ox; 150 +} 151 152 - XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); 153 +void 154 +drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) { 155 + int x; 156 + XSetForeground(dpy, dc.gc, col[ ColFG ]); 157 x = (dc.font.ascent + dc.font.descent + 2) / 4; 158 if(filled) 159 XFillRectangle(dpy, dc.drawable, dc.gc, dc.x+1, dc.y+1, x+1, x+1); 160 @@ -792,17 +821,17 @@ drawsquare(Bool filled, Bool empty, Bool 161 } 162 163 void 164 -drawtext(const char *text, unsigned long col[ColLast], Bool invert) { 165 +drawtext(const char *text, unsigned long col[ColLast], Bool pad) { 166 char buf[256]; 167 int i, x, y, h, len, olen; 168 169 - XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]); 170 + XSetForeground(dpy, dc.gc, col[ ColBG ]); 171 XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h); 172 if(!text) 173 return; 174 olen = strlen(text); 175 - h = dc.font.ascent + dc.font.descent; 176 - y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; 177 + h = pad ? (dc.font.ascent + dc.font.descent) : 0; 178 + y = dc.y + ((dc.h + dc.font.ascent - dc.font.descent) / 2); 179 x = dc.x + (h / 2); 180 /* shorten text if necessary */ 181 for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--); 182 @@ -811,7 +840,7 @@ drawtext(const char *text, unsigned long 183 memcpy(buf, text, len); 184 if(len < olen) 185 for(i = len; i && i > len - 3; buf[--i] = '.'); 186 - XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); 187 + XSetForeground(dpy, dc.gc, col[ ColFG ]); 188 if(dc.font.set) 189 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); 190 else 191 @@ -861,7 +890,7 @@ focus(Client *c) { 192 detachstack(c); 193 attachstack(c); 194 grabbuttons(c, True); 195 - XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]); 196 + XSetWindowBorder(dpy, c->win, dc.colors[1][ColBorder]); 197 setfocus(c); 198 } 199 else 200 @@ -1137,7 +1166,7 @@ manage(Window w, XWindowAttributes *wa) 201 } 202 wc.border_width = c->bw; 203 XConfigureWindow(dpy, w, CWBorderWidth, &wc); 204 - XSetWindowBorder(dpy, w, dc.norm[ColBorder]); 205 + XSetWindowBorder(dpy, w, dc.colors[0][ColBorder]); 206 configure(c); /* propagates border_width, if size doesn't change */ 207 updatesizehints(c); 208 updatewmhints(c); 209 @@ -1550,12 +1579,11 @@ setup(void) { 210 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); 211 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); 212 /* init appearance */ 213 - dc.norm[ColBorder] = getcolor(normbordercolor); 214 - dc.norm[ColBG] = getcolor(normbgcolor); 215 - dc.norm[ColFG] = getcolor(normfgcolor); 216 - dc.sel[ColBorder] = getcolor(selbordercolor); 217 - dc.sel[ColBG] = getcolor(selbgcolor); 218 - dc.sel[ColFG] = getcolor(selfgcolor); 219 + for(int i=0; i<NUMCOLORS; i++) { 220 + dc.colors[i][ColBorder] = getcolor( colors[i][ColBorder] ); 221 + dc.colors[i][ColFG] = getcolor( colors[i][ColFG] ); 222 + dc.colors[i][ColBG] = getcolor( colors[i][ColBG] ); 223 + } 224 dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen)); 225 dc.gc = XCreateGC(dpy, root, 0, NULL); 226 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); 227 @@ -1716,7 +1744,7 @@ unfocus(Client *c, Bool setfocus) { 228 if(!c) 229 return; 230 grabbuttons(c, False); 231 - XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]); 232 + XSetWindowBorder(dpy, c->win, dc.colors[0][ColBorder]); 233 if(setfocus) 234 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); 235 } 236 Only in dwm-5.9: dwm.o