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.

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