Merge pull request #264 from sce/fix_ws_next_name

workspace: Improve workspace_next_name.
master
Drew DeVault 9 years ago
commit cad2694a3c

@ -27,13 +27,19 @@ char *workspace_next_name(void) {
for (i = 0; i < mode->bindings->length; ++i) { for (i = 0; i < mode->bindings->length; ++i) {
struct sway_binding *binding = mode->bindings->items[i]; struct sway_binding *binding = mode->bindings->items[i];
const char* command = binding->command; char *cmdlist = strdup(binding->command);
list_t *args = split_string(command, " "); char *dup = cmdlist;
char *name = NULL;
if (strcmp("workspace", args->items[0]) == 0 && args->length > 1) { // workspace n
sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", (char *)args->items[1]); char *cmd = argsep(&cmdlist, " ");
char* target = malloc(strlen(args->items[1]) + 1); if (cmdlist) {
strcpy(target, args->items[1]); name = argsep(&cmdlist, " ,;");
}
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') while (*target == ' ' || *target == '\t')
target++; target++;
@ -47,22 +53,20 @@ char *workspace_next_name(void) {
strcmp(target, "back_and_forth") == 0 || strcmp(target, "back_and_forth") == 0 ||
strcmp(target, "current") == 0) strcmp(target, "current") == 0)
{ {
free_flat_list(args); free(target);
continue; continue;
} }
// Make sure that the workspace doesn't already exist // Make sure that the workspace doesn't already exist
if (workspace_by_name(target)) { if (workspace_by_name(target)) {
free_flat_list(args); free(target);
continue; continue;
} }
free(dup);
free_flat_list(args);
sway_log(L_DEBUG, "Workspace: Found free name %s", target); sway_log(L_DEBUG, "Workspace: Found free name %s", target);
return target; return target;
} }
free_flat_list(args); free(dup);
} }
// As a fall back, get the current number of active workspaces // As a fall back, get the current number of active workspaces
// and return that + 1 for the next workspace's name // and return that + 1 for the next workspace's name

Loading…
Cancel
Save