summaryrefslogtreecommitdiffstats
path: root/sway/workspace.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-12-18 18:52:14 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-12-18 18:52:51 -0500
commit7647762bab3b625bba6004de761454a2ae4edc5d (patch)
tree3c3f83675c8ca1612c13d147ecb52aaf19381f37 /sway/workspace.c
parentMerge pull request #360 from sce/fix_arrange_windows (diff)
downloadsway-7647762bab3b625bba6004de761454a2ae4edc5d.tar.gz
sway-7647762bab3b625bba6004de761454a2ae4edc5d.tar.zst
sway-7647762bab3b625bba6004de761454a2ae4edc5d.zip
Fix default workspace name generation
This fixes the issue where workspace 10 ends up being the default.
Diffstat (limited to 'sway/workspace.c')
-rw-r--r--sway/workspace.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/sway/workspace.c b/sway/workspace.c
index 761a5f4e..f7523b79 100644
--- a/sway/workspace.c
+++ b/sway/workspace.c
@@ -1,5 +1,7 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <stdbool.h> 2#include <stdbool.h>
3#include <limits.h>
4#include <ctype.h>
3#include <wlc/wlc.h> 5#include <wlc/wlc.h>
4#include <string.h> 6#include <string.h>
5#include <strings.h> 7#include <strings.h>
@@ -31,6 +33,8 @@ char *workspace_next_name(void) {
31 // if none are found/available then default to a number 33 // if none are found/available then default to a number
32 struct sway_mode *mode = config->current_mode; 34 struct sway_mode *mode = config->current_mode;
33 35
36 int order = INT_MAX;
37 char *target = NULL;
34 for (i = 0; i < mode->bindings->length; ++i) { 38 for (i = 0; i < mode->bindings->length; ++i) {
35 struct sway_binding *binding = mode->bindings->items[i]; 39 struct sway_binding *binding = mode->bindings->items[i];
36 char *cmdlist = strdup(binding->command); 40 char *cmdlist = strdup(binding->command);
@@ -45,35 +49,40 @@ char *workspace_next_name(void) {
45 49
46 if (strcmp("workspace", cmd) == 0 && name) { 50 if (strcmp("workspace", cmd) == 0 && name) {
47 sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", name); 51 sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", name);
48 char* target = strdup(name); 52 char *_target = strdup(name);
49 while (*target == ' ' || *target == '\t') 53 while (isspace(*_target))
50 target++; 54 _target++;
51 55
52 // Make sure that the command references an actual workspace 56 // Make sure that the command references an actual workspace
53 // not a command about workspaces 57 // not a command about workspaces
54 if (strcmp(target, "next") == 0 || 58 if (strcmp(_target, "next") == 0 ||
55 strcmp(target, "prev") == 0 || 59 strcmp(_target, "prev") == 0 ||
56 strcmp(target, "next_on_output") == 0 || 60 strcmp(_target, "next_on_output") == 0 ||
57 strcmp(target, "prev_on_output") == 0 || 61 strcmp(_target, "prev_on_output") == 0 ||
58 strcmp(target, "number") == 0 || 62 strcmp(_target, "number") == 0 ||
59 strcmp(target, "back_and_forth") == 0 || 63 strcmp(_target, "back_and_forth") == 0 ||
60 strcmp(target, "current") == 0) 64 strcmp(_target, "current") == 0)
61 { 65 {
62 free(target); 66 free(_target);
63 continue; 67 continue;
64 } 68 }
65 69
66 // Make sure that the workspace doesn't already exist 70 // Make sure that the workspace doesn't already exist
67 if (workspace_by_name(target)) { 71 if (workspace_by_name(_target)) {
68 free(target); 72 free(_target);
69 continue; 73 continue;
70 } 74 }
71 free(dup); 75 if (binding->order < order) {
72 sway_log(L_DEBUG, "Workspace: Found free name %s", target); 76 order = binding->order;
73 return target; 77 target = _target;
78 sway_log(L_DEBUG, "Workspace: Found free name %s", _target);
79 }
74 } 80 }
75 free(dup); 81 free(dup);
76 } 82 }
83 if (target != NULL) {
84 return target;
85 }
77 // As a fall back, get the current number of active workspaces 86 // As a fall back, get the current number of active workspaces
78 // and return that + 1 for the next workspace's name 87 // and return that + 1 for the next workspace's name
79 int ws_num = root_container.children->length; 88 int ws_num = root_container.children->length;