diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-01-14 16:11:48 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-14 16:11:48 -0500 |
commit | 81102e8eacbf72ad0c5e81c935a957a8824a0922 (patch) | |
tree | f8b51dd1f5214966ad30b0bd7b561afa70dcb4dc /sway/container.c | |
parent | 0001b00706bfdaa185a9fd6823ff947c14aa3b5f (diff) | |
parent | a2cf3be890241a27cbbfd38a9367181a75cd2277 (diff) | |
download | sway-81102e8eacbf72ad0c5e81c935a957a8824a0922.tar.xz |
Merge pull request #1024 from willakat/master
Add Awesome/Monad style automatic layouts to Sway
Diffstat (limited to 'sway/container.c')
-rw-r--r-- | sway/container.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/sway/container.c b/sway/container.c index e557f450..cf7d7dda 100644 --- a/sway/container.c +++ b/sway/container.c @@ -32,6 +32,8 @@ static swayc_t *new_swayc(enum swayc_types type) { c->layout = L_NONE; c->workspace_layout = L_NONE; c->type = type; + c->nb_master = 1; + c->nb_slave_groups = 1; if (type != C_VIEW) { c->children = create_list(); } @@ -960,11 +962,29 @@ swayc_t *swayc_tabbed_stacked_parent(swayc_t *con) { } swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout) { + // if layout change modifies the auto layout's major axis, swap width and height + // to preserve current ratios. + if (is_auto_layout(layout) && is_auto_layout(container->layout)) { + enum swayc_layouts prev_major = + container->layout == L_AUTO_LEFT || container->layout == L_AUTO_RIGHT + ? L_HORIZ : L_VERT; + enum swayc_layouts new_major = + layout == L_AUTO_LEFT || layout == L_AUTO_RIGHT + ? L_HORIZ : L_VERT; + if (new_major != prev_major) { + for (int i = 0; i < container->children->length; ++i) { + swayc_t *child = container->children->items[i]; + double h = child->height; + child->height = child->width; + child->width = h; + } + } + } if (container->type == C_WORKSPACE) { container->workspace_layout = layout; - if (layout == L_HORIZ || layout == L_VERT) { - container->layout = layout; - } + if (layout == L_HORIZ || layout == L_VERT || is_auto_layout(layout)) { + container->layout = layout; + } } else { container->layout = layout; } |