Configuration file for DWM on MacBook Air
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.

236 lines
4.8 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /*
  2. * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
  3. * See LICENSE file for license details.
  4. */
  5. #include "dwm.h"
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <X11/Xlocale.h>
  9. /* static functions */
  10. static void
  11. drawborder(void)
  12. {
  13. XPoint points[5];
  14. XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
  15. XSetForeground(dpy, dc.gc, dc.border);
  16. points[0].x = dc.x;
  17. points[0].y = dc.y;
  18. points[1].x = dc.w - 1;
  19. points[1].y = 0;
  20. points[2].x = 0;
  21. points[2].y = dc.h - 1;
  22. points[3].x = -(dc.w - 1);
  23. points[3].y = 0;
  24. points[4].x = 0;
  25. points[4].y = -(dc.h - 1);
  26. XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
  27. }
  28. /* extern functions */
  29. void
  30. drawall()
  31. {
  32. Client *c;
  33. for(c = clients; c; c = getnext(c->next))
  34. drawtitle(c);
  35. drawstatus();
  36. }
  37. void
  38. drawstatus()
  39. {
  40. int i;
  41. Bool istile = arrange == dotile;
  42. dc.x = dc.y = 0;
  43. dc.w = bw;
  44. drawtext(NULL, !istile, False);
  45. dc.w = 0;
  46. for(i = 0; i < TLast; i++) {
  47. dc.x += dc.w;
  48. dc.w = textw(tags[i]);
  49. if(istile)
  50. drawtext(tags[i], (i == tsel), True);
  51. else
  52. drawtext(tags[i], (i != tsel), True);
  53. }
  54. if(sel) {
  55. dc.x += dc.w;
  56. dc.w = textw(sel->name);
  57. drawtext(sel->name, istile, True);
  58. }
  59. dc.w = textw(stext);
  60. dc.x = bx + bw - dc.w;
  61. drawtext(stext, !istile, False);
  62. XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
  63. XFlush(dpy);
  64. }
  65. void
  66. drawtext(const char *text, Bool invert, Bool border)
  67. {
  68. int x, y, w, h;
  69. unsigned int len;
  70. static char buf[256];
  71. XGCValues gcv;
  72. XRectangle r = { dc.x, dc.y, dc.w, dc.h };
  73. XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg);
  74. XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
  75. w = 0;
  76. if(border)
  77. drawborder();
  78. if(!text)
  79. return;
  80. len = strlen(text);
  81. if(len >= sizeof(buf))
  82. len = sizeof(buf) - 1;
  83. memcpy(buf, text, len);
  84. buf[len] = 0;
  85. h = dc.font.ascent + dc.font.descent;
  86. y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
  87. x = dc.x + (h / 2);
  88. /* shorten text if necessary */
  89. while(len && (w = textnw(buf, len)) > dc.w - h)
  90. buf[--len] = 0;
  91. if(w > dc.w)
  92. return; /* too long */
  93. gcv.foreground = invert ? dc.bg : dc.fg;
  94. gcv.background = invert ? dc.fg : dc.bg;
  95. if(dc.font.set) {
  96. XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv);
  97. XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc,
  98. x, y, buf, len);
  99. }
  100. else {
  101. gcv.font = dc.font.xfont->fid;
  102. XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv);
  103. XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len);
  104. }
  105. }
  106. void
  107. drawtitle(Client *c)
  108. {
  109. int i;
  110. Bool istile = arrange == dotile;
  111. if(c == sel) {
  112. drawstatus();
  113. XUnmapWindow(dpy, c->title);
  114. XSetWindowBorder(dpy, c->win, dc.fg);
  115. return;
  116. }
  117. XSetWindowBorder(dpy, c->win, dc.bg);
  118. XMapWindow(dpy, c->title);
  119. dc.x = dc.y = 0;
  120. dc.w = 0;
  121. for(i = 0; i < TLast; i++) {
  122. if(c->tags[i]) {
  123. dc.x += dc.w;
  124. dc.w = textw(c->tags[i]);
  125. drawtext(c->tags[i], !istile, True);
  126. }
  127. }
  128. dc.x += dc.w;
  129. dc.w = textw(c->name);
  130. drawtext(c->name, !istile, True);
  131. XCopyArea(dpy, dc.drawable, c->title, dc.gc,
  132. 0, 0, c->tw, c->th, 0, 0);
  133. XFlush(dpy);
  134. }
  135. unsigned long
  136. getcolor(const char *colstr)
  137. {
  138. XColor color;
  139. Colormap cmap = DefaultColormap(dpy, screen);
  140. XAllocNamedColor(dpy, cmap, colstr, &color, &color);
  141. return color.pixel;
  142. }
  143. void
  144. setfont(const char *fontstr)
  145. {
  146. char **missing, *def;
  147. int i, n;
  148. missing = NULL;
  149. setlocale(LC_ALL, "");
  150. if(dc.font.set)
  151. XFreeFontSet(dpy, dc.font.set);
  152. dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
  153. if(missing) {
  154. while(n--)
  155. fprintf(stderr, "missing fontset: %s\n", missing[n]);
  156. XFreeStringList(missing);
  157. if(dc.font.set) {
  158. XFreeFontSet(dpy, dc.font.set);
  159. dc.font.set = NULL;
  160. }
  161. }
  162. if(dc.font.set) {
  163. XFontSetExtents *font_extents;
  164. XFontStruct **xfonts;
  165. char **font_names;
  166. dc.font.ascent = dc.font.descent = 0;
  167. font_extents = XExtentsOfFontSet(dc.font.set);
  168. n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
  169. for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
  170. if(dc.font.ascent < (*xfonts)->ascent)
  171. dc.font.ascent = (*xfonts)->ascent;
  172. if(dc.font.descent < (*xfonts)->descent)
  173. dc.font.descent = (*xfonts)->descent;
  174. xfonts++;
  175. }
  176. }
  177. else {
  178. if(dc.font.xfont)
  179. XFreeFont(dpy, dc.font.xfont);
  180. dc.font.xfont = NULL;
  181. dc.font.xfont = XLoadQueryFont(dpy, fontstr);
  182. if (!dc.font.xfont)
  183. dc.font.xfont = XLoadQueryFont(dpy, "fixed");
  184. if (!dc.font.xfont)
  185. eprint("error, cannot init 'fixed' font\n");
  186. dc.font.ascent = dc.font.xfont->ascent;
  187. dc.font.descent = dc.font.xfont->descent;
  188. }
  189. dc.font.height = dc.font.ascent + dc.font.descent;
  190. }
  191. unsigned int
  192. textnw(char *text, unsigned int len)
  193. {
  194. XRectangle r;
  195. if(dc.font.set) {
  196. XmbTextExtents(dc.font.set, text, len, NULL, &r);
  197. return r.width;
  198. }
  199. return XTextWidth(dc.font.xfont, text, len);
  200. }
  201. unsigned int
  202. textw(char *text)
  203. {
  204. return textnw(text, strlen(text)) + dc.font.height;
  205. }