commit 0a78af0accf032087d4c25c8ae530311d2ee5874
parent 04bd9386fe93d596ca0af7a9895598b709088484
Author: S. Christoffer Eliesen <christoffer@eliesen.no>
Date: Tue, 24 Nov 2015 23:03:00 +0100
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.
Diffstat:
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git 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