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.

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