dwm-statuscolors-6.1.diff 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. diff -up dwm/drw.c dwm-statuscolors/drw.c
  2. --- dwm/drw.c 2015-11-08 15:39:37.000000000 -0700
  3. +++ dwm-statuscolors/drw.c 2015-11-28 15:42:28.534399525 -0700
  4. @@ -206,6 +206,68 @@ drw_setscheme(Drw *drw, ClrScheme *schem
  5. drw->scheme = scheme;
  6. }
  7. +int
  8. +drw_get_width(Drw *drw, int numcolors, const char *text)
  9. +{
  10. + int i;
  11. + Fnt *curfont = drw->fonts[0];
  12. + int w = drw_text(drw, 0, 0, 0, 0, text, 0) + curfont->h;
  13. +
  14. + for (i = 0; i < strlen(text); i++) {
  15. + if (text[i] > 0 && text[i] <= numcolors) {
  16. + /* we found a color code
  17. + * drw_text counted it as a normal character and added one character's width
  18. + * we aren't going to render this character, so we remove one character's width */
  19. + w -= curfont->xfont->max_advance_width;
  20. +
  21. + if (i == 0 || i + 1 == strlen(text)) {
  22. + /* we're on the first or the last character of the string
  23. + * drw_text already added one character's height (divided by 2) as padding to the beginning and end
  24. + * we don't want to double this padding, so we skip this character */
  25. + continue;
  26. + }
  27. +
  28. + if (text[i - 1] > 0 && text[i - 1] <= numcolors) {
  29. + /* the previous character was also a color code
  30. + * we already added padding in the previous iteration
  31. + * we don't want to double this padding, so we skip this character */
  32. + continue;
  33. + }
  34. +
  35. + /* we are somewhere in the middle of the string and the color has changed
  36. + * we want to add one character's height (divided by 2) as padding to the end of the previous colored text
  37. + * and to the beginning of the new colored text */
  38. + w += curfont->h;
  39. + }
  40. + }
  41. +
  42. + return w;
  43. +}
  44. +
  45. +void
  46. +drw_colored_text(Drw *drw, ClrScheme *scheme, int numcolors, int x, int y, unsigned int w, unsigned int h, char *text)
  47. +{
  48. + if (!drw || !drw->fontcount || !drw->scheme)
  49. + return;
  50. +
  51. + char *buf = text, *ptr = buf, c = 1;
  52. + int i;
  53. +
  54. + while (*ptr) {
  55. + for (i = 0; *ptr < 0 || *ptr > numcolors; i++, ptr++);
  56. + if (!*ptr)
  57. + break;
  58. + c = *ptr;
  59. + *ptr = 0;
  60. + if (i)
  61. + x = drw_text(drw, x, y, w, h, buf, 0) + drw->fonts[0]->h;
  62. + *ptr = c;
  63. + drw_setscheme(drw, &scheme[c-1]);
  64. + buf = ++ptr;
  65. + }
  66. + drw_text(drw, x, y, w, h, buf, 0);
  67. +}
  68. +
  69. void
  70. drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert)
  71. {
  72. diff -up dwm/drw.h dwm-statuscolors/drw.h
  73. --- dwm/drw.h 2015-11-08 15:39:37.000000000 -0700
  74. +++ dwm-statuscolors/drw.h 2015-11-28 15:39:44.427726312 -0700
  75. @@ -67,6 +67,8 @@ void drw_setfont(Drw *, Fnt *);
  76. void drw_setscheme(Drw *, ClrScheme *);
  77. /* Drawing functions */
  78. +int drw_get_width(Drw *, int, const char *);
  79. +void drw_colored_text(Drw *, ClrScheme *, int, int, int, unsigned int, unsigned int, char *);
  80. void drw_rect(Drw *, int, int, unsigned int, unsigned int, int, int, int);
  81. int drw_text(Drw *, int, int, unsigned int, unsigned int, const char *, int);
  82. diff -up dwm/dwm.c dwm-statuscolors/dwm.c
  83. --- dwm/dwm.c 2015-11-08 15:39:37.000000000 -0700
  84. +++ dwm-statuscolors/dwm.c 2015-11-28 15:45:32.134406853 -0700
  85. @@ -51,6 +51,7 @@
  86. * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
  87. #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
  88. #define LENGTH(X) (sizeof X / sizeof X[0])
  89. +#define MAXCOLORS 9
  90. #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
  91. #define WIDTH(X) ((X)->w + 2 * (X)->bw)
  92. #define HEIGHT(X) ((X)->h + 2 * (X)->bw)
  93. @@ -261,7 +262,7 @@ static void (*handler[LASTEvent]) (XEven
  94. static Atom wmatom[WMLast], netatom[NetLast];
  95. static int running = 1;
  96. static Cur *cursor[CurLast];
  97. -static ClrScheme scheme[SchemeLast];
  98. +static ClrScheme scheme[MAXCOLORS];
  99. static Display *dpy;
  100. static Drw *drw;
  101. static Monitor *mons, *selmon;
  102. @@ -718,35 +719,35 @@ drawbar(Monitor *m)
  103. x = 0;
  104. for (i = 0; i < LENGTH(tags); i++) {
  105. w = TEXTW(tags[i]);
  106. - drw_setscheme(drw, m->tagset[m->seltags] & 1 << i ? &scheme[SchemeSel] : &scheme[SchemeNorm]);
  107. - drw_text(drw, x, 0, w, bh, tags[i], urg & 1 << i);
  108. + drw_setscheme(drw, &scheme[(m->tagset[m->seltags] & 1 << i) ? 1 : (urg & 1 << i ? 2 : 0)]);
  109. + drw_text(drw, x, 0, w, bh, tags[i], 0);
  110. drw_rect(drw, x + 1, 1, dx, dx, m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
  111. - occ & 1 << i, urg & 1 << i);
  112. + occ & 1 << i, 0);
  113. x += w;
  114. }
  115. w = blw = TEXTW(m->ltsymbol);
  116. - drw_setscheme(drw, &scheme[SchemeNorm]);
  117. + drw_setscheme(drw, &scheme[0]);
  118. drw_text(drw, x, 0, w, bh, m->ltsymbol, 0);
  119. x += w;
  120. xx = x;
  121. if (m == selmon) { /* status is only drawn on selected monitor */
  122. - w = TEXTW(stext);
  123. + w = drw_get_width(drw, NUMCOLORS, stext);
  124. x = m->ww - w;
  125. if (x < xx) {
  126. x = xx;
  127. w = m->ww - xx;
  128. }
  129. - drw_text(drw, x, 0, w, bh, stext, 0);
  130. + drw_colored_text(drw, scheme, NUMCOLORS, x, 0, w, bh, stext);
  131. } else
  132. x = m->ww;
  133. if ((w = x - xx) > bh) {
  134. x = xx;
  135. if (m->sel) {
  136. - drw_setscheme(drw, m == selmon ? &scheme[SchemeSel] : &scheme[SchemeNorm]);
  137. + drw_setscheme(drw, &scheme[m == selmon ? 1 : 0]);
  138. drw_text(drw, x, 0, w, bh, m->sel->name, 0);
  139. drw_rect(drw, x + 1, 1, dx, dx, m->sel->isfixed, m->sel->isfloating, 0);
  140. } else {
  141. - drw_setscheme(drw, &scheme[SchemeNorm]);
  142. + drw_setscheme(drw, &scheme[0]);
  143. drw_rect(drw, x, 0, w, bh, 1, 0, 1);
  144. }
  145. }
  146. @@ -807,7 +808,7 @@ focus(Client *c)
  147. detachstack(c);
  148. attachstack(c);
  149. grabbuttons(c, 1);
  150. - XSetWindowBorder(dpy, c->win, scheme[SchemeSel].border->pix);
  151. + XSetWindowBorder(dpy, c->win, scheme[1].border->pix);
  152. setfocus(c);
  153. } else {
  154. XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
  155. @@ -1065,7 +1066,7 @@ manage(Window w, XWindowAttributes *wa)
  156. wc.border_width = c->bw;
  157. XConfigureWindow(dpy, w, CWBorderWidth, &wc);
  158. - XSetWindowBorder(dpy, w, scheme[SchemeNorm].border->pix);
  159. + XSetWindowBorder(dpy, w, scheme[0].border->pix);
  160. configure(c); /* propagates border_width, if size doesn't change */
  161. updatewindowtype(c);
  162. updatesizehints(c);
  163. @@ -1580,12 +1581,12 @@ setup(void)
  164. cursor[CurResize] = drw_cur_create(drw, XC_sizing);
  165. cursor[CurMove] = drw_cur_create(drw, XC_fleur);
  166. /* init appearance */
  167. - scheme[SchemeNorm].border = drw_clr_create(drw, normbordercolor);
  168. - scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor);
  169. - scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor);
  170. - scheme[SchemeSel].border = drw_clr_create(drw, selbordercolor);
  171. - scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor);
  172. - scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor);
  173. + for(int i = 0; i < NUMCOLORS; i++){
  174. + scheme[i].border = drw_clr_create(drw, colors[i][0]);
  175. + scheme[i].fg = drw_clr_create(drw, colors[i][1]);
  176. + scheme[i].bg = drw_clr_create(drw, colors[i][2]);
  177. + }
  178. +
  179. /* init bars */
  180. updatebars();
  181. updatestatus();
  182. @@ -1745,7 +1746,7 @@ unfocus(Client *c, int setfocus)
  183. if (!c)
  184. return;
  185. grabbuttons(c, 0);
  186. - XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->pix);
  187. + XSetWindowBorder(dpy, c->win, scheme[0].border->pix);
  188. if (setfocus) {
  189. XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
  190. XDeleteProperty(dpy, root, netatom[NetActiveWindow]);