aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/workspace.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-08-12 03:22:47 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-08-13 09:16:45 +0900
commit804aacb8c7657f5e806d1b605652c6b71d5ab800 (patch)
tree5483766f44d1c717596b135acb3f2ebfe1fc3871 /sway/tree/workspace.c
parentRemove redundant checks (diff)
downloadsway-804aacb8c7657f5e806d1b605652c6b71d5ab800.tar.gz
sway-804aacb8c7657f5e806d1b605652c6b71d5ab800.tar.zst
sway-804aacb8c7657f5e806d1b605652c6b71d5ab800.zip
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/workspace.c')
-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) {
499 return strcmp(id1, id2); 499 return strcmp(id1, id2);
500} 500}
501 501
502static int workspace_output_get_priority(struct sway_workspace *ws,
503 struct sway_output *output) {
504 char identifier[128];
505 output_get_identifier(identifier, sizeof(identifier), output);
506 int index_id = list_seq_find(ws->output_priority, find_output, identifier);
507 int index_name = list_seq_find(ws->output_priority, find_output,
508 output->wlr_output->name);
509 return index_name < 0 || index_id < index_name ? index_id : index_name;
510}
511
502void workspace_output_raise_priority(struct sway_workspace *ws, 512void workspace_output_raise_priority(struct sway_workspace *ws,
503 struct sway_output *old_output, struct sway_output *output) { 513 struct sway_output *old_output, struct sway_output *output) {
504 int old_index = list_seq_find(ws->output_priority, find_output, 514 int old_index = workspace_output_get_priority(ws, old_output);
505 old_output->wlr_output->name);
506 if (old_index < 0) { 515 if (old_index < 0) {
507 return; 516 return;
508 } 517 }
509 518
510 int new_index = list_seq_find(ws->output_priority, find_output, 519 int new_index = workspace_output_get_priority(ws, output);
511 output->wlr_output->name);
512 if (new_index < 0) { 520 if (new_index < 0) {
513 list_insert(ws->output_priority, old_index, 521 char identifier[128];
514 strdup(output->wlr_output->name)); 522 output_get_identifier(identifier, sizeof(identifier), output);
523 list_insert(ws->output_priority, old_index, strdup(identifier));
515 } else if (new_index > old_index) { 524 } else if (new_index > old_index) {
516 char *name = ws->output_priority->items[new_index]; 525 char *name = ws->output_priority->items[new_index];
517 list_del(ws->output_priority, new_index); 526 list_del(ws->output_priority, new_index);
@@ -521,10 +530,10 @@ void workspace_output_raise_priority(struct sway_workspace *ws,
521 530
522void workspace_output_add_priority(struct sway_workspace *workspace, 531void workspace_output_add_priority(struct sway_workspace *workspace,
523 struct sway_output *output) { 532 struct sway_output *output) {
524 int index = list_seq_find(workspace->output_priority, 533 if (workspace_output_get_priority(workspace, output) < 0) {
525 find_output, output->wlr_output->name); 534 char identifier[128];
526 if (index < 0) { 535 output_get_identifier(identifier, sizeof(identifier), output);
527 list_add(workspace->output_priority, strdup(output->wlr_output->name)); 536 list_add(workspace->output_priority, strdup(identifier));
528 } 537 }
529} 538}
530 539