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.

311 lines
5.7 KiB

17 years ago
17 years ago
17 years ago
  1. /* See LICENSE file for copyright and license details. */
  2. #include "dwm.h"
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. unsigned int blw = 0;
  6. Layout *lt = NULL;
  7. /* static */
  8. static double hratio = HRATIO;
  9. static double vratio = VRATIO;
  10. static unsigned int nlayouts = 0;
  11. static unsigned int nmaster = NMASTER;
  12. static double /* simple pow() */
  13. spow(double x, double y)
  14. {
  15. if(y == 0)
  16. return 1;
  17. while(--y)
  18. x *= x;
  19. return x;
  20. }
  21. static void
  22. tile(void) {
  23. Bool mmaxtile = False, smaxtile = False; /* fallback tiling */
  24. double mscale = 0, sscale = 0, sum = 0;
  25. unsigned int i, n, nx, ny, nw, nh, mw, tw;
  26. Client *c;
  27. /* preparation */
  28. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  29. n++;
  30. nx = wax;
  31. ny = way;
  32. mw = (n <= nmaster) ? waw : waw / (1 + hratio);
  33. tw = waw - mw;
  34. if(n > 0) {
  35. if(n <= nmaster) {
  36. for(i = 0; i < n; i++)
  37. sum += spow(vratio, i);
  38. mscale = wah / sum;
  39. if(vratio >= 1)
  40. mmaxtile = bh > (mscale * spow(vratio, 0));
  41. else
  42. mmaxtile = bh > (mscale * spow(vratio, n - 1));
  43. }
  44. else {
  45. for(i = 0; i < nmaster; i++)
  46. sum += spow(vratio, i);
  47. mscale = wah / sum;
  48. for(sum = 0, i = 0; i < (n - nmaster); i++)
  49. sum += spow(vratio, i);
  50. sscale = wah / sum;
  51. if(vratio >= 1) {
  52. mmaxtile = bh > (mscale * spow(vratio, 0));
  53. smaxtile = bh > (sscale * spow(vratio, 0));
  54. }
  55. else {
  56. mmaxtile = bh > (mscale * spow(vratio, nmaster - 1));
  57. smaxtile = bh > (sscale * spow(vratio, n - nmaster - 1));
  58. }
  59. }
  60. }
  61. /* tiling */
  62. for(i = 0, c = clients; c; c = c->next)
  63. if(isvisible(c)) {
  64. unban(c);
  65. if(c->isfloating)
  66. continue;
  67. c->ismax = False;
  68. if(i < nmaster) { /* master window */
  69. nw = mw - 2 * c->border;
  70. if(mmaxtile) {
  71. ny = way;
  72. nh = wah - 2 * c->border;
  73. }
  74. else if(i + 1 == (n < nmaster ? n : nmaster))
  75. nh = (way + wah) - ny - 2 * c->border;
  76. else
  77. nh = (mscale * spow(vratio, i)) - 2 * c->border;
  78. }
  79. else { /* tile window */
  80. nw = tw - 2 * c->border;
  81. if(i == nmaster) {
  82. ny = way;
  83. nx = wax + mw;
  84. }
  85. if(smaxtile) {
  86. ny = way;
  87. nh = wah - 2 * c->border;
  88. }
  89. else if(i + 1 == n)
  90. nh = (way + wah) - ny - 2 * c->border;
  91. else
  92. nh = (sscale * spow(vratio, i - nmaster)) - 2 * c->border;
  93. }
  94. resize(c, nx, ny, nw, nh, False);
  95. ny += nh;
  96. i++;
  97. }
  98. else
  99. ban(c);
  100. focus(NULL);
  101. restack();
  102. }
  103. LAYOUTS
  104. static void
  105. incratio(const char *arg, double *ratio, double def) {
  106. double delta;
  107. if(lt->arrange != tile)
  108. return;
  109. if(!arg)
  110. *ratio = def;
  111. else {
  112. if(1 == sscanf(arg, "%lf", &delta)) {
  113. if(delta + (*ratio) < .1 || delta + (*ratio) > 1.9)
  114. return;
  115. *ratio += delta;
  116. }
  117. }
  118. lt->arrange();
  119. }
  120. /* extern */
  121. void
  122. floating(void) {
  123. Client *c;
  124. for(c = clients; c; c = c->next)
  125. if(isvisible(c)) {
  126. unban(c);
  127. resize(c, c->x, c->y, c->w, c->h, True);
  128. }
  129. else
  130. ban(c);
  131. focus(NULL);
  132. restack();
  133. }
  134. void
  135. focusclient(const char *arg) {
  136. Client *c;
  137. if(!sel || !arg)
  138. return;
  139. if(atoi(arg) < 0) {
  140. for(c = sel->prev; c && !isvisible(c); c = c->prev);
  141. if(!c) {
  142. for(c = clients; c && c->next; c = c->next);
  143. for(; c && !isvisible(c); c = c->prev);
  144. }
  145. }
  146. else {
  147. for(c = sel->next; c && !isvisible(c); c = c->next);
  148. if(!c)
  149. for(c = clients; c && !isvisible(c); c = c->next);
  150. }
  151. if(c) {
  152. focus(c);
  153. restack();
  154. }
  155. }
  156. void
  157. inchratio(const char *arg) {
  158. incratio(arg, &hratio, HRATIO);
  159. }
  160. void
  161. incvratio(const char *arg) {
  162. incratio(arg, &vratio, VRATIO);
  163. }
  164. void
  165. incnmaster(const char *arg) {
  166. int i;
  167. if(!arg)
  168. nmaster = NMASTER;
  169. else {
  170. i = atoi(arg);
  171. if((lt->arrange != tile) || (nmaster + i < 1)
  172. || (wah / (nmaster + i) <= 2 * BORDERPX))
  173. return;
  174. nmaster += i;
  175. }
  176. if(sel)
  177. lt->arrange();
  178. else
  179. drawstatus();
  180. }
  181. void
  182. initlayouts(void) {
  183. unsigned int i, w;
  184. lt = &layout[0];
  185. nlayouts = sizeof layout / sizeof layout[0];
  186. for(blw = i = 0; i < nlayouts; i++) {
  187. w = textw(layout[i].symbol);
  188. if(w > blw)
  189. blw = w;
  190. }
  191. }
  192. Client *
  193. nexttiled(Client *c) {
  194. for(; c && (c->isfloating || !isvisible(c)); c = c->next);
  195. return c;
  196. }
  197. void
  198. restack(void) {
  199. Client *c;
  200. XEvent ev;
  201. XWindowChanges wc;
  202. drawstatus();
  203. if(!sel)
  204. return;
  205. if(sel->isfloating || lt->arrange == floating)
  206. XRaiseWindow(dpy, sel->win);
  207. if(lt->arrange != floating) {
  208. wc.stack_mode = Below;
  209. wc.sibling = barwin;
  210. if(!sel->isfloating) {
  211. XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc);
  212. wc.sibling = sel->win;
  213. }
  214. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  215. if(c == sel)
  216. continue;
  217. XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
  218. wc.sibling = c->win;
  219. }
  220. }
  221. XSync(dpy, False);
  222. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  223. }
  224. void
  225. setlayout(const char *arg) {
  226. int i;
  227. if(!arg) {
  228. lt++;
  229. if(lt == layout + nlayouts)
  230. lt = layout;
  231. }
  232. else {
  233. i = atoi(arg);
  234. if(i < 0 || i >= nlayouts)
  235. return;
  236. lt = &layout[i];
  237. }
  238. if(sel)
  239. lt->arrange();
  240. else
  241. drawstatus();
  242. }
  243. void
  244. togglebar(const char *arg) {
  245. if(bpos == BarOff)
  246. bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
  247. else
  248. bpos = BarOff;
  249. updatebarpos();
  250. lt->arrange();
  251. }
  252. void
  253. togglemax(const char *arg) {
  254. XEvent ev;
  255. if(!sel || (lt->arrange != floating && !sel->isfloating) || sel->isfixed)
  256. return;
  257. if((sel->ismax = !sel->ismax)) {
  258. sel->rx = sel->x;
  259. sel->ry = sel->y;
  260. sel->rw = sel->w;
  261. sel->rh = sel->h;
  262. resize(sel, wax, way, waw - 2 * sel->border, wah - 2 * sel->border, True);
  263. }
  264. else
  265. resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
  266. drawstatus();
  267. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  268. }
  269. void
  270. zoom(const char *arg) {
  271. Client *c;
  272. if(!sel || lt->arrange == floating || sel->isfloating)
  273. return;
  274. if((c = sel) == nexttiled(clients))
  275. if(!(c = nexttiled(c->next)))
  276. return;
  277. detach(c);
  278. attach(c);
  279. focus(c);
  280. lt->arrange();
  281. }