]> git.sur5r.net Git - i3/i3/commitdiff
Make the resize command honor criteria (Thanks Tblue)
authorMichael Stapelberg <michael@stapelberg.de>
Fri, 28 Sep 2012 18:36:25 +0000 (20:36 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Fri, 28 Sep 2012 18:36:25 +0000 (20:36 +0200)
fixes #816

src/commands.c
testcases/t/141-resize.t

index 607e1c11dbaae0b42ba4a75b6eb7d43d61a1e174..070f635373971d56d2ad079e9e3786c6f05dd32b 100644 (file)
@@ -575,10 +575,9 @@ static void cmd_resize_floating(I3_CMD, char *way, char *direction, Con *floatin
     }
 }
 
-static bool cmd_resize_tiling_direction(I3_CMD, char *way, char *direction, int ppt) {
+static bool cmd_resize_tiling_direction(I3_CMD, Con *current, char *way, char *direction, int ppt) {
     LOG("tiling resize\n");
     /* get the appropriate current container (skip stacked/tabbed cons) */
-    Con *current = focused;
     Con *other = NULL;
     double percentage = 0;
     while (current->parent->layout == L_STACKED ||
@@ -658,10 +657,9 @@ static bool cmd_resize_tiling_direction(I3_CMD, char *way, char *direction, int
     return true;
 }
 
-static bool cmd_resize_tiling_width_height(I3_CMD, char *way, char *direction, int ppt) {
+static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, char *way, char *direction, int ppt) {
     LOG("width/height resize\n");
     /* get the appropriate current container (skip stacked/tabbed cons) */
-    Con *current = focused;
     while (current->parent->layout == L_STACKED ||
            current->parent->layout == L_TABBED)
         current = current->parent;
@@ -756,17 +754,22 @@ void cmd_resize(I3_CMD, char *way, char *direction, char *resize_px, char *resiz
         ppt *= -1;
     }
 
-    Con *floating_con;
-    if ((floating_con = con_inside_floating(focused))) {
-        cmd_resize_floating(current_match, cmd_output, way, direction, floating_con, px);
-    } else {
-        if (strcmp(direction, "width") == 0 ||
-            strcmp(direction, "height") == 0) {
-            if (!cmd_resize_tiling_width_height(current_match, cmd_output, way, direction, ppt))
-                return;
+    HANDLE_EMPTY_MATCH;
+
+    owindow *current;
+    TAILQ_FOREACH(current, &owindows, owindows) {
+        Con *floating_con;
+        if ((floating_con = con_inside_floating(current->con))) {
+            cmd_resize_floating(current_match, cmd_output, way, direction, floating_con, px);
         } else {
-            if (!cmd_resize_tiling_direction(current_match, cmd_output, way, direction, ppt))
-                return;
+            if (strcmp(direction, "width") == 0 ||
+                strcmp(direction, "height") == 0) {
+                if (!cmd_resize_tiling_width_height(current_match, cmd_output, current->con, way, direction, ppt))
+                    return;
+            } else {
+                if (!cmd_resize_tiling_direction(current_match, cmd_output, current->con, way, direction, ppt))
+                    return;
+            }
         }
     }
 
index e038a87b1647fe41915e6672e34e714a18841f4e..97315c3deb2f5876f404f41058bf42af54db9db9 100644 (file)
@@ -255,4 +255,38 @@ cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y the same as before');
 cmp_ok($content[0]->{rect}->{height}, '<', $oldrect->{height}, 'height smaller than before');
 cmp_ok($content[0]->{rect}->{width}, '==', $oldrect->{width}, 'width the same as before');
 
+################################################################################
+# Check that resizing with criteria works
+################################################################################
+
+$tmp = fresh_workspace;
+
+my $left = open_floating_window;
+my $right = open_floating_window;
+
+sub get_floating_rect {
+    my ($window_id) = @_;
+
+    my $floating_nodes = get_ws($tmp)->{floating_nodes};
+    for my $floating_node (@$floating_nodes) {
+        # Get all the windows within that floating container
+        my @window_ids = map { $_->{window} } @{$floating_node->{nodes}};
+        if ($window_id ~~ @window_ids) {
+            return $floating_node->{rect};
+        }
+    }
+
+    return undef;
+}
+
+# focus is on the right window, so we resize the left one using criteria
+my $leftold = get_floating_rect($left->id);
+my $rightold = get_floating_rect($right->id);
+cmd '[id="' . $left->id . '"] resize shrink height 10px or 10ppt';
+
+my $leftnew = get_floating_rect($left->id);
+my $rightnew = get_floating_rect($right->id);
+is($rightnew->{height}, $rightold->{height}, 'height of right container unchanged');
+is($leftnew->{height}, $leftold->{height} - 10, 'height of left container changed');
+
 done_testing;