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.

216 lines
3.3 KiB

18 years ago
18 years ago
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 <regex.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <sys/types.h>
  10. #include <X11/Xutil.h>
  11. /* static */
  12. typedef struct {
  13. const char *pattern;
  14. Bool tags[TLast];
  15. Bool isfloat;
  16. } Rule;
  17. TAGS
  18. RULES
  19. void (*arrange)(Arg *) = DEFMODE;
  20. /* extern */
  21. void
  22. appendtag(Arg *arg)
  23. {
  24. if(!sel)
  25. return;
  26. sel->tags[arg->i] = True;
  27. arrange(NULL);
  28. }
  29. void
  30. dofloat(Arg *arg)
  31. {
  32. Client *c;
  33. for(c = clients; c; c = c->next) {
  34. c->ismax = False;
  35. if(c->tags[tsel]) {
  36. resize(c, True, TopLeft);
  37. }
  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. else
  47. XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
  48. }
  49. drawall();
  50. }
  51. void
  52. dotile(Arg *arg)
  53. {
  54. int n, i, w, h;
  55. Client *c;
  56. w = sw - mw;
  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. c->ismax = False;
  66. if(c->tags[tsel]) {
  67. if(c->isfloat) {
  68. higher(c);
  69. resize(c, True, TopLeft);
  70. continue;
  71. }
  72. if(n == 1) {
  73. c->x = sx;
  74. c->y = sy + bh;
  75. c->w = sw - 2;
  76. c->h = sh - 2 - bh;
  77. }
  78. else if(i == 0) {
  79. c->x = sx;
  80. c->y = sy + bh;
  81. c->w = mw - 2;
  82. c->h = sh - 2 - bh;
  83. }
  84. else if(h > bh) {
  85. c->x = sx + mw;
  86. c->y = sy + (i - 1) * h + bh;
  87. c->w = w - 2;
  88. c->h = h - 2;
  89. }
  90. else { /* fallback if h < bh */
  91. c->x = sx + mw;
  92. c->y = sy + bh;
  93. c->w = w - 2;
  94. c->h = sh - 2 - bh;
  95. }
  96. resize(c, False, TopLeft);
  97. i++;
  98. }
  99. else
  100. ban(c);
  101. }
  102. if(!sel || (sel && !sel->tags[tsel])) {
  103. if((sel = getnext(clients))) {
  104. higher(sel);
  105. focus(sel);
  106. }
  107. else
  108. XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
  109. }
  110. drawall();
  111. }
  112. Client *
  113. getnext(Client *c)
  114. {
  115. for(; c && !c->tags[tsel]; c = c->next);
  116. return c;
  117. }
  118. Client *
  119. getprev(Client *c)
  120. {
  121. for(; c && !c->tags[tsel]; c = c->prev);
  122. return 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] = False;
  132. appendtag(arg);
  133. }
  134. void
  135. settags(Client *c)
  136. {
  137. char classinst[256];
  138. static unsigned int len = sizeof(rule) / sizeof(rule[0]);
  139. unsigned int i, j;
  140. regex_t regex;
  141. regmatch_t tmp;
  142. Bool matched = False;
  143. XClassHint ch;
  144. if(XGetClassHint(dpy, c->win, &ch)) {
  145. snprintf(classinst, sizeof(classinst), "%s:%s",
  146. ch.res_class ? ch.res_class : "",
  147. ch.res_name ? ch.res_name : "");
  148. for(i = 0; !matched && i < len; i++) {
  149. if(!regcomp(&regex, rule[i].pattern, 0)) {
  150. if(!regexec(&regex, classinst, 1, &tmp, 0)) {
  151. for(j = 0; j < TLast; j++) {
  152. if((c->tags[j] = rule[i].tags[j]))
  153. matched = True;
  154. }
  155. c->isfloat = rule[i].isfloat;
  156. }
  157. regfree(&regex);
  158. }
  159. }
  160. if(ch.res_class)
  161. XFree(ch.res_class);
  162. if(ch.res_name)
  163. XFree(ch.res_name);
  164. }
  165. if(!matched)
  166. c->tags[tsel] = True;
  167. }
  168. void
  169. togglemode(Arg *arg)
  170. {
  171. arrange = arrange == dofloat ? dotile : dofloat;
  172. arrange(NULL);
  173. }
  174. void
  175. view(Arg *arg)
  176. {
  177. tsel = arg->i;
  178. arrange(NULL);
  179. drawall();
  180. }
  181. void
  182. viewnext(Arg *arg)
  183. {
  184. arg->i = (tsel < TLast-1) ? tsel+1 : 0;
  185. view(arg);
  186. }
  187. void
  188. viewprev(Arg *arg)
  189. {
  190. arg->i = (tsel > 0) ? tsel-1 : TLast-1;
  191. view(arg);
  192. }