From 1312b5bb9faf7ab50c3024fc4f05b58481bf318c Mon Sep 17 00:00:00 2001 From: Pedro CĂ´rte-Real Date: Sun, 23 Jun 2019 18:28:26 +0100 Subject: Layout correctly with several new windows If there is more than one new window layout correctly by calculating the default size of the new windows using the information of how many of them there are in total. This helps with issue #3547 but doesn't fix it in all situations. Things now work correctly if the first layout of new windows happens after leaving fullscreen. But if for some reason an arrange_container() gets called while we are fullscreen the windows will still be incorrectly sized after saved_width/saved_height get used to restore the first window's size before going fullscreen. --- sway/tree/arrange.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index 8583c53e..fc5d49ed 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -18,13 +18,22 @@ static void apply_horiz_layout(list_t *children, struct wlr_box *parent) { return; } + // Count the number of new windows we are resizing + int new_children = 0; + for (int i = 0; i < children->length; ++i) { + struct sway_container *child = children->items[i]; + if (child->width <= 0) { + new_children += 1; + } + } + // Calculate total width of children double total_width = 0; for (int i = 0; i < children->length; ++i) { struct sway_container *child = children->items[i]; if (child->width <= 0) { - if (children->length > 1) { - child->width = parent->width / (children->length - 1); + if (children->length > new_children) { + child->width = parent->width / (children->length - new_children); } else { child->width = parent->width; } @@ -58,13 +67,22 @@ static void apply_vert_layout(list_t *children, struct wlr_box *parent) { return; } + // Count the number of new windows we are resizing + int new_children = 0; + for (int i = 0; i < children->length; ++i) { + struct sway_container *child = children->items[i]; + if (child->height <= 0) { + new_children += 1; + } + } + // Calculate total height of children double total_height = 0; for (int i = 0; i < children->length; ++i) { struct sway_container *child = children->items[i]; if (child->height <= 0) { - if (children->length > 1) { - child->height = parent->height / (children->length - 1); + if (children->length > new_children) { + child->height = parent->height / (children->length - new_children); } else { child->height = parent->height; } -- cgit v1.2.3-54-g00ecf