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.

276 lines
4.4 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
  1. /* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
  2. * See LICENSE file for license details.
  3. */
  4. #include "dwm.h"
  5. /* static */
  6. static Client *
  7. nexttiled(Client *c) {
  8. for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
  9. return c;
  10. }
  11. static void
  12. togglemax(Client *c) {
  13. XEvent ev;
  14. if(c->isfixed)
  15. return;
  16. if((c->ismax = !c->ismax)) {
  17. c->rx = c->x; c->x = wax;
  18. c->ry = c->y; c->y = way;
  19. c->rw = c->w; c->w = waw - 2 * BORDERPX;
  20. c->rh = c->h; c->h = wah - 2 * BORDERPX;
  21. }
  22. else {
  23. c->x = c->rx;
  24. c->y = c->ry;
  25. c->w = c->rw;
  26. c->h = c->rh;
  27. }
  28. resize(c, True, TopLeft);
  29. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  30. }
  31. /* extern */
  32. void (*arrange)(void) = DEFMODE;
  33. void
  34. detach(Client *c) {
  35. if(c->prev)
  36. c->prev->next = c->next;
  37. if(c->next)
  38. c->next->prev = c->prev;
  39. if(c == clients)
  40. clients = c->next;
  41. c->next = c->prev = NULL;
  42. }
  43. void
  44. dofloat(void) {
  45. Client *c;
  46. for(c = clients; c; c = c->next) {
  47. if(isvisible(c)) {
  48. resize(c, True, TopLeft);
  49. }
  50. else
  51. ban(c);
  52. }
  53. if(!sel || !isvisible(sel)) {
  54. for(c = stack; c && !isvisible(c); c = c->snext);
  55. focus(c);
  56. }
  57. restack();
  58. }
  59. void
  60. dotile(void) {
  61. unsigned int i, n, mpx, stackw, th;
  62. Client *c;
  63. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  64. n++;
  65. mpx = (waw * master) / 1000;
  66. stackw = waw - mpx;
  67. for(i = 0, c = clients; c; c = c->next)
  68. if(isvisible(c)) {
  69. if(c->isfloat) {
  70. resize(c, True, TopLeft);
  71. continue;
  72. }
  73. c->ismax = False;
  74. c->x = wax;
  75. c->y = way;
  76. if(n == 1) { /* only 1 window */
  77. c->w = waw - 2 * BORDERPX;
  78. c->h = wah - 2 * BORDERPX;
  79. }
  80. else if(i == 0) { /* master window */
  81. c->w = mpx - 2 * BORDERPX;
  82. c->h = wah - 2 * BORDERPX;
  83. th = wah / (n - 1);
  84. }
  85. else { /* tile window */
  86. c->x += mpx;
  87. c->w = stackw - 2 * BORDERPX;
  88. if(th > bh) {
  89. c->y = way + (i - 1) * 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. Bool
  133. isvisible(Client *c) {
  134. unsigned int i;
  135. for(i = 0; i < ntags; i++)
  136. if(c->tags[i] && seltag[i])
  137. return True;
  138. return False;
  139. }
  140. void
  141. resizemaster(Arg *arg) {
  142. if(arg->i == 0)
  143. master = MASTER;
  144. else {
  145. if(master + arg->i > 950 || master + arg->i < 50)
  146. return;
  147. master += arg->i;
  148. }
  149. arrange();
  150. }
  151. void
  152. restack(void) {
  153. Client *c;
  154. XEvent ev;
  155. if(!sel) {
  156. drawstatus();
  157. return;
  158. }
  159. if(sel->isfloat || arrange == dofloat) {
  160. XRaiseWindow(dpy, sel->win);
  161. XRaiseWindow(dpy, sel->twin);
  162. }
  163. if(arrange != dofloat) {
  164. if(!sel->isfloat) {
  165. XLowerWindow(dpy, sel->twin);
  166. XLowerWindow(dpy, sel->win);
  167. }
  168. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  169. if(c == sel)
  170. continue;
  171. XLowerWindow(dpy, c->twin);
  172. XLowerWindow(dpy, c->win);
  173. }
  174. }
  175. drawall();
  176. XSync(dpy, False);
  177. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  178. }
  179. void
  180. togglefloat(Arg *arg) {
  181. if (!sel)
  182. return;
  183. sel->isfloat = !sel->isfloat;
  184. arrange();
  185. }
  186. void
  187. togglemode(Arg *arg) {
  188. arrange = (arrange == dofloat) ? dotile : dofloat;
  189. if(sel)
  190. arrange();
  191. else
  192. drawstatus();
  193. }
  194. void
  195. toggleview(Arg *arg) {
  196. unsigned int i;
  197. seltag[arg->i] = !seltag[arg->i];
  198. for(i = 0; i < ntags && !seltag[i]; i++);
  199. if(i == ntags)
  200. seltag[arg->i] = True; /* cannot toggle last view */
  201. arrange();
  202. }
  203. void
  204. view(Arg *arg) {
  205. unsigned int i;
  206. for(i = 0; i < ntags; i++)
  207. seltag[i] = False;
  208. seltag[arg->i] = True;
  209. arrange();
  210. }
  211. void
  212. viewall(Arg *arg) {
  213. unsigned int i;
  214. for(i = 0; i < ntags; i++)
  215. seltag[i] = True;
  216. arrange();
  217. }
  218. void
  219. zoom(Arg *arg) {
  220. unsigned int n;
  221. Client *c;
  222. if(!sel)
  223. return;
  224. if(sel->isfloat || (arrange == dofloat)) {
  225. togglemax(sel);
  226. return;
  227. }
  228. for(n = 0, c = clients; c; c = c->next)
  229. if(isvisible(c) && !c->isfloat)
  230. n++;
  231. if(n < 2 || (arrange == dofloat))
  232. return;
  233. if((c = sel) == nexttiled(clients))
  234. if(!(c = nexttiled(c->next)))
  235. return;
  236. detach(c);
  237. if(clients)
  238. clients->prev = c;
  239. c->next = clients;
  240. clients = c;
  241. focus(c);
  242. arrange();
  243. }