summaryrefslogtreecommitdiffstats
path: root/sway/container.c
diff options
context:
space:
mode:
authorLibravatar progandy <code@progandy>2015-12-18 01:01:02 +0100
committerLibravatar progandy <code@progandy>2015-12-18 01:22:07 +0100
commit76c520a04b09490591c8ca7f854592f2a7a50042 (patch)
tree32c96595026c36cbb88a7c57544396b74c9128f0 /sway/container.c
parentsway: enable workspace selection by number (diff)
downloadsway-76c520a04b09490591c8ca7f854592f2a7a50042.tar.gz
sway-76c520a04b09490591c8ca7f854592f2a7a50042.tar.zst
sway-76c520a04b09490591c8ca7f854592f2a7a50042.zip
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 ...
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 @@
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