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.

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