]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: Make the 'resize' command work inside tabbed/stacked cons (+test) (Thanks...
authorMichael Stapelberg <michael@stapelberg.de>
Wed, 24 Aug 2011 13:14:04 +0000 (15:14 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 24 Aug 2011 13:14:04 +0000 (15:14 +0200)
Fixes #461

src/cmdparse.y
testcases/t/41-resize.t

index d271c997b756a47ce19277618c285dc90254ca1b..c9e9fc7c71e39898710059fbc3bde062dde2e409 100644 (file)
@@ -799,39 +799,44 @@ resize:
             }
         } else {
             LOG("tiling 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;
             /* get the default percentage */
-            int children = con_num_children(focused->parent);
+            int children = con_num_children(current->parent);
             Con *other;
             LOG("ins. %d children\n", children);
             double percentage = 1.0 / children;
             LOG("default percentage = %f\n", percentage);
 
             if (direction == TOK_UP || direction == TOK_LEFT) {
-                other = TAILQ_PREV(focused, nodes_head, nodes);
+                other = TAILQ_PREV(current, nodes_head, nodes);
             } else {
-                other = TAILQ_NEXT(focused, nodes);
+                other = TAILQ_NEXT(current, nodes);
             }
             if (other == TAILQ_END(workspaces)) {
                 LOG("No other container in this direction found, cannot resize.\n");
                 return 0;
             }
             LOG("other->percent = %f\n", other->percent);
-            LOG("focused->percent before = %f\n", focused->percent);
-            if (focused->percent == 0.0)
-                focused->percent = percentage;
+            LOG("current->percent before = %f\n", current->percent);
+            if (current->percent == 0.0)
+                current->percent = percentage;
             if (other->percent == 0.0)
                 other->percent = percentage;
-            double new_focused_percent = focused->percent + ((double)ppt / 100.0);
+            double new_current_percent = current->percent + ((double)ppt / 100.0);
             double new_other_percent = other->percent - ((double)ppt / 100.0);
-            LOG("new_focused_percent = %f\n", new_focused_percent);
+            LOG("new_current_percent = %f\n", new_current_percent);
             LOG("new_other_percent = %f\n", new_other_percent);
             /* Ensure that the new percentages are positive and greater than
              * 0.05 to have a reasonable minimum size. */
-            if (definitelyGreaterThan(new_focused_percent, 0.05, DBL_EPSILON) &&
+            if (definitelyGreaterThan(new_current_percent, 0.05, DBL_EPSILON) &&
                 definitelyGreaterThan(new_other_percent, 0.05, DBL_EPSILON)) {
-                focused->percent += ((double)ppt / 100.0);
+                current->percent += ((double)ppt / 100.0);
                 other->percent -= ((double)ppt / 100.0);
-                LOG("focused->percent after = %f\n", focused->percent);
+                LOG("current->percent after = %f\n", current->percent);
                 LOG("other->percent after = %f\n", other->percent);
             } else {
                 LOG("Not resizing, already at minimum size\n");
index 33f4889caf2cc37e7b3ee930079fd48585067161..1d1b1206667c42de6c1ce04566535b87609780d5 100644 (file)
@@ -46,6 +46,32 @@ cmd 'split h';
 is($nodes->[0]->{percent}, 0.25, 'top window got only 25%');
 is($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');
 
+############################################################
+# checks that resizing within stacked/tabbed cons works
+############################################################
+
+$tmp = fresh_workspace;
+
+cmd 'split v';
+
+$top = open_standard_window($x);
+sleep 0.25;
+$bottom = open_standard_window($x);
+sleep 0.25;
+
+cmd 'split h';
+cmd 'layout stacked';
+
+($nodes, $focus) = get_ws_content($tmp);
+is($nodes->[0]->{percent}, 0.5, 'top window got 50%');
+is($nodes->[1]->{percent}, 0.5, 'bottom window got 50%');
+
+cmd 'resize grow up 10 px or 25 ppt';
+
+($nodes, $focus) = get_ws_content($tmp);
+is($nodes->[0]->{percent}, 0.25, 'top window got 25%');
+is($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');
+
 ############################################################
 # checks that resizing floating windows works
 ############################################################