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.

262 lines
4.8 KiB

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