]> Dogcows Code - chaz/openbox/blobdiff - openbox/moveresize.c
let you resize aspect ratio windows in north and south directions, and make them...
[chaz/openbox] / openbox / moveresize.c
index c0ddcca89ef4ef29c0a0f44a967eb29a3a77acd3..b93871ba401fa094814728ae79656abb8e601eab 100644 (file)
@@ -374,12 +374,47 @@ 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 (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;
+    g_print("trydw %d trydh %d\n", trydw, trydh);
+
     /* resist_size_* needs the frame size */
     nw += moveresize_client->frame->size.left +
         moveresize_client->frame->size.right;
@@ -400,7 +435,31 @@ 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 (*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.024993 seconds and 4 git commands to generate.