Configuration of dwm for Mac Computers
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.

306 lines
4.4 KiB

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. #include <stdio.h>
  7. /* static */
  8. static Client *
  9. minclient()
  10. {
  11. Client *c, *min;
  12. for(min = c = clients; c; c = c->next)
  13. if(c->weight < min->weight)
  14. min = c;
  15. return min;
  16. }
  17. static void
  18. reorder()
  19. {
  20. Client *c, *newclients, *tail;
  21. newclients = tail = NULL;
  22. while((c = minclient())) {
  23. detach(c);
  24. if(tail) {
  25. c->prev = tail;
  26. tail->next = c;
  27. tail = c;
  28. }
  29. else
  30. tail = newclients = c;
  31. }
  32. clients = newclients;
  33. }
  34. static Client *
  35. nexttiled(Client *c)
  36. {
  37. for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
  38. return c;
  39. }
  40. /* extern */
  41. void (*arrange)(Arg *) = DEFMODE;
  42. void
  43. detach(Client *c)
  44. {
  45. if(c->prev)
  46. c->prev->next = c->next;
  47. if(c->next)
  48. c->next->prev = c->prev;
  49. if(c == clients)
  50. clients = c->next;
  51. c->next = c->prev = NULL;
  52. }
  53. void
  54. dofloat(Arg *arg)
  55. {
  56. Client *c;
  57. maximized = False;
  58. for(c = clients; c; c = c->next) {
  59. if(isvisible(c)) {
  60. resize(c, True, TopLeft);
  61. }
  62. else
  63. ban(c);
  64. }
  65. if(!sel || !isvisible(sel))
  66. focus(getnext(clients));
  67. restack();
  68. }
  69. void
  70. dotile(Arg *arg)
  71. {
  72. int h, i, n, w;
  73. Client *c;
  74. maximized = False;
  75. w = sw - mw;
  76. for(n = 0, c = clients; c; c = c->next)
  77. if(isvisible(c) && !c->isfloat)
  78. n++;
  79. if(n > 1)
  80. h = (sh - bh) / (n - 1);
  81. else
  82. h = sh - bh;
  83. for(i = 0, c = clients; c; c = c->next) {
  84. if(isvisible(c)) {
  85. if(c->isfloat) {
  86. resize(c, True, TopLeft);
  87. continue;
  88. }
  89. if(n == 1) {
  90. c->x = sx;
  91. c->y = sy + bh;
  92. c->w = sw - 2;
  93. c->h = sh - 2 - bh;
  94. }
  95. else if(i == 0) {
  96. c->x = sx;
  97. c->y = sy + bh;
  98. c->w = mw - 2;
  99. c->h = sh - 2 - bh;
  100. }
  101. else if(h > bh) {
  102. c->x = sx + mw;
  103. c->y = sy + (i - 1) * h + bh;
  104. c->w = w - 2;
  105. if(i + 1 == n)
  106. c->h = sh - c->y - 2;
  107. else
  108. c->h = h - 2;
  109. }
  110. else { /* fallback if h < bh */
  111. c->x = sx + mw;
  112. c->y = sy + bh;
  113. c->w = w - 2;
  114. c->h = sh - 2 - bh;
  115. }
  116. resize(c, False, TopLeft);
  117. i++;
  118. }
  119. else
  120. ban(c);
  121. }
  122. if(!sel || !isvisible(sel))
  123. focus(getnext(clients));
  124. restack();
  125. }
  126. void
  127. focusnext(Arg *arg)
  128. {
  129. Client *c;
  130. if(!sel)
  131. return;
  132. if(!(c = getnext(sel->next)))
  133. c = getnext(clients);
  134. if(c) {
  135. focus(c);
  136. restack();
  137. }
  138. }
  139. void
  140. focusprev(Arg *arg)
  141. {
  142. Client *c;
  143. if(!sel)
  144. return;
  145. if(!(c = getprev(sel->prev))) {
  146. for(c = clients; c && c->next; c = c->next);
  147. c = getprev(c);
  148. }
  149. if(c) {
  150. focus(c);
  151. restack();
  152. }
  153. }
  154. Bool
  155. isvisible(Client *c)
  156. {
  157. unsigned int i;
  158. for(i = 0; i < ntags; i++)
  159. if(c->tags[i] && seltag[i])
  160. return True;
  161. return False;
  162. }
  163. void
  164. resizecol(Arg *arg)
  165. {
  166. unsigned int n;
  167. Client *c;
  168. for(n = 0, c = clients; c; c = c->next)
  169. if(isvisible(c) && !c->isfloat)
  170. n++;
  171. if(!sel || sel->isfloat || n < 2 || (arrange != dotile) || maximized)
  172. return;
  173. if(sel == getnext(clients)) {
  174. if(mw + arg->i > sw - 100 || mw + arg->i < 100)
  175. return;
  176. mw += arg->i;
  177. }
  178. else {
  179. if(mw - arg->i > sw - 100 || mw - arg->i < 100)
  180. return;
  181. mw -= arg->i;
  182. }
  183. arrange(NULL);
  184. }
  185. void
  186. restack()
  187. {
  188. Client *c;
  189. XEvent ev;
  190. if(!sel) {
  191. drawstatus();
  192. return;
  193. }
  194. if(sel->isfloat || arrange == dofloat) {
  195. XRaiseWindow(dpy, sel->win);
  196. XRaiseWindow(dpy, sel->twin);
  197. }
  198. if(arrange != dofloat)
  199. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  200. XLowerWindow(dpy, c->twin);
  201. XLowerWindow(dpy, c->win);
  202. }
  203. drawall();
  204. XSync(dpy, False);
  205. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  206. }
  207. void
  208. togglemode(Arg *arg)
  209. {
  210. arrange = (arrange == dofloat) ? dotile : dofloat;
  211. if(sel)
  212. arrange(NULL);
  213. else
  214. drawstatus();
  215. }
  216. void
  217. toggleview(Arg *arg)
  218. {
  219. unsigned int i;
  220. seltag[arg->i] = !seltag[arg->i];
  221. for(i = 0; i < ntags && !seltag[i]; i++);
  222. if(i == ntags)
  223. seltag[arg->i] = True; /* cannot toggle last view */
  224. reorder();
  225. arrange(NULL);
  226. }
  227. void
  228. view(Arg *arg)
  229. {
  230. unsigned int i;
  231. for(i = 0; i < ntags; i++)
  232. seltag[i] = False;
  233. seltag[arg->i] = True;
  234. reorder();
  235. arrange(NULL);
  236. }
  237. void
  238. viewall(Arg *arg)
  239. {
  240. unsigned int i;
  241. for(i = 0; i < ntags; i++)
  242. seltag[i] = True;
  243. reorder();
  244. arrange(NULL);
  245. }
  246. void
  247. zoom(Arg *arg)
  248. {
  249. unsigned int n;
  250. Client *c;
  251. for(n = 0, c = clients; c; c = c->next)
  252. if(isvisible(c) && !c->isfloat)
  253. n++;
  254. if(!sel || sel->isfloat || n < 2 || (arrange != dotile) || maximized)
  255. return;
  256. if((c = sel) == nexttiled(clients))
  257. if(!(c = nexttiled(c->next)))
  258. return;
  259. detach(c);
  260. c->next = clients;
  261. clients->prev = c;
  262. clients = c;
  263. focus(c);
  264. arrange(NULL);
  265. }