diff options
author | Calvin Lee <cyrus296@gmail.com> | 2017-03-01 11:35:47 -0700 |
---|---|---|
committer | Calvin Lee <cyrus296@gmail.com> | 2017-03-01 11:35:47 -0700 |
commit | d47d3d78de15fd0bc04550e35e40b97a82d6e1ca (patch) | |
tree | f6e28a20f3852e20b4333146490dcb507ab69065 | |
parent | Merge pull request #1092 from 4e554c4c/move_floating (diff) | |
download | sway-d47d3d78de15fd0bc04550e35e40b97a82d6e1ca.tar.gz sway-d47d3d78de15fd0bc04550e35e40b97a82d6e1ca.tar.zst sway-d47d3d78de15fd0bc04550e35e40b97a82d6e1ca.zip |
Fix #1099: Allow spaces in worspace names
This commit allows unquoted spaces in worspace names in order to keep
compatability with i3. The names _must not_ contain the string "output"
which is documented in 'sway.5' because how sway detects the `move
<workspace> output <output>` command. Also I documented that "number"
may be used before the worspace name without affecting how the name is
evaluated.
-rw-r--r-- | sway/commands/workspace.c | 66 | ||||
-rw-r--r-- | sway/sway.5.txt | 7 |
2 files changed, 43 insertions, 30 deletions
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index 14fe242f..7db1f332 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c | |||
@@ -12,12 +12,44 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
12 | if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) { | 12 | if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) { |
13 | return error; | 13 | return error; |
14 | } | 14 | } |
15 | if (argc == 1 || (argc >= 2 && strcasecmp(argv[0], "number") == 0) ) { | 15 | |
16 | int output_location = -1; | ||
17 | |||
18 | for (int i = 0; i < argc; ++i) { | ||
19 | if (strcasecmp(argv[i], "output") == 0) { | ||
20 | output_location = i; | ||
21 | break; | ||
22 | } | ||
23 | } | ||
24 | if (output_location >= 0) { | ||
25 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, output_location + 2))) { | ||
26 | return error; | ||
27 | } | ||
28 | struct workspace_output *wso = calloc(1, sizeof(struct workspace_output)); | ||
29 | if (!wso) { | ||
30 | return cmd_results_new(CMD_FAILURE, "workspace output", | ||
31 | "Unable to allocate workspace output"); | ||
32 | } | ||
33 | wso->workspace = join_args(argv, argc - 2); | ||
34 | wso->output = strdup(argv[output_location]); | ||
35 | int i = -1; | ||
36 | if ((i = list_seq_find(config->workspace_outputs, workspace_output_cmp_workspace, wso)) != -1) { | ||
37 | struct workspace_output *old = config->workspace_outputs->items[i]; | ||
38 | free(old); // workspaces can only be assigned to a single output | ||
39 | list_del(config->workspace_outputs, i); | ||
40 | } | ||
41 | sway_log(L_DEBUG, "Assigning workspace %s to output %s", wso->workspace, wso->output); | ||
42 | list_add(config->workspace_outputs, wso); | ||
43 | if (!config->reading) { | ||
44 | // TODO: Move workspace to output. (don't do so when reloading) | ||
45 | } | ||
46 | } | ||
47 | else { | ||
16 | if (config->reading || !config->active) { | 48 | if (config->reading || !config->active) { |
17 | return cmd_results_new(CMD_DEFER, "workspace", NULL); | 49 | return cmd_results_new(CMD_DEFER, "workspace", NULL); |
18 | } | 50 | } |
19 | swayc_t *ws = NULL; | 51 | swayc_t *ws = NULL; |
20 | if (argc >= 2) { | 52 | if (strcasecmp(argv[0], "number") == 0) { |
21 | if (!(ws = workspace_by_number(argv[1]))) { | 53 | if (!(ws = workspace_by_number(argv[1]))) { |
22 | char *name = join_args(argv + 1, argc - 1); | 54 | char *name = join_args(argv + 1, argc - 1); |
23 | ws = workspace_create(name); | 55 | ws = workspace_create(name); |
@@ -41,9 +73,11 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
41 | ws = workspace_create(prev_workspace_name); | 73 | ws = workspace_create(prev_workspace_name); |
42 | } | 74 | } |
43 | } else { | 75 | } else { |
44 | if (!(ws = workspace_by_name(argv[0]))) { | 76 | char *name = join_args(argv, argc); |
45 | ws = workspace_create(argv[0]); | 77 | if (!(ws = workspace_by_name(name))) { |
78 | ws = workspace_create(name); | ||
46 | } | 79 | } |
80 | free(name); | ||
47 | } | 81 | } |
48 | swayc_t *old_output = swayc_active_output(); | 82 | swayc_t *old_output = swayc_active_output(); |
49 | workspace_switch(ws); | 83 | workspace_switch(ws); |
@@ -55,30 +89,6 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
55 | center_pointer_on(focused); | 89 | center_pointer_on(focused); |
56 | } | 90 | } |
57 | } | 91 | } |
58 | } else { | ||
59 | if (strcasecmp(argv[1], "output") == 0) { | ||
60 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 3))) { | ||
61 | return error; | ||
62 | } | ||
63 | struct workspace_output *wso = calloc(1, sizeof(struct workspace_output)); | ||
64 | if (!wso) { | ||
65 | return cmd_results_new(CMD_FAILURE, "workspace output", | ||
66 | "Unable to allocate workspace output"); | ||
67 | } | ||
68 | wso->workspace = strdup(argv[0]); | ||
69 | wso->output = strdup(argv[2]); | ||
70 | int i = -1; | ||
71 | if ((i = list_seq_find(config->workspace_outputs, workspace_output_cmp_workspace, wso)) != -1) { | ||
72 | struct workspace_output *old = config->workspace_outputs->items[i]; | ||
73 | free(old); // workspaces can only be assigned to a single output | ||
74 | list_del(config->workspace_outputs, i); | ||
75 | } | ||
76 | sway_log(L_DEBUG, "Assigning workspace %s to output %s", argv[0], argv[2]); | ||
77 | list_add(config->workspace_outputs, wso); | ||
78 | if (!config->reading) { | ||
79 | // TODO: Move workspace to output. (don't do so when reloading) | ||
80 | } | ||
81 | } | ||
82 | } | 92 | } |
83 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 93 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
84 | } | 94 | } |
diff --git a/sway/sway.5.txt b/sway/sway.5.txt index f425cfe7..8e3f64ab 100644 --- a/sway/sway.5.txt +++ b/sway/sway.5.txt | |||
@@ -364,8 +364,11 @@ The default colors are: | |||
364 | be configured with perfectly aligned adjacent positions for this option to | 364 | be configured with perfectly aligned adjacent positions for this option to |
365 | have any effect. | 365 | have any effect. |
366 | 366 | ||
367 | **workspace** <name>:: | 367 | **workspace** [number] <name>:: |
368 | Switches to the specified workspace. | 368 | Switches to the specified workspace. The string "number" is optional. The |
369 | worspace _name_, if unquoted, may not contain the string "output", as sway | ||
370 | will assume that the command is moving a worspace to an output, as described | ||
371 | below. | ||
369 | 372 | ||
370 | **workspace** <prev|next>:: | 373 | **workspace** <prev|next>:: |
371 | Switches to the next workspace on the current output or on the next output | 374 | Switches to the next workspace on the current output or on the next output |