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.

269 lines
4.8 KiB

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