+/* Tile all windows in the given display
+ * This performs all the actual window tiling
+ * Currently supports split, stack and maximized modes */
+static void wm_update_dpy(dpy_t *dpy)
+{
+ int x=0, y=0; // Current window top-left position
+ int tx=0, ty=0; // Total size (sum of initial col widths and row heights w/o margin)
+ int mx=0, my=0; // Maximum usable size (screen size minus margins)
+ int sy=0; // Stack size (height of focused stack window)
+
+ /* Scale horizontally */
+ x = dpy->geom->x;
+ mx = dpy->geom->w - (list_length(dpy->cols)+1)*MARGIN;
+ for (list_t *lcol = dpy->cols; lcol; lcol = lcol->next)
+ tx += COL(lcol)->width;
+ for (list_t *lcol = dpy->cols; lcol; lcol = lcol->next)
+ COL(lcol)->width *= (float)mx / tx;
+
+ /* Scale each column vertically */
+ for (list_t *lcol = dpy->cols; lcol; lcol = lcol->next) {
+ col_t *col = lcol->data;
+ int nrows = list_length(col->rows);
+ ty = 0;
+ for (list_t *lrow = col->rows; lrow; lrow = lrow->next)
+ ty += ROW(lrow)->height;
+ y = dpy->geom->y;
+ my = dpy->geom->h - (MARGIN + (nrows-1)* MARGIN + MARGIN);
+ sy = dpy->geom->h - (MARGIN + (nrows-1)*(MARGIN/2) + MARGIN)
+ - (nrows-1)* STACK;
+ for (list_t *lrow = col->rows; lrow; lrow = lrow->next) {
+ win_t *win = ROW(lrow)->win;
+ win->h = ROW(lrow)->height;
+ int height = 0;
+ switch (col->mode) {
+ case split:
+ sys_move(win, x+MARGIN, y+MARGIN,
+ col->width, win->h * ((float)my / ty));
+ height = win->h;
+ y += height + MARGIN;
+ break;
+ case stack:
+ if (lrow->next && ROW(lrow->next)->win == col->row->win) {
+ /* Hack to prevent flashing */
+ win_t *next = ROW(lrow->next)->win;
+ sys_move(next, x+MARGIN, y+MARGIN+STACK+MARGIN/2,
+ col->width, sy);
+ }
+ height = win == col->row->win ? sy : STACK;
+ sys_move(win, x+MARGIN, y+MARGIN,
+ col->width, height);
+ y += height + (MARGIN/2);
+ break;
+ case max:
+ case tab:
+ sys_move(win, x+MARGIN, 0+MARGIN,
+ col->width, dpy->geom->h-2*MARGIN);
+ if (col->row->win == win)
+ sys_raise(win);
+ break;
+ }
+ ROW(lrow)->height = win->h;
+ }
+ x += col->width + MARGIN;
+ }
+}
+
+/*******************************
+ * Window management functions *
+ *******************************/