X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fmoveresize.c;h=dd0605c692a249da7d8443e0e4a7bb4e24d963b4;hb=098ae047f89f23d888f26425f7c5f77b75437d91;hp=c0ddcca89ef4ef29c0a0f44a967eb29a3a77acd3;hpb=019e80355920a29fb1b6c800b268004e8573c98a;p=chaz%2Fopenbox diff --git a/openbox/moveresize.c b/openbox/moveresize.c index c0ddcca8..dd0605c6 100644 --- a/openbox/moveresize.c +++ b/openbox/moveresize.c @@ -374,12 +374,49 @@ static void calc_resize(gboolean keyboard, gint keydist, gint *dw, gint *dh, ObDirection dir) { gint resist, x = 0, y = 0, lw, lh, ow, oh, nw, nh; + gint trydw, trydh; ow = cur_w; oh = cur_h; nw = ow + *dw; nh = oh + *dh; + if (!keyboard && + (moveresize_client->max_ratio || moveresize_client->min_ratio)) + { + switch (dir) { + case OB_DIRECTION_NORTH: + case OB_DIRECTION_SOUTH: + /* resize the width based on the height */ + if (moveresize_client->min_ratio) { + if (nh * moveresize_client->min_ratio > nw) + nw = (gint)(nh * moveresize_client->min_ratio); + } + if (moveresize_client->max_ratio) { + if (nh * moveresize_client->max_ratio < nw) + nw = (gint)(nh * moveresize_client->max_ratio); + } + break; + default: + /* resize the height based on the width */ + if (moveresize_client->min_ratio) { + if (nh * moveresize_client->min_ratio > nw) + nh = (gint)(nw / moveresize_client->min_ratio); + } + if (moveresize_client->max_ratio) { + if (nh * moveresize_client->max_ratio < nw) + nh = (gint)(nw / moveresize_client->max_ratio); + } + break; + } + + /* see its actual size (apply aspect ratios) */ + client_try_configure(moveresize_client, &x, &y, &nw, &nh, &lw, &lh, + TRUE); + trydw = nw - ow; + trydh = nh - oh; + } + /* resist_size_* needs the frame size */ nw += moveresize_client->frame->size.left + moveresize_client->frame->size.right; @@ -400,7 +437,35 @@ static void calc_resize(gboolean keyboard, gint keydist, gint *dw, gint *dh, *dw = nw - ow; *dh = nh - oh; - /* make sure it's a valid size */ + /* take aspect ratios into account for resistance */ + if (!keyboard && + (moveresize_client->max_ratio || moveresize_client->min_ratio)) + { + if (*dh != trydh) { /* got resisted */ + /* resize the width based on the height */ + if (moveresize_client->min_ratio) { + if (nh * moveresize_client->min_ratio > nw) + nw = (gint)(nh * moveresize_client->min_ratio); + } + if (moveresize_client->max_ratio) { + if (nh * moveresize_client->max_ratio < nw) + nw = (gint)(nh * moveresize_client->max_ratio); + } + } + if (*dw != trydw) { /* got resisted */ + /* resize the height based on the width */ + if (moveresize_client->min_ratio) { + if (nh * moveresize_client->min_ratio > nw) + nh = (gint)(nw / moveresize_client->min_ratio); + } + if (moveresize_client->max_ratio) { + if (nh * moveresize_client->max_ratio < nw) + nh = (gint)(nw / moveresize_client->max_ratio); + } + } + } + + /* make sure it's all valid */ client_try_configure(moveresize_client, &x, &y, &nw, &nh, &lw, &lh, TRUE); *dw = nw - ow;