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 <workspace> output <outputs...>`

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.
This commit is contained in:
Brian Ashworth 2018-11-11 11:22:38 -05:00
parent 80a1c340a9
commit 12876932a9
5 changed files with 66 additions and 25 deletions

View file

@ -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;