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.

259 lines
4.7 KiB

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