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 | Fix swaygrab memory leak (diff) | |
download | sway-0a78af0accf032087d4c25c8ae530311d2ee5874.tar.gz sway-0a78af0accf032087d4c25c8ae530311d2ee5874.tar.zst sway-0a78af0accf032087d4c25c8ae530311d2ee5874.zip |
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) { | |||
27 | 27 | ||
28 | for (i = 0; i < mode->bindings->length; ++i) { | 28 | for (i = 0; i < mode->bindings->length; ++i) { |
29 | struct sway_binding *binding = mode->bindings->items[i]; | 29 | struct sway_binding *binding = mode->bindings->items[i]; |
30 | const char* command = binding->command; | 30 | char *cmdlist = strdup(binding->command); |
31 | list_t *args = split_string(command, " "); | 31 | char *dup = cmdlist; |
32 | char *name = NULL; | ||
33 | |||
34 | // workspace n | ||
35 | char *cmd = argsep(&cmdlist, " "); | ||
36 | if (cmdlist) { | ||
37 | name = argsep(&cmdlist, " ,;"); | ||
38 | } | ||
32 | 39 | ||
33 | if (strcmp("workspace", args->items[0]) == 0 && args->length > 1) { | 40 | if (strcmp("workspace", cmd) == 0 && name) { |
34 | sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", (char *)args->items[1]); | 41 | sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", name); |
35 | char* target = malloc(strlen(args->items[1]) + 1); | 42 | char* target = strdup(name); |
36 | strcpy(target, args->items[1]); | ||
37 | while (*target == ' ' || *target == '\t') | 43 | while (*target == ' ' || *target == '\t') |
38 | target++; | 44 | target++; |
39 | 45 | ||
@@ -47,22 +53,20 @@ char *workspace_next_name(void) { | |||
47 | strcmp(target, "back_and_forth") == 0 || | 53 | strcmp(target, "back_and_forth") == 0 || |
48 | strcmp(target, "current") == 0) | 54 | strcmp(target, "current") == 0) |
49 | { | 55 | { |
50 | free_flat_list(args); | 56 | free(target); |
51 | continue; | 57 | continue; |
52 | } | 58 | } |
53 | 59 | ||
54 | // Make sure that the workspace doesn't already exist | 60 | // Make sure that the workspace doesn't already exist |
55 | if (workspace_by_name(target)) { | 61 | if (workspace_by_name(target)) { |
56 | free_flat_list(args); | 62 | free(target); |
57 | continue; | 63 | continue; |
58 | } | 64 | } |
59 | 65 | free(dup); | |
60 | free_flat_list(args); | ||
61 | |||
62 | sway_log(L_DEBUG, "Workspace: Found free name %s", target); | 66 | sway_log(L_DEBUG, "Workspace: Found free name %s", target); |
63 | return target; | 67 | return target; |
64 | } | 68 | } |
65 | free_flat_list(args); | 69 | free(dup); |
66 | } | 70 | } |
67 | // As a fall back, get the current number of active workspaces | 71 | // As a fall back, get the current number of active workspaces |
68 | // and return that + 1 for the next workspace's name | 72 | // and return that + 1 for the next workspace's name |