aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
authorLuminarys <kizunanohikari@gmail.com>2015-08-13 11:12:09 -0500
committerLuminarys <kizunanohikari@gmail.com>2015-08-13 14:41:36 -0500
commit8d63ac594bdea7e1e34f0aa99dc72becbb4f4949 (patch)
tree942dbf6f67d1e62f54abc9598903a83c07aeeec8 /sway
parent0dc1d87490eaadbe245af7406b0e5ca4d53f17a0 (diff)
Changed workspace name generation to try and use bindsyms when possible
Diffstat (limited to 'sway')
-rw-r--r--sway/workspace.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/sway/workspace.c b/sway/workspace.c
index 53675c03..96604678 100644
--- a/sway/workspace.c
+++ b/sway/workspace.c
@@ -12,7 +12,42 @@ swayc_t *active_workspace = NULL;
int ws_num = 1;
char *workspace_next_name(void) {
- int l = 1;
+ int i;
+ // Scan all workspace bindings to find the next available workspace name,
+ // if none are found/available then default to a number
+ struct sway_mode *mode = config->current_mode;
+
+ for (i = 0; i < mode->bindings->length; ++i) {
+ const char* command = *binding = mode->bindings->items[i]->command;
+ list_t *args = split_string(command, " ");
+
+ if (strcmp("workspace", args->items[0]) == 0 && args->length > 2) {
+ const char* target = args->items[1];
+
+ while (*target == ' ' || *target == '\t')
+ target++;
+
+ // Make sure that the command references an actual workspace
+ // not a command about workspaces
+ if (strcmp(target, "next") == 0 ||
+ strcmp(target, "prev") == 0 ||
+ strcmp(target, "next_on_output") == 0 ||
+ strcmp(target, "prev_on_output") == 0 ||
+ strcmp(target, "number") == 0 ||
+ strcmp(target, "back_and_forth") == 0 ||
+ strcmp(target, "current") == 0)
+ continue;
+
+ //Make sure that the workspace doesn't already exist
+ if (workspace_find_by_name(args->items[2]))
+ continue;
+
+ return args->items[2];
+ }
+ }
+ // As a fall back, get the current number of active workspaces
+ // and return that + 1 for the next workspace's name
+ int ws_num = root_container.children->length;
if (ws_num >= 10) {
l = 2;
} else if (ws_num >= 100) {