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.

281 lines
4.8 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 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 <stdio.h>
  6. /* static */
  7. static Client *
  8. nexttiled(Client *c) {
  9. for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
  10. return c;
  11. }
  12. static void
  13. togglemax(Client *c) {
  14. XEvent ev;
  15. if(c->isfixed)
  16. return;
  17. if((c->ismax = !c->ismax)) {
  18. c->rx = c->x; c->x = wax;
  19. c->ry = c->y; c->y = way;
  20. c->rw = c->w; c->w = waw - 2 * BORDERPX;
  21. c->rh = c->h; c->h = wah - 2 * BORDERPX;
  22. }
  23. else {
  24. c->x = c->rx;
  25. c->y = c->ry;
  26. c->w = c->rw;
  27. c->h = c->rh;
  28. }
  29. resize(c, True, TopLeft);
  30. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  31. }
  32. /* extern */
  33. void (*arrange)(void) = DEFMODE;
  34. void
  35. detach(Client *c) {
  36. if(c->prev)
  37. c->prev->next = c->next;
  38. if(c->next)
  39. c->next->prev = c->prev;
  40. if(c == clients)
  41. clients = c->next;
  42. c->next = c->prev = NULL;
  43. }
  44. void
  45. dofloat(void) {
  46. Client *c;
  47. for(c = clients; c; c = c->next) {
  48. if(isvisible(c)) {
  49. resize(c, True, TopLeft);
  50. }
  51. else
  52. ban(c);
  53. }
  54. if(!sel || !isvisible(sel)) {
  55. for(c = stack; c && !isvisible(c); c = c->snext);
  56. focus(c);
  57. }
  58. restack();
  59. }
  60. void
  61. dotile(void) {
  62. unsigned int i, n, mw, mh, tw, th;
  63. Client *c;
  64. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  65. n++;
  66. /* window geoms */
  67. mw = (n > nmaster) ? (waw * master) / 1000 : waw;
  68. mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
  69. tw = waw - mw;
  70. th = (n > nmaster) ? wah / (n - nmaster) : 0;
  71. for(i = 0, c = clients; c; c = c->next)
  72. if(isvisible(c)) {
  73. if(c->isfloat) {
  74. resize(c, True, TopLeft);
  75. continue;
  76. }
  77. c->ismax = False;
  78. c->x = wax;
  79. c->y = way;
  80. if(i < nmaster) {
  81. c->y += i * mh;
  82. c->w = mw - 2 * BORDERPX;
  83. c->h = mh - 2 * BORDERPX;
  84. }
  85. else { /* tile window */
  86. c->x += mw;
  87. c->w = tw - 2 * BORDERPX;
  88. if(th > bh) {
  89. c->y += (i - nmaster) * th;
  90. c->h = th - 2 * BORDERPX;
  91. }
  92. else /* fallback if th < bh */
  93. c->h = wah - 2 * BORDERPX;
  94. }
  95. resize(c, False, TopLeft);
  96. i++;
  97. }
  98. else
  99. ban(c);
  100. if(!sel || !isvisible(sel)) {
  101. for(c = stack; c && !isvisible(c); c = c->snext);
  102. focus(c);
  103. }
  104. restack();
  105. }
  106. void
  107. focusnext(Arg *arg) {
  108. Client *c;
  109. if(!sel)
  110. return;
  111. if(!(c = getnext(sel->next)))
  112. c = getnext(clients);
  113. if(c) {
  114. focus(c);
  115. restack();
  116. }
  117. }
  118. void
  119. focusprev(Arg *arg) {
  120. Client *c;
  121. if(!sel)
  122. return;
  123. if(!(c = getprev(sel->prev))) {
  124. for(c = clients; c && c->next; c = c->next);
  125. c = getprev(c);
  126. }
  127. if(c) {
  128. focus(c);
  129. restack();
  130. }
  131. }
  132. void
  133. incnmaster(Arg *arg) {
  134. if((arrange == dofloat) || (nmaster + arg->i < 1) || (wah / (nmaster + arg->i) < bh))
  135. return;
  136. nmaster += arg->i;
  137. snprintf(mtext, sizeof mtext, arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, nmaster);
  138. bmw = textw(mtext);
  139. if(sel)
  140. arrange();
  141. else
  142. drawstatus();
  143. }
  144. Bool
  145. isvisible(Client *c) {
  146. unsigned int i;
  147. for(i = 0; i < ntags; i++)
  148. if(c->tags[i] && seltag[i])
  149. return True;
  150. return False;
  151. }
  152. void
  153. resizemaster(Arg *arg) {
  154. if(arg->i == 0)
  155. master = MASTER;
  156. else {
  157. if(master + arg->i > 950 || master + arg->i < 50)
  158. return;
  159. master += arg->i;
  160. }
  161. arrange();
  162. }
  163. void
  164. restack(void) {
  165. Client *c;
  166. XEvent ev;
  167. if(!sel) {
  168. drawstatus();
  169. return;
  170. }
  171. if(sel->isfloat || arrange == dofloat) {
  172. XRaiseWindow(dpy, sel->win);
  173. XRaiseWindow(dpy, sel->twin);
  174. }
  175. if(arrange != dofloat) {
  176. if(!sel->isfloat) {
  177. XLowerWindow(dpy, sel->twin);
  178. XLowerWindow(dpy, sel->win);
  179. }
  180. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  181. if(c == sel)
  182. continue;
  183. XLowerWindow(dpy, c->twin);
  184. XLowerWindow(dpy, c->win);
  185. }
  186. }
  187. drawall();
  188. XSync(dpy, False);
  189. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  190. }
  191. void
  192. togglefloat(Arg *arg) {
  193. if (!sel || arrange == dofloat)
  194. return;
  195. sel->isfloat = !sel->isfloat;
  196. arrange();
  197. }
  198. void
  199. togglemode(Arg *arg) {
  200. arrange = (arrange == dofloat) ? dotile : dofloat;
  201. snprintf(mtext, sizeof mtext, arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, nmaster);
  202. bmw = textw(mtext);
  203. if(sel)
  204. arrange();
  205. else
  206. drawstatus();
  207. }
  208. void
  209. toggleview(Arg *arg) {
  210. unsigned int i;
  211. seltag[arg->i] = !seltag[arg->i];
  212. for(i = 0; i < ntags && !seltag[i]; i++);
  213. if(i == ntags)
  214. seltag[arg->i] = True; /* cannot toggle last view */
  215. arrange();
  216. }
  217. void
  218. view(Arg *arg) {
  219. unsigned int i;
  220. for(i = 0; i < ntags; i++)
  221. seltag[i] = (arg->i == -1) ? True : False;
  222. if(arg->i >= 0 && arg->i < ntags)
  223. seltag[arg->i] = True;
  224. arrange();
  225. }
  226. void
  227. zoom(Arg *arg) {
  228. unsigned int n;
  229. Client *c;
  230. if(!sel)
  231. return;
  232. if(sel->isfloat || (arrange == dofloat)) {
  233. togglemax(sel);
  234. return;
  235. }
  236. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  237. n++;
  238. if((c = sel) == nexttiled(clients))
  239. if(!(c = nexttiled(c->next)))
  240. return;
  241. detach(c);
  242. if(clients)
  243. clients->prev = c;
  244. c->next = clients;
  245. clients = c;
  246. focus(c);
  247. arrange();
  248. }