Configuration of dwm for Mac Computers
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.

138 lines
3.0 KiB

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