summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2017-03-01 14:09:17 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2017-03-07 09:43:00 -0500
commit154188f685ba6436e4daf9fb493f2ee56814e428 (patch)
tree78a3b4671ea4b540c36a098714eb28fb279fab74
parentFix #1087 (diff)
downloadsway-154188f685ba6436e4daf9fb493f2ee56814e428.tar.gz
sway-154188f685ba6436e4daf9fb493f2ee56814e428.tar.zst
sway-154188f685ba6436e4daf9fb493f2ee56814e428.zip
Merge pull request #1101 from 4e554c4c/worspace_names
Fix #1099: Allow spaces in worspace names
-rw-r--r--sway/commands/workspace.c66
-rw-r--r--sway/sway.5.txt7
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 19f7eb1d..45307b03 100644
--- a/sway/sway.5.txt
+++ b/sway/sway.5.txt
@@ -360,8 +360,11 @@ The default colors are:
360 be configured with perfectly aligned adjacent positions for this option to 360 be configured with perfectly aligned adjacent positions for this option to
361 have any effect. 361 have any effect.
362 362
363**workspace** <name>:: 363**workspace** [number] <name>::
364 Switches to the specified workspace. 364 Switches to the specified workspace. The string "number" is optional. The
365 worspace _name_, if unquoted, may not contain the string "output", as sway
366 will assume that the command is moving a worspace to an output, as described
367 below.
365 368
366**workspace** <prev|next>:: 369**workspace** <prev|next>::
367 Switches to the next workspace on the current output or on the next output 370 Switches to the next workspace on the current output or on the next output