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.

215 lines
3.9 KiB

  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. unsigned int master = MASTER;
  6. unsigned int nmaster = NMASTER;
  7. unsigned int blw = 0;
  8. Layout *lt = NULL;
  9. /* static */
  10. static unsigned int nlayouts = 0;
  11. static void
  12. tile(void) {
  13. unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
  14. Client *c;
  15. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  16. n++;
  17. /* window geoms */
  18. mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
  19. mw = (n > nmaster) ? (waw * master) / 1000 : waw;
  20. th = (n > nmaster) ? wah / (n - nmaster) : 0;
  21. tw = waw - mw;
  22. for(i = 0, c = clients; c; c = c->next)
  23. if(isvisible(c)) {
  24. if(c->isbanned)
  25. XMoveWindow(dpy, c->win, c->x, c->y);
  26. c->isbanned = False;
  27. if(c->isversatile)
  28. continue;
  29. c->ismax = False;
  30. nx = wax;
  31. ny = way;
  32. if(i < nmaster) {
  33. ny += i * mh;
  34. nw = mw - 2 * BORDERPX;
  35. nh = mh - 2 * BORDERPX;
  36. }
  37. else { /* tile window */
  38. nx += mw;
  39. nw = tw - 2 * BORDERPX;
  40. if(th > 2 * BORDERPX) {
  41. ny += (i - nmaster) * th;
  42. nh = th - 2 * BORDERPX;
  43. }
  44. else /* fallback if th <= 2 * BORDERPX */
  45. nh = wah - 2 * BORDERPX;
  46. }
  47. resize(c, nx, ny, nw, nh, False);
  48. i++;
  49. }
  50. else {
  51. c->isbanned = True;
  52. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  53. }
  54. if(!sel || !isvisible(sel)) {
  55. for(c = stack; c && !isvisible(c); c = c->snext);
  56. focus(c);
  57. }
  58. restack();
  59. }
  60. LAYOUTS
  61. /* extern */
  62. void
  63. focusnext(Arg *arg) {
  64. Client *c;
  65. if(!sel)
  66. return;
  67. for(c = sel->next; c && !isvisible(c); c = c->next);
  68. if(!c)
  69. for(c = clients; c && !isvisible(c); c = c->next);
  70. if(c) {
  71. focus(c);
  72. restack();
  73. }
  74. }
  75. void
  76. focusprev(Arg *arg) {
  77. Client *c;
  78. if(!sel)
  79. return;
  80. for(c = sel->prev; c && !isvisible(c); c = c->prev);
  81. if(!c) {
  82. for(c = clients; c && c->next; c = c->next);
  83. for(; c && !isvisible(c); c = c->prev);
  84. }
  85. if(c) {
  86. focus(c);
  87. restack();
  88. }
  89. }
  90. void
  91. incnmaster(Arg *arg) {
  92. if((lt->arrange != tile) || (nmaster + arg->i < 1)
  93. || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
  94. return;
  95. nmaster += arg->i;
  96. if(sel)
  97. lt->arrange();
  98. else
  99. drawstatus();
  100. }
  101. void
  102. initlayouts(void) {
  103. unsigned int i, w;
  104. lt = &layout[0];
  105. nlayouts = sizeof layout / sizeof layout[0];
  106. for(blw = i = 0; i < nlayouts; i++) {
  107. w = textw(layout[i].symbol);
  108. if(w > blw)
  109. blw = w;
  110. }
  111. }
  112. Client *
  113. nexttiled(Client *c) {
  114. for(; c && (c->isversatile || !isvisible(c)); c = c->next);
  115. return c;
  116. }
  117. void
  118. resizemaster(Arg *arg) {
  119. if(lt->arrange != tile)
  120. return;
  121. if(arg->i == 0)
  122. master = MASTER;
  123. else {
  124. if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
  125. || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
  126. return;
  127. master += arg->i;
  128. }
  129. lt->arrange();
  130. }
  131. void
  132. restack(void) {
  133. Client *c;
  134. XEvent ev;
  135. drawstatus();
  136. if(!sel)
  137. return;
  138. if(sel->isversatile || lt->arrange == versatile)
  139. XRaiseWindow(dpy, sel->win);
  140. if(lt->arrange != versatile) {
  141. if(!sel->isversatile)
  142. XLowerWindow(dpy, sel->win);
  143. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  144. if(c == sel)
  145. continue;
  146. XLowerWindow(dpy, c->win);
  147. }
  148. }
  149. XSync(dpy, False);
  150. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  151. }
  152. void
  153. setlayout(Arg *arg) {
  154. unsigned int i;
  155. if(arg->i == -1) {
  156. for(i = 0; i < nlayouts && lt != &layout[i]; i++);
  157. if(i == nlayouts - 1)
  158. lt = &layout[0];
  159. else
  160. lt = &layout[++i];
  161. }
  162. else {
  163. if(arg->i < 0 || arg->i >= nlayouts)
  164. return;
  165. lt = &layout[arg->i];
  166. }
  167. if(sel)
  168. lt->arrange();
  169. else
  170. drawstatus();
  171. }
  172. void
  173. versatile(void) {
  174. Client *c;
  175. for(c = clients; c; c = c->next) {
  176. if(isvisible(c)) {
  177. if(c->isbanned)
  178. XMoveWindow(dpy, c->win, c->x, c->y);
  179. c->isbanned = False;
  180. resize(c, c->x, c->y, c->w, c->h, True);
  181. }
  182. else {
  183. c->isbanned = True;
  184. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  185. }
  186. }
  187. if(!sel || !isvisible(sel)) {
  188. for(c = stack; c && !isvisible(c); c = c->snext);
  189. focus(c);
  190. }
  191. restack();
  192. }