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.

200 lines
3.1 KiB

18 years ago
  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", "firefox-bin", { [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. setgeom(c);
  38. if(c->tags[tsel]) {
  39. resize(c, True, TopLeft);
  40. }
  41. else
  42. ban(c);
  43. }
  44. if(sel && !sel->tags[tsel]) {
  45. if((sel = getnext(clients, tsel))) {
  46. higher(sel);
  47. focus(sel);
  48. }
  49. }
  50. drawall();
  51. }
  52. void
  53. dotile(Arg *arg)
  54. {
  55. Client *c;
  56. int n, i, w, h;
  57. w = sw - mw;
  58. arrange = dotile;
  59. for(n = 0, c = clients; c; c = c->next)
  60. if(c->tags[tsel] && !c->isfloat)
  61. n++;
  62. if(n > 1)
  63. h = (sh - bh) / (n - 1);
  64. else
  65. h = sh - bh;
  66. for(i = 0, c = clients; c; c = c->next) {
  67. setgeom(c);
  68. if(c->tags[tsel]) {
  69. if(c->isfloat) {
  70. higher(c);
  71. resize(c, True, TopLeft);
  72. continue;
  73. }
  74. if(n == 1) {
  75. *c->x = sx;
  76. *c->y = sy + bh;
  77. *c->w = sw - 2 * c->border;
  78. *c->h = sh - 2 * c->border - bh;
  79. }
  80. else if(i == 0) {
  81. *c->x = sx;
  82. *c->y = sy + bh;
  83. *c->w = mw - 2 * c->border;
  84. *c->h = sh - 2 * c->border - bh;
  85. }
  86. else {
  87. *c->x = sx + mw;
  88. *c->y = sy + (i - 1) * h + bh;
  89. *c->w = w - 2 * c->border;
  90. *c->h = h - 2 * c->border;
  91. }
  92. resize(c, False, TopLeft);
  93. i++;
  94. }
  95. else
  96. ban(c);
  97. }
  98. if(!sel || (sel && !sel->tags[tsel])) {
  99. if((sel = getnext(clients, tsel))) {
  100. higher(sel);
  101. focus(sel);
  102. }
  103. }
  104. drawall();
  105. }
  106. Client *
  107. getnext(Client *c, unsigned int t)
  108. {
  109. for(; c && !c->tags[t]; c = c->next);
  110. return c;
  111. }
  112. void
  113. heretag(Arg *arg)
  114. {
  115. int i;
  116. Client *c;
  117. if(arg->i == tsel)
  118. return;
  119. if(!(c = getnext(clients, arg->i)))
  120. return;
  121. for(i = 0; i < TLast; i++)
  122. c->tags[i] = NULL;
  123. c->tags[tsel] = tags[tsel];
  124. pop(c);
  125. focus(c);
  126. }
  127. void
  128. replacetag(Arg *arg)
  129. {
  130. int i;
  131. if(!sel)
  132. return;
  133. for(i = 0; i < TLast; i++)
  134. sel->tags[i] = NULL;
  135. appendtag(arg);
  136. }
  137. void
  138. settags(Client *c)
  139. {
  140. XClassHint ch;
  141. static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
  142. unsigned int i, j;
  143. Bool matched = False;
  144. if(!len) {
  145. c->tags[tsel] = tags[tsel];
  146. return;
  147. }
  148. if(XGetClassHint(dpy, c->win, &ch)) {
  149. if(ch.res_class && ch.res_name) {
  150. for(i = 0; i < len; i++)
  151. if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
  152. && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
  153. {
  154. for(j = 0; j < TLast; j++)
  155. c->tags[j] = rule[i].tags[j];
  156. c->isfloat = rule[i].isfloat;
  157. matched = True;
  158. break;
  159. }
  160. }
  161. if(ch.res_class)
  162. XFree(ch.res_class);
  163. if(ch.res_name)
  164. XFree(ch.res_name);
  165. }
  166. if(!matched)
  167. c->tags[tsel] = tags[tsel];
  168. }
  169. void
  170. view(Arg *arg)
  171. {
  172. tsel = arg->i;
  173. arrange(NULL);
  174. drawall();
  175. }