From c08f9bf257c38c92a75988d89fba2d4de6bb2aea Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 19 May 2018 22:54:50 +1000 Subject: Implement tabbed layout --- sway/tree/arrange.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'sway/tree/arrange.c') diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index 83bb20fb..8aebc0cc 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -86,6 +86,13 @@ static void apply_horiz_layout(struct sway_container *parent) { if (!num_children) { return; } + size_t parent_height = parent->height; + size_t parent_offset = 0; + if (parent->parent->layout == L_TABBED) { + parent_offset = config->border_thickness * 2 + config->font_height; + parent_height -= parent_offset; + } + // Calculate total width of children double total_width = 0; for (size_t i = 0; i < num_children; ++i) { @@ -111,9 +118,9 @@ static void apply_horiz_layout(struct sway_container *parent) { "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, child->width, scale); child->x = child_x; - child->y = parent->y; + child->y = parent->y + parent_offset; child->width = floor(child->width * scale); - child->height = parent->height; + child->height = parent_height; child_x += child->width; } // Make last child use remaining width of parent @@ -125,24 +132,31 @@ static void apply_vert_layout(struct sway_container *parent) { if (!num_children) { return; } + size_t parent_height = parent->height; + size_t parent_offset = 0; + if (parent->parent->layout == L_TABBED) { + parent_offset = config->border_thickness * 2 + config->font_height; + parent_height -= parent_offset; + } + // Calculate total height of children double total_height = 0; for (size_t i = 0; i < num_children; ++i) { struct sway_container *child = parent->children->items[i]; if (child->height <= 0) { if (num_children > 1) { - child->height = parent->height / (num_children - 1); + child->height = parent_height / (num_children - 1); } else { - child->height = parent->height; + child->height = parent_height; } } total_height += child->height; } - double scale = parent->height / total_height; + double scale = parent_height / total_height; // Resize wlr_log(L_DEBUG, "Arranging %p vertically", parent); - double child_y = parent->y; + double child_y = parent->y + parent_offset; struct sway_container *child; for (size_t i = 0; i < num_children; ++i) { child = parent->children->items[i]; @@ -156,7 +170,20 @@ static void apply_vert_layout(struct sway_container *parent) { child_y += child->height; } // Make last child use remaining height of parent - child->height = parent->y + parent->height - child->y; + child->height = parent->y + parent_offset + parent_height - child->y; +} + +static void apply_tabbed_layout(struct sway_container *parent) { + if (!parent->children->length) { + return; + } + for (int i = 0; i < parent->children->length; ++i) { + struct sway_container *child = parent->children->items[i]; + child->x = parent->x; + child->y = parent->y; + child->width = parent->width; + child->height = parent->height; + } } void arrange_children_of(struct sway_container *parent) { @@ -189,6 +216,9 @@ void arrange_children_of(struct sway_container *parent) { case L_VERT: apply_vert_layout(parent); break; + case L_TABBED: + apply_tabbed_layout(parent); + break; default: wlr_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout); apply_horiz_layout(parent); -- cgit v1.2.3 From 664169fbf1c4e07f17a48b2b801dad9cea31ea4c Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 21 May 2018 22:58:46 +1000 Subject: Implement stacked layout --- sway/tree/arrange.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'sway/tree/arrange.c') diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index 8aebc0cc..b8e07bca 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -86,12 +86,14 @@ static void apply_horiz_layout(struct sway_container *parent) { if (!num_children) { return; } - size_t parent_height = parent->height; size_t parent_offset = 0; if (parent->parent->layout == L_TABBED) { - parent_offset = config->border_thickness * 2 + config->font_height; - parent_height -= parent_offset; + parent_offset = config->font_height + 8; + } else if (parent->parent->layout == L_STACKED) { + parent_offset = (config->font_height + 8) + * parent->parent->children->length; } + size_t parent_height = parent->height - parent_offset; // Calculate total width of children double total_width = 0; @@ -132,12 +134,14 @@ static void apply_vert_layout(struct sway_container *parent) { if (!num_children) { return; } - size_t parent_height = parent->height; size_t parent_offset = 0; if (parent->parent->layout == L_TABBED) { - parent_offset = config->border_thickness * 2 + config->font_height; - parent_height -= parent_offset; + parent_offset = config->font_height + 8; + } else if (parent->parent->layout == L_STACKED) { + parent_offset = (config->font_height + 8) + * parent->parent->children->length; } + size_t parent_height = parent->height - parent_offset; // Calculate total height of children double total_height = 0; @@ -186,6 +190,19 @@ static void apply_tabbed_layout(struct sway_container *parent) { } } +static void apply_stacked_layout(struct sway_container *parent) { + if (!parent->children->length) { + return; + } + for (int i = 0; i < parent->children->length; ++i) { + struct sway_container *child = parent->children->items[i]; + child->x = parent->x; + child->y = parent->y; + child->width = parent->width; + child->height = parent->height; + } +} + void arrange_children_of(struct sway_container *parent) { if (config->reloading) { return; @@ -219,6 +236,9 @@ void arrange_children_of(struct sway_container *parent) { case L_TABBED: apply_tabbed_layout(parent); break; + case L_STACKED: + apply_stacked_layout(parent); + break; default: wlr_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout); apply_horiz_layout(parent); -- cgit v1.2.3 From f6c3682c05bce05f00b13b8f469b52923ecd8ddb Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 22 May 2018 08:27:42 +1000 Subject: Use constants for titlebar dimensions --- sway/tree/arrange.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'sway/tree/arrange.c') diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index b8e07bca..37f4a066 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -88,10 +88,10 @@ static void apply_horiz_layout(struct sway_container *parent) { } size_t parent_offset = 0; if (parent->parent->layout == L_TABBED) { - parent_offset = config->font_height + 8; + parent_offset = container_titlebar_height(); } else if (parent->parent->layout == L_STACKED) { - parent_offset = (config->font_height + 8) - * parent->parent->children->length; + parent_offset = + container_titlebar_height() * parent->parent->children->length; } size_t parent_height = parent->height - parent_offset; @@ -136,10 +136,10 @@ static void apply_vert_layout(struct sway_container *parent) { } size_t parent_offset = 0; if (parent->parent->layout == L_TABBED) { - parent_offset = config->font_height + 8; + parent_offset = container_titlebar_height(); } else if (parent->parent->layout == L_STACKED) { - parent_offset = (config->font_height + 8) - * parent->parent->children->length; + parent_offset = + container_titlebar_height() * parent->parent->children->length; } size_t parent_height = parent->height - parent_offset; -- cgit v1.2.3