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.

139 lines
3.1 KiB

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