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.

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