aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--include/config.h1
-rw-r--r--sway/commands.c3
-rw-r--r--sway/workspace.c41
3 files changed, 29 insertions, 16 deletions
diff --git a/include/config.h b/include/config.h
index e6fc9f28..b97acb57 100644
--- a/include/config.h
+++ b/include/config.h
@@ -21,6 +21,7 @@ struct sway_variable {
21 * A key binding and an associated command. 21 * A key binding and an associated command.
22 */ 22 */
23struct sway_binding { 23struct sway_binding {
24 int order;
24 list_t *keys; 25 list_t *keys;
25 uint32_t modifiers; 26 uint32_t modifiers;
26 char *command; 27 char *command;
diff --git a/sway/commands.c b/sway/commands.c
index 4af9186a..3d882a7b 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -167,6 +167,8 @@ static struct cmd_results *checkarg(int argc, const char *name, enum expected_ar
167 return error; 167 return error;
168} 168}
169 169
170int binding_order = 0;
171
170static struct cmd_results *cmd_bindsym(int argc, char **argv) { 172static struct cmd_results *cmd_bindsym(int argc, char **argv) {
171 struct cmd_results *error = NULL; 173 struct cmd_results *error = NULL;
172 if ((error = checkarg(argc, "bindsym", EXPECTED_MORE_THAN, 1))) { 174 if ((error = checkarg(argc, "bindsym", EXPECTED_MORE_THAN, 1))) {
@@ -215,6 +217,7 @@ static struct cmd_results *cmd_bindsym(int argc, char **argv) {
215 free_sway_binding(dup); 217 free_sway_binding(dup);
216 list_del(mode->bindings, i); 218 list_del(mode->bindings, i);
217 } 219 }
220 binding->order = binding_order++;
218 list_add(mode->bindings, binding); 221 list_add(mode->bindings, binding);
219 list_sort(mode->bindings, sway_binding_cmp); 222 list_sort(mode->bindings, sway_binding_cmp);
220 223
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;