diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-11-27 09:53:27 -0700 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-11-27 09:53:27 -0700 |
commit | cad2694a3c704c90c602ea5b009923c3a8388141 (patch) | |
tree | 092dff42aee8ea9bf537ac9867aa5c7d32512bfb /sway | |
parent | Merge pull request #263 from sce/floating_enable_disable (diff) | |
parent | workspace: Improve workspace_next_name. (diff) | |
download | sway-cad2694a3c704c90c602ea5b009923c3a8388141.tar.gz sway-cad2694a3c704c90c602ea5b009923c3a8388141.tar.zst sway-cad2694a3c704c90c602ea5b009923c3a8388141.zip |
Merge pull request #264 from sce/fix_ws_next_name
workspace: Improve workspace_next_name.
Diffstat (limited to 'sway')
-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 |