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.

319 lines
5.1 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /*
  2. * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
  3. * See LICENSE file for license details.
  4. */
  5. #include "dwm.h"
  6. /* static */
  7. static Client *
  8. minclient(void) {
  9. Client *c, *min;
  10. if((clients && clients->isfloat) || arrange == dofloat)
  11. return clients; /* don't touch floating order */
  12. for(min = c = clients; c; c = c->next)
  13. if(c->weight < min->weight)
  14. min = c;
  15. return min;
  16. }
  17. static Client *
  18. nexttiled(Client *c) {
  19. for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
  20. return c;
  21. }
  22. static void
  23. reorder(void) {
  24. Client *c, *newclients, *tail;
  25. newclients = tail = NULL;
  26. while((c = minclient())) {
  27. detach(c);
  28. if(tail) {
  29. c->prev = tail;
  30. tail->next = c;
  31. tail = c;
  32. }
  33. else
  34. tail = newclients = c;
  35. }
  36. clients = newclients;
  37. }
  38. static void
  39. togglemax(Client *c)
  40. {
  41. XEvent ev;
  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)(Arg *) = 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(Arg *arg) {
  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(Arg *arg) {
  87. int h, i, n, w;
  88. Client *c;
  89. w = sw - mw;
  90. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  91. n++;
  92. if(n > 1)
  93. h = (sh - bh) / (n - 1);
  94. else
  95. h = sh - bh;
  96. for(i = 0, c = clients; c; c = c->next) {
  97. if(isvisible(c)) {
  98. if(c->isfloat) {
  99. resize(c, True, TopLeft);
  100. continue;
  101. }
  102. c->ismax = False;
  103. if(n == 1) {
  104. c->x = sx;
  105. c->y = sy + bh;
  106. c->w = sw - 2 * BORDERPX;
  107. c->h = sh - 2 * BORDERPX - bh;
  108. }
  109. else if(i == 0) {
  110. c->x = sx;
  111. c->y = sy + bh;
  112. c->w = mw - 2 * BORDERPX;
  113. c->h = sh - 2 * BORDERPX - bh;
  114. }
  115. else if(h > bh) {
  116. c->x = sx + mw;
  117. c->y = sy + (i - 1) * h + bh;
  118. c->w = w - 2 * BORDERPX;
  119. if(i + 1 == n)
  120. c->h = sh - c->y - 2 * BORDERPX;
  121. else
  122. c->h = h - 2 * BORDERPX;
  123. }
  124. else { /* fallback if h < bh */
  125. c->x = sx + mw;
  126. c->y = sy + bh;
  127. c->w = w - 2 * BORDERPX;
  128. c->h = sh - 2 * BORDERPX - bh;
  129. }
  130. resize(c, False, TopLeft);
  131. i++;
  132. }
  133. else
  134. ban(c);
  135. }
  136. if(!sel || !isvisible(sel)) {
  137. for(c = stack; c && !isvisible(c); c = c->snext);
  138. focus(c);
  139. }
  140. restack();
  141. }
  142. void
  143. focusnext(Arg *arg) {
  144. Client *c;
  145. if(!sel)
  146. return;
  147. if(!(c = getnext(sel->next)))
  148. c = getnext(clients);
  149. if(c) {
  150. focus(c);
  151. restack();
  152. }
  153. }
  154. void
  155. focusprev(Arg *arg) {
  156. Client *c;
  157. if(!sel)
  158. return;
  159. if(!(c = getprev(sel->prev))) {
  160. for(c = clients; c && c->next; c = c->next);
  161. c = getprev(c);
  162. }
  163. if(c) {
  164. focus(c);
  165. restack();
  166. }
  167. }
  168. Bool
  169. isvisible(Client *c) {
  170. unsigned int i;
  171. for(i = 0; i < ntags; i++)
  172. if(c->tags[i] && seltag[i])
  173. return True;
  174. return False;
  175. }
  176. void
  177. resizecol(Arg *arg) {
  178. unsigned int n;
  179. Client *c;
  180. for(n = 0, c = clients; c; c = c->next)
  181. if(isvisible(c) && !c->isfloat)
  182. n++;
  183. if(!sel || sel->isfloat || n < 2 || (arrange == dofloat))
  184. return;
  185. if(sel == getnext(clients)) {
  186. if(mw + arg->i > sw - 100 || mw + arg->i < 100)
  187. return;
  188. mw += arg->i;
  189. }
  190. else {
  191. if(mw - arg->i > sw - 100 || mw - arg->i < 100)
  192. return;
  193. mw -= arg->i;
  194. }
  195. arrange(NULL);
  196. }
  197. void
  198. restack(void) {
  199. Client *c;
  200. XEvent ev;
  201. if(!sel) {
  202. drawstatus();
  203. return;
  204. }
  205. if(sel->isfloat || arrange == dofloat) {
  206. XRaiseWindow(dpy, sel->win);
  207. XRaiseWindow(dpy, sel->twin);
  208. }
  209. if(arrange != dofloat)
  210. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  211. XLowerWindow(dpy, c->twin);
  212. XLowerWindow(dpy, c->win);
  213. }
  214. drawall();
  215. XSync(dpy, False);
  216. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  217. }
  218. void
  219. togglemode(Arg *arg) {
  220. arrange = (arrange == dofloat) ? dotile : dofloat;
  221. if(sel)
  222. arrange(NULL);
  223. else
  224. drawstatus();
  225. }
  226. void
  227. toggleview(Arg *arg) {
  228. unsigned int i;
  229. seltag[arg->i] = !seltag[arg->i];
  230. for(i = 0; i < ntags && !seltag[i]; i++);
  231. if(i == ntags)
  232. seltag[arg->i] = True; /* cannot toggle last view */
  233. reorder();
  234. arrange(NULL);
  235. }
  236. void
  237. view(Arg *arg) {
  238. unsigned int i;
  239. for(i = 0; i < ntags; i++)
  240. seltag[i] = False;
  241. seltag[arg->i] = True;
  242. reorder();
  243. arrange(NULL);
  244. }
  245. void
  246. viewall(Arg *arg) {
  247. unsigned int i;
  248. for(i = 0; i < ntags; i++)
  249. seltag[i] = True;
  250. reorder();
  251. arrange(NULL);
  252. }
  253. void
  254. zoom(Arg *arg) {
  255. unsigned int n;
  256. Client *c;
  257. if(!sel)
  258. return;
  259. if(sel->isfloat || (arrange == dofloat)) {
  260. togglemax(sel);
  261. return;
  262. }
  263. for(n = 0, c = clients; c; c = c->next)
  264. if(isvisible(c) && !c->isfloat)
  265. n++;
  266. if(n < 2 || (arrange == dofloat))
  267. return;
  268. if((c = sel) == nexttiled(clients))
  269. if(!(c = nexttiled(c->next)))
  270. return;
  271. detach(c);
  272. if(clients)
  273. clients->prev = c;
  274. c->next = clients;
  275. clients = c;
  276. focus(c);
  277. arrange(NULL);
  278. }