Configuration of dwm for Mac Computers
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.

257 lines
4.7 KiB

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