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.

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