Bugfix: Make the 'resize' command work inside tabbed/stacked cons (+test) (Thanks sbedivere)

Fixes #461
This commit is contained in:
Michael Stapelberg 2011-08-24 15:14:04 +02:00
parent 16f9c9aee7
commit 0d35feb71b
2 changed files with 42 additions and 11 deletions

View File

@ -799,39 +799,44 @@ resize:
} }
} else { } else {
LOG("tiling resize\n"); 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 */ /* get the default percentage */
int children = con_num_children(focused->parent); int children = con_num_children(current->parent);
Con *other; Con *other;
LOG("ins. %d children\n", children); LOG("ins. %d children\n", children);
double percentage = 1.0 / children; double percentage = 1.0 / children;
LOG("default percentage = %f\n", percentage); LOG("default percentage = %f\n", percentage);
if (direction == TOK_UP || direction == TOK_LEFT) { if (direction == TOK_UP || direction == TOK_LEFT) {
other = TAILQ_PREV(focused, nodes_head, nodes); other = TAILQ_PREV(current, nodes_head, nodes);
} else { } else {
other = TAILQ_NEXT(focused, nodes); other = TAILQ_NEXT(current, nodes);
} }
if (other == TAILQ_END(workspaces)) { if (other == TAILQ_END(workspaces)) {
LOG("No other container in this direction found, cannot resize.\n"); LOG("No other container in this direction found, cannot resize.\n");
return 0; return 0;
} }
LOG("other->percent = %f\n", other->percent); LOG("other->percent = %f\n", other->percent);
LOG("focused->percent before = %f\n", focused->percent); LOG("current->percent before = %f\n", current->percent);
if (focused->percent == 0.0) if (current->percent == 0.0)
focused->percent = percentage; current->percent = percentage;
if (other->percent == 0.0) if (other->percent == 0.0)
other->percent = percentage; 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); 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); LOG("new_other_percent = %f\n", new_other_percent);
/* Ensure that the new percentages are positive and greater than /* Ensure that the new percentages are positive and greater than
* 0.05 to have a reasonable minimum size. */ * 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)) { 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); 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); LOG("other->percent after = %f\n", other->percent);
} else { } else {
LOG("Not resizing, already at minimum size\n"); LOG("Not resizing, already at minimum size\n");

View File

@ -46,6 +46,32 @@ cmd 'split h';
is($nodes->[0]->{percent}, 0.25, 'top window got only 25%'); is($nodes->[0]->{percent}, 0.25, 'top window got only 25%');
is($nodes->[1]->{percent}, 0.75, 'bottom window got 75%'); 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 # checks that resizing floating windows works
############################################################ ############################################################