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.

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