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.

336 lines
4.9 KiB

18 years ago
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. 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. static unsigned int nwins = 0;
  189. static Window *wins = NULL;
  190. unsigned int f, fi, m, mi, n;
  191. Client *c;
  192. XEvent ev;
  193. for(f = 0, m = 0, c = clients; c; c = c->next)
  194. if(isvisible(c)) {
  195. if(c->isfloat || arrange == dofloat)
  196. f++;
  197. else
  198. m++;
  199. }
  200. if(!(n = 2 * (f + m))) {
  201. drawstatus();
  202. return;
  203. }
  204. if(nwins < n) {
  205. nwins = n;
  206. wins = erealloc(wins, nwins * sizeof(Window));
  207. }
  208. fi = 0;
  209. mi = 2 * f;
  210. if(sel) {
  211. if(sel->isfloat || arrange == dofloat) {
  212. wins[fi++] = sel->twin;
  213. wins[fi++] = sel->win;
  214. }
  215. else {
  216. wins[mi++] = sel->twin;
  217. wins[mi++] = sel->win;
  218. }
  219. }
  220. for(c = clients; c; c = c->next)
  221. if(isvisible(c) && c != sel) {
  222. if(c->isfloat || arrange == dofloat) {
  223. wins[fi++] = c->twin;
  224. wins[fi++] = c->win;
  225. }
  226. else {
  227. wins[mi++] = c->twin;
  228. wins[mi++] = c->win;
  229. }
  230. }
  231. XRestackWindows(dpy, wins, n);
  232. drawall();
  233. XSync(dpy, False);
  234. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  235. }
  236. void
  237. togglemode(Arg *arg)
  238. {
  239. arrange = (arrange == dofloat) ? dotile : dofloat;
  240. if(sel)
  241. arrange(NULL);
  242. else
  243. drawstatus();
  244. }
  245. void
  246. toggleview(Arg *arg)
  247. {
  248. unsigned int i;
  249. seltag[arg->i] = !seltag[arg->i];
  250. for(i = 0; i < ntags && !seltag[i]; i++);
  251. if(i == ntags)
  252. seltag[arg->i] = True; /* cannot toggle last view */
  253. reorder();
  254. arrange(NULL);
  255. }
  256. void
  257. view(Arg *arg)
  258. {
  259. unsigned int i;
  260. for(i = 0; i < ntags; i++)
  261. seltag[i] = False;
  262. seltag[arg->i] = True;
  263. reorder();
  264. arrange(NULL);
  265. }
  266. void
  267. viewall(Arg *arg)
  268. {
  269. unsigned int i;
  270. for(i = 0; i < ntags; i++)
  271. seltag[i] = True;
  272. reorder();
  273. arrange(NULL);
  274. }
  275. void
  276. zoom(Arg *arg)
  277. {
  278. unsigned int n;
  279. Client *c;
  280. for(n = 0, c = clients; c; c = c->next)
  281. if(isvisible(c) && !c->isfloat)
  282. n++;
  283. if(!sel || sel->isfloat || n < 2 || (arrange != dotile) || maximized)
  284. return;
  285. if((c = sel) == nexttiled(clients))
  286. if(!(c = nexttiled(c->next)))
  287. return;
  288. detach(c);
  289. c->next = clients;
  290. clients->prev = c;
  291. clients = c;
  292. focus(c);
  293. arrange(NULL);
  294. }