From 76c520a04b09490591c8ca7f854592f2a7a50042 Mon Sep 17 00:00:00 2001 From: progandy Date: Fri, 18 Dec 2015 01:01:02 +0100 Subject: sway: insert numbered workspaces in order fixes #308 Ordered by number ascending, with insert before same numbers. Workspaces without numbers are appended at the end of the list. Example order: 1 2:named 3:the_second 3:the_first 9 FIRST_NAME SECOND_NAME ... --- sway/container.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'sway') 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 #include #include #include @@ -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; } -- cgit v1.2.3