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.

142 lines
3.0 KiB

18 years ago
  1. /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
  2. * See LICENSE file for license details.
  3. */
  4. #include "dwm.h"
  5. #include <string.h>
  6. /* static */
  7. static void
  8. drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
  9. int x;
  10. XGCValues gcv;
  11. XRectangle r = { dc.x, dc.y, dc.w, dc.h };
  12. gcv.foreground = col[ColFG];
  13. XChangeGC(dpy, dc.gc, GCForeground, &gcv);
  14. x = (dc.font.ascent + dc.font.descent + 2) / 4;
  15. r.x = dc.x + 1;
  16. r.y = dc.y + 1;
  17. if(filled) {
  18. r.width = r.height = x + 1;
  19. XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
  20. }
  21. else if(empty) {
  22. r.width = r.height = x;
  23. XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
  24. }
  25. }
  26. static Bool
  27. isoccupied(unsigned int t) {
  28. Client *c;
  29. for(c = clients; c; c = c->next)
  30. if(c->tags[t])
  31. return True;
  32. return False;
  33. }
  34. static unsigned int
  35. textnw(const char *text, unsigned int len) {
  36. XRectangle r;
  37. if(dc.font.set) {
  38. XmbTextExtents(dc.font.set, text, len, NULL, &r);
  39. return r.width;
  40. }
  41. return XTextWidth(dc.font.xfont, text, len);
  42. }
  43. /* extern */
  44. void
  45. drawstatus(void) {
  46. int i, x;
  47. dc.x = dc.y = 0;
  48. for(i = 0; i < ntags; i++) {
  49. dc.w = textw(tags[i]);
  50. if(seltag[i]) {
  51. drawtext(tags[i], dc.sel);
  52. drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel);
  53. }
  54. else {
  55. drawtext(tags[i], dc.norm);
  56. drawsquare(sel && sel->tags[i], isoccupied(i), dc.norm);
  57. }
  58. dc.x += dc.w;
  59. }
  60. dc.w = blw;
  61. drawtext(lt->symbol, dc.norm);
  62. x = dc.x + dc.w;
  63. dc.w = textw(stext);
  64. dc.x = sw - dc.w;
  65. if(dc.x < x) {
  66. dc.x = x;
  67. dc.w = sw - x;
  68. }
  69. drawtext(stext, dc.norm);
  70. if((dc.w = dc.x - x) > bh) {
  71. dc.x = x;
  72. if(sel) {
  73. drawtext(sel->name, dc.sel);
  74. drawsquare(sel->ismax, sel->isversatile, dc.sel);
  75. }
  76. else
  77. drawtext(NULL, dc.norm);
  78. }
  79. XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0);
  80. XSync(dpy, False);
  81. }
  82. void
  83. drawtext(const char *text, unsigned long col[ColLast]) {
  84. int x, y, w, h;
  85. static char buf[256];
  86. unsigned int len, olen;
  87. XGCValues gcv;
  88. XRectangle r = { dc.x, dc.y, dc.w, dc.h };
  89. XSetForeground(dpy, dc.gc, col[ColBG]);
  90. XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
  91. if(!text)
  92. return;
  93. w = 0;
  94. olen = len = strlen(text);
  95. if(len >= sizeof buf)
  96. len = sizeof buf - 1;
  97. memcpy(buf, text, len);
  98. buf[len] = 0;
  99. h = dc.font.ascent + dc.font.descent;
  100. y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
  101. x = dc.x + (h / 2);
  102. /* shorten text if necessary */
  103. while(len && (w = textnw(buf, len)) > dc.w - h)
  104. buf[--len] = 0;
  105. if(len < olen) {
  106. if(len > 1)
  107. buf[len - 1] = '.';
  108. if(len > 2)
  109. buf[len - 2] = '.';
  110. if(len > 3)
  111. buf[len - 3] = '.';
  112. }
  113. if(w > dc.w)
  114. return; /* too long */
  115. gcv.foreground = col[ColFG];
  116. if(dc.font.set) {
  117. XChangeGC(dpy, dc.gc, GCForeground, &gcv);
  118. XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
  119. }
  120. else {
  121. gcv.font = dc.font.xfont->fid;
  122. XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv);
  123. XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
  124. }
  125. }
  126. unsigned int
  127. textw(const char *text) {
  128. return textnw(text, strlen(text)) + dc.font.height;
  129. }