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.

220 lines
3.5 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 <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. char *tags[TLast];
  15. Bool isfloat;
  16. } Rule;
  17. /* CUSTOMIZE */
  18. static Rule rule[] = {
  19. /* class instance tags isfloat */
  20. { "Firefox.*", { [Twww] = "www" }, False },
  21. { "Gimp.*", { 0 }, True},
  22. };
  23. /* extern */
  24. /* CUSTOMIZE */
  25. char *tags[TLast] = {
  26. [Tscratch] = "scratch",
  27. [Tdev] = "dev",
  28. [Twww] = "www",
  29. [Twork] = "work",
  30. };
  31. void (*arrange)(Arg *) = dotile;
  32. void
  33. appendtag(Arg *arg)
  34. {
  35. if(!sel)
  36. return;
  37. sel->tags[arg->i] = tags[arg->i];
  38. arrange(NULL);
  39. }
  40. void
  41. dofloat(Arg *arg)
  42. {
  43. Client *c;
  44. arrange = dofloat;
  45. for(c = clients; c; c = c->next) {
  46. if(c->tags[tsel]) {
  47. resize(c, True, TopLeft);
  48. }
  49. else
  50. ban(c);
  51. }
  52. if(sel && !sel->tags[tsel]) {
  53. if((sel = getnext(clients, tsel))) {
  54. higher(sel);
  55. focus(sel);
  56. }
  57. }
  58. drawall();
  59. }
  60. void
  61. dotile(Arg *arg)
  62. {
  63. Client *c;
  64. int n, i, w, h;
  65. w = sw - mw;
  66. arrange = dotile;
  67. for(n = 0, c = clients; c; c = c->next)
  68. if(c->tags[tsel] && !c->isfloat)
  69. n++;
  70. if(n > 1)
  71. h = (sh - bh) / (n - 1);
  72. else
  73. h = sh - bh;
  74. for(i = 0, c = clients; c; c = c->next) {
  75. if(c->tags[tsel]) {
  76. if(c->isfloat) {
  77. higher(c);
  78. resize(c, True, TopLeft);
  79. continue;
  80. }
  81. if(n == 1) {
  82. c->x = sx;
  83. c->y = sy + bh;
  84. c->w = sw - 2 * c->border;
  85. c->h = sh - 2 * c->border - bh;
  86. }
  87. else if(i == 0) {
  88. c->x = sx;
  89. c->y = sy + bh;
  90. c->w = mw - 2 * c->border;
  91. c->h = sh - 2 * c->border - bh;
  92. }
  93. else if(h > bh) {
  94. c->x = sx + mw;
  95. c->y = sy + (i - 1) * h + bh;
  96. c->w = w - 2 * c->border;
  97. c->h = h - 2 * c->border;
  98. }
  99. else { /* fallback if h < bh */
  100. c->x = sx + mw;
  101. c->y = sy + bh;
  102. c->w = w - 2 * c->border;
  103. c->h = sh - 2 * c->border - bh;
  104. }
  105. resize(c, False, TopLeft);
  106. i++;
  107. }
  108. else
  109. ban(c);
  110. }
  111. if(!sel || (sel && !sel->tags[tsel])) {
  112. if((sel = getnext(clients, tsel))) {
  113. higher(sel);
  114. focus(sel);
  115. }
  116. }
  117. drawall();
  118. }
  119. Client *
  120. getnext(Client *c, unsigned int t)
  121. {
  122. for(; c && !c->tags[t]; c = c->next);
  123. return c;
  124. }
  125. void
  126. heretag(Arg *arg)
  127. {
  128. int i;
  129. Client *c;
  130. if(arg->i == tsel)
  131. return;
  132. if(!(c = getnext(clients, arg->i)))
  133. return;
  134. for(i = 0; i < TLast; i++)
  135. c->tags[i] = NULL;
  136. c->tags[tsel] = tags[tsel];
  137. pop(c);
  138. focus(c);
  139. }
  140. void
  141. replacetag(Arg *arg)
  142. {
  143. int i;
  144. if(!sel)
  145. return;
  146. for(i = 0; i < TLast; i++)
  147. sel->tags[i] = NULL;
  148. appendtag(arg);
  149. }
  150. void
  151. settags(Client *c)
  152. {
  153. char classinst[256];
  154. static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
  155. unsigned int i, j;
  156. regex_t regex;
  157. regmatch_t tmp;
  158. Bool matched = False;
  159. XClassHint ch;
  160. if(!len) {
  161. c->tags[tsel] = tags[tsel];
  162. return;
  163. }
  164. if(XGetClassHint(dpy, c->win, &ch)) {
  165. snprintf(classinst, sizeof(classinst), "%s:%s",
  166. ch.res_class ? ch.res_class : "",
  167. ch.res_name ? ch.res_name : "");
  168. for(i = 0; !matched && i < len; i++) {
  169. if(!regcomp(&regex, rule[i].pattern, 0)) {
  170. if(!regexec(&regex, classinst, 1, &tmp, 0)) {
  171. for(j = 0; j < TLast; j++) {
  172. if(rule[i].tags[j])
  173. matched = True;
  174. c->tags[j] = rule[i].tags[j];
  175. }
  176. c->isfloat = rule[i].isfloat;
  177. }
  178. regfree(&regex);
  179. }
  180. }
  181. if(ch.res_class)
  182. XFree(ch.res_class);
  183. if(ch.res_name)
  184. XFree(ch.res_name);
  185. }
  186. if(!matched)
  187. c->tags[tsel] = tags[tsel];
  188. }
  189. void
  190. view(Arg *arg)
  191. {
  192. tsel = arg->i;
  193. arrange(NULL);
  194. drawall();
  195. }