diff options
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands/layout.c | 43 | ||||
-rw-r--r-- | sway/tree/layout.c | 4 | ||||
-rw-r--r-- | sway/tree/workspace.c | 2 |
3 files changed, 29 insertions, 20 deletions
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) { | |||
42 | parent = parent->parent; | 42 | parent = parent->parent; |
43 | } | 43 | } |
44 | 44 | ||
45 | if (strcasecmp(argv[0], "default") == 0) { | 45 | enum sway_container_layout prev = parent->layout; |
46 | parent->layout = parent->prev_layout; | 46 | bool assigned_directly = parse_layout_string(argv[0], &parent->layout); |
47 | } else { | 47 | if (!assigned_directly) { |
48 | if (parent->layout != L_TABBED && parent->layout != L_STACKED) { | 48 | if (strcasecmp(argv[0], "default") == 0) { |
49 | parent->prev_layout = parent->layout; | 49 | parent->layout = parent->prev_split_layout; |
50 | } | 50 | } else if (strcasecmp(argv[0], "toggle") == 0) { |
51 | |||
52 | bool assigned_directly = parse_layout_string(argv[0], &parent->layout); | ||
53 | if (!assigned_directly && strcasecmp(argv[0], "toggle") == 0) { | ||
54 | if (argc == 1) { | 51 | if (argc == 1) { |
55 | parent->layout = | 52 | parent->layout = |
56 | parent->layout == L_STACKED ? L_TABBED : | 53 | parent->layout == L_STACKED ? L_TABBED : |
57 | parent->layout == L_TABBED ? parent->prev_layout : L_STACKED; | 54 | parent->layout == L_TABBED ? parent->prev_split_layout : L_STACKED; |
58 | } else if (argc == 2) { | 55 | } else if (argc == 2) { |
59 | if (strcasecmp(argv[1], "all") == 0) { | 56 | if (strcasecmp(argv[1], "all") == 0) { |
60 | parent->layout = | 57 | parent->layout = |
@@ -62,17 +59,20 @@ struct cmd_results *cmd_layout(int argc, char **argv) { | |||
62 | parent->layout == L_VERT ? L_STACKED : | 59 | parent->layout == L_VERT ? L_STACKED : |
63 | parent->layout == L_STACKED ? L_TABBED : L_HORIZ; | 60 | parent->layout == L_STACKED ? L_TABBED : L_HORIZ; |
64 | } else if (strcasecmp(argv[1], "split") == 0) { | 61 | } else if (strcasecmp(argv[1], "split") == 0) { |
65 | parent->layout = parent->layout == L_VERT ? L_HORIZ : L_VERT; | 62 | parent->layout = |
63 | parent->layout == L_HORIZ ? L_VERT : | ||
64 | parent->layout == L_VERT ? L_HORIZ : parent->prev_split_layout; | ||
66 | } else { | 65 | } else { |
67 | return cmd_results_new(CMD_INVALID, "layout", expected_syntax); | 66 | return cmd_results_new(CMD_INVALID, "layout", expected_syntax); |
68 | } | 67 | } |
69 | } else { | 68 | } else { |
70 | bool valid; | ||
71 | enum sway_container_layout parsed_layout; | 69 | enum sway_container_layout parsed_layout; |
72 | int curr = 1; | 70 | int curr = 1; |
73 | for (; curr < argc; curr++) { | 71 | for (; curr < argc; curr++) { |
74 | valid = parse_layout_string(argv[curr], &parsed_layout); | 72 | bool valid = parse_layout_string(argv[curr], &parsed_layout); |
75 | if (valid && parsed_layout == parent->layout) { | 73 | if ((valid && parsed_layout == parent->layout) || |
74 | (strcmp(argv[curr], "split") == 0 && | ||
75 | (parent->layout == L_VERT || parent->layout == L_HORIZ))) { | ||
76 | break; | 76 | break; |
77 | } | 77 | } |
78 | } | 78 | } |
@@ -83,6 +83,11 @@ struct cmd_results *cmd_layout(int argc, char **argv) { | |||
83 | } | 83 | } |
84 | if (parse_layout_string(argv[i], &parent->layout)) { | 84 | if (parse_layout_string(argv[i], &parent->layout)) { |
85 | break; | 85 | break; |
86 | } else if (strcmp(argv[i], "split") == 0) { | ||
87 | parent->layout = | ||
88 | parent->layout == L_HORIZ ? L_VERT : | ||
89 | parent->layout == L_VERT ? L_HORIZ : parent->prev_split_layout; | ||
90 | break; | ||
86 | } // invalid layout strings are silently ignored | 91 | } // invalid layout strings are silently ignored |
87 | } | 92 | } |
88 | } | 93 | } |
@@ -93,9 +98,13 @@ struct cmd_results *cmd_layout(int argc, char **argv) { | |||
93 | if (parent->layout == L_NONE) { | 98 | if (parent->layout == L_NONE) { |
94 | parent->layout = container_get_default_layout(parent); | 99 | parent->layout = container_get_default_layout(parent); |
95 | } | 100 | } |
96 | 101 | if (prev != parent->layout) { | |
97 | container_notify_subtree_changed(parent); | 102 | if (prev != L_TABBED && prev != L_STACKED) { |
98 | arrange_windows(parent); | 103 | parent->prev_split_layout = prev; |
104 | } | ||
105 | container_notify_subtree_changed(parent); | ||
106 | arrange_windows(parent); | ||
107 | } | ||
99 | 108 | ||
100 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 109 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
101 | } | 110 | } |
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, | |||
859 | } | 859 | } |
860 | if (child->type == C_WORKSPACE && child->children->length == 0) { | 860 | if (child->type == C_WORKSPACE && child->children->length == 0) { |
861 | // Special case: this just behaves like splitt | 861 | // Special case: this just behaves like splitt |
862 | child->prev_layout = child->layout; | 862 | child->prev_split_layout = child->layout; |
863 | child->layout = layout; | 863 | child->layout = layout; |
864 | return child; | 864 | return child; |
865 | } | 865 | } |
@@ -870,7 +870,7 @@ struct sway_container *container_split(struct sway_container *child, | |||
870 | 870 | ||
871 | remove_gaps(child); | 871 | remove_gaps(child); |
872 | 872 | ||
873 | cont->prev_layout = L_NONE; | 873 | cont->prev_split_layout = L_NONE; |
874 | cont->width = child->width; | 874 | cont->width = child->width; |
875 | cont->height = child->height; | 875 | cont->height = child->height; |
876 | cont->x = child->x; | 876 | 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, | |||
59 | workspace->width = output->width; | 59 | workspace->width = output->width; |
60 | workspace->height = output->height; | 60 | workspace->height = output->height; |
61 | workspace->name = !name ? NULL : strdup(name); | 61 | workspace->name = !name ? NULL : strdup(name); |
62 | workspace->prev_layout = L_NONE; | 62 | workspace->prev_split_layout = L_NONE; |
63 | workspace->layout = container_get_default_layout(output); | 63 | workspace->layout = container_get_default_layout(output); |
64 | 64 | ||
65 | struct sway_workspace *swayws = calloc(1, sizeof(struct sway_workspace)); | 65 | struct sway_workspace *swayws = calloc(1, sizeof(struct sway_workspace)); |