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.

325 lines
5.0 KiB

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