From 12876932a948d7265745efaccafea509bdbaffe8 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Sun, 11 Nov 2018 11:22:38 -0500 Subject: Allow multiple outputs for workspace output `i3 4.16` allows users to list multiple outputs for a workspace and the first available will be used. The syntax is as follows: `workspace output ` Additionally when the workspace is created, the outputs get added to the output priority list in the order specified. This ensures that if a higher output gets connected, the workspace will move to the higher output. This works the same way as if the user had a workspace on an output, disconnected the output, and then later reconnected the output. --- sway/commands/workspace.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'sway/commands') diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index 168494d2..92118ecf 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c @@ -21,6 +21,7 @@ static struct workspace_config *workspace_config_find_or_create(char *ws_name) { return NULL; } wsc->workspace = strdup(ws_name); + wsc->outputs = create_list(); wsc->gaps_inner = INT_MIN; wsc->gaps_outer.top = INT_MIN; wsc->gaps_outer.right = INT_MIN; @@ -32,7 +33,7 @@ static struct workspace_config *workspace_config_find_or_create(char *ws_name) { void free_workspace_config(struct workspace_config *wsc) { free(wsc->workspace); - free(wsc->output); + free_flat_list(wsc->outputs); free(wsc); } @@ -141,18 +142,20 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { } } if (output_location >= 0) { - if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, output_location + 2))) { + if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, + output_location + 2))) { return error; } - char *ws_name = join_args(argv, argc - 2); + char *ws_name = join_args(argv, output_location); struct workspace_config *wsc = workspace_config_find_or_create(ws_name); free(ws_name); if (!wsc) { return cmd_results_new(CMD_FAILURE, "workspace output", "Unable to allocate workspace output"); } - free(wsc->output); - wsc->output = strdup(argv[output_location + 1]); + for (int i = output_location + 1; i < argc; ++i) { + list_add(wsc->outputs, strdup(argv[i])); + } } else if (gaps_location >= 0) { if ((error = cmd_workspace_gaps(argc, argv, gaps_location))) { return error; -- cgit v1.2.3