Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

261 lines
6.7 KiB

  1. #if BAR_STATUS2D_XRDB_TERMCOLORS_PATCH
  2. static char termcol0[] = "#000000"; /* black */
  3. static char termcol1[] = "#ff0000"; /* red */
  4. static char termcol2[] = "#33ff00"; /* green */
  5. static char termcol3[] = "#ff0099"; /* yellow */
  6. static char termcol4[] = "#0066ff"; /* blue */
  7. static char termcol5[] = "#cc00ff"; /* magenta */
  8. static char termcol6[] = "#00ffff"; /* cyan */
  9. static char termcol7[] = "#d0d0d0"; /* white */
  10. static char termcol8[] = "#808080"; /* black */
  11. static char termcol9[] = "#ff0000"; /* red */
  12. static char termcol10[] = "#33ff00"; /* green */
  13. static char termcol11[] = "#ff0099"; /* yellow */
  14. static char termcol12[] = "#0066ff"; /* blue */
  15. static char termcol13[] = "#cc00ff"; /* magenta */
  16. static char termcol14[] = "#00ffff"; /* cyan */
  17. static char termcol15[] = "#ffffff"; /* white */
  18. static char *termcolor[] = {
  19. termcol0, termcol1, termcol2, termcol3, termcol4, termcol5, termcol6, termcol7,
  20. termcol8, termcol9, termcol10, termcol11, termcol12, termcol13, termcol14, termcol15,
  21. };
  22. #endif // BAR_STATUS2D_XRDB_TERMCOLORS_PATCH
  23. int
  24. width_status2d(Bar *bar, BarArg *a)
  25. {
  26. int width;
  27. #if BAR_EXTRASTATUS_PATCH || BAR_STATUSCMD_PATCH
  28. width = status2dtextlength(rawstext);
  29. #else
  30. width = status2dtextlength(stext);
  31. #endif // #if BAR_EXTRASTATUS_PATCH | BAR_STATUSCMD_PATCH
  32. return width ? width + lrpad : 0;
  33. }
  34. #if BAR_EXTRASTATUS_PATCH
  35. int
  36. width_status2d_es(Bar *bar, BarArg *a)
  37. {
  38. int width;
  39. #if BAR_STATUSCMD_PATCH
  40. width = status2dtextlength(rawestext);
  41. #else
  42. width = status2dtextlength(estext);
  43. #endif // BAR_STATUSCMD_PATCH
  44. return width ? width + lrpad : 0;
  45. }
  46. #endif // BAR_EXTRASTATUS_PATCH
  47. int
  48. draw_status2d(Bar *bar, BarArg *a)
  49. {
  50. #if BAR_EXTRASTATUS_PATCH || BAR_STATUSCMD_PATCH
  51. return drawstatusbar(a, rawstext);
  52. #else
  53. return drawstatusbar(a, stext);
  54. #endif // #if BAR_EXTRASTATUS_PATCH | BAR_STATUSCMD_PATCH
  55. }
  56. #if BAR_EXTRASTATUS_PATCH
  57. int
  58. draw_status2d_es(Bar *bar, BarArg *a)
  59. {
  60. #if BAR_STATUSCMD_PATCH
  61. return drawstatusbar(a, rawestext);
  62. #else
  63. return drawstatusbar(a, estext);
  64. #endif // BAR_STATUSCMD_PATCH
  65. }
  66. #endif // BAR_EXTRASTATUS_PATCH
  67. #if !BAR_STATUSCMD_PATCH
  68. int
  69. click_status2d(Bar *bar, Arg *arg, BarArg *a)
  70. {
  71. return ClkStatusText;
  72. }
  73. #endif // BAR_STATUSCMD_PATCH
  74. int
  75. drawstatusbar(BarArg *a, char* stext)
  76. {
  77. int i, w, len;
  78. int x = a->x;
  79. int y = a->y;
  80. short isCode = 0;
  81. char *text;
  82. char *p;
  83. Clr oldbg, oldfg;
  84. len = strlen(stext) + 1;
  85. if (!(text = (char*) malloc(sizeof(char)*len)))
  86. die("malloc");
  87. p = text;
  88. #if BAR_STATUSCMD_PATCH
  89. copyvalidchars(text, stext);
  90. #else
  91. memcpy(text, stext, len);
  92. #endif // BAR_STATUSCMD_PATCH
  93. x += lrpad / 2;
  94. drw_setscheme(drw, scheme[LENGTH(colors)]);
  95. drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
  96. drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
  97. /* process status text */
  98. i = -1;
  99. while (text[++i]) {
  100. if (text[i] == '^' && !isCode) {
  101. isCode = 1;
  102. text[i] = '\0';
  103. w = TEXTWM(text) - lrpad;
  104. drw_text(drw, x, y, w, bh, 0, text, 0, True);
  105. x += w;
  106. /* process code */
  107. while (text[++i] != '^') {
  108. if (text[i] == 'c') {
  109. char buf[8];
  110. if (i + 7 > len) {
  111. i += 7;
  112. break;
  113. }
  114. memcpy(buf, (char*)text+i+1, 7);
  115. buf[7] = '\0';
  116. #if BAR_ALPHA_PATCH && BAR_STATUS2D_NO_ALPHA_PATCH
  117. drw_clr_create(drw, &drw->scheme[ColFg], buf, 0xff);
  118. #elif BAR_ALPHA_PATCH
  119. drw_clr_create(drw, &drw->scheme[ColFg], buf, alphas[SchemeNorm][ColFg]);
  120. #else
  121. drw_clr_create(drw, &drw->scheme[ColFg], buf);
  122. #endif // BAR_ALPHA_PATCH
  123. i += 7;
  124. } else if (text[i] == 'b') {
  125. char buf[8];
  126. if (i + 7 > len) {
  127. i += 7;
  128. break;
  129. }
  130. memcpy(buf, (char*)text+i+1, 7);
  131. buf[7] = '\0';
  132. #if BAR_ALPHA_PATCH && BAR_STATUS2D_NO_ALPHA_PATCH
  133. drw_clr_create(drw, &drw->scheme[ColBg], buf, 0xff);
  134. #elif BAR_ALPHA_PATCH
  135. drw_clr_create(drw, &drw->scheme[ColBg], buf, alphas[SchemeNorm][ColBg]);
  136. #else
  137. drw_clr_create(drw, &drw->scheme[ColBg], buf);
  138. #endif // BAR_ALPHA_PATCH
  139. i += 7;
  140. #if BAR_STATUS2D_XRDB_TERMCOLORS_PATCH
  141. } else if (text[i] == 'C') {
  142. int c = atoi(text + ++i) % 16;
  143. #if BAR_ALPHA_PATCH && BAR_STATUS2D_NO_ALPHA_PATCH
  144. drw_clr_create(drw, &drw->scheme[ColFg], termcolor[c], 0xff);
  145. #elif BAR_ALPHA_PATCH
  146. drw_clr_create(drw, &drw->scheme[ColFg], termcolor[c], alphas[SchemeNorm][ColBg]);
  147. #else
  148. drw_clr_create(drw, &drw->scheme[ColFg], termcolor[c]);
  149. #endif // BAR_ALPHA_PATCH
  150. } else if (text[i] == 'B') {
  151. int c = atoi(text + ++i) % 16;
  152. #if BAR_ALPHA_PATCH && BAR_STATUS2D_NO_ALPHA_PATCH
  153. drw_clr_create(drw, &drw->scheme[ColBg], termcolor[c], 0xff);
  154. #elif BAR_ALPHA_PATCH
  155. drw_clr_create(drw, &drw->scheme[ColBg], termcolor[c], alphas[SchemeNorm][ColBg]);
  156. #else
  157. drw_clr_create(drw, &drw->scheme[ColBg], termcolor[c]);
  158. #endif // BAR_ALPHA_PATCH
  159. #endif // BAR_STATUS2D_XRDB_TERMCOLORS_PATCH
  160. } else if (text[i] == 'd') {
  161. drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
  162. drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
  163. } else if (text[i] == 'w') {
  164. Clr swp;
  165. swp = drw->scheme[ColFg];
  166. drw->scheme[ColFg] = drw->scheme[ColBg];
  167. drw->scheme[ColBg] = swp;
  168. } else if (text[i] == 'v') {
  169. oldfg = drw->scheme[ColFg];
  170. oldbg = drw->scheme[ColBg];
  171. } else if (text[i] == 't') {
  172. drw->scheme[ColFg] = oldfg;
  173. drw->scheme[ColBg] = oldbg;
  174. } else if (text[i] == 'r') {
  175. int rx = atoi(text + ++i);
  176. while (text[++i] != ',');
  177. int ry = atoi(text + ++i);
  178. while (text[++i] != ',');
  179. int rw = atoi(text + ++i);
  180. while (text[++i] != ',');
  181. int rh = atoi(text + ++i);
  182. if (ry < 0)
  183. ry = 0;
  184. if (rx < 0)
  185. rx = 0;
  186. drw_rect(drw, rx + x, y + ry, rw, rh, 1, 0);
  187. } else if (text[i] == 'f') {
  188. x += atoi(text + ++i);
  189. }
  190. }
  191. text = text + i + 1;
  192. i=-1;
  193. isCode = 0;
  194. }
  195. }
  196. if (!isCode) {
  197. w = TEXTWM(text) - lrpad;
  198. drw_text(drw, x, y, w, bh, 0, text, 0, True);
  199. x += w;
  200. }
  201. free(p);
  202. drw_setscheme(drw, scheme[SchemeNorm]);
  203. return len - 1;
  204. }
  205. int
  206. status2dtextlength(char* stext)
  207. {
  208. int i, w, len;
  209. short isCode = 0;
  210. char *text;
  211. char *p;
  212. len = strlen(stext) + 1;
  213. if (!(text = (char*) malloc(sizeof(char)*len)))
  214. die("malloc");
  215. p = text;
  216. #if BAR_STATUSCMD_PATCH
  217. copyvalidchars(text, stext);
  218. #else
  219. memcpy(text, stext, len);
  220. #endif // BAR_STATUSCMD_PATCH
  221. /* compute width of the status text */
  222. w = 0;
  223. i = -1;
  224. while (text[++i]) {
  225. if (text[i] == '^') {
  226. if (!isCode) {
  227. isCode = 1;
  228. text[i] = '\0';
  229. w += TEXTWM(text) - lrpad;
  230. text[i] = '^';
  231. if (text[++i] == 'f')
  232. w += atoi(text + ++i);
  233. } else {
  234. isCode = 0;
  235. text = text + i + 1;
  236. i = -1;
  237. }
  238. }
  239. }
  240. if (!isCode)
  241. w += TEXTWM(text) - lrpad;
  242. free(p);
  243. return w;
  244. }