diff options
-rw-r--r-- | include/sway/tree/container.h | 2 | ||||
-rw-r--r-- | sway/commands/layout.c | 43 | ||||
-rw-r--r-- | sway/tree/layout.c | 4 | ||||
-rw-r--r-- | sway/tree/workspace.c | 2 |
4 files changed, 30 insertions, 21 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 44ff9f7d..16a180f8 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -113,7 +113,7 @@ struct sway_container { enum sway_container_type type; enum sway_container_layout layout; - enum sway_container_layout prev_layout; + enum sway_container_layout prev_split_layout; bool is_sticky; diff --git a/sway/commands/layout.c b/sway/commands/layout.c index ec170591..f4e4dda9 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c @@ -42,19 +42,16 @@ struct cmd_results *cmd_layout(int argc, char **argv) { parent = parent->parent; } - if (strcasecmp(argv[0], "default") == 0) { - parent->layout = parent->prev_layout; - } else { - if (parent->layout != L_TABBED && parent->layout != L_STACKED) { - parent->prev_layout = parent->layout; - } - - bool assigned_directly = parse_layout_string(argv[0], &parent->layout); - if (!assigned_directly && strcasecmp(argv[0], "toggle") == 0) { + enum sway_container_layout prev = parent->layout; + bool assigned_directly = parse_layout_string(argv[0], &parent->layout); + if (!assigned_directly) { + if (strcasecmp(argv[0], "default") == 0) { + parent->layout = parent->prev_split_layout; + } else if (strcasecmp(argv[0], "toggle") == 0) { if (argc == 1) { parent->layout = parent->layout == L_STACKED ? L_TABBED : - parent->layout == L_TABBED ? parent->prev_layout : L_STACKED; + parent->layout == L_TABBED ? parent->prev_split_layout : L_STACKED; } else if (argc == 2) { if (strcasecmp(argv[1], "all") == 0) { parent->layout = @@ -62,17 +59,20 @@ struct cmd_results *cmd_layout(int argc, char **argv) { parent->layout == L_VERT ? L_STACKED : parent->layout == L_STACKED ? L_TABBED : L_HORIZ; } else if (strcasecmp(argv[1], "split") == 0) { - parent->layout = parent->layout == L_VERT ? L_HORIZ : L_VERT; + parent->layout = + parent->layout == L_HORIZ ? L_VERT : + parent->layout == L_VERT ? L_HORIZ : parent->prev_split_layout; } else { return cmd_results_new(CMD_INVALID, "layout", expected_syntax); } } else { - bool valid; enum sway_container_layout parsed_layout; int curr = 1; for (; curr < argc; curr++) { - valid = parse_layout_string(argv[curr], &parsed_layout); - if (valid && parsed_layout == parent->layout) { + bool valid = parse_layout_string(argv[curr], &parsed_layout); + if ((valid && parsed_layout == parent->layout) || + (strcmp(argv[curr], "split") == 0 && + (parent->layout == L_VERT || parent->layout == L_HORIZ))) { break; } } @@ -83,6 +83,11 @@ struct cmd_results *cmd_layout(int argc, char **argv) { } if (parse_layout_string(argv[i], &parent->layout)) { break; + } else if (strcmp(argv[i], "split") == 0) { + parent->layout = + parent->layout == L_HORIZ ? L_VERT : + parent->layout == L_VERT ? L_HORIZ : parent->prev_split_layout; + break; } // invalid layout strings are silently ignored } } @@ -93,9 +98,13 @@ struct cmd_results *cmd_layout(int argc, char **argv) { if (parent->layout == L_NONE) { parent->layout = container_get_default_layout(parent); } - - container_notify_subtree_changed(parent); - arrange_windows(parent); + if (prev != parent->layout) { + if (prev != L_TABBED && prev != L_STACKED) { + parent->prev_split_layout = prev; + } + container_notify_subtree_changed(parent); + arrange_windows(parent); + } return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 07de9664..28cdc71e 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -859,7 +859,7 @@ struct sway_container *container_split(struct sway_container *child, } if (child->type == C_WORKSPACE && child->children->length == 0) { // Special case: this just behaves like splitt - child->prev_layout = child->layout; + child->prev_split_layout = child->layout; child->layout = layout; return child; } @@ -870,7 +870,7 @@ struct sway_container *container_split(struct sway_container *child, remove_gaps(child); - cont->prev_layout = L_NONE; + cont->prev_split_layout = L_NONE; cont->width = child->width; cont->height = child->height; cont->x = child->x; diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index cc225e79..250d5ba7 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -59,7 +59,7 @@ struct sway_container *workspace_create(struct sway_container *output, workspace->width = output->width; workspace->height = output->height; workspace->name = !name ? NULL : strdup(name); - workspace->prev_layout = L_NONE; + workspace->prev_split_layout = L_NONE; workspace->layout = container_get_default_layout(output); struct sway_workspace *swayws = calloc(1, sizeof(struct sway_workspace)); |