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.

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