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.

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