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.

267 lines
4.7 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. if(c->isbanned)
  80. XMoveWindow(dpy, c->win, c->x, c->y);
  81. c->isbanned = False;
  82. resize(c, c->x, c->y, c->w, c->h, True);
  83. }
  84. else
  85. ban(c);
  86. focus(NULL);
  87. restack();
  88. }
  89. void
  90. focusclient(const char *arg) {
  91. Client *c;
  92. if(!sel || !arg)
  93. return;
  94. if(atoi(arg) < 0) {
  95. for(c = sel->prev; c && !isvisible(c); c = c->prev);
  96. if(!c) {
  97. for(c = clients; c && c->next; c = c->next);
  98. for(; c && !isvisible(c); c = c->prev);
  99. }
  100. }
  101. else {
  102. for(c = sel->next; c && !isvisible(c); c = c->next);
  103. if(!c)
  104. for(c = clients; c && !isvisible(c); c = c->next);
  105. }
  106. if(c) {
  107. focus(c);
  108. restack();
  109. }
  110. }
  111. void
  112. incmasterw(const char *arg) {
  113. int i;
  114. if(lt->arrange != tile)
  115. return;
  116. if(!arg)
  117. masterw = MASTERWIDTH;
  118. else {
  119. i = atoi(arg);
  120. if(waw * (masterw + i) / 1000 >= waw - 2 * BORDERPX
  121. || waw * (masterw + i) / 1000 <= 2 * BORDERPX)
  122. return;
  123. masterw += i;
  124. }
  125. lt->arrange();
  126. }
  127. void
  128. incnmaster(const char *arg) {
  129. int i;
  130. if(!arg)
  131. nmaster = NMASTER;
  132. else {
  133. i = atoi(arg);
  134. if((lt->arrange != tile) || (nmaster + i < 1)
  135. || (wah / (nmaster + i) <= 2 * BORDERPX))
  136. return;
  137. nmaster += i;
  138. }
  139. if(sel)
  140. lt->arrange();
  141. else
  142. drawstatus();
  143. }
  144. void
  145. initlayouts(void) {
  146. unsigned int i, w;
  147. lt = &layout[0];
  148. nlayouts = sizeof layout / sizeof layout[0];
  149. for(blw = i = 0; i < nlayouts; i++) {
  150. w = textw(layout[i].symbol);
  151. if(w > blw)
  152. blw = w;
  153. }
  154. }
  155. Client *
  156. nexttiled(Client *c) {
  157. for(; c && (c->isfloating || !isvisible(c)); c = c->next);
  158. return c;
  159. }
  160. void
  161. restack(void) {
  162. Client *c;
  163. XEvent ev;
  164. drawstatus();
  165. if(!sel)
  166. return;
  167. if(sel->isfloating || lt->arrange == floating)
  168. XRaiseWindow(dpy, sel->win);
  169. if(lt->arrange != floating) {
  170. if(!sel->isfloating)
  171. XLowerWindow(dpy, sel->win);
  172. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  173. if(c == sel)
  174. continue;
  175. XLowerWindow(dpy, c->win);
  176. }
  177. }
  178. XSync(dpy, False);
  179. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  180. }
  181. void
  182. setlayout(const char *arg) {
  183. int i;
  184. if(!arg) {
  185. lt++;
  186. if(lt == layout + nlayouts)
  187. lt = layout;
  188. }
  189. else {
  190. i = atoi(arg);
  191. if(i < 0 || i >= nlayouts)
  192. return;
  193. lt = &layout[i];
  194. }
  195. if(sel)
  196. lt->arrange();
  197. else
  198. drawstatus();
  199. }
  200. void
  201. togglebar(const char *arg) {
  202. if(bpos == BarOff)
  203. bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
  204. else
  205. bpos = BarOff;
  206. updatebarpos();
  207. lt->arrange();
  208. }
  209. void
  210. togglemax(const char *arg) {
  211. XEvent ev;
  212. if(!sel || (lt->arrange != floating && !sel->isfloating) || sel->isfixed)
  213. return;
  214. if((sel->ismax = !sel->ismax)) {
  215. sel->rx = sel->x;
  216. sel->ry = sel->y;
  217. sel->rw = sel->w;
  218. sel->rh = sel->h;
  219. resize(sel, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
  220. }
  221. else
  222. resize(sel, sel->rx, sel->ry, sel->rw, sel->rh, True);
  223. drawstatus();
  224. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  225. }
  226. void
  227. zoom(const char *arg) {
  228. Client *c;
  229. if(!sel || lt->arrange == floating || sel->isfloating)
  230. return;
  231. if((c = sel) == nexttiled(clients))
  232. if(!(c = nexttiled(c->next)))
  233. return;
  234. detach(c);
  235. attach(c);
  236. focus(c);
  237. lt->arrange();
  238. }