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.

303 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 = 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(master + arg->i > 950 || master + arg->i < 50)
  175. return;
  176. master += arg->i;
  177. arrange();
  178. }
  179. void
  180. restack(void) {
  181. Client *c;
  182. XEvent ev;
  183. if(!sel) {
  184. drawstatus();
  185. return;
  186. }
  187. if(sel->isfloat || arrange == dofloat) {
  188. XRaiseWindow(dpy, sel->win);
  189. XRaiseWindow(dpy, sel->twin);
  190. }
  191. if(arrange != dofloat) {
  192. if(!sel->isfloat) {
  193. XLowerWindow(dpy, sel->twin);
  194. XLowerWindow(dpy, sel->win);
  195. }
  196. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  197. if(c == sel)
  198. continue;
  199. XLowerWindow(dpy, c->twin);
  200. XLowerWindow(dpy, c->win);
  201. }
  202. }
  203. drawall();
  204. XSync(dpy, False);
  205. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  206. }
  207. void
  208. togglemode(Arg *arg) {
  209. arrange = (arrange == dofloat) ? dotile : dofloat;
  210. if(sel)
  211. arrange();
  212. else
  213. drawstatus();
  214. }
  215. void
  216. toggleview(Arg *arg) {
  217. unsigned int i;
  218. seltag[arg->i] = !seltag[arg->i];
  219. for(i = 0; i < ntags && !seltag[i]; i++);
  220. if(i == ntags)
  221. seltag[arg->i] = True; /* cannot toggle last view */
  222. reorder();
  223. arrange();
  224. }
  225. void
  226. view(Arg *arg) {
  227. unsigned int i;
  228. for(i = 0; i < ntags; i++)
  229. seltag[i] = False;
  230. seltag[arg->i] = True;
  231. reorder();
  232. arrange();
  233. }
  234. void
  235. viewall(Arg *arg) {
  236. unsigned int i;
  237. for(i = 0; i < ntags; i++)
  238. seltag[i] = True;
  239. reorder();
  240. arrange();
  241. }
  242. void
  243. zoom(Arg *arg) {
  244. unsigned int n;
  245. Client *c;
  246. if(!sel)
  247. return;
  248. if(sel->isfloat || (arrange == dofloat)) {
  249. togglemax(sel);
  250. return;
  251. }
  252. for(n = 0, c = clients; c; c = c->next)
  253. if(isvisible(c) && !c->isfloat)
  254. n++;
  255. if(n < 2 || (arrange == dofloat))
  256. return;
  257. if((c = sel) == nexttiled(clients))
  258. if(!(c = nexttiled(c->next)))
  259. return;
  260. detach(c);
  261. if(clients)
  262. clients->prev = c;
  263. c->next = clients;
  264. clients = c;
  265. focus(c);
  266. arrange();
  267. }