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.

341 lines
5.5 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(void) {
  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(void) {
  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 - 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)(Arg *) = DEFMODE;
  59. Bool isvertical = VERTICALSTACK;
  60. StackPos stackpos = STACKPOS;
  61. void
  62. detach(Client *c) {
  63. if(c->prev)
  64. c->prev->next = c->next;
  65. if(c->next)
  66. c->next->prev = c->prev;
  67. if(c == clients)
  68. clients = c->next;
  69. c->next = c->prev = NULL;
  70. }
  71. void
  72. dofloat(Arg *arg) {
  73. Client *c;
  74. for(c = clients; c; c = c->next) {
  75. if(isvisible(c)) {
  76. resize(c, True, TopLeft);
  77. }
  78. else
  79. ban(c);
  80. }
  81. if(!sel || !isvisible(sel)) {
  82. for(c = stack; c && !isvisible(c); c = c->snext);
  83. focus(c);
  84. }
  85. restack();
  86. }
  87. /* This algorithm is based on a (M)aster area and a (S)tacking area.
  88. * It supports following arrangements:
  89. * MMMS MMMM SMMM
  90. * MMMS MMMM SMMM
  91. * MMMS SSSS SMMM
  92. */
  93. void
  94. dotile(Arg *arg) {
  95. int h, i, n, w;
  96. Client *c;
  97. for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
  98. n++;
  99. if(isvertical) {
  100. if(stackpos == StackBottom) {
  101. w = sw;
  102. if(n > 1)
  103. h = (sh - bh) / (n - 1);
  104. else
  105. h = sh - bh;
  106. }
  107. else {
  108. w = sw - master;
  109. if(n > 1)
  110. h = (sh - bh) / (n - 1);
  111. else
  112. h = sh - bh;
  113. }
  114. }
  115. else { /* horizontal stack */
  116. }
  117. for(i = 0, c = clients; c; c = c->next) {
  118. if(isvisible(c)) {
  119. if(c->isfloat) {
  120. resize(c, True, TopLeft);
  121. continue;
  122. }
  123. c->ismax = False;
  124. if(n == 1) {
  125. c->x = sx;
  126. c->y = sy + bh;
  127. c->w = sw - 2 * BORDERPX;
  128. c->h = sh - 2 * BORDERPX - bh;
  129. }
  130. else if(i == 0) {
  131. c->x = sx;
  132. c->y = sy + bh;
  133. c->w = master - 2 * BORDERPX;
  134. c->h = sh - 2 * BORDERPX - bh;
  135. }
  136. else if(h > bh) {
  137. c->x = sx + master;
  138. c->y = sy + (i - 1) * h + bh;
  139. c->w = w - 2 * BORDERPX;
  140. if(i + 1 == n)
  141. c->h = sh - c->y - 2 * BORDERPX;
  142. else
  143. c->h = h - 2 * BORDERPX;
  144. }
  145. else { /* fallback if h < bh */
  146. c->x = sx + master;
  147. c->y = sy + bh;
  148. c->w = w - 2 * BORDERPX;
  149. c->h = sh - 2 * BORDERPX - bh;
  150. }
  151. resize(c, False, TopLeft);
  152. i++;
  153. }
  154. else
  155. ban(c);
  156. }
  157. if(!sel || !isvisible(sel)) {
  158. for(c = stack; c && !isvisible(c); c = c->snext);
  159. focus(c);
  160. }
  161. restack();
  162. }
  163. void
  164. focusnext(Arg *arg) {
  165. Client *c;
  166. if(!sel)
  167. return;
  168. if(!(c = getnext(sel->next)))
  169. c = getnext(clients);
  170. if(c) {
  171. focus(c);
  172. restack();
  173. }
  174. }
  175. void
  176. focusprev(Arg *arg) {
  177. Client *c;
  178. if(!sel)
  179. return;
  180. if(!(c = getprev(sel->prev))) {
  181. for(c = clients; c && c->next; c = c->next);
  182. c = getprev(c);
  183. }
  184. if(c) {
  185. focus(c);
  186. restack();
  187. }
  188. }
  189. Bool
  190. isvisible(Client *c) {
  191. unsigned int i;
  192. for(i = 0; i < ntags; i++)
  193. if(c->tags[i] && seltag[i])
  194. return True;
  195. return False;
  196. }
  197. void
  198. resizecol(Arg *arg) {
  199. unsigned int n;
  200. Client *c;
  201. for(n = 0, c = clients; c; c = c->next)
  202. if(isvisible(c) && !c->isfloat)
  203. n++;
  204. if(!sel || sel->isfloat || n < 2 || (arrange == dofloat))
  205. return;
  206. if(sel == getnext(clients)) {
  207. if(master + arg->i > sw - 100 || master + arg->i < 100)
  208. return;
  209. master += arg->i;
  210. }
  211. else {
  212. if(master - arg->i > sw - 100 || master - arg->i < 100)
  213. return;
  214. master -= arg->i;
  215. }
  216. arrange(NULL);
  217. }
  218. void
  219. restack(void) {
  220. Client *c;
  221. XEvent ev;
  222. if(!sel) {
  223. drawstatus();
  224. return;
  225. }
  226. if(sel->isfloat || arrange == dofloat) {
  227. XRaiseWindow(dpy, sel->win);
  228. XRaiseWindow(dpy, sel->twin);
  229. }
  230. if(arrange != dofloat)
  231. for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
  232. XLowerWindow(dpy, c->twin);
  233. XLowerWindow(dpy, c->win);
  234. }
  235. drawall();
  236. XSync(dpy, False);
  237. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  238. }
  239. void
  240. togglemode(Arg *arg) {
  241. arrange = (arrange == dofloat) ? dotile : dofloat;
  242. if(sel)
  243. arrange(NULL);
  244. else
  245. drawstatus();
  246. }
  247. void
  248. toggleview(Arg *arg) {
  249. unsigned int i;
  250. seltag[arg->i] = !seltag[arg->i];
  251. for(i = 0; i < ntags && !seltag[i]; i++);
  252. if(i == ntags)
  253. seltag[arg->i] = True; /* cannot toggle last view */
  254. reorder();
  255. arrange(NULL);
  256. }
  257. void
  258. view(Arg *arg) {
  259. unsigned int i;
  260. for(i = 0; i < ntags; i++)
  261. seltag[i] = False;
  262. seltag[arg->i] = True;
  263. reorder();
  264. arrange(NULL);
  265. }
  266. void
  267. viewall(Arg *arg) {
  268. unsigned int i;
  269. for(i = 0; i < ntags; i++)
  270. seltag[i] = True;
  271. reorder();
  272. arrange(NULL);
  273. }
  274. void
  275. zoom(Arg *arg) {
  276. unsigned int n;
  277. Client *c;
  278. if(!sel)
  279. return;
  280. if(sel->isfloat || (arrange == dofloat)) {
  281. togglemax(sel);
  282. return;
  283. }
  284. for(n = 0, c = clients; c; c = c->next)
  285. if(isvisible(c) && !c->isfloat)
  286. n++;
  287. if(n < 2 || (arrange == dofloat))
  288. return;
  289. if((c = sel) == nexttiled(clients))
  290. if(!(c = nexttiled(c->next)))
  291. return;
  292. detach(c);
  293. if(clients)
  294. clients->prev = c;
  295. c->next = clients;
  296. clients = c;
  297. focus(c);
  298. arrange(NULL);
  299. }