aboutsummaryrefslogtreecommitdiff
path: root/sway/tree
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2019-08-12 03:22:47 -0400
committerDrew DeVault <sir@cmpwn.com>2019-08-13 09:16:45 +0900
commit804aacb8c7657f5e806d1b605652c6b71d5ab800 (patch)
tree5483766f44d1c717596b135acb3f2ebfe1fc3871 /sway/tree
parent813e1209795f7016fd1223c5ce96b2185eed5a9a (diff)
downloadsway-804aacb8c7657f5e806d1b605652c6b71d5ab800.tar.xz
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 (limited to 'sway/tree')
-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));
}
}