diff options
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r-- | sway/tree/workspace.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 3c42e259..9ba210fd 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -68,7 +68,9 @@ struct sway_container *workspace_create(struct sway_container *output, | |||
68 | swayws->floating = container_create(C_CONTAINER); | 68 | swayws->floating = container_create(C_CONTAINER); |
69 | swayws->floating->parent = swayws->swayc; | 69 | swayws->floating->parent = swayws->swayc; |
70 | swayws->floating->layout = L_FLOATING; | 70 | swayws->floating->layout = L_FLOATING; |
71 | swayws->output_priority = create_list(); | ||
71 | workspace->sway_workspace = swayws; | 72 | workspace->sway_workspace = swayws; |
73 | workspace_output_add_priority(workspace, output); | ||
72 | 74 | ||
73 | container_add_child(output, workspace); | 75 | container_add_child(output, workspace); |
74 | container_sort_workspaces(output); | 76 | container_sort_workspaces(output); |
@@ -454,3 +456,60 @@ bool workspace_is_empty(struct sway_container *ws) { | |||
454 | } | 456 | } |
455 | return true; | 457 | return true; |
456 | } | 458 | } |
459 | |||
460 | static int find_output(const void *id1, const void *id2) { | ||
461 | return strcmp(id1, id2) ? 0 : 1; | ||
462 | } | ||
463 | |||
464 | void workspace_output_raise_priority(struct sway_container *workspace, | ||
465 | struct sway_container *old_output, struct sway_container *output) { | ||
466 | struct sway_workspace *ws = workspace->sway_workspace; | ||
467 | |||
468 | int old_index = list_seq_find(ws->output_priority, find_output, | ||
469 | old_output->name); | ||
470 | if (old_index < 0) { | ||
471 | return; | ||
472 | } | ||
473 | |||
474 | int new_index = list_seq_find(ws->output_priority, find_output, | ||
475 | output->name); | ||
476 | if (new_index < 0) { | ||
477 | list_insert(ws->output_priority, old_index, strdup(output->name)); | ||
478 | } else if (new_index > old_index) { | ||
479 | char *name = ws->output_priority->items[new_index]; | ||
480 | list_del(ws->output_priority, new_index); | ||
481 | list_insert(ws->output_priority, old_index, name); | ||
482 | } | ||
483 | } | ||
484 | |||
485 | void workspace_output_add_priority(struct sway_container *workspace, | ||
486 | struct sway_container *output) { | ||
487 | int index = list_seq_find(workspace->sway_workspace->output_priority, | ||
488 | find_output, output->name); | ||
489 | if (index < 0) { | ||
490 | list_add(workspace->sway_workspace->output_priority, | ||
491 | strdup(output->name)); | ||
492 | } | ||
493 | } | ||
494 | |||
495 | static bool _output_by_name(struct sway_container *output, void *data) { | ||
496 | return output->type == C_OUTPUT && strcasecmp(output->name, data) == 0; | ||
497 | } | ||
498 | |||
499 | struct sway_container *workspace_output_get_highest_available( | ||
500 | struct sway_container *ws, struct sway_container *exclude) { | ||
501 | for (int i = 0; i < ws->sway_workspace->output_priority->length; i++) { | ||
502 | char *name = ws->sway_workspace->output_priority->items[i]; | ||
503 | if (exclude && strcasecmp(name, exclude->name) == 0) { | ||
504 | continue; | ||
505 | } | ||
506 | |||
507 | struct sway_container *output = container_find(&root_container, | ||
508 | _output_by_name, name); | ||
509 | if (output) { | ||
510 | return output; | ||
511 | } | ||
512 | } | ||
513 | |||
514 | return NULL; | ||
515 | } | ||