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.

263 lines
4.9 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, remainder;
  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. remainder = (n > nmaster) ? wah - th * (n - nmaster) : 0;
  23. tw = waw - mw;
  24. for(i = 0, c = clients; c; c = c->next)
  25. if(isvisible(c)) {
  26. if(c->isbanned)
  27. XMoveWindow(dpy, c->win, c->x, c->y);
  28. c->isbanned = False;
  29. if(c->isfloating)
  30. continue;
  31. c->ismax = False;
  32. nx = wax;
  33. ny = way;
  34. if(i < nmaster) {
  35. ny += i * mh;
  36. nw = mw - 2 * c->border;
  37. nh = mh - 2 * c->border;
  38. }
  39. else { /* tile window */
  40. nx += mw;
  41. nw = tw - 2 * c->border;
  42. if(th > 2 * c->border) {
  43. ny += (i - nmaster) * th;
  44. nh = th - 2 * c->border;
  45. if (i == n - 1)
  46. nh += remainder;
  47. }
  48. else /* fallback if th <= 2 * c->border */
  49. nh = wah - 2 * c->border;
  50. }
  51. resize(c, nx, ny, nw, nh, False);
  52. i++;
  53. }
  54. else {
  55. c->isbanned = True;
  56. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  57. }
  58. if(!sel || !isvisible(sel))
  59. focustopvisible();
  60. restack();
  61. }
  62. LAYOUTS
  63. /* extern */
  64. void
  65. floating(void) {
  66. Client *c;
  67. for(c = clients; c; c = c->next) {
  68. if(isvisible(c)) {
  69. if(c->isbanned)
  70. XMoveWindow(dpy, c->win, c->x, c->y);
  71. c->isbanned = False;
  72. resize(c, c->x, c->y, c->w, c->h, True);
  73. }
  74. else {
  75. c->isbanned = True;
  76. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  77. }
  78. }
  79. if(!sel || !isvisible(sel))
  80. focustopvisible();
  81. restack();
  82. }
  83. void
  84. focusclient(const char *arg) {
  85. Client *c;
  86. if(!sel || !arg)
  87. return;
  88. if(atoi(arg) < 0) {
  89. for(c = sel->prev; c && !isvisible(c); c = c->prev);
  90. if(!c) {
  91. for(c = clients; c && c->next; c = c->next);
  92. for(; c && !isvisible(c); c = c->prev);
  93. }
  94. }
  95. else {
  96. for(c = sel->next; c && !isvisible(c); c = c->next);
  97. if(!c)
  98. for(c = clients; c && !isvisible(c); c = c->next);
  99. }
  100. if(c) {
  101. focus(c);
  102. restack();
  103. }
  104. }
  105. void
  106. incmasterw(const char *arg) {
  107. int i;
  108. if(lt->arrange != tile)
  109. return;
  110. if(!arg)
  111. masterw = MASTERWIDTH;
  112. else {
  113. i = atoi(arg);
  114. if(waw * (masterw + i) / 1000 >= waw - 2 * BORDERPX
  115. || waw * (masterw + i) / 1000 <= 2 * BORDERPX)
  116. return;
  117. masterw += i;
  118. }
  119. lt->arrange();
  120. }
  121. void
  122. incnmaster(const char *arg) {
  123. int i;
  124. if(!arg)
  125. nmaster = NMASTER;
  126. else {
  127. i = atoi(arg);
  128. if((lt->arrange != tile) || (nmaster + i < 1)
  129. || (wah / (nmaster + i) <= 2 * BORDERPX))
  130. return;
  131. nmaster += i;
  132. }
  133. if(sel)
  134. lt->arrange();
  135. else
  136. drawstatus();
  137. }
  138. void
  139. initlayouts(void) {
  140. unsigned int i, w;
  141. lt = &layout[0];
  142. nlayouts = sizeof layout / sizeof layout[0];
  143. for(blw = i = 0; i < nlayouts; i++) {
  144. w = textw(layout[i].symbol);
  145. if(w > blw)
  146. blw = w;
  147. }
  148. }
  149. Client *
  150. nexttiled(Client *c) {
  151. for(; c && (c->isfloating || !isvisible(c)); c = c->next);
  152. return c;
  153. }
  154. void
  155. restack(void) {
  156. Client *c;
  157. XEvent ev;
  158. drawstatus();
  159. if(!sel)
  160. return;
  161. if(sel->isfloating || lt->arrange == floating)
  162. XRaiseWindow(dpy, sel->win);
  163. if(lt->arrange != floating) {
  164. if(!sel->isfloating)
  165. XLowerWindow(dpy, sel->win);
  166. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  167. if(c == sel)
  168. continue;
  169. XLowerWindow(dpy, c->win);
  170. }
  171. }
  172. XSync(dpy, False);
  173. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  174. }
  175. void
  176. setlayout(const char *arg) {
  177. int i;
  178. if(!arg) {
  179. for(i = 0; i < nlayouts && lt != &layout[i]; i++);
  180. if(i == nlayouts - 1)
  181. lt = &layout[0];
  182. else
  183. lt = &layout[++i];
  184. }
  185. else {
  186. i = atoi(arg);
  187. if(i < 0 || i >= nlayouts)
  188. return;
  189. lt = &layout[i];
  190. }
  191. if(sel)
  192. lt->arrange();
  193. else
  194. drawstatus();
  195. }
  196. void
  197. togglebar(const char *arg) {
  198. if(bpos == BarOff) {
  199. if((bpos = BARPOS) == BarOff)
  200. bpos = BarTop;
  201. }
  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 * BORDERPX, wah - 2 * BORDERPX, 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 != tile || 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. }