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.

255 lines
4.8 KiB

17 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 - 2 * c->border;
  37. }
  38. else { /* tile window */
  39. nx += mw;
  40. nw = tw - 2 * c->border;
  41. if(th > 2 * c->border) {
  42. ny += (i - nmaster) * th;
  43. nh = th - 2 * c->border;
  44. }
  45. else /* fallback if th <= 2 * c->border */
  46. nh = wah - 2 * c->border;
  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. floating(void) {
  65. Client *c;
  66. for(c = clients; c; c = c->next) {
  67. if(isvisible(c)) {
  68. if(c->isbanned)
  69. XMoveWindow(dpy, c->win, c->x, c->y);
  70. c->isbanned = False;
  71. resize(c, c->x, c->y, c->w, c->h, True);
  72. }
  73. else {
  74. c->isbanned = True;
  75. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  76. }
  77. }
  78. if(!sel || !isvisible(sel)) {
  79. for(c = stack; c && !isvisible(c); c = c->snext);
  80. focus(c);
  81. }
  82. restack();
  83. }
  84. void
  85. focusclient(const char *arg) {
  86. Client *c;
  87. if(!sel || !arg)
  88. return;
  89. if(atoi(arg) < 0) {
  90. for(c = sel->prev; c && !isvisible(c); c = c->prev);
  91. if(!c) {
  92. for(c = clients; c && c->next; c = c->next);
  93. for(; c && !isvisible(c); c = c->prev);
  94. }
  95. }
  96. else {
  97. for(c = sel->next; c && !isvisible(c); c = c->next);
  98. if(!c)
  99. for(c = clients; c && !isvisible(c); c = c->next);
  100. }
  101. if(c) {
  102. focus(c);
  103. restack();
  104. }
  105. }
  106. void
  107. incmasterw(const char *arg) {
  108. int i;
  109. if(lt->arrange != tile)
  110. return;
  111. if(!arg)
  112. masterw = MASTERWIDTH;
  113. else {
  114. i = atoi(arg);
  115. if(waw * (masterw + i) / 1000 >= waw - 2 * BORDERPX
  116. || waw * (masterw + i) / 1000 <= 2 * BORDERPX)
  117. return;
  118. masterw += i;
  119. }
  120. lt->arrange();
  121. }
  122. void
  123. incnmaster(const char *arg) {
  124. int i;
  125. if(!arg)
  126. nmaster = NMASTER;
  127. else {
  128. i = atoi(arg);
  129. if((lt->arrange != tile) || (nmaster + i < 1)
  130. || (wah / (nmaster + i) <= 2 * BORDERPX))
  131. return;
  132. nmaster += i;
  133. }
  134. if(sel)
  135. lt->arrange();
  136. else
  137. drawstatus();
  138. }
  139. void
  140. initlayouts(void) {
  141. unsigned int i, w;
  142. lt = &layout[0];
  143. nlayouts = sizeof layout / sizeof layout[0];
  144. for(blw = i = 0; i < nlayouts; i++) {
  145. w = textw(layout[i].symbol);
  146. if(w > blw)
  147. blw = w;
  148. }
  149. }
  150. Client *
  151. nexttiled(Client *c) {
  152. for(; c && (c->isfloating || !isvisible(c)); c = c->next);
  153. return c;
  154. }
  155. void
  156. restack(void) {
  157. Client *c;
  158. XEvent ev;
  159. drawstatus();
  160. if(!sel)
  161. return;
  162. if(sel->isfloating || lt->arrange == floating)
  163. XRaiseWindow(dpy, sel->win);
  164. if(lt->arrange != floating) {
  165. if(!sel->isfloating)
  166. XLowerWindow(dpy, sel->win);
  167. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  168. if(c == sel)
  169. continue;
  170. XLowerWindow(dpy, c->win);
  171. }
  172. }
  173. XSync(dpy, False);
  174. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  175. }
  176. void
  177. setlayout(const char *arg) {
  178. int i;
  179. if(!arg) {
  180. for(i = 0; i < nlayouts && lt != &layout[i]; i++);
  181. if(i == nlayouts - 1)
  182. lt = &layout[0];
  183. else
  184. lt = &layout[++i];
  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. togglemax(const char *arg) {
  199. XEvent ev;
  200. if(!sel || (lt->arrange != floating && !sel->isfloating) || sel->isfixed)
  201. return;
  202. if((sel->ismax = !sel->ismax)) {
  203. sel->rx = sel->x;
  204. sel->ry = sel->y;
  205. sel->rw = sel->w;
  206. sel->rh = sel->h;
  207. resize(sel, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
  208. }
  209. else
  210. resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
  211. drawstatus();
  212. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  213. }
  214. void
  215. zoom(const char *arg) {
  216. unsigned int n;
  217. Client *c;
  218. if(!sel || lt->arrange != tile || sel->isfloating)
  219. return;
  220. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  221. n++;
  222. if((c = sel) == nexttiled(clients))
  223. if(!(c = nexttiled(c->next)))
  224. return;
  225. detach(c);
  226. attach(c);
  227. focus(c);
  228. lt->arrange();
  229. }