From: Orestis Floros Date: Thu, 23 Aug 2018 23:14:11 +0000 (+0300) Subject: Make cmd_resize_tiling_width_height work with pixels X-Git-Tag: 4.16~54^2~4 X-Git-Url: https://git.sur5r.net/?p=i3%2Fi3;a=commitdiff_plain;h=26bbaf62378dce6cb68c4e35454bc463a138131c Make cmd_resize_tiling_width_height work with pixels --- diff --git a/src/commands.c b/src/commands.c index 99c5368e..1f6d1daf 100644 --- a/src/commands.c +++ b/src/commands.c @@ -516,7 +516,7 @@ static bool cmd_resize_tiling_direction(I3_CMD, Con *current, const char *way, c return resize_neighboring_cons(first, second, px, ppt); } -static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *way, const char *direction, int ppt) { +static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *way, const char *direction, int px, int _ppt) { LOG("width/height resize\n"); /* get the appropriate current container (skip stacked/tabbed cons) */ @@ -542,8 +542,17 @@ static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *way child->percent = percentage; } - double new_current_percent = current->percent + ((double)ppt / 100.0); - double subtract_percent = ((double)ppt / 100.0) / (children - 1); + double ppt = (double)_ppt / 100.0; + double new_current_percent; + double subtract_percent; + if (_ppt) { + new_current_percent = current->percent + ppt; + } else { + new_current_percent = px_resize_to_percent(current, px); + ppt = new_current_percent - current->percent; + } + subtract_percent = ppt / (children - 1); + LOG("new_current_percent = %f\n", new_current_percent); LOG("subtract_percent = %f\n", subtract_percent); /* Ensure that the new percentages are positive. */ @@ -603,7 +612,8 @@ void cmd_resize(I3_CMD, const char *way, const char *direction, long resize_px, if (strcmp(direction, "width") == 0 || strcmp(direction, "height") == 0) { if (!cmd_resize_tiling_width_height(current_match, cmd_output, - current->con, way, direction, resize_ppt)) + current->con, way, direction, + resize_px, resize_ppt)) return; } else { if (!cmd_resize_tiling_direction(current_match, cmd_output, @@ -676,7 +686,7 @@ void cmd_resize_set(I3_CMD, long cwidth, const char *mode_width, long cheight, c /* perform resizing and report failure if not possible */ if (!cmd_resize_tiling_width_height(current_match, cmd_output, - target, action_string, "width", adjustment)) { + target, action_string, "width", 0, adjustment)) { success = false; } } @@ -702,7 +712,7 @@ void cmd_resize_set(I3_CMD, long cwidth, const char *mode_width, long cheight, c /* perform resizing and report failure if not possible */ if (!cmd_resize_tiling_width_height(current_match, cmd_output, - target, action_string, "height", adjustment)) { + target, action_string, "height", 0, adjustment)) { success = false; } } diff --git a/testcases/t/141-resize.t b/testcases/t/141-resize.t index 7e8249f1..5a264169 100644 --- a/testcases/t/141-resize.t +++ b/testcases/t/141-resize.t @@ -141,6 +141,72 @@ cmp_float($nodes->[1]->{percent}, 0.166666666666667, 'second window got 16%'); cmp_float($nodes->[2]->{percent}, 0.166666666666667, 'third window got 16%'); cmp_float($nodes->[3]->{percent}, 0.50, 'fourth window got 50%'); +################################################################################ +# Same but using pixels instead of ppt. +################################################################################ + +# Use two windows +$tmp = fresh_workspace; + +$left = open_window; +$right = open_window; + +($nodes, $focus) = get_ws_content($tmp); +my @widths = ($nodes->[0]->{rect}->{width}, $nodes->[1]->{rect}->{width}); + +cmd 'resize grow width 10 px'; + +($nodes, $focus) = get_ws_content($tmp); +cmp_float($nodes->[0]->{rect}->{width}, $widths[0] - 10, 'left window is 10px smaller'); +cmp_float($nodes->[1]->{rect}->{width}, $widths[1] + 10, 'right window is 10px larger'); + +# Now test it with four windows +$tmp = fresh_workspace; + +open_window for (1..4); + +($nodes, $focus) = get_ws_content($tmp); +my $width = $nodes->[0]->{rect}->{width}; + +cmd 'resize grow width 10 px'; + +($nodes, $focus) = get_ws_content($tmp); +cmp_float($nodes->[3]->{rect}->{width}, $width + 10, 'last window is 10px larger'); + +################################################################################ +# Same but for height +################################################################################ + +# Use two windows +$tmp = fresh_workspace; +cmd 'split v'; + +$left = open_window; +$right = open_window; + +($nodes, $focus) = get_ws_content($tmp); +my @heights = ($nodes->[0]->{rect}->{height}, $nodes->[1]->{rect}->{height}); + +cmd 'resize grow height 10 px'; + +($nodes, $focus) = get_ws_content($tmp); +cmp_float($nodes->[0]->{rect}->{height}, $heights[0] - 10, 'left window is 10px smaller'); +cmp_float($nodes->[1]->{rect}->{height}, $heights[1] + 10, 'right window is 10px larger'); + +# Now test it with four windows +$tmp = fresh_workspace; +cmd 'split v'; + +open_window for (1..4); + +($nodes, $focus) = get_ws_content($tmp); +my $height = $nodes->[0]->{rect}->{height}; + +cmd 'resize grow height 10 px'; + +($nodes, $focus) = get_ws_content($tmp); +cmp_float($nodes->[3]->{rect}->{height}, $height + 10, 'last window is 10px larger'); + ################################################################################ # Check that we can grow tiled windows by pixels ################################################################################