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.

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