Configuration file for DWM on MacBook Air
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.5 KiB

17 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. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  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. mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
  68. mw = (n > nmaster) ? (waw * master) / 1000 : waw;
  69. th = (n > nmaster) ? wah / (n - nmaster) : 0;
  70. tw = waw - mw;
  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. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  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. if(sel)
  138. arrange();
  139. else
  140. drawstatus();
  141. }
  142. Bool
  143. isvisible(Client *c) {
  144. unsigned int i;
  145. for(i = 0; i < ntags; i++)
  146. if(c->tags[i] && seltag[i])
  147. return True;
  148. return False;
  149. }
  150. void
  151. resizemaster(Arg *arg) {
  152. if(arg->i == 0)
  153. master = MASTER;
  154. else {
  155. if(master + arg->i > 950 || master + arg->i < 50)
  156. return;
  157. master += arg->i;
  158. }
  159. arrange();
  160. }
  161. void
  162. restack(void) {
  163. Client *c;
  164. XEvent ev;
  165. drawstatus();
  166. if(!sel)
  167. return;
  168. if(sel->isfloat || arrange == dofloat)
  169. XRaiseWindow(dpy, sel->win);
  170. if(arrange != dofloat) {
  171. if(!sel->isfloat)
  172. XLowerWindow(dpy, sel->win);
  173. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  174. if(c == sel)
  175. continue;
  176. XLowerWindow(dpy, c->win);
  177. }
  178. }
  179. XSync(dpy, False);
  180. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  181. }
  182. void
  183. togglefloat(Arg *arg) {
  184. if (!sel || arrange == dofloat)
  185. return;
  186. sel->isfloat = !sel->isfloat;
  187. arrange();
  188. }
  189. void
  190. togglemode(Arg *arg) {
  191. arrange = (arrange == dofloat) ? dotile : dofloat;
  192. if(sel)
  193. arrange();
  194. else
  195. drawstatus();
  196. }
  197. void
  198. toggleview(Arg *arg) {
  199. unsigned int i;
  200. seltag[arg->i] = !seltag[arg->i];
  201. for(i = 0; i < ntags && !seltag[i]; i++);
  202. if(i == ntags)
  203. seltag[arg->i] = True; /* cannot toggle last view */
  204. arrange();
  205. }
  206. void
  207. view(Arg *arg) {
  208. unsigned int i;
  209. for(i = 0; i < ntags; i++)
  210. seltag[i] = (arg->i == -1) ? True : False;
  211. if(arg->i >= 0 && arg->i < ntags)
  212. seltag[arg->i] = True;
  213. arrange();
  214. }
  215. void
  216. zoom(Arg *arg) {
  217. unsigned int n;
  218. Client *c;
  219. if(!sel)
  220. return;
  221. if(sel->isfloat || (arrange == dofloat)) {
  222. togglemax(sel);
  223. return;
  224. }
  225. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  226. n++;
  227. if((c = sel) == nexttiled(clients))
  228. if(!(c = nexttiled(c->next)))
  229. return;
  230. detach(c);
  231. if(clients)
  232. clients->prev = c;
  233. c->next = clients;
  234. clients = c;
  235. focus(c);
  236. arrange();
  237. }