Configuration file for DWM on MacBook Air
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.

300 lines
4.3 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 <stdio.h>
  7. /* static */
  8. static Client *
  9. minclient()
  10. {
  11. Client *c, *min;
  12. for(min = c = clients; c; c = c->next)
  13. if(c->weight < min->weight)
  14. min = c;
  15. return min;
  16. }
  17. static void
  18. reorder()
  19. {
  20. Client *c, *newclients, *tail;
  21. newclients = tail = NULL;
  22. while((c = minclient())) {
  23. detach(c);
  24. if(tail) {
  25. c->prev = tail;
  26. tail->next = c;
  27. tail = c;
  28. }
  29. else
  30. tail = newclients = c;
  31. }
  32. clients = newclients;
  33. }
  34. /* extern */
  35. void (*arrange)(Arg *) = DEFMODE;
  36. void
  37. detach(Client *c)
  38. {
  39. if(c->prev)
  40. c->prev->next = c->next;
  41. if(c->next)
  42. c->next->prev = c->prev;
  43. if(c == clients)
  44. clients = c->next;
  45. c->next = c->prev = NULL;
  46. }
  47. void
  48. dofloat(Arg *arg)
  49. {
  50. Client *c, *fc;
  51. maximized = False;
  52. for(c = clients; c; c = c->next) {
  53. if(isvisible(c)) {
  54. resize(c, True, TopLeft);
  55. }
  56. else
  57. ban(c);
  58. }
  59. if(!(fc = sel) || !isvisible(fc))
  60. fc = getnext(clients);
  61. focus(fc);
  62. restack();
  63. }
  64. void
  65. dotile(Arg *arg)
  66. {
  67. int h, i, n, w;
  68. Client *c, *fc;
  69. maximized = False;
  70. w = sw - mw;
  71. for(n = 0, c = clients; c; c = c->next)
  72. if(isvisible(c) && !c->isfloat)
  73. n++;
  74. if(n > 1)
  75. h = (sh - bh) / (n - 1);
  76. else
  77. h = sh - bh;
  78. for(i = 0, c = clients; c; c = c->next) {
  79. if(isvisible(c)) {
  80. if(c->isfloat) {
  81. resize(c, True, TopLeft);
  82. continue;
  83. }
  84. if(n == 1) {
  85. c->x = sx;
  86. c->y = sy + bh;
  87. c->w = sw - 2;
  88. c->h = sh - 2 - bh;
  89. }
  90. else if(i == 0) {
  91. c->x = sx;
  92. c->y = sy + bh;
  93. c->w = mw - 2;
  94. c->h = sh - 2 - bh;
  95. }
  96. else if(h > bh) {
  97. c->x = sx + mw;
  98. c->y = sy + (i - 1) * h + bh;
  99. c->w = w - 2;
  100. if(i + 1 == n)
  101. c->h = sh - c->y - 2;
  102. else
  103. c->h = h - 2;
  104. }
  105. else { /* fallback if h < bh */
  106. c->x = sx + mw;
  107. c->y = sy + bh;
  108. c->w = w - 2;
  109. c->h = sh - 2 - bh;
  110. }
  111. resize(c, False, TopLeft);
  112. i++;
  113. }
  114. else
  115. ban(c);
  116. }
  117. if(!(fc = sel) || !isvisible(fc))
  118. fc = getnext(clients);
  119. focus(fc);
  120. restack();
  121. }
  122. void
  123. focusnext(Arg *arg)
  124. {
  125. Client *c;
  126. if(!sel)
  127. return;
  128. if(!(c = getnext(sel->next)))
  129. c = getnext(clients);
  130. if(c) {
  131. focus(c);
  132. restack();
  133. }
  134. }
  135. void
  136. focusprev(Arg *arg)
  137. {
  138. Client *c;
  139. if(!sel)
  140. return;
  141. if(!(c = getprev(sel->prev))) {
  142. for(c = clients; c && c->next; c = c->next);
  143. c = getprev(c);
  144. }
  145. if(c) {
  146. focus(c);
  147. restack();
  148. }
  149. }
  150. Bool
  151. isvisible(Client *c)
  152. {
  153. unsigned int i;
  154. for(i = 0; i < ntags; i++)
  155. if(c->tags[i] && seltag[i])
  156. return True;
  157. return False;
  158. }
  159. void
  160. restack()
  161. {
  162. static unsigned int nwins = 0;
  163. static Window *wins = NULL;
  164. unsigned int f, fi, m, mi, n;
  165. Client *c;
  166. XEvent ev;
  167. for(f = 0, m = 0, c = clients; c; c = c->next)
  168. if(isvisible(c)) {
  169. if(c->isfloat || arrange == dofloat)
  170. f++;
  171. else
  172. m++;
  173. }
  174. if(!(n = 2 * (f + m))) {
  175. drawstatus();
  176. return;
  177. }
  178. if(nwins < n) {
  179. nwins = n;
  180. wins = erealloc(wins, nwins * sizeof(Window));
  181. }
  182. fi = 0;
  183. mi = 2 * f;
  184. if(sel->isfloat || arrange == dofloat) {
  185. wins[fi++] = sel->twin;
  186. wins[fi++] = sel->win;
  187. }
  188. else {
  189. wins[mi++] = sel->twin;
  190. wins[mi++] = sel->win;
  191. }
  192. for(c = clients; c; c = c->next)
  193. if(isvisible(c) && c != sel) {
  194. if(c->isfloat || arrange == dofloat) {
  195. wins[fi++] = c->twin;
  196. wins[fi++] = c->win;
  197. }
  198. else {
  199. wins[mi++] = c->twin;
  200. wins[mi++] = c->win;
  201. }
  202. }
  203. XRestackWindows(dpy, wins, n);
  204. drawall();
  205. XSync(dpy, False);
  206. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  207. }
  208. void
  209. togglemode(Arg *arg)
  210. {
  211. arrange = (arrange == dofloat) ? dotile : dofloat;
  212. if(sel)
  213. arrange(NULL);
  214. else
  215. drawstatus();
  216. }
  217. void
  218. toggleview(Arg *arg)
  219. {
  220. unsigned int i;
  221. seltag[arg->i] = !seltag[arg->i];
  222. for(i = 0; i < ntags && !seltag[i]; i++);
  223. if(i == ntags)
  224. seltag[arg->i] = True; /* cannot toggle last view */
  225. reorder();
  226. arrange(NULL);
  227. }
  228. void
  229. view(Arg *arg)
  230. {
  231. unsigned int i;
  232. for(i = 0; i < ntags; i++)
  233. seltag[i] = False;
  234. seltag[arg->i] = True;
  235. reorder();
  236. arrange(NULL);
  237. }
  238. void
  239. viewall(Arg *arg)
  240. {
  241. unsigned int i;
  242. for(i = 0; i < ntags; i++)
  243. seltag[i] = True;
  244. reorder();
  245. arrange(NULL);
  246. }
  247. void
  248. zoom(Arg *arg)
  249. {
  250. Client *c = sel;
  251. if(!c || (arrange != dotile) || c->isfloat || maximized)
  252. return;
  253. if(c == getnext(clients))
  254. if(!(c = getnext(c->next)))
  255. return;
  256. detach(c);
  257. c->next = clients;
  258. clients->prev = c;
  259. clients = c;
  260. focus(c);
  261. arrange(NULL);
  262. }