sway

i3-compatible Wayland compositor
git clone https://git.awy.one/sway
Log | Files | Refs | README | LICENSE

commit 804aacb8c7657f5e806d1b605652c6b71d5ab800
parent 813e1209795f7016fd1223c5ce96b2185eed5a9a
Author: Brian Ashworth <bosrsf04@gmail.com>
Date:   Mon, 12 Aug 2019 03:22:47 -0400

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.

Diffstat:
Msway/tree/workspace.c | 29+++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c @@ -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)); } }