diff options
-rw-r--r-- | include/layout.h | 4 | ||||
-rw-r--r-- | sway/container.c | 20 |
2 files changed, 23 insertions, 1 deletions
diff --git a/include/layout.h b/include/layout.h index 62e4c202..b7731031 100644 --- a/include/layout.h +++ b/include/layout.h | |||
@@ -24,6 +24,10 @@ int index_child(const swayc_t *child); | |||
24 | // parent must be of type C_WORKSPACE or C_CONTAINER | 24 | // parent must be of type C_WORKSPACE or C_CONTAINER |
25 | void add_child(swayc_t *parent, swayc_t *child); | 25 | void add_child(swayc_t *parent, swayc_t *child); |
26 | 26 | ||
27 | // Adds child to parent at index, if parent has no focus, it is set to child | ||
28 | // parent must be of type C_WORKSPACE or C_CONTAINER | ||
29 | void insert_child(swayc_t *parent, swayc_t *child, int index); | ||
30 | |||
27 | // Adds child as floating window to ws, if there is no focus it is set to child. | 31 | // Adds child as floating window to ws, if there is no focus it is set to child. |
28 | // ws must be of type C_WORKSPACE | 32 | // ws must be of type C_WORKSPACE |
29 | void add_floating(swayc_t *ws, swayc_t *child); | 33 | void add_floating(swayc_t *ws, swayc_t *child); |
diff --git a/sway/container.c b/sway/container.c index 8165bbad..36056ff7 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #include <ctype.h> | ||
1 | #include <stdlib.h> | 2 | #include <stdlib.h> |
2 | #include <stdbool.h> | 3 | #include <stdbool.h> |
3 | #include <strings.h> | 4 | #include <strings.h> |
@@ -168,7 +169,24 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { | |||
168 | workspace->visible = false; | 169 | workspace->visible = false; |
169 | workspace->floating = create_list(); | 170 | workspace->floating = create_list(); |
170 | 171 | ||
171 | add_child(output, workspace); | 172 | if (isdigit(workspace->name[0])) { |
173 | // find position for numbered workspace | ||
174 | // order: ascending numbers, insert before same number | ||
175 | // numbers before unnumbered | ||
176 | int num = strtol(workspace->name, NULL, 10); | ||
177 | int i; | ||
178 | for (i = 0; i < output->children->length; ++i) { | ||
179 | char *name = ((swayc_t *)output->children->items[i])->name; | ||
180 | if (!isdigit(name[0]) || num <= strtol(name, NULL, 10)) { | ||
181 | break; | ||
182 | } | ||
183 | } | ||
184 | insert_child(output, workspace, i); | ||
185 | |||
186 | } else { | ||
187 | // append new unnumbered to the end | ||
188 | add_child(output, workspace); | ||
189 | } | ||
172 | return workspace; | 190 | return workspace; |
173 | } | 191 | } |
174 | 192 | ||