Configuration of dwm for Mac Computers
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.

171 lines
2.7 KiB

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