diff options
author | S. Christoffer Eliesen <christoffer@eliesen.no> | 2015-11-24 23:03:00 +0100 |
---|---|---|
committer | S. Christoffer Eliesen <christoffer@eliesen.no> | 2015-11-27 17:30:05 +0100 |
commit | 0a78af0accf032087d4c25c8ae530311d2ee5874 (patch) | |
tree | 65156046e43bda23420d56ac80432ba8aebca174 | |
parent | 04bd9386fe93d596ca0af7a9895598b709088484 (diff) |
workspace: Improve workspace_next_name.
This function looks for bound commands that start with `workspace` (ie.
the commands that change to a static workspace) and fetches the
workspace name.
However, if it's actually a list of commands, then the parsing will pick
up the delimiter ("," or ";") and also fail to recognize keywords
("next" etc).
This patch fixes that by properly separating with delimiters.
-rw-r--r-- | sway/workspace.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/sway/workspace.c b/sway/workspace.c index 55b1ffbf..f18a691f 100644 --- a/sway/workspace.c +++ b/sway/workspace.c @@ -27,13 +27,19 @@ char *workspace_next_name(void) { for (i = 0; i < mode->bindings->length; ++i) { struct sway_binding *binding = mode->bindings->items[i]; - const char* command = binding->command; - list_t *args = split_string(command, " "); + char *cmdlist = strdup(binding->command); + char *dup = cmdlist; + char *name = NULL; + + // workspace n + char *cmd = argsep(&cmdlist, " "); + if (cmdlist) { + name = argsep(&cmdlist, " ,;"); + } - if (strcmp("workspace", args->items[0]) == 0 && args->length > 1) { - sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", (char *)args->items[1]); - char* target = malloc(strlen(args->items[1]) + 1); - strcpy(target, args->items[1]); + if (strcmp("workspace", cmd) == 0 && name) { + sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", name); + char* target = strdup(name); while (*target == ' ' || *target == '\t') target++; @@ -47,22 +53,20 @@ char *workspace_next_name(void) { strcmp(target, "back_and_forth") == 0 || strcmp(target, "current") == 0) { - free_flat_list(args); + free(target); continue; } // Make sure that the workspace doesn't already exist if (workspace_by_name(target)) { - free_flat_list(args); + free(target); continue; } - - free_flat_list(args); - + free(dup); sway_log(L_DEBUG, "Workspace: Found free name %s", target); return target; } - free_flat_list(args); + free(dup); } // As a fall back, get the current number of active workspaces // and return that + 1 for the next workspace's name |