2007-09-05 20:15:00 +02:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
|
|
|
|
#include "grid.h"
|
|
|
|
#include "layout.h"
|
|
|
|
#include "tag.h"
|
|
|
|
|
|
|
|
extern int wah, waw; /* windowarea geometry */
|
|
|
|
extern int bh, bpos; /* bar height, bar position */
|
|
|
|
extern Client *clients; /* global client list and stack */
|
|
|
|
extern DC dc;
|
|
|
|
|
|
|
|
void
|
|
|
|
grid(Display *disp, jdwm_config *jdwmconf)
|
|
|
|
{
|
|
|
|
unsigned int i, n, cx, cy, cw, ch, aw, ah, cols, rows;
|
|
|
|
Client *c;
|
|
|
|
|
2007-09-06 20:02:30 +02:00
|
|
|
for(n = 0, c = clients; c; c = c->next)
|
|
|
|
if(IS_TILED(c, jdwmconf->selected_tags, jdwmconf->ntags))
|
|
|
|
n++;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
|
|
|
/* grid dimensions */
|
|
|
|
for(rows = 0; rows <= n / 2; rows++)
|
|
|
|
if(rows * rows >= n)
|
|
|
|
break;
|
|
|
|
cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows;
|
|
|
|
|
|
|
|
/* window geoms (cell height/width) */
|
|
|
|
ch = wah / (rows ? rows : 1);
|
|
|
|
cw = waw / (cols ? cols : 1);
|
|
|
|
|
|
|
|
for(i = 0, c = clients; c; c = c->next)
|
2007-09-06 19:05:26 +02:00
|
|
|
if(isvisible(c, jdwmconf->selected_tags, jdwmconf->ntags))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
unban(c);
|
|
|
|
if(c->isfloating)
|
|
|
|
continue;
|
|
|
|
c->ismax = False;
|
|
|
|
cx = (i / rows) * cw;
|
2007-09-05 20:39:11 +02:00
|
|
|
cy = (i % rows) * ch + (jdwmconf->current_bpos == BarTop ? bh : 0); // bh? adjust
|
2007-09-05 20:15:00 +02:00
|
|
|
/* adjust height/width of last row/column's windows */
|
|
|
|
ah = ((i + 1) % rows == 0) ? wah - ch * rows : 0;
|
|
|
|
aw = (i >= rows * (cols - 1)) ? waw - cw * cols : 0;
|
|
|
|
resize(c, cx, cy, cw - 2 * c->border + aw, ch - 2 * c->border + ah, False);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ban(c);
|
|
|
|
focus(disp, &dc, NULL, jdwmconf);
|
|
|
|
restack(disp, jdwmconf);
|
|
|
|
}
|