diff options
Diffstat (limited to 'sway/commands/workspace.c')
-rw-r--r-- | sway/commands/workspace.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index f026a39d..2ce7872d 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c | |||
@@ -10,6 +10,26 @@ | |||
10 | #include "log.h" | 10 | #include "log.h" |
11 | #include "stringop.h" | 11 | #include "stringop.h" |
12 | 12 | ||
13 | static struct workspace_config *workspace_config_find_or_create(char *ws_name) { | ||
14 | struct workspace_config *wsc = workspace_find_config(ws_name); | ||
15 | if (wsc) { | ||
16 | return wsc; | ||
17 | } | ||
18 | wsc = calloc(1, sizeof(struct workspace_config)); | ||
19 | if (!wsc) { | ||
20 | return NULL; | ||
21 | } | ||
22 | wsc->workspace = strdup(ws_name); | ||
23 | list_add(config->workspace_configs, wsc); | ||
24 | return wsc; | ||
25 | } | ||
26 | |||
27 | void free_workspace_config(struct workspace_config *wsc) { | ||
28 | free(wsc->workspace); | ||
29 | free(wsc->output); | ||
30 | free(wsc); | ||
31 | } | ||
32 | |||
13 | struct cmd_results *cmd_workspace(int argc, char **argv) { | 33 | struct cmd_results *cmd_workspace(int argc, char **argv) { |
14 | struct cmd_results *error = NULL; | 34 | struct cmd_results *error = NULL; |
15 | if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) { | 35 | if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) { |
@@ -28,21 +48,15 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
28 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, output_location + 2))) { | 48 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, output_location + 2))) { |
29 | return error; | 49 | return error; |
30 | } | 50 | } |
31 | struct workspace_output *wso = calloc(1, sizeof(struct workspace_output)); | 51 | char *ws_name = join_args(argv, argc - 2); |
32 | if (!wso) { | 52 | struct workspace_config *wsc = workspace_config_find_or_create(ws_name); |
53 | free(ws_name); | ||
54 | if (!wsc) { | ||
33 | return cmd_results_new(CMD_FAILURE, "workspace output", | 55 | return cmd_results_new(CMD_FAILURE, "workspace output", |
34 | "Unable to allocate workspace output"); | 56 | "Unable to allocate workspace output"); |
35 | } | 57 | } |
36 | wso->workspace = join_args(argv, argc - 2); | 58 | free(wsc->output); |
37 | wso->output = strdup(argv[output_location + 1]); | 59 | wsc->output = strdup(argv[output_location + 1]); |
38 | int i = -1; | ||
39 | if ((i = list_seq_find(config->workspace_outputs, workspace_output_cmp_workspace, wso)) != -1) { | ||
40 | struct workspace_output *old = config->workspace_outputs->items[i]; | ||
41 | free(old); // workspaces can only be assigned to a single output | ||
42 | list_del(config->workspace_outputs, i); | ||
43 | } | ||
44 | wlr_log(WLR_DEBUG, "Assigning workspace %s to output %s", wso->workspace, wso->output); | ||
45 | list_add(config->workspace_outputs, wso); | ||
46 | } else { | 60 | } else { |
47 | if (config->reading || !config->active) { | 61 | if (config->reading || !config->active) { |
48 | return cmd_results_new(CMD_DEFER, "workspace", NULL); | 62 | return cmd_results_new(CMD_DEFER, "workspace", NULL); |