layouts.c 806 B

12345678910111213141516171819202122232425262728
  1. void
  2. grid(Monitor *m) {
  3. unsigned int i, n, cx, cy, cw, ch, aw, ah, cols, rows;
  4. Client *c;
  5. for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next))
  6. n++;
  7. /* grid dimensions */
  8. for(rows = 0; rows <= n/2; rows++)
  9. if(rows*rows >= n)
  10. break;
  11. cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows;
  12. /* window geoms (cell height/width) */
  13. ch = m->wh / (rows ? rows : 1);
  14. cw = m->ww / (cols ? cols : 1);
  15. for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
  16. cx = m->wx + (i / rows) * cw;
  17. cy = m->wy + (i % rows) * ch;
  18. /* adjust height/width of last row/column's windows */
  19. ah = ((i + 1) % rows == 0) ? m->wh - ch * rows : 0;
  20. aw = (i >= rows * (cols - 1)) ? m->ww - cw * cols : 0;
  21. resize(c, cx, cy, cw - 2 * c->bw + aw, ch - 2 * c->bw + ah, False);
  22. i++;
  23. }
  24. }