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.

270 lines
4.6 KiB

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