gaplessgrid.c 851 B

1234567891011121314151617181920212223242526272829303132333435
  1. void
  2. gaplessgrid(Monitor *m) {
  3. unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
  4. Client *c;
  5. for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ;
  6. if(n == 0)
  7. return;
  8. /* grid dimensions */
  9. for(cols = 0; cols <= n/2; cols++)
  10. if(cols*cols >= n)
  11. break;
  12. if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
  13. cols = 2;
  14. rows = n/cols;
  15. /* window geometries */
  16. cw = cols ? m->ww / cols : m->ww;
  17. cn = 0; /* current column number */
  18. rn = 0; /* current row number */
  19. for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
  20. if(i/rows + 1 > cols - n%cols)
  21. rows = n/cols + 1;
  22. ch = rows ? m->wh / rows : m->wh;
  23. cx = m->wx + cn*cw;
  24. cy = m->wy + rn*ch;
  25. resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False);
  26. rn++;
  27. if(rn >= rows) {
  28. rn = 0;
  29. cn++;
  30. }
  31. }
  32. }