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.

332 lines
5.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
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. /* This algorithm is based on a (M)aster area and a (S)tacking area.
  86. * It supports following arrangements:
  87. * SSMMM MMMMM MMMSS
  88. * SSMMM SSSSS MMMSS
  89. */
  90. void
  91. dotile(Arg *arg) {
  92. unsigned int i, n, md, stackw, stackh, th;
  93. Client *c;
  94. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  95. n++;
  96. md = (sw * master) / 1000;
  97. stackw = sw - md;
  98. stackh = sh - bh;
  99. th = stackh;
  100. if(n > 1)
  101. th /= (n - 1);
  102. for(i = 0, c = clients; c; c = c->next) {
  103. if(isvisible(c)) {
  104. if(c->isfloat) {
  105. resize(c, True, TopLeft);
  106. continue;
  107. }
  108. c->ismax = False;
  109. c->x = sx;
  110. c->y = sy + bh;
  111. if(n == 1) { /* only 1 window */
  112. c->w = sw - 2 * BORDERPX;
  113. c->h = sh - 2 * BORDERPX - bh;
  114. }
  115. else if(i == 0) { /* master window */
  116. c->w = md - 2 * BORDERPX;
  117. c->h = sh - bh - 2 * BORDERPX;
  118. }
  119. else { /* tile window */
  120. c->x += md;
  121. if(th > bh) {
  122. c->y = sy + (i - 1) * th + bh;
  123. if(i + 1 == n)
  124. c->h = sh - c->y - 2 * BORDERPX;
  125. c->w = stackw - 2 * BORDERPX;
  126. c->h = th - 2 * BORDERPX;
  127. }
  128. else { /* fallback if th < bh */
  129. c->w = stackw - 2 * BORDERPX;
  130. c->h = stackh - 2 * BORDERPX;
  131. }
  132. }
  133. resize(c, False, TopLeft);
  134. i++;
  135. }
  136. else
  137. ban(c);
  138. }
  139. if(!sel || !isvisible(sel)) {
  140. for(c = stack; c && !isvisible(c); c = c->snext);
  141. focus(c);
  142. }
  143. restack();
  144. }
  145. void
  146. focusnext(Arg *arg) {
  147. Client *c;
  148. if(!sel)
  149. return;
  150. if(!(c = getnext(sel->next)))
  151. c = getnext(clients);
  152. if(c) {
  153. focus(c);
  154. restack();
  155. }
  156. }
  157. void
  158. focusprev(Arg *arg) {
  159. Client *c;
  160. if(!sel)
  161. return;
  162. if(!(c = getprev(sel->prev))) {
  163. for(c = clients; c && c->next; c = c->next);
  164. c = getprev(c);
  165. }
  166. if(c) {
  167. focus(c);
  168. restack();
  169. }
  170. }
  171. Bool
  172. isvisible(Client *c) {
  173. unsigned int i;
  174. for(i = 0; i < ntags; i++)
  175. if(c->tags[i] && seltag[i])
  176. return True;
  177. return False;
  178. }
  179. void
  180. resizecol(Arg *arg) {
  181. unsigned int n;
  182. Client *c;
  183. for(n = 0, c = clients; c; c = c->next)
  184. if(isvisible(c) && !c->isfloat)
  185. n++;
  186. if(!sel || sel->isfloat || n < 2 || (arrange == dofloat))
  187. return;
  188. if(sel == getnext(clients)) {
  189. if(master + arg->i > 950 || master + arg->i < 50)
  190. return;
  191. master += arg->i;
  192. }
  193. else {
  194. if(master - arg->i > 950 || master - arg->i < 50)
  195. return;
  196. master -= arg->i;
  197. }
  198. arrange(NULL);
  199. }
  200. void
  201. restack(void) {
  202. Client *c;
  203. XEvent ev;
  204. if(!sel) {
  205. drawstatus();
  206. return;
  207. }
  208. if(sel->isfloat || arrange == dofloat) {
  209. XRaiseWindow(dpy, sel->win);
  210. XRaiseWindow(dpy, sel->twin);
  211. }
  212. if(arrange != dofloat) {
  213. if(!sel->isfloat) {
  214. XLowerWindow(dpy, sel->twin);
  215. XLowerWindow(dpy, sel->win);
  216. }
  217. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  218. if(c == sel)
  219. continue;
  220. XLowerWindow(dpy, c->twin);
  221. XLowerWindow(dpy, c->win);
  222. }
  223. }
  224. drawall();
  225. XSync(dpy, False);
  226. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  227. }
  228. void
  229. togglemode(Arg *arg) {
  230. arrange = (arrange == dofloat) ? dotile : dofloat;
  231. if(sel)
  232. arrange(NULL);
  233. else
  234. drawstatus();
  235. }
  236. void
  237. toggleview(Arg *arg) {
  238. unsigned int i;
  239. seltag[arg->i] = !seltag[arg->i];
  240. for(i = 0; i < ntags && !seltag[i]; i++);
  241. if(i == ntags)
  242. seltag[arg->i] = True; /* cannot toggle last view */
  243. reorder();
  244. arrange(NULL);
  245. }
  246. void
  247. view(Arg *arg) {
  248. unsigned int i;
  249. for(i = 0; i < ntags; i++)
  250. seltag[i] = False;
  251. seltag[arg->i] = True;
  252. reorder();
  253. arrange(NULL);
  254. }
  255. void
  256. viewall(Arg *arg) {
  257. unsigned int i;
  258. for(i = 0; i < ntags; i++)
  259. seltag[i] = True;
  260. reorder();
  261. arrange(NULL);
  262. }
  263. void
  264. zoom(Arg *arg) {
  265. unsigned int n;
  266. Client *c;
  267. if(!sel)
  268. return;
  269. if(sel->isfloat || (arrange == dofloat)) {
  270. togglemax(sel);
  271. return;
  272. }
  273. for(n = 0, c = clients; c; c = c->next)
  274. if(isvisible(c) && !c->isfloat)
  275. n++;
  276. if(n < 2 || (arrange == dofloat))
  277. return;
  278. if((c = sel) == nexttiled(clients))
  279. if(!(c = nexttiled(c->next)))
  280. return;
  281. detach(c);
  282. if(clients)
  283. clients->prev = c;
  284. c->next = clients;
  285. clients = c;
  286. focus(c);
  287. arrange(NULL);
  288. }