For resizing, convert pixel diff to percentage, based on parent.

Previously, it first calculated one of the containers' next percentage, and then subtracted the previous percentage to find the actual change.

Now it directly calculates the change, and subtracts and adds the change to the two affected containers.

Added util function con_rect_size_in_orientation.

Removed px_resize_to_percent; inlined, using con_rect_size_in_orientation.

Also, prematurely return when pixel diff is 0, as no action is necessary.

This is related to [this issue on i3-gaps](https://github.com/Airblader/i3/issues/247).
This commit is contained in:
aksel
2018-11-07 22:49:04 +01:00
parent 44e8fddc28
commit bbfa140c0f
6 changed files with 33 additions and 29 deletions

View File

@ -537,8 +537,9 @@ static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *dir
if (ppt != 0.0) {
new_current_percent = current->percent + ppt;
} else {
new_current_percent = px_resize_to_percent(current, px);
ppt = new_current_percent - current->percent;
/* Convert px change to change in percentages */
ppt = (double)px / (double)con_rect_size_in_orientation(current->parent);
new_current_percent = current->percent + ppt;
}
subtract_percent = ppt / (children - 1);
if (ppt < 0.0 && new_current_percent < percent_for_1px(current)) {