Another copy of my dotfiles. Because I don't completely trust GitHub.
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.

98 lines
2.2 KiB

  1. #if VANITYGAPS_PATCH
  2. void
  3. gaplessgrid(Monitor *m)
  4. {
  5. unsigned int i, n;
  6. int x, y, cols, rows, ch, cw, cn, rn, rrest, crest; // counters
  7. int oh, ov, ih, iv;
  8. Client *c;
  9. getgaps(m, &oh, &ov, &ih, &iv, &n);
  10. if (n == 0)
  11. return;
  12. /* grid dimensions */
  13. for (cols = 0; cols <= n/2; cols++)
  14. if (cols*cols >= n)
  15. break;
  16. if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
  17. cols = 2;
  18. rows = n/cols;
  19. cn = rn = 0; // reset column no, row no, client count
  20. ch = (m->wh - 2*oh - ih * (rows - 1)) / rows;
  21. cw = (m->ww - 2*ov - iv * (cols - 1)) / cols;
  22. rrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
  23. crest = (m->ww - 2*ov - iv * (cols - 1)) - cw * cols;
  24. x = m->wx + ov;
  25. y = m->wy + oh;
  26. for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
  27. if (i/rows + 1 > cols - n%cols) {
  28. rows = n/cols + 1;
  29. ch = (m->wh - 2*oh - ih * (rows - 1)) / rows;
  30. rrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
  31. }
  32. resize(c,
  33. x,
  34. y + rn*(ch + ih) + MIN(rn, rrest),
  35. cw + (cn < crest ? 1 : 0) - 2*c->bw,
  36. ch + (rn < rrest ? 1 : 0) - 2*c->bw,
  37. 0);
  38. rn++;
  39. if (rn >= rows) {
  40. rn = 0;
  41. x += cw + ih + (cn < crest ? 1 : 0);
  42. cn++;
  43. }
  44. }
  45. }
  46. #else
  47. void
  48. gaplessgrid(Monitor *m)
  49. {
  50. unsigned int i, n;
  51. int x, y, cols, rows, ch, cw, cn, rn, rrest, crest; // counters
  52. Client *c;
  53. for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
  54. if (n == 0)
  55. return;
  56. /* grid dimensions */
  57. for (cols = 0; cols <= n/2; cols++)
  58. if (cols*cols >= n)
  59. break;
  60. if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
  61. cols = 2;
  62. rows = n/cols;
  63. cn = rn = 0; // reset column no, row no, client count
  64. ch = m->wh / rows;
  65. cw = m->ww / cols;
  66. rrest = m->wh - ch * rows;
  67. crest = m->ww - cw * cols;
  68. x = m->wx;
  69. y = m->wy;
  70. for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
  71. if (i/rows + 1 > cols - n%cols) {
  72. rows = n/cols + 1;
  73. ch = m->wh / rows;
  74. rrest = m->wh - ch * rows;
  75. }
  76. resize(c,
  77. x,
  78. y + rn*ch + MIN(rn, rrest),
  79. cw + (cn < crest ? 1 : 0) - 2*c->bw,
  80. ch + (rn < rrest ? 1 : 0) - 2*c->bw,
  81. 0);
  82. rn++;
  83. if (rn >= rows) {
  84. rn = 0;
  85. x += cw + (cn < crest ? 1 : 0);
  86. cn++;
  87. }
  88. }
  89. }
  90. #endif