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.

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