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.

197 lines
3.0 KiB

19 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", "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, tsel))) {
  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, tsel))) {
  97. higher(sel);
  98. focus(sel);
  99. }
  100. }
  101. drawall();
  102. }
  103. Client *
  104. getnext(Client *c, unsigned int t)
  105. {
  106. for(; c && !c->tags[t]; c = c->next);
  107. return c;
  108. }
  109. void
  110. heretag(Arg *arg)
  111. {
  112. int i;
  113. Client *c;
  114. if(arg->i == tsel)
  115. return;
  116. if(!(c = getnext(clients, arg->i)))
  117. return;
  118. for(i = 0; i < TLast; i++)
  119. c->tags[i] = NULL;
  120. c->tags[tsel] = tags[tsel];
  121. pop(c);
  122. focus(c);
  123. }
  124. void
  125. replacetag(Arg *arg)
  126. {
  127. int i;
  128. if(!sel)
  129. return;
  130. for(i = 0; i < TLast; i++)
  131. sel->tags[i] = NULL;
  132. appendtag(arg);
  133. }
  134. void
  135. settags(Client *c)
  136. {
  137. XClassHint ch;
  138. static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
  139. unsigned int i, j;
  140. Bool matched = False;
  141. if(!len) {
  142. c->tags[tsel] = tags[tsel];
  143. return;
  144. }
  145. if(XGetClassHint(dpy, c->win, &ch)) {
  146. if(ch.res_class && ch.res_name) {
  147. for(i = 0; i < len; i++)
  148. if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
  149. && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
  150. {
  151. for(j = 0; j < TLast; j++)
  152. c->tags[j] = rule[i].tags[j];
  153. c->isfloat = rule[i].isfloat;
  154. matched = True;
  155. break;
  156. }
  157. }
  158. if(ch.res_class)
  159. XFree(ch.res_class);
  160. if(ch.res_name)
  161. XFree(ch.res_name);
  162. }
  163. if(!matched)
  164. c->tags[tsel] = tags[tsel];
  165. }
  166. void
  167. view(Arg *arg)
  168. {
  169. tsel = arg->i;
  170. arrange(NULL);
  171. drawall();
  172. }