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.

263 lines
4.8 KiB

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