Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- dwm.c.orig 2011-12-19 16:02:46.000000000 +0100
- +++ dwm.c.patched 2012-04-05 17:44:01.779171506 +0200
- @@ -54,6 +54,7 @@
- #define HEIGHT(X) ((X)->h + 2 * (X)->bw)
- #define TAGMASK ((1 << LENGTH(tags)) - 1)
- #define TEXTW(X) (textnw(X, strlen(X)) + dc.font.height)
- +#define MAXCOLORS 8
- /* enums */
- enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
- @@ -99,8 +100,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 {
- @@ -178,8 +178,9 @@
- static Monitor *dirtomon(int dir);
- static void drawbar(Monitor *m);
- static void drawbars(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(Monitor *m, 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);
- @@ -730,36 +731,35 @@
- dc.x = 0;
- for(i = 0; i < LENGTH(tags); i++) {
- dc.w = TEXTW(tags[i]);
- - col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm;
- - drawtext(tags[i], col, urg & 1 << i);
- - drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
- - occ & 1 << i, urg & 1 << i, col);
- + col = dc.colors[ (urg & 1 << i) ? 2 : (m->tagset[m->seltags] & 1 << i) ? 1 : 0 ];
- + drawtext(tags[i], col, True);
- + drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i, occ & 1 << i, col);
- dc.x += dc.w;
- }
- - dc.w = blw = TEXTW(m->ltsymbol);
- - drawtext(m->ltsymbol, dc.norm, False);
- + dc.w = blw = textnw(m->ltsymbol, strlen(m->ltsymbol));
- + drawtext(m->ltsymbol, dc.colors[0], False);
- dc.x += dc.w;
- x = dc.x;
- if(m == selmon) { /* status is only drawn on selected monitor */
- - dc.w = TEXTW(stext);
- + dc.w = textnw(stext, strlen(stext));
- dc.x = m->ww - dc.w;
- if(dc.x < x) {
- dc.x = x;
- dc.w = m->ww - x;
- }
- - drawtext(stext, dc.norm, False);
- + drawcoloredtext(m, stext);
- }
- else
- dc.x = m->ww;
- if((dc.w = dc.x - x) > bh) {
- dc.x = x;
- if(m->sel) {
- - col = m == selmon ? dc.sel : dc.norm;
- - drawtext(m->sel->name, col, False);
- - drawsquare(m->sel->isfixed, m->sel->isfloating, False, col);
- + col = dc.colors[ m == selmon ? 1 : 0 ];
- + drawtext(m->sel->name, col, True);
- + drawsquare(m->sel->isfixed, m->sel->isfloating, col);
- }
- else
- - drawtext(NULL, dc.norm, False);
- + drawtext(NULL, dc.colors[0], False);
- }
- XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0);
- XSync(dpy, False);
- @@ -774,10 +774,34 @@
- }
- void
- -drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
- +drawcoloredtext(Monitor *m, char *text) {
- + char *buf = text, *ptr = buf, c = 1;
- + unsigned long *col = dc.colors[0];
- + int i, ox = dc.x;
- +
- + while(*ptr) {
- + for(i = 0; *ptr < 0 || *ptr > MAXCOLORS; i++, ptr++);
- + if(!*ptr) break;
- + c=*ptr;
- + *ptr=0;
- + if(i) {
- + dc.w = m->ww - dc.x;
- + drawtext(buf, col, False);
- + dc.x += textnw(buf, i);
- + }
- + *ptr = c;
- + col = dc.colors[ c-1 ];
- + buf = ++ptr;
- + }
- + drawtext(buf, col, False);
- + dc.x = ox;
- +}
- +
- +void
- +drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
- int x;
- - XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
- + XSetForeground(dpy, dc.gc, col[ColFG]);
- x = (dc.font.ascent + dc.font.descent + 2) / 4;
- if(filled)
- XFillRectangle(dpy, dc.drawable, dc.gc, dc.x+1, dc.y+1, x+1, x+1);
- @@ -786,17 +810,17 @@
- }
- 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;
- - XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
- + XSetForeground(dpy, dc.gc, col[ColBG]);
- XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h);
- 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--);
- @@ -805,7 +829,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
- @@ -855,7 +879,7 @@
- detachstack(c);
- attachstack(c);
- grabbuttons(c, True);
- - XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
- + XSetWindowBorder(dpy, c->win, dc.colors[1][ColBorder]);
- setfocus(c);
- }
- else
- @@ -1144,7 +1168,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 */
- updatewindowtype(c);
- updatesizehints(c);
- @@ -1612,12 +1636,11 @@
- cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
- 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(int i=0; i<MAXCOLORS; i++) {
- + dc.colors[i][ColBorder] = getcolor(colors[i][ColBorder]);
- + dc.colors[i][ColFG] = getcolor(colors[i][ColFG]);
- + dc.colors[i][ColBG] = getcolor(colors[i][ColBG]);
- + }
- dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
- dc.gc = XCreateGC(dpy, root, 0, NULL);
- XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
- @@ -1692,13 +1715,25 @@
- int
- textnw(const char *text, unsigned int len) {
- + char *ptr = (char *)text, buf[len+1];
- + unsigned int i, ibuf, lenbuf = len;
- XRectangle r;
- + for(i = 0, ibuf = 0; *ptr && i < len; i++, ptr++) {
- + if(*ptr <= MAXCOLORS && *ptr > 0) {
- + if(i < len) { lenbuf--; }
- + } else {
- + buf[ibuf] = *ptr;
- + ibuf++;
- + }
- + }
- + buf[ibuf]=0;
- +
- if(dc.font.set) {
- - XmbTextExtents(dc.font.set, text, len, NULL, &r);
- + XmbTextExtents(dc.font.set, buf, lenbuf, NULL, &r);
- return r.width;
- }
- - return XTextWidth(dc.font.xfont, text, len);
- + return XTextWidth(dc.font.xfont, buf, lenbuf);
- }
- void
- @@ -1776,7 +1811,7 @@
- if(!c)
- return;
- grabbuttons(c, False);
- - XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
- + XSetWindowBorder(dpy, c->win, dc.colors[0][ColBorder]);
- if(setfocus)
- XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
- }
- @@ -2031,8 +2066,11 @@
- wmh->flags &= ~XUrgencyHint;
- XSetWMHints(dpy, c->win, wmh);
- }
- - else
- + else {
- c->isurgent = (wmh->flags & XUrgencyHint) ? True : False;
- + if(c->isurgent)
- + XSetWindowBorder(dpy, c->win, dc.colors[2][ColBorder]);
- + }
- if(wmh->flags & InputHint)
- c->neverfocus = !wmh->input;
- else
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement