+ frame_frame_gravity(self->frame, x, y);
+
+ /* work within the preferred sizes given by the window, these may have
+ changed rather than it's requested width and height, so always run
+ through this code */
+ {
+ gint basew, baseh, minw, minh;
+ gint incw, inch;
+ gfloat minratio, maxratio;
+
+ incw = self->fullscreen || self->max_horz ? 1 : self->size_inc.width;
+ inch = self->fullscreen || self->max_vert ? 1 : self->size_inc.height;
+ minratio = self->fullscreen || (self->max_horz && self->max_vert) ?
+ 0 : self->min_ratio;
+ maxratio = self->fullscreen || (self->max_horz && self->max_vert) ?
+ 0 : self->max_ratio;
+
+ /* base size is substituted with min size if not specified */
+ if (self->base_size.width >= 0 || self->base_size.height >= 0) {
+ basew = self->base_size.width;
+ baseh = self->base_size.height;
+ } else {
+ basew = self->min_size.width;
+ baseh = self->min_size.height;
+ }
+ /* min size is substituted with base size if not specified */
+ if (self->min_size.width || self->min_size.height) {
+ minw = self->min_size.width;
+ minh = self->min_size.height;
+ } else {
+ minw = self->base_size.width;
+ minh = self->base_size.height;
+ }
+
+ /* This comment is no longer true */
+ /* if this is a user-requested resize, then check against min/max
+ sizes */
+
+ /* smaller than min size or bigger than max size? */
+ if (*w > self->max_size.width) *w = self->max_size.width;
+ if (*w < minw) *w = minw;
+ if (*h > self->max_size.height) *h = self->max_size.height;
+ if (*h < minh) *h = minh;
+
+ *w -= basew;
+ *h -= baseh;
+
+ /* keep to the increments */
+ *w /= incw;
+ *h /= inch;
+
+ /* you cannot resize to nothing */
+ if (basew + *w < 1) *w = 1 - basew;
+ if (baseh + *h < 1) *h = 1 - baseh;
+
+ /* save the logical size */
+ *logicalw = incw > 1 ? *w : *w + basew;
+ *logicalh = inch > 1 ? *h : *h + baseh;
+
+ *w *= incw;
+ *h *= inch;
+
+ *w += basew;
+ *h += baseh;
+
+ /* adjust the height to match the width for the aspect ratios.
+ for this, min size is not substituted for base size ever. */
+ *w -= self->base_size.width;
+ *h -= self->base_size.height;
+
+ if (minratio)
+ if (*h * minratio > *w) {
+ *h = (gint)(*w / minratio);
+
+ /* you cannot resize to nothing */
+ if (*h < 1) {
+ *h = 1;
+ *w = (gint)(*h * minratio);
+ }
+ }
+ if (maxratio)
+ if (*h * maxratio < *w) {
+ *h = (gint)(*w / maxratio);
+
+ /* you cannot resize to nothing */
+ if (*h < 1) {
+ *h = 1;
+ *w = (gint)(*h * minratio);
+ }
+ }
+
+ *w += self->base_size.width;
+ *h += self->base_size.height;
+ }