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.

134 lines
2.6 KiB

  1. /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
  2. * See LICENSE file for license details.
  3. */
  4. #include "dwm.h"
  5. unsigned int master = MASTER;
  6. unsigned int nmaster = NMASTER;
  7. /* static */
  8. static void
  9. togglemax(Client *c) {
  10. XEvent ev;
  11. if(c->isfixed)
  12. return;
  13. if((c->ismax = !c->ismax)) {
  14. c->rx = c->x;
  15. c->ry = c->y;
  16. c->rw = c->w;
  17. c->rh = c->h;
  18. resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
  19. }
  20. else
  21. resize(c, c->rx, c->ry, c->rw, c->rh, True);
  22. while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
  23. }
  24. /* extern */
  25. void
  26. dotile(void) {
  27. unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
  28. Client *c;
  29. for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next))
  30. n++;
  31. /* window geoms */
  32. mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
  33. mw = (n > nmaster) ? (waw * master) / 1000 : waw;
  34. th = (n > nmaster) ? wah / (n - nmaster) : 0;
  35. tw = waw - mw;
  36. for(i = 0, c = clients; c; c = c->next)
  37. if(isvisible(c)) {
  38. if(c->isbanned)
  39. XMoveWindow(dpy, c->win, c->x, c->y);
  40. c->isbanned = False;
  41. if(c->isfloat)
  42. continue;
  43. c->ismax = False;
  44. nx = wax;
  45. ny = way;
  46. if(i < nmaster) {
  47. ny += i * mh;
  48. nw = mw - 2 * BORDERPX;
  49. nh = mh - 2 * BORDERPX;
  50. }
  51. else { /* tile window */
  52. nx += mw;
  53. nw = tw - 2 * BORDERPX;
  54. if(th > 2 * BORDERPX) {
  55. ny += (i - nmaster) * th;
  56. nh = th - 2 * BORDERPX;
  57. }
  58. else /* fallback if th <= 2 * BORDERPX */
  59. nh = wah - 2 * BORDERPX;
  60. }
  61. resize(c, nx, ny, nw, nh, False);
  62. i++;
  63. }
  64. else {
  65. c->isbanned = True;
  66. XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
  67. }
  68. if(!sel || !isvisible(sel)) {
  69. for(c = stack; c && !isvisible(c); c = c->snext);
  70. focus(c);
  71. }
  72. restack();
  73. }
  74. void
  75. incnmaster(Arg *arg) {
  76. if((arrange == dofloat) || (nmaster + arg->i < 1)
  77. || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
  78. return;
  79. nmaster += arg->i;
  80. if(sel)
  81. arrange();
  82. else
  83. drawstatus();
  84. }
  85. void
  86. resizemaster(Arg *arg) {
  87. if(arrange != dotile)
  88. return;
  89. if(arg->i == 0)
  90. master = MASTER;
  91. else {
  92. if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
  93. || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
  94. return;
  95. master += arg->i;
  96. }
  97. arrange();
  98. }
  99. void
  100. zoom(Arg *arg) {
  101. unsigned int n;
  102. Client *c;
  103. if(!sel)
  104. return;
  105. if(sel->isfloat || (arrange == dofloat)) {
  106. togglemax(sel);
  107. return;
  108. }
  109. for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next))
  110. n++;
  111. if((c = sel) == nextmanaged(clients))
  112. if(!(c = nextmanaged(c->next)))
  113. return;
  114. detach(c);
  115. if(clients)
  116. clients->prev = c;
  117. c->next = clients;
  118. clients = c;
  119. focus(c);
  120. arrange();
  121. }