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.

279 lines
4.9 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. resize(c, c->x, c->y, c->w, c->h, True);
  49. }
  50. else {
  51. c->isbanned = True;
  52. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  53. }
  54. }
  55. if(!sel || !isvisible(sel)) {
  56. for(c = stack; c && !isvisible(c); c = c->snext);
  57. focus(c);
  58. }
  59. restack();
  60. }
  61. void
  62. dotile(void) {
  63. unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
  64. Client *c;
  65. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  66. n++;
  67. /* window geoms */
  68. mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
  69. mw = (n > nmaster) ? (waw * master) / 1000 : waw;
  70. th = (n > nmaster) ? wah / (n - nmaster) : 0;
  71. tw = waw - mw;
  72. for(i = 0, c = clients; c; c = c->next)
  73. if(isvisible(c)) {
  74. if(c->isbanned)
  75. XMoveWindow(dpy, c->win, c->x, c->y);
  76. c->isbanned = False;
  77. if(c->isfloat)
  78. continue;
  79. c->ismax = False;
  80. nx = wax;
  81. ny = way;
  82. if(i < nmaster) {
  83. ny += i * mh;
  84. nw = mw - 2 * BORDERPX;
  85. nh = mh - 2 * BORDERPX;
  86. }
  87. else { /* tile window */
  88. nx += mw;
  89. nw = tw - 2 * BORDERPX;
  90. if(th > 2 * BORDERPX) {
  91. ny += (i - nmaster) * th;
  92. nh = th - 2 * BORDERPX;
  93. }
  94. else /* fallback if th <= 2 * BORDERPX */
  95. nh = wah - 2 * BORDERPX;
  96. }
  97. resize(c, nx, ny, nw, nh, False);
  98. i++;
  99. }
  100. else {
  101. c->isbanned = True;
  102. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  103. }
  104. if(!sel || !isvisible(sel)) {
  105. for(c = stack; c && !isvisible(c); c = c->snext);
  106. focus(c);
  107. }
  108. restack();
  109. }
  110. void
  111. focusnext(Arg *arg) {
  112. Client *c;
  113. if(!sel)
  114. return;
  115. for(c = sel->next; c && !isvisible(c); c = c->next);
  116. if(!c)
  117. for(c = clients; c && !isvisible(c); c = c->next);
  118. if(c) {
  119. focus(c);
  120. restack();
  121. }
  122. }
  123. void
  124. focusprev(Arg *arg) {
  125. Client *c;
  126. if(!sel)
  127. return;
  128. for(c = sel->prev; c && !isvisible(c); c = c->prev);
  129. if(!c) {
  130. for(c = clients; c && c->next; c = c->next);
  131. for(; c && !isvisible(c); c = c->prev);
  132. }
  133. if(c) {
  134. focus(c);
  135. restack();
  136. }
  137. }
  138. void
  139. incnmaster(Arg *arg) {
  140. if((arrange == dofloat) || (nmaster + arg->i < 1)
  141. || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
  142. return;
  143. nmaster += arg->i;
  144. if(sel)
  145. arrange();
  146. else
  147. drawstatus();
  148. }
  149. Bool
  150. isvisible(Client *c) {
  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. resizemaster(Arg *arg) {
  159. if(arrange != dotile)
  160. return;
  161. if(arg->i == 0)
  162. master = MASTER;
  163. else {
  164. if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
  165. || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
  166. return;
  167. master += arg->i;
  168. }
  169. arrange();
  170. }
  171. void
  172. restack(void) {
  173. Client *c;
  174. XEvent ev;
  175. drawstatus();
  176. if(!sel)
  177. return;
  178. if(sel->isfloat || arrange == dofloat)
  179. XRaiseWindow(dpy, sel->win);
  180. if(arrange != dofloat) {
  181. if(!sel->isfloat)
  182. XLowerWindow(dpy, sel->win);
  183. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  184. if(c == sel)
  185. continue;
  186. XLowerWindow(dpy, c->win);
  187. }
  188. }
  189. XSync(dpy, False);
  190. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  191. }
  192. void
  193. togglefloat(Arg *arg) {
  194. if(!sel || arrange == dofloat)
  195. return;
  196. sel->isfloat = !sel->isfloat;
  197. arrange();
  198. }
  199. void
  200. togglemode(Arg *arg) {
  201. arrange = (arrange == dofloat) ? dotile : dofloat;
  202. if(sel)
  203. arrange();
  204. else
  205. drawstatus();
  206. }
  207. void
  208. toggleview(Arg *arg) {
  209. unsigned int i;
  210. seltag[arg->i] = !seltag[arg->i];
  211. for(i = 0; i < ntags && !seltag[i]; i++);
  212. if(i == ntags)
  213. seltag[arg->i] = True; /* cannot toggle last view */
  214. arrange();
  215. }
  216. void
  217. view(Arg *arg) {
  218. unsigned int i;
  219. for(i = 0; i < ntags; i++)
  220. seltag[i] = (arg->i == -1) ? True : False;
  221. if(arg->i >= 0 && arg->i < ntags)
  222. seltag[arg->i] = True;
  223. arrange();
  224. }
  225. void
  226. zoom(Arg *arg) {
  227. unsigned int n;
  228. Client *c;
  229. if(!sel)
  230. return;
  231. if(sel->isfloat || (arrange == dofloat)) {
  232. togglemax(sel);
  233. return;
  234. }
  235. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  236. n++;
  237. if((c = sel) == nexttiled(clients))
  238. if(!(c = nexttiled(c->next)))
  239. return;
  240. detach(c);
  241. if(clients)
  242. clients->prev = c;
  243. c->next = clients;
  244. clients = c;
  245. focus(c);
  246. arrange();
  247. }