mirror of
https://github.com/swaywm/sway.git
synced 2024-12-29 00:16:22 +01:00
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.
This commit is contained in:
parent
04bd9386fe
commit
0a78af0acc
1 changed files with 16 additions and 12 deletions
|
@ -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;
|
||||
|
||||
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]);
|
||||
// workspace n
|
||||
char *cmd = argsep(&cmdlist, " ");
|
||||
if (cmdlist) {
|
||||
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')
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue