aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sway/tree/workspace.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index d6819c61..30cf3ebe 100644
--- 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));
}
}