aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2019-02-17 13:07:04 -0500
committerDrew DeVault <sir@cmpwn.com>2019-02-18 15:11:48 -0500
commit34f5c1e7c40d479a00b384ac0849c0cf0a6c3f5e (patch)
tree3618a18849457ab89ae16d772f66d5e1fc6acbbf
parentf22aef018ba1f2ff50d35676ec6aa2e18e2a4ad5 (diff)
downloadsway-34f5c1e7c40d479a00b384ac0849c0cf0a6c3f5e.zip
sway-34f5c1e7c40d479a00b384ac0849c0cf0a6c3f5e.tar.gz
sway-34f5c1e7c40d479a00b384ac0849c0cf0a6c3f5e.tar.bz2
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
-rw-r--r--sway/tree/workspace.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index cda6caf..9b7c511 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -334,16 +334,13 @@ char *workspace_next_name(const char *output_name) {
if (target != NULL) {
return target;
}
- // As a fall back, get the current number of active workspaces
- // and return that + 1 for the next workspace's name
- int ws_num = root->outputs->length;
- int l = snprintf(NULL, 0, "%d", ws_num);
- char *name = malloc(l + 1);
- if (!sway_assert(name, "Could not allocate workspace name")) {
- return NULL;
- }
- sprintf(name, "%d", ws_num++);
- return name;
+ // As a fall back, use the next available number
+ char name[12] = "";
+ unsigned int ws_num = 1;
+ do {
+ snprintf(name, sizeof(name), "%u", ws_num++);
+ } while (workspace_by_number(name));
+ return strdup(name);
}
static bool _workspace_by_number(struct sway_workspace *ws, void *data) {