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.

277 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(arg->i == 0)
  160. master = MASTER;
  161. else {
  162. if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
  163. || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
  164. return;
  165. master += arg->i;
  166. }
  167. arrange();
  168. }
  169. void
  170. restack(void) {
  171. Client *c;
  172. XEvent ev;
  173. drawstatus();
  174. if(!sel)
  175. return;
  176. if(sel->isfloat || arrange == dofloat)
  177. XRaiseWindow(dpy, sel->win);
  178. if(arrange != dofloat) {
  179. if(!sel->isfloat)
  180. XLowerWindow(dpy, sel->win);
  181. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  182. if(c == sel)
  183. continue;
  184. XLowerWindow(dpy, c->win);
  185. }
  186. }
  187. XSync(dpy, False);
  188. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  189. }
  190. void
  191. togglefloat(Arg *arg) {
  192. if(!sel || arrange == dofloat)
  193. return;
  194. sel->isfloat = !sel->isfloat;
  195. arrange();
  196. }
  197. void
  198. togglemode(Arg *arg) {
  199. arrange = (arrange == dofloat) ? dotile : dofloat;
  200. if(sel)
  201. arrange();
  202. else
  203. drawstatus();
  204. }
  205. void
  206. toggleview(Arg *arg) {
  207. unsigned int i;
  208. seltag[arg->i] = !seltag[arg->i];
  209. for(i = 0; i < ntags && !seltag[i]; i++);
  210. if(i == ntags)
  211. seltag[arg->i] = True; /* cannot toggle last view */
  212. arrange();
  213. }
  214. void
  215. view(Arg *arg) {
  216. unsigned int i;
  217. for(i = 0; i < ntags; i++)
  218. seltag[i] = (arg->i == -1) ? True : False;
  219. if(arg->i >= 0 && arg->i < ntags)
  220. seltag[arg->i] = True;
  221. arrange();
  222. }
  223. void
  224. zoom(Arg *arg) {
  225. unsigned int n;
  226. Client *c;
  227. if(!sel)
  228. return;
  229. if(sel->isfloat || (arrange == dofloat)) {
  230. togglemax(sel);
  231. return;
  232. }
  233. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  234. n++;
  235. if((c = sel) == nexttiled(clients))
  236. if(!(c = nexttiled(c->next)))
  237. return;
  238. detach(c);
  239. if(clients)
  240. clients->prev = c;
  241. c->next = clients;
  242. clients = c;
  243. focus(c);
  244. arrange();
  245. }