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.

214 lines
3.4 KiB

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