]> Dogcows Code - chaz/openbox/blobdiff - openbox/moveresize.c
don't resist in orthoganal directions when key resizing windows with aspect ratios
[chaz/openbox] / openbox / moveresize.c
index c0ddcca89ef4ef29c0a0f44a967eb29a3a77acd3..dd0605c692a249da7d8443e0e4a7bb4e24d963b4 100644 (file)
@@ -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;
This page took 0.025638 seconds and 4 git commands to generate.