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.

276 lines
4.8 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
  2. * See LICENSE file for license details.
  3. */
  4. #include "dwm.h"
  5. #include <stdio.h>
  6. /* static */
  7. static Client *
  8. nexttiled(Client *c) {
  9. for(; c && (c->isfloat || !isvisible(c)); c = c->next);
  10. return c;
  11. }
  12. static void
  13. togglemax(Client *c) {
  14. XEvent ev;
  15. if(c->isfixed)
  16. return;
  17. if((c->ismax = !c->ismax)) {
  18. c->rx = c->x;
  19. c->ry = c->y;
  20. c->rw = c->w;
  21. c->rh = c->h;
  22. resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
  23. }
  24. else
  25. resize(c, c->rx, c->ry, c->rw, c->rh, True);
  26. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  27. }
  28. /* extern */
  29. void (*arrange)(void) = DEFMODE;
  30. void
  31. detach(Client *c) {
  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(void) {
  42. Client *c;
  43. for(c = clients; c; c = c->next) {
  44. if(isvisible(c)) {
  45. if(c->isbanned)
  46. XMoveWindow(dpy, c->win, c->x, c->y);
  47. c->isbanned = False;
  48. }
  49. else {
  50. c->isbanned = True;
  51. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  52. }
  53. }
  54. if(!sel || !isvisible(sel)) {
  55. for(c = stack; c && !isvisible(c); c = c->snext);
  56. focus(c);
  57. }
  58. restack();
  59. }
  60. void
  61. dotile(void) {
  62. unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
  63. Client *c;
  64. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  65. n++;
  66. /* window geoms */
  67. mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
  68. mw = (n > nmaster) ? (waw * master) / 1000 : waw;
  69. th = (n > nmaster) ? wah / (n - nmaster) : 0;
  70. tw = waw - mw;
  71. for(i = 0, c = clients; c; c = c->next)
  72. if(isvisible(c)) {
  73. if(c->isbanned)
  74. XMoveWindow(dpy, c->win, c->x, c->y);
  75. c->isbanned = False;
  76. if(c->isfloat)
  77. continue;
  78. c->ismax = False;
  79. nx = wax;
  80. ny = way;
  81. if(i < nmaster) {
  82. ny += i * mh;
  83. nw = mw - 2 * BORDERPX;
  84. nh = mh - 2 * BORDERPX;
  85. }
  86. else { /* tile window */
  87. nx += mw;
  88. nw = tw - 2 * BORDERPX;
  89. if(th > 2 * BORDERPX) {
  90. ny += (i - nmaster) * th;
  91. nh = th - 2 * BORDERPX;
  92. }
  93. else /* fallback if th <= 2 * BORDERPX */
  94. nh = wah - 2 * BORDERPX;
  95. }
  96. resize(c, nx, ny, nw, nh, False);
  97. i++;
  98. }
  99. else {
  100. c->isbanned = True;
  101. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  102. }
  103. if(!sel || !isvisible(sel)) {
  104. for(c = stack; c && !isvisible(c); c = c->snext);
  105. focus(c);
  106. }
  107. restack();
  108. }
  109. void
  110. focusnext(Arg *arg) {
  111. Client *c;
  112. if(!sel)
  113. return;
  114. for(c = sel->next; c && !isvisible(c); c = c->next);
  115. if(!c)
  116. for(c = clients; c && !isvisible(c); c = c->next);
  117. if(c) {
  118. focus(c);
  119. restack();
  120. }
  121. }
  122. void
  123. focusprev(Arg *arg) {
  124. Client *c;
  125. if(!sel)
  126. return;
  127. for(c = sel->prev; c && !isvisible(c); c = c->prev);
  128. if(!c) {
  129. for(c = clients; c && c->next; c = c->next);
  130. for(; c && !isvisible(c); c = c->prev);
  131. }
  132. if(c) {
  133. focus(c);
  134. restack();
  135. }
  136. }
  137. void
  138. incnmaster(Arg *arg) {
  139. if((arrange == dofloat) || (nmaster + arg->i < 1)
  140. || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
  141. return;
  142. nmaster += arg->i;
  143. if(sel)
  144. arrange();
  145. else
  146. drawstatus();
  147. }
  148. Bool
  149. isvisible(Client *c) {
  150. unsigned int i;
  151. for(i = 0; i < ntags; i++)
  152. if(c->tags[i] && seltag[i])
  153. return True;
  154. return False;
  155. }
  156. void
  157. resizemaster(Arg *arg) {
  158. if(arg->i == 0)
  159. master = MASTER;
  160. else {
  161. if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
  162. || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
  163. return;
  164. master += arg->i;
  165. }
  166. arrange();
  167. }
  168. void
  169. restack(void) {
  170. Client *c;
  171. XEvent ev;
  172. drawstatus();
  173. if(!sel)
  174. return;
  175. if(sel->isfloat || arrange == dofloat)
  176. XRaiseWindow(dpy, sel->win);
  177. if(arrange != dofloat) {
  178. if(!sel->isfloat)
  179. XLowerWindow(dpy, sel->win);
  180. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  181. if(c == sel)
  182. continue;
  183. XLowerWindow(dpy, c->win);
  184. }
  185. }
  186. XSync(dpy, False);
  187. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  188. }
  189. void
  190. togglefloat(Arg *arg) {
  191. if(!sel || arrange == dofloat)
  192. return;
  193. sel->isfloat = !sel->isfloat;
  194. arrange();
  195. }
  196. void
  197. togglemode(Arg *arg) {
  198. arrange = (arrange == dofloat) ? dotile : dofloat;
  199. if(sel)
  200. arrange();
  201. else
  202. drawstatus();
  203. }
  204. void
  205. toggleview(Arg *arg) {
  206. unsigned int i;
  207. seltag[arg->i] = !seltag[arg->i];
  208. for(i = 0; i < ntags && !seltag[i]; i++);
  209. if(i == ntags)
  210. seltag[arg->i] = True; /* cannot toggle last view */
  211. arrange();
  212. }
  213. void
  214. view(Arg *arg) {
  215. unsigned int i;
  216. for(i = 0; i < ntags; i++)
  217. seltag[i] = (arg->i == -1) ? True : False;
  218. if(arg->i >= 0 && arg->i < ntags)
  219. seltag[arg->i] = True;
  220. arrange();
  221. }
  222. void
  223. zoom(Arg *arg) {
  224. unsigned int n;
  225. Client *c;
  226. if(!sel)
  227. return;
  228. if(sel->isfloat || (arrange == dofloat)) {
  229. togglemax(sel);
  230. return;
  231. }
  232. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  233. n++;
  234. if((c = sel) == nexttiled(clients))
  235. if(!(c = nexttiled(c->next)))
  236. return;
  237. detach(c);
  238. if(clients)
  239. clients->prev = c;
  240. c->next = clients;
  241. clients = c;
  242. focus(c);
  243. arrange();
  244. }