+ int tsx, tsy, ts;
+ /*
+ * Each window dimension equals the tile size times two more
+ * than the grid dimension (the border containing the arrows is
+ * the same width as the tiles), plus TILE_BORDER, plus twice
+ * WINDOW_OFFSET.
+ */
+ tsx = (*x - 2*WINDOW_OFFSET - TILE_BORDER) / (params->width + 2);
+ tsy = (*y - 2*WINDOW_OFFSET - TILE_BORDER) / (params->height + 2);
+ ts = min(tsx, tsy);
+
+ if (expand)
+ ds->tilesize = ts;
+ else
+ ds->tilesize = min(ts, PREFERRED_TILE_SIZE);
+