aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/workspace.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-02-17 13:07:04 -0500
committerLibravatar emersion <contact@emersion.fr>2019-02-17 19:15:19 +0100
commitfaf15ee733681f14797d8b47078854a00f03f8fc (patch)
tree1d909ff1b9fc25581c32d3a0c8e55e4c49d3ab7f /sway/tree/workspace.c
parentAdd workspace {prev,next}_on_output --create (diff)
downloadsway-faf15ee733681f14797d8b47078854a00f03f8fc.tar.gz
sway-faf15ee733681f14797d8b47078854a00f03f8fc.tar.zst
sway-faf15ee733681f14797d8b47078854a00f03f8fc.zip
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
Diffstat (limited to 'sway/tree/workspace.c')
-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 68f1de50..73322491 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -336,16 +336,13 @@ char *workspace_next_name(const char *output_name) {
336 if (target != NULL) { 336 if (target != NULL) {
337 return target; 337 return target;
338 } 338 }
339 // As a fall back, get the current number of active workspaces 339 // As a fall back, use the next available number
340 // and return that + 1 for the next workspace's name 340 char name[12] = "";
341 int ws_num = root->outputs->length; 341 unsigned int ws_num = 1;
342 int l = snprintf(NULL, 0, "%d", ws_num); 342 do {
343 char *name = malloc(l + 1); 343 snprintf(name, sizeof(name), "%u", ws_num++);
344 if (!sway_assert(name, "Could not allocate workspace name")) { 344 } while (workspace_by_number(name));
345 return NULL; 345 return strdup(name);
346 }
347 sprintf(name, "%d", ws_num++);
348 return name;
349} 346}
350 347
351static bool _workspace_by_number(struct sway_workspace *ws, void *data) { 348static bool _workspace_by_number(struct sway_workspace *ws, void *data) {