diff options
-rw-r--r-- | sway/tree/workspace.c | 17 |
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 | ||
349 | static bool _workspace_by_number(struct sway_workspace *ws, void *data) { | 346 | static bool _workspace_by_number(struct sway_workspace *ws, void *data) { |