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.

179 lines
2.8 KiB

  1. /*
  2. * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
  3. * See LICENSE file for license details.
  4. */
  5. #include "dwm.h"
  6. #include <string.h>
  7. #include <X11/Xutil.h>
  8. /********** CUSTOMIZE **********/
  9. char *tags[TLast] = {
  10. [Tscratch] = "scratch",
  11. [Tdev] = "dev",
  12. [Twww] = "www",
  13. [Twork] = "work",
  14. };
  15. static Rule rule[] = {
  16. /* class instance tags dofloat */
  17. { "Firefox-bin", "Gecko", { [Twww] = "www" }, False },
  18. };
  19. /********** CUSTOMIZE **********/
  20. /* extern functions */
  21. void (*arrange)(Arg *) = dotile;
  22. void
  23. appendtag(Arg *arg)
  24. {
  25. if(!sel)
  26. return;
  27. sel->tags[arg->i] = tags[arg->i];
  28. arrange(NULL);
  29. }
  30. void
  31. dofloat(Arg *arg)
  32. {
  33. Client *c;
  34. arrange = dofloat;
  35. for(c = clients; c; c = c->next) {
  36. if(c->tags[tsel])
  37. resize(c, True);
  38. else
  39. ban(c);
  40. }
  41. if(sel && !sel->tags[tsel]) {
  42. if((sel = getnext(clients))) {
  43. higher(sel);
  44. focus(sel);
  45. }
  46. }
  47. drawall();
  48. }
  49. void
  50. dotile(Arg *arg)
  51. {
  52. Client *c;
  53. int n, i, w, h;
  54. w = sw - mw;
  55. arrange = dotile;
  56. for(n = 0, c = clients; c; c = c->next)
  57. if(c->tags[tsel] && !c->dofloat)
  58. n++;
  59. if(n > 1)
  60. h = (sh - bh) / (n - 1);
  61. else
  62. h = sh - bh;
  63. for(i = 0, c = clients; c; c = c->next) {
  64. if(c->tags[tsel]) {
  65. if(c->dofloat) {
  66. higher(c);
  67. resize(c, True);
  68. continue;
  69. }
  70. if(n == 1) {
  71. c->x = sx;
  72. c->y = sy + bh;
  73. c->w = sw - 2 * c->border;
  74. c->h = sh - 2 * c->border - bh;
  75. }
  76. else if(i == 0) {
  77. c->x = sx;
  78. c->y = sy + bh;
  79. c->w = mw - 2 * c->border;
  80. c->h = sh - 2 * c->border - bh;
  81. }
  82. else {
  83. c->x = sx + mw;
  84. c->y = sy + (i - 1) * h + bh;
  85. c->w = w - 2 * c->border;
  86. c->h = h - 2 * c->border;
  87. }
  88. resize(c, False);
  89. i++;
  90. }
  91. else
  92. ban(c);
  93. }
  94. if(!sel || (sel && !sel->tags[tsel])) {
  95. if((sel = getnext(clients))) {
  96. higher(sel);
  97. focus(sel);
  98. }
  99. }
  100. drawall();
  101. }
  102. Client *
  103. getnext(Client *c)
  104. {
  105. for(; c && !c->tags[tsel]; c = c->next);
  106. return c;
  107. }
  108. void
  109. replacetag(Arg *arg)
  110. {
  111. int i;
  112. if(!sel)
  113. return;
  114. for(i = 0; i < TLast; i++)
  115. sel->tags[i] = NULL;
  116. appendtag(arg);
  117. }
  118. void
  119. settags(Client *c)
  120. {
  121. XClassHint ch;
  122. static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
  123. unsigned int i, j;
  124. Bool matched = False;
  125. if(!len) {
  126. c->tags[tsel] = tags[tsel];
  127. return;
  128. }
  129. if(XGetClassHint(dpy, c->win, &ch)) {
  130. if(ch.res_class && ch.res_name) {
  131. for(i = 0; i < len; i++)
  132. if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
  133. && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
  134. {
  135. for(j = 0; j < TLast; j++)
  136. c->tags[j] = rule[i].tags[j];
  137. c->dofloat = rule[i].dofloat;
  138. matched = True;
  139. break;
  140. }
  141. }
  142. if(ch.res_class)
  143. XFree(ch.res_class);
  144. if(ch.res_name)
  145. XFree(ch.res_name);
  146. }
  147. if(!matched)
  148. c->tags[tsel] = tags[tsel];
  149. }
  150. void
  151. view(Arg *arg)
  152. {
  153. tsel = arg->i;
  154. arrange(NULL);
  155. drawall();
  156. }