workspace_next_name: fallback to next available number
This changes `workspace_next_name` to use the next available number as the workspace name instead of the number of outputs. This fixes the case where a number that is already in use could be returned. The workspace numbers in use have no relation to the number of outputs so it makes more sense to use the lowest available number
This commit is contained in:
parent
487c83f0de
commit
faf15ee733
|
@ -336,16 +336,13 @@ char *workspace_next_name(const char *output_name) {
|
||||||
if (target != NULL) {
|
if (target != NULL) {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
// As a fall back, get the current number of active workspaces
|
// As a fall back, use the next available number
|
||||||
// and return that + 1 for the next workspace's name
|
char name[12] = "";
|
||||||
int ws_num = root->outputs->length;
|
unsigned int ws_num = 1;
|
||||||
int l = snprintf(NULL, 0, "%d", ws_num);
|
do {
|
||||||
char *name = malloc(l + 1);
|
snprintf(name, sizeof(name), "%u", ws_num++);
|
||||||
if (!sway_assert(name, "Could not allocate workspace name")) {
|
} while (workspace_by_number(name));
|
||||||
return NULL;
|
return strdup(name);
|
||||||
}
|
|
||||||
sprintf(name, "%d", ws_num++);
|
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool _workspace_by_number(struct sway_workspace *ws, void *data) {
|
static bool _workspace_by_number(struct sway_workspace *ws, void *data) {
|
||||||
|
|
Loading…
Reference in a new issue