Advertisement
Guest User

Untitled

a guest
Apr 5th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.47 KB | None | 0 0
  1. --- dwm.c.orig 2011-12-19 16:02:46.000000000 +0100
  2. +++ dwm.c.patched 2012-04-05 17:44:01.779171506 +0200
  3. @@ -54,6 +54,7 @@
  4. #define HEIGHT(X) ((X)->h + 2 * (X)->bw)
  5. #define TAGMASK ((1 << LENGTH(tags)) - 1)
  6. #define TEXTW(X) (textnw(X, strlen(X)) + dc.font.height)
  7. +#define MAXCOLORS 8
  8.  
  9. /* enums */
  10. enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
  11. @@ -99,8 +100,7 @@
  12.  
  13. typedef struct {
  14. int x, y, w, h;
  15. - unsigned long norm[ColLast];
  16. - unsigned long sel[ColLast];
  17. + unsigned long colors[MAXCOLORS][ColLast];
  18. Drawable drawable;
  19. GC gc;
  20. struct {
  21. @@ -178,8 +178,9 @@
  22. static Monitor *dirtomon(int dir);
  23. static void drawbar(Monitor *m);
  24. static void drawbars(void);
  25. -static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
  26. -static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
  27. +static void drawcoloredtext(Monitor *m, char *text);
  28. +static void drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]);
  29. +static void drawtext(const char *text, unsigned long col[ColLast], Bool pad);
  30. static void enternotify(XEvent *e);
  31. static void expose(XEvent *e);
  32. static void focus(Client *c);
  33. @@ -730,36 +731,35 @@
  34. dc.x = 0;
  35. for(i = 0; i < LENGTH(tags); i++) {
  36. dc.w = TEXTW(tags[i]);
  37. - col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm;
  38. - drawtext(tags[i], col, urg & 1 << i);
  39. - drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
  40. - occ & 1 << i, urg & 1 << i, col);
  41. + col = dc.colors[ (urg & 1 << i) ? 2 : (m->tagset[m->seltags] & 1 << i) ? 1 : 0 ];
  42. + drawtext(tags[i], col, True);
  43. + drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i, occ & 1 << i, col);
  44. dc.x += dc.w;
  45. }
  46. - dc.w = blw = TEXTW(m->ltsymbol);
  47. - drawtext(m->ltsymbol, dc.norm, False);
  48. + dc.w = blw = textnw(m->ltsymbol, strlen(m->ltsymbol));
  49. + drawtext(m->ltsymbol, dc.colors[0], False);
  50. dc.x += dc.w;
  51. x = dc.x;
  52. if(m == selmon) { /* status is only drawn on selected monitor */
  53. - dc.w = TEXTW(stext);
  54. + dc.w = textnw(stext, strlen(stext));
  55. dc.x = m->ww - dc.w;
  56. if(dc.x < x) {
  57. dc.x = x;
  58. dc.w = m->ww - x;
  59. }
  60. - drawtext(stext, dc.norm, False);
  61. + drawcoloredtext(m, stext);
  62. }
  63. else
  64. dc.x = m->ww;
  65. if((dc.w = dc.x - x) > bh) {
  66. dc.x = x;
  67. if(m->sel) {
  68. - col = m == selmon ? dc.sel : dc.norm;
  69. - drawtext(m->sel->name, col, False);
  70. - drawsquare(m->sel->isfixed, m->sel->isfloating, False, col);
  71. + col = dc.colors[ m == selmon ? 1 : 0 ];
  72. + drawtext(m->sel->name, col, True);
  73. + drawsquare(m->sel->isfixed, m->sel->isfloating, col);
  74. }
  75. else
  76. - drawtext(NULL, dc.norm, False);
  77. + drawtext(NULL, dc.colors[0], False);
  78. }
  79. XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0);
  80. XSync(dpy, False);
  81. @@ -774,10 +774,34 @@
  82. }
  83.  
  84. void
  85. -drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
  86. +drawcoloredtext(Monitor *m, char *text) {
  87. + char *buf = text, *ptr = buf, c = 1;
  88. + unsigned long *col = dc.colors[0];
  89. + int i, ox = dc.x;
  90. +
  91. + while(*ptr) {
  92. + for(i = 0; *ptr < 0 || *ptr > MAXCOLORS; i++, ptr++);
  93. + if(!*ptr) break;
  94. + c=*ptr;
  95. + *ptr=0;
  96. + if(i) {
  97. + dc.w = m->ww - dc.x;
  98. + drawtext(buf, col, False);
  99. + dc.x += textnw(buf, i);
  100. + }
  101. + *ptr = c;
  102. + col = dc.colors[ c-1 ];
  103. + buf = ++ptr;
  104. + }
  105. + drawtext(buf, col, False);
  106. + dc.x = ox;
  107. +}
  108. +
  109. +void
  110. +drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
  111. int x;
  112.  
  113. - XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
  114. + XSetForeground(dpy, dc.gc, col[ColFG]);
  115. x = (dc.font.ascent + dc.font.descent + 2) / 4;
  116. if(filled)
  117. XFillRectangle(dpy, dc.drawable, dc.gc, dc.x+1, dc.y+1, x+1, x+1);
  118. @@ -786,17 +810,17 @@
  119. }
  120.  
  121. void
  122. -drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
  123. +drawtext(const char *text, unsigned long col[ColLast], Bool pad) {
  124. char buf[256];
  125. int i, x, y, h, len, olen;
  126.  
  127. - XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
  128. + XSetForeground(dpy, dc.gc, col[ColBG]);
  129. XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h);
  130. if(!text)
  131. return;
  132. olen = strlen(text);
  133. - h = dc.font.ascent + dc.font.descent;
  134. - y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
  135. + h = pad ? (dc.font.ascent + dc.font.descent) : 0;
  136. + y = dc.y + ((dc.h + dc.font.ascent - dc.font.descent) / 2);
  137. x = dc.x + (h / 2);
  138. /* shorten text if necessary */
  139. for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--);
  140. @@ -805,7 +829,7 @@
  141. memcpy(buf, text, len);
  142. if(len < olen)
  143. for(i = len; i && i > len - 3; buf[--i] = '.');
  144. - XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
  145. + XSetForeground(dpy, dc.gc, col[ColFG]);
  146. if(dc.font.set)
  147. XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
  148. else
  149. @@ -855,7 +879,7 @@
  150. detachstack(c);
  151. attachstack(c);
  152. grabbuttons(c, True);
  153. - XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
  154. + XSetWindowBorder(dpy, c->win, dc.colors[1][ColBorder]);
  155. setfocus(c);
  156. }
  157. else
  158. @@ -1144,7 +1168,7 @@
  159.  
  160. wc.border_width = c->bw;
  161. XConfigureWindow(dpy, w, CWBorderWidth, &wc);
  162. - XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
  163. + XSetWindowBorder(dpy, w, dc.colors[0][ColBorder]);
  164. configure(c); /* propagates border_width, if size doesn't change */
  165. updatewindowtype(c);
  166. updatesizehints(c);
  167. @@ -1612,12 +1636,11 @@
  168. cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
  169. cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
  170. /* init appearance */
  171. - dc.norm[ColBorder] = getcolor(normbordercolor);
  172. - dc.norm[ColBG] = getcolor(normbgcolor);
  173. - dc.norm[ColFG] = getcolor(normfgcolor);
  174. - dc.sel[ColBorder] = getcolor(selbordercolor);
  175. - dc.sel[ColBG] = getcolor(selbgcolor);
  176. - dc.sel[ColFG] = getcolor(selfgcolor);
  177. + for(int i=0; i<MAXCOLORS; i++) {
  178. + dc.colors[i][ColBorder] = getcolor(colors[i][ColBorder]);
  179. + dc.colors[i][ColFG] = getcolor(colors[i][ColFG]);
  180. + dc.colors[i][ColBG] = getcolor(colors[i][ColBG]);
  181. + }
  182. dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
  183. dc.gc = XCreateGC(dpy, root, 0, NULL);
  184. XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
  185. @@ -1692,13 +1715,25 @@
  186.  
  187. int
  188. textnw(const char *text, unsigned int len) {
  189. + char *ptr = (char *)text, buf[len+1];
  190. + unsigned int i, ibuf, lenbuf = len;
  191. XRectangle r;
  192.  
  193. + for(i = 0, ibuf = 0; *ptr && i < len; i++, ptr++) {
  194. + if(*ptr <= MAXCOLORS && *ptr > 0) {
  195. + if(i < len) { lenbuf--; }
  196. + } else {
  197. + buf[ibuf] = *ptr;
  198. + ibuf++;
  199. + }
  200. + }
  201. + buf[ibuf]=0;
  202. +
  203. if(dc.font.set) {
  204. - XmbTextExtents(dc.font.set, text, len, NULL, &r);
  205. + XmbTextExtents(dc.font.set, buf, lenbuf, NULL, &r);
  206. return r.width;
  207. }
  208. - return XTextWidth(dc.font.xfont, text, len);
  209. + return XTextWidth(dc.font.xfont, buf, lenbuf);
  210. }
  211.  
  212. void
  213. @@ -1776,7 +1811,7 @@
  214. if(!c)
  215. return;
  216. grabbuttons(c, False);
  217. - XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
  218. + XSetWindowBorder(dpy, c->win, dc.colors[0][ColBorder]);
  219. if(setfocus)
  220. XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
  221. }
  222. @@ -2031,8 +2066,11 @@
  223. wmh->flags &= ~XUrgencyHint;
  224. XSetWMHints(dpy, c->win, wmh);
  225. }
  226. - else
  227. + else {
  228. c->isurgent = (wmh->flags & XUrgencyHint) ? True : False;
  229. + if(c->isurgent)
  230. + XSetWindowBorder(dpy, c->win, dc.colors[2][ColBorder]);
  231. + }
  232. if(wmh->flags & InputHint)
  233. c->neverfocus = !wmh->input;
  234. else
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement