summaryrefslogtreecommitdiff
path: root/sway/container.c
diff options
context:
space:
mode:
authorDrew DeVault <[email protected]>2015-12-17 19:48:55 -0500
committerDrew DeVault <[email protected]>2015-12-17 19:48:55 -0500
commitf994f00d0059039d952d7dcfb72a683f303878bc (patch)
tree32c96595026c36cbb88a7c57544396b74c9128f0 /sway/container.c
parent89341c0c702573065676eb5cf1ac2fcc6091eacf (diff)
parent76c520a04b09490591c8ca7f854592f2a7a50042 (diff)
Merge pull request #352 from progandy/workspace-numbers
Workspace numbers
Diffstat (limited to 'sway/container.c')
-rw-r--r--sway/container.c20
1 files changed, 19 insertions, 1 deletions
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;
}