summaryrefslogtreecommitdiffstats
path: root/sway/container.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/container.c')
-rw-r--r--sway/container.c26
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) {
32 c->layout = L_NONE; 32 c->layout = L_NONE;
33 c->workspace_layout = L_NONE; 33 c->workspace_layout = L_NONE;
34 c->type = type; 34 c->type = type;
35 c->nb_master = 1;
36 c->nb_slave_groups = 1;
35 if (type != C_VIEW) { 37 if (type != C_VIEW) {
36 c->children = create_list(); 38 c->children = create_list();
37 } 39 }
@@ -960,11 +962,29 @@ swayc_t *swayc_tabbed_stacked_parent(swayc_t *con) {
960} 962}
961 963
962swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout) { 964swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout) {
965 // if layout change modifies the auto layout's major axis, swap width and height
966 // to preserve current ratios.
967 if (is_auto_layout(layout) && is_auto_layout(container->layout)) {
968 enum swayc_layouts prev_major =
969 container->layout == L_AUTO_LEFT || container->layout == L_AUTO_RIGHT
970 ? L_HORIZ : L_VERT;
971 enum swayc_layouts new_major =
972 layout == L_AUTO_LEFT || layout == L_AUTO_RIGHT
973 ? L_HORIZ : L_VERT;
974 if (new_major != prev_major) {
975 for (int i = 0; i < container->children->length; ++i) {
976 swayc_t *child = container->children->items[i];
977 double h = child->height;
978 child->height = child->width;
979 child->width = h;
980 }
981 }
982 }
963 if (container->type == C_WORKSPACE) { 983 if (container->type == C_WORKSPACE) {
964 container->workspace_layout = layout; 984 container->workspace_layout = layout;
965 if (layout == L_HORIZ || layout == L_VERT) { 985 if (layout == L_HORIZ || layout == L_VERT || is_auto_layout(layout)) {
966 container->layout = layout; 986 container->layout = layout;
967 } 987 }
968 } else { 988 } else {
969 container->layout = layout; 989 container->layout = layout;
970 } 990 }