aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-02-17 13:07:04 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-02-18 15:11:48 -0500
commit34f5c1e7c40d479a00b384ac0849c0cf0a6c3f5e (patch)
tree3618a18849457ab89ae16d772f66d5e1fc6acbbf
parentRemove refs to unimplemented debuglog command (diff)
downloadsway-34f5c1e7c40d479a00b384ac0849c0cf0a6c3f5e.tar.gz
sway-34f5c1e7c40d479a00b384ac0849c0cf0a6c3f5e.tar.zst
sway-34f5c1e7c40d479a00b384ac0849c0cf0a6c3f5e.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
-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 cda6caf7..9b7c5112 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -334,16 +334,13 @@ char *workspace_next_name(const char *output_name) {
334 if (target != NULL) { 334 if (target != NULL) {
335 return target; 335 return target;
336 } 336 }
337 // As a fall back, get the current number of active workspaces 337 // As a fall back, use the next available number
338 // and return that + 1 for the next workspace's name 338 char name[12] = "";
339 int ws_num = root->outputs->length; 339 unsigned int ws_num = 1;
340 int l = snprintf(NULL, 0, "%d", ws_num); 340 do {
341 char *name = malloc(l + 1); 341 snprintf(name, sizeof(name), "%u", ws_num++);
342 if (!sway_assert(name, "Could not allocate workspace name")) { 342 } while (workspace_by_number(name));
343 return NULL; 343 return strdup(name);
344 }
345 sprintf(name, "%d", ws_num++);
346 return name;
347} 344}
348 345
349static bool _workspace_by_number(struct sway_workspace *ws, void *data) { 346static bool _workspace_by_number(struct sway_workspace *ws, void *data) {