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.

292 lines
4.8 KiB

18 years ago
18 years ago
18 years ago
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. if(nmaster > 0) {
  68. mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
  69. mw = (n > nmaster) ? (waw * master) / 1000 : waw;
  70. }
  71. else
  72. mh = mw = 0;
  73. th = (n > nmaster) ? wah / (n - nmaster) : 0;
  74. tw = waw - mw;
  75. for(i = 0, c = clients; c; c = c->next)
  76. if(isvisible(c)) {
  77. if(c->isfloat) {
  78. resize(c, True, TopLeft);
  79. continue;
  80. }
  81. c->ismax = False;
  82. c->x = wax;
  83. c->y = way;
  84. if((nmaster > 0) && (i < nmaster)) {
  85. c->y += i * mh;
  86. c->w = mw - 2 * BORDERPX;
  87. c->h = mh - 2 * BORDERPX;
  88. }
  89. else { /* tile window */
  90. c->x += mw;
  91. c->w = tw - 2 * BORDERPX;
  92. if(th > bh) {
  93. c->y += (i - nmaster) * th;
  94. c->h = th - 2 * BORDERPX;
  95. }
  96. else /* fallback if th < bh */
  97. c->h = wah - 2 * BORDERPX;
  98. }
  99. resize(c, False, TopLeft);
  100. i++;
  101. }
  102. else
  103. ban(c);
  104. if(!sel || !isvisible(sel)) {
  105. for(c = stack; c && !isvisible(c); c = c->snext);
  106. focus(c);
  107. }
  108. restack();
  109. }
  110. void
  111. focusnext(Arg *arg) {
  112. Client *c;
  113. if(!sel)
  114. return;
  115. if(!(c = getnext(sel->next)))
  116. c = getnext(clients);
  117. if(c) {
  118. focus(c);
  119. restack();
  120. }
  121. }
  122. void
  123. focusprev(Arg *arg) {
  124. Client *c;
  125. if(!sel)
  126. return;
  127. if(!(c = getprev(sel->prev))) {
  128. for(c = clients; c && c->next; c = c->next);
  129. c = getprev(c);
  130. }
  131. if(c) {
  132. focus(c);
  133. restack();
  134. }
  135. }
  136. void
  137. incnmaster(Arg *arg) {
  138. if((arrange == dofloat)
  139. || ((int)nmaster + arg->i < 0)
  140. || (((int)nmaster + arg->i > 0) && (wah / (nmaster + arg->i) < bh)))
  141. return;
  142. nmaster += arg->i;
  143. updatemodetext();
  144. if(sel)
  145. arrange();
  146. else
  147. drawstatus();
  148. }
  149. Bool
  150. isvisible(Client *c) {
  151. unsigned int i;
  152. for(i = 0; i < ntags; i++)
  153. if(c->tags[i] && seltag[i])
  154. return True;
  155. return False;
  156. }
  157. void
  158. resizemaster(Arg *arg) {
  159. if(arg->i == 0)
  160. master = MASTER;
  161. else {
  162. if(master + arg->i > 950 || master + arg->i < 50)
  163. return;
  164. master += arg->i;
  165. }
  166. arrange();
  167. }
  168. void
  169. restack(void) {
  170. Client *c;
  171. XEvent ev;
  172. if(!sel) {
  173. drawstatus();
  174. return;
  175. }
  176. if(sel->isfloat || arrange == dofloat) {
  177. XRaiseWindow(dpy, sel->win);
  178. XRaiseWindow(dpy, sel->twin);
  179. }
  180. if(arrange != dofloat) {
  181. if(!sel->isfloat) {
  182. XLowerWindow(dpy, sel->twin);
  183. XLowerWindow(dpy, sel->win);
  184. }
  185. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  186. if(c == sel)
  187. continue;
  188. XLowerWindow(dpy, c->twin);
  189. XLowerWindow(dpy, c->win);
  190. }
  191. }
  192. drawall();
  193. XSync(dpy, False);
  194. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  195. }
  196. void
  197. togglefloat(Arg *arg) {
  198. if (!sel || arrange == dofloat)
  199. return;
  200. sel->isfloat = !sel->isfloat;
  201. arrange();
  202. }
  203. void
  204. togglemode(Arg *arg) {
  205. arrange = (arrange == dofloat) ? dotile : dofloat;
  206. updatemodetext();
  207. if(sel)
  208. arrange();
  209. else
  210. drawstatus();
  211. }
  212. void
  213. toggleview(Arg *arg) {
  214. unsigned int i;
  215. seltag[arg->i] = !seltag[arg->i];
  216. for(i = 0; i < ntags && !seltag[i]; i++);
  217. if(i == ntags)
  218. seltag[arg->i] = True; /* cannot toggle last view */
  219. arrange();
  220. }
  221. void
  222. updatemodetext() {
  223. snprintf(mtext, sizeof mtext, arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, nmaster);
  224. bmw = textw(mtext);
  225. }
  226. void
  227. view(Arg *arg) {
  228. unsigned int i;
  229. for(i = 0; i < ntags; i++)
  230. seltag[i] = (arg->i == -1) ? True : False;
  231. if(arg->i >= 0 && arg->i < ntags)
  232. seltag[arg->i] = True;
  233. arrange();
  234. }
  235. void
  236. zoom(Arg *arg) {
  237. unsigned int n;
  238. Client *c;
  239. if(!sel)
  240. return;
  241. if(sel->isfloat || (arrange == dofloat)) {
  242. togglemax(sel);
  243. return;
  244. }
  245. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  246. n++;
  247. if((c = sel) == nexttiled(clients))
  248. if(!(c = nexttiled(c->next)))
  249. return;
  250. detach(c);
  251. if(clients)
  252. clients->prev = c;
  253. c->next = clients;
  254. clients = c;
  255. focus(c);
  256. arrange();
  257. }