workspace: prefer identifiers for output priority

Since output names can change in various configurations, including
DisplayPort MST, prefer output identifiers for the output priority.
Users can still use `workspace <ws> output <names-or-ids>`, but any
output that is programmatically added to the list will be added under
the output identifier. If the output name exists in the list (from the
user workspace output configs), then that will be retained instead of
switching to the output identifier for that output.
This commit is contained in:
Brian Ashworth 2019-08-12 03:22:47 -04:00 committed by Drew DeVault
parent 813e120979
commit 804aacb8c7

View file

@ -499,19 +499,28 @@ static int find_output(const void *id1, const void *id2) {
return strcmp(id1, id2);
}
static int workspace_output_get_priority(struct sway_workspace *ws,
struct sway_output *output) {
char identifier[128];
output_get_identifier(identifier, sizeof(identifier), output);
int index_id = list_seq_find(ws->output_priority, find_output, identifier);
int index_name = list_seq_find(ws->output_priority, find_output,
output->wlr_output->name);
return index_name < 0 || index_id < index_name ? index_id : index_name;
}
void workspace_output_raise_priority(struct sway_workspace *ws,
struct sway_output *old_output, struct sway_output *output) {
int old_index = list_seq_find(ws->output_priority, find_output,
old_output->wlr_output->name);
int old_index = workspace_output_get_priority(ws, old_output);
if (old_index < 0) {
return;
}
int new_index = list_seq_find(ws->output_priority, find_output,
output->wlr_output->name);
int new_index = workspace_output_get_priority(ws, output);
if (new_index < 0) {
list_insert(ws->output_priority, old_index,
strdup(output->wlr_output->name));
char identifier[128];
output_get_identifier(identifier, sizeof(identifier), output);
list_insert(ws->output_priority, old_index, strdup(identifier));
} else if (new_index > old_index) {
char *name = ws->output_priority->items[new_index];
list_del(ws->output_priority, new_index);
@ -521,10 +530,10 @@ void workspace_output_raise_priority(struct sway_workspace *ws,
void workspace_output_add_priority(struct sway_workspace *workspace,
struct sway_output *output) {
int index = list_seq_find(workspace->output_priority,
find_output, output->wlr_output->name);
if (index < 0) {
list_add(workspace->output_priority, strdup(output->wlr_output->name));
if (workspace_output_get_priority(workspace, output) < 0) {
char identifier[128];
output_get_identifier(identifier, sizeof(identifier), output);
list_add(workspace->output_priority, strdup(identifier));
}
}