comparison layout.c @ 5:e060ab82b136

gapless grid
author paulo@thepaulopc
date Wed, 27 Jan 2010 23:28:29 -0800
parents faa4cb9d7bd6
children 162accc5d36d
comparison
equal deleted inserted replaced
2:49d41869cdb0 3:a2dde5f412d7
220 restack(); 220 restack();
221 } 221 }
222 222
223 static void 223 static void
224 grid(void) { 224 grid(void) {
225 unsigned int i, n, nx, ny, nw, nh, aw, ah, tw, th, cols, rows; 225 unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
226 Client *c; 226 Client *c;
227 227
228 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) 228 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
229 n++; 229 n++;
230 if(n == 0)
231 return;
230 232
231 for(rows = 0; rows <= n/2; rows++) 233 /* grid dimensions */
232 if(rows*rows >= n) 234 for(cols = 0; cols <= n/2; cols++)
235 if(cols*cols >= n)
233 break; 236 break;
234 cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows; 237 if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
238 cols = 2;
239 rows = n/cols;
235 240
236 th = wah / (rows ? rows : 1); 241 /* window geometries */
237 tw = waw / (cols ? cols : 1); 242 cw = cols ? waw / cols : waw;
238 nw = tw - 2 * BORDERPX; 243 cn = 0; /* current column number */
239 nh = th - 2 * BORDERPX; 244 rn = 0; /* current row number */
240 245 for(i = 0, c = clients; c; c = c->next)
241 for(i = 0, c = clients; c; c = c->next) 246 if(isvisible(c)) {
242 if(isvisible(c)) { 247 if(i/rows + 1 > cols - n%cols)
243 if(c->isbanned) 248 rows = n/cols + 1;
244 XMoveWindow(dpy, c->win, c->x, c->y); 249 ch = rows ? wah / rows : wah;
245 c->isbanned = False; 250 cx = cn*cw;
246 if(c->isversatile) 251 cy = (TOPBAR ? dc.h : 0) + rn*ch;
247 continue; 252 resize(c, cx, cy, cw - 2 * BORDERPX, ch - 2 * BORDERPX, False);
248 c->ismax = False; 253 rn++;
249 nx = (i / rows) * tw; 254 if(rn >= rows) {
250 ny = (i % rows) * th + (TOPBAR ? dc.h : 0); 255 rn = 0;
251 /* adjust height and width of last row's and last column's windows */ 256 cn++;
252 ah = ((i + 1) % rows == 0) ? wah - th * rows : 0; 257 }
253 aw = (i >= rows * (cols - 1)) ? waw - tw * cols : 0;
254 resize(c, nx, ny, nw + aw, nh + ah, False);
255 i++; 258 i++;
256 } 259 }
257 else { 260 else {
258 c->isbanned = True; 261 c->isbanned = True;
259 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); 262 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
260 } 263 }
261 264
262 if(!sel || !isvisible(sel)) { 265 if(!sel || !isvisible(sel)) {
263 for(c = stack; c && !isvisible(c); c = c->snext); 266 for(c = stack; c && !isvisible(c); c = c->snext);
264 focus(c); 267 focus(c);
265 } 268 }
266 restack(); 269 restack();