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.

103 lines
1.9 KiB

  1. /* See LICENSE file for copyright and license details. */
  2. double mfact = MFACT;
  3. int bx, by, bw, bh, blw, mx, my, mw, mh, tx, ty, tw, th, wx, wy, ww, wh;
  4. void setmfact(const char *arg);
  5. void tile(void);
  6. void tileresize(Client *c, int x, int y, int w, int h);
  7. void updatetilegeom(void);
  8. void
  9. setmfact(const char *arg) {
  10. double d;
  11. if(lt->arrange != tile)
  12. return;
  13. if(!arg)
  14. mfact = MFACT;
  15. else {
  16. d = strtod(arg, NULL);
  17. if(arg[0] == '-' || arg[0] == '+')
  18. d += mfact;
  19. if(d < 0.1 || d > 0.9)
  20. return;
  21. mfact = d;
  22. }
  23. updategeom();
  24. arrange();
  25. }
  26. void
  27. tile(void) {
  28. int y, h;
  29. unsigned int i, n;
  30. Client *c;
  31. for(n = 0, c = nextunfloating(clients); c; c = nextunfloating(c->next), n++);
  32. if(n == 0)
  33. return;
  34. /* master */
  35. c = nextunfloating(clients);
  36. if(n == 1)
  37. tileresize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw);
  38. else
  39. tileresize(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw);
  40. if(--n == 0)
  41. return;
  42. /* tile stack */
  43. y = ty;
  44. h = th / n;
  45. if(h < bh)
  46. h = th;
  47. for(i = 0, c = nextunfloating(c->next); c; c = nextunfloating(c->next), i++) {
  48. if(i + 1 == n) /* remainder */
  49. tileresize(c, tx, y, tw - 2 * c->bw, (ty + th) - y - 2 * c->bw);
  50. else
  51. tileresize(c, tx, y, tw - 2 * c->bw, h - 2 * c->bw);
  52. if(h != th)
  53. y = c->y + c->h + 2 * c->bw;
  54. }
  55. }
  56. void
  57. tileresize(Client *c, int x, int y, int w, int h) {
  58. resize(c, x, y, w, h, RESIZEHINTS);
  59. if((RESIZEHINTS) && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w)))
  60. /* client doesn't accept size constraints */
  61. resize(c, x, y, w, h, False);
  62. }
  63. void
  64. zoom(const char *arg) {
  65. Client *c = sel;
  66. if(c == nextunfloating(clients))
  67. if(!c || !(c = nextunfloating(c->next)))
  68. return;
  69. if(lt->arrange == tile && !sel->isfloating) {
  70. detach(c);
  71. attach(c);
  72. focus(c);
  73. }
  74. arrange();
  75. }
  76. void
  77. updatetilegeom(void) {
  78. /* master area geometry */
  79. mx = wx;
  80. my = wy;
  81. mw = mfact * ww;
  82. mh = wh;
  83. /* tile area geometry */
  84. tx = mx + mw;
  85. ty = wy;
  86. tw = ww - mw;
  87. th = wh;
  88. }