diff options
author | 2015-08-13 11:12:09 -0500 | |
---|---|---|
committer | 2015-08-13 14:41:36 -0500 | |
commit | 8d63ac594bdea7e1e34f0aa99dc72becbb4f4949 (patch) | |
tree | 942dbf6f67d1e62f54abc9598903a83c07aeeec8 | |
parent | Merge pull request #25 from taiyu-len/master (diff) | |
download | sway-8d63ac594bdea7e1e34f0aa99dc72becbb4f4949.tar.gz sway-8d63ac594bdea7e1e34f0aa99dc72becbb4f4949.tar.zst sway-8d63ac594bdea7e1e34f0aa99dc72becbb4f4949.zip |
Changed workspace name generation to try and use bindsyms when possible
-rw-r--r-- | sway/workspace.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/sway/workspace.c b/sway/workspace.c index 53675c03..96604678 100644 --- a/sway/workspace.c +++ b/sway/workspace.c | |||
@@ -12,7 +12,42 @@ swayc_t *active_workspace = NULL; | |||
12 | int ws_num = 1; | 12 | int ws_num = 1; |
13 | 13 | ||
14 | char *workspace_next_name(void) { | 14 | char *workspace_next_name(void) { |
15 | int l = 1; | 15 | int i; |
16 | // Scan all workspace bindings to find the next available workspace name, | ||
17 | // if none are found/available then default to a number | ||
18 | struct sway_mode *mode = config->current_mode; | ||
19 | |||
20 | for (i = 0; i < mode->bindings->length; ++i) { | ||
21 | const char* command = *binding = mode->bindings->items[i]->command; | ||
22 | list_t *args = split_string(command, " "); | ||
23 | |||
24 | if (strcmp("workspace", args->items[0]) == 0 && args->length > 2) { | ||
25 | const char* target = args->items[1]; | ||
26 | |||
27 | while (*target == ' ' || *target == '\t') | ||
28 | target++; | ||
29 | |||
30 | // Make sure that the command references an actual workspace | ||
31 | // not a command about workspaces | ||
32 | if (strcmp(target, "next") == 0 || | ||
33 | strcmp(target, "prev") == 0 || | ||
34 | strcmp(target, "next_on_output") == 0 || | ||
35 | strcmp(target, "prev_on_output") == 0 || | ||
36 | strcmp(target, "number") == 0 || | ||
37 | strcmp(target, "back_and_forth") == 0 || | ||
38 | strcmp(target, "current") == 0) | ||
39 | continue; | ||
40 | |||
41 | //Make sure that the workspace doesn't already exist | ||
42 | if (workspace_find_by_name(args->items[2])) | ||
43 | continue; | ||
44 | |||
45 | return args->items[2]; | ||
46 | } | ||
47 | } | ||
48 | // As a fall back, get the current number of active workspaces | ||
49 | // and return that + 1 for the next workspace's name | ||
50 | int ws_num = root_container.children->length; | ||
16 | if (ws_num >= 10) { | 51 | if (ws_num >= 10) { |
17 | l = 2; | 52 | l = 2; |
18 | } else if (ws_num >= 100) { | 53 | } else if (ws_num >= 100) { |