From c284ed379c60884f70418e6720a41c3af6e600e2 Mon Sep 17 00:00:00 2001 From: Pedro CĂ´rte-Real Date: Sun, 28 Jul 2019 11:17:33 +0100 Subject: Avoid numerical instability in resize Because the layout code rounds down the dimensions of the windows resizing would often be off by one pixel. The width/height fraction would not exactly reflect the final computed width and so the resize code would end up calculating things wrong. To fix this first snap the container size fractions to the pixel grid and only then do the resize. Also use round() instead of floor() during layout to avoid a slightly too small width. This applies in two cases: 1. For the container we are actually resizing using floor() might result in being 1px too small. 2. For the other containers it might result in resizing them down by 1px and then if the container being resized is the last all those extra pixels would make the resize too large. Fixes #4391 --- sway/tree/arrange.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'sway/tree/arrange.c') diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index 7b88b3a2..e4f59110 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -78,9 +78,10 @@ static void apply_horiz_layout(list_t *children, struct wlr_box *parent) { double child_x = parent->x; for (int i = 0; i < children->length; ++i) { struct sway_container *child = children->items[i]; + child->child_total_width = child_total_width; child->x = child_x; child->y = parent->y; - child->width = floor(child->width_fraction * child_total_width); + child->width = round(child->width_fraction * child_total_width); child->height = parent->height; child_x += child->width + inner_gap; @@ -156,10 +157,11 @@ static void apply_vert_layout(list_t *children, struct wlr_box *parent) { double child_y = parent->y; for (int i = 0; i < children->length; ++i) { struct sway_container *child = children->items[i]; + child->child_total_height = child_total_height; child->x = parent->x; child->y = child_y; child->width = parent->width; - child->height = floor(child->height_fraction * child_total_height); + child->height = round(child->height_fraction * child_total_height); child_y += child->height + inner_gap; // Make last child use remaining height of parent -- cgit v1.2.3-54-g00ecf