aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/layout.h4
-rw-r--r--sway/container.c20
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);
// parent must be of type C_WORKSPACE or C_CONTAINER
void add_child(swayc_t *parent, swayc_t *child);
+// Adds child to parent at index, if parent has no focus, it is set to child
+// parent must be of type C_WORKSPACE or C_CONTAINER
+void insert_child(swayc_t *parent, swayc_t *child, int index);
+
// Adds child as floating window to ws, if there is no focus it is set to child.
// ws must be of type C_WORKSPACE
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 @@
+#include <ctype.h>
#include <stdlib.h>
#include <stdbool.h>
#include <strings.h>
@@ -168,7 +169,24 @@ swayc_t *new_workspace(swayc_t *output, const char *name) {
workspace->visible = false;
workspace->floating = create_list();
- add_child(output, workspace);
+ if (isdigit(workspace->name[0])) {
+ // find position for numbered workspace
+ // order: ascending numbers, insert before same number
+ // numbers before unnumbered
+ int num = strtol(workspace->name, NULL, 10);
+ int i;
+ for (i = 0; i < output->children->length; ++i) {
+ char *name = ((swayc_t *)output->children->items[i])->name;
+ if (!isdigit(name[0]) || num <= strtol(name, NULL, 10)) {
+ break;
+ }
+ }
+ insert_child(output, workspace, i);
+
+ } else {
+ // append new unnumbered to the end
+ add_child(output, workspace);
+ }
return workspace;
}