dwm-5.7.2-statuscolors.diff - sites - public wiki contents of suckless.org
HTML git clone git://git.suckless.org/sites
DIR Log
DIR Files
DIR Refs
---
dwm-5.7.2-statuscolors.diff (8516B)
---
1 diff -r 2bcd25cce4ab config.def.h
2 --- a/config.def.h Sun Sep 27 20:20:14 2009 +0100
3 +++ b/config.def.h Mon Oct 05 22:01:49 2009 -0300
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[] = "-*-*-medium-*-*-*-14-*-*-*-*-*-*-*";
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 @@
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 diff -r 2bcd25cce4ab dwm.c
37 --- a/dwm.c Sun Sep 27 20:20:14 2009 +0100
38 +++ b/dwm.c Mon Oct 05 22:01:49 2009 -0300
39 @@ -48,6 +48,7 @@
40 #define LENGTH(X) (sizeof X / sizeof X[0])
41 #define MAX(A, B) ((A) > (B) ? (A) : (B))
42 #define MIN(A, B) ((A) < (B) ? (A) : (B))
43 +#define MAXCOLORS 8
44 #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
45 #define WIDTH(X) ((X)->w + 2 * (X)->bw)
46 #define HEIGHT(X) ((X)->h + 2 * (X)->bw)
47 @@ -95,8 +96,7 @@
48
49 typedef struct {
50 int x, y, w, h;
51 - unsigned long norm[ColLast];
52 - unsigned long sel[ColLast];
53 + unsigned long colors[MAXCOLORS][ColLast];
54 Drawable drawable;
55 GC gc;
56 struct {
57 @@ -172,8 +172,9 @@
58 static Monitor *dirtomon(int dir);
59 static void drawbar(Monitor *m);
60 static void drawbars(void);
61 -static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
62 -static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
63 +static void drawcoloredtext(char *text);
64 +static void drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]);
65 +static void drawtext(const char *text, unsigned long col[ColLast], Bool pad);
66 static void enternotify(XEvent *e);
67 static void expose(XEvent *e);
68 static void focus(Client *c);
69 @@ -691,14 +692,13 @@
70 dc.x = 0;
71 for(i = 0; i < LENGTH(tags); i++) {
72 dc.w = TEXTW(tags[i]);
73 - col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm;
74 - drawtext(tags[i], col, urg & 1 << i);
75 - drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
76 - occ & 1 << i, urg & 1 << i, col);
77 + col = dc.colors[ (m->tagset[m->seltags] & 1 << i ? 1:(urg & 1 << i ? 2:0))];
78 + drawtext(tags[i], col, True);
79 + drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i, occ & 1 << i, col);
80 dc.x += dc.w;
81 }
82 dc.w = blw = TEXTW(m->ltsymbol);
83 - drawtext(m->ltsymbol, dc.norm, False);
84 + drawtext(m->ltsymbol, dc.colors[0], True);
85 dc.x += dc.w;
86 x = dc.x;
87 if(m == selmon) { /* status is only drawn on selected monitor */
88 @@ -708,19 +708,19 @@
89 dc.x = x;
90 dc.w = m->ww - x;
91 }
92 - drawtext(stext, dc.norm, False);
93 + drawcoloredtext(stext);
94 }
95 else
96 dc.x = m->ww;
97 if((dc.w = dc.x - x) > bh) {
98 dc.x = x;
99 if(m->sel) {
100 - col = m == selmon ? dc.sel : dc.norm;
101 - drawtext(m->sel->name, col, False);
102 - drawsquare(m->sel->isfixed, m->sel->isfloating, False, col);
103 + col = m == selmon ? dc.colors[1] : dc.colors[0];
104 + drawtext(m->sel->name, col, True);
105 + drawsquare(m->sel->isfixed, m->sel->isfloating, col);
106 }
107 else
108 - drawtext(NULL, dc.norm, False);
109 + drawtext(NULL, dc.colors[0], False);
110 }
111 XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0);
112 XSync(dpy, False);
113 @@ -735,12 +735,42 @@
114 }
115
116 void
117 -drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
118 +drawcoloredtext(char *text) {
119 + Bool first=True;
120 + char *buf = text, *ptr = buf, c = 1;
121 + unsigned long *col = dc.colors[0];
122 + int i, ox = dc.x;
123 +
124 + while( *ptr ) {
125 + for( i = 0; *ptr < 0 || *ptr > NUMCOLORS; i++, ptr++);
126 + if( !*ptr ) break;
127 + c=*ptr;
128 + *ptr=0;
129 + if( i ) {
130 + dc.w = selmon->ww - dc.x;
131 + drawtext(buf, col, first);
132 + dc.x += textnw(buf, i) + textnw(&c,1);
133 + if( first ) dc.x += ( dc.font.ascent + dc.font.descent ) / 2;
134 + first = False;
135 + } else if( first ) {
136 + ox = dc.x += textnw(&c,1);
137 + }
138 + *ptr = c;
139 + col = dc.colors[ c-1 ];
140 + buf = ++ptr;
141 + }
142 + if( !first ) dc.x-=(dc.font.ascent+dc.font.descent)/2;
143 + drawtext(buf, col, True);
144 + dc.x = ox;
145 +}
146 +
147 +void
148 +drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
149 int x;
150 XGCValues gcv;
151 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
152
153 - gcv.foreground = col[invert ? ColBG : ColFG];
154 + gcv.foreground = col[ ColFG ];
155 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
156 x = (dc.font.ascent + dc.font.descent + 2) / 4;
157 r.x = dc.x + 1;
158 @@ -756,18 +786,18 @@
159 }
160
161 void
162 -drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
163 +drawtext(const char *text, unsigned long col[ColLast], Bool pad) {
164 char buf[256];
165 int i, x, y, h, len, olen;
166 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
167
168 - XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
169 + XSetForeground(dpy, dc.gc, col[ ColBG ]);
170 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
171 if(!text)
172 return;
173 olen = strlen(text);
174 - h = dc.font.ascent + dc.font.descent;
175 - y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
176 + h = pad ? (dc.font.ascent + dc.font.descent) : 0;
177 + y = dc.y + ((dc.h + dc.font.ascent - dc.font.descent) / 2);
178 x = dc.x + (h / 2);
179 /* shorten text if necessary */
180 for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--);
181 @@ -776,7 +806,7 @@
182 memcpy(buf, text, len);
183 if(len < olen)
184 for(i = len; i && i > len - 3; buf[--i] = '.');
185 - XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
186 + XSetForeground(dpy, dc.gc, col[ ColFG ]);
187 if(dc.font.set)
188 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
189 else
190 @@ -824,7 +854,7 @@
191 detachstack(c);
192 attachstack(c);
193 grabbuttons(c, True);
194 - XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
195 + XSetWindowBorder(dpy, c->win, dc.colors[1][ColBorder]);
196 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
197 }
198 else
199 @@ -1132,7 +1162,7 @@
200 }
201 wc.border_width = c->bw;
202 XConfigureWindow(dpy, w, CWBorderWidth, &wc);
203 - XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
204 + XSetWindowBorder(dpy, w, dc.colors[0][ColBorder]);
205 configure(c); /* propagates border_width, if size doesn't change */
206 updatesizehints(c);
207 XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
208 @@ -1498,12 +1528,11 @@
209 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
210 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
211 /* init appearance */
212 - dc.norm[ColBorder] = getcolor(normbordercolor);
213 - dc.norm[ColBG] = getcolor(normbgcolor);
214 - dc.norm[ColFG] = getcolor(normfgcolor);
215 - dc.sel[ColBorder] = getcolor(selbordercolor);
216 - dc.sel[ColBG] = getcolor(selbgcolor);
217 - dc.sel[ColFG] = getcolor(selfgcolor);
218 + for(int i=0; i<NUMCOLORS; i++) {
219 + dc.colors[i][ColBorder] = getcolor( colors[i][ColBorder] );
220 + dc.colors[i][ColFG] = getcolor( colors[i][ColFG] );
221 + dc.colors[i][ColBG] = getcolor( colors[i][ColBG] );
222 + }
223 dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
224 dc.gc = XCreateGC(dpy, root, 0, NULL);
225 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
226 @@ -1665,7 +1694,7 @@
227 if(!c)
228 return;
229 grabbuttons(c, False);
230 - XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
231 + XSetWindowBorder(dpy, c->win, dc.colors[0][ColBorder]);
232 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
233 }
234