diff options
author | Ronan Pigott <ronan@rjp.ie> | 2022-11-16 15:50:34 -0700 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2022-11-26 09:48:58 +0100 |
commit | 864b3a9a18f236f92f1898bb44ab977ceaebfd68 (patch) | |
tree | bab0ea888c50af46725c94fe5c0c024bdf432a69 /sway/tree | |
parent | launcher: rename pid_workspace to launcher_ctx (diff) | |
download | sway-864b3a9a18f236f92f1898bb44ab977ceaebfd68.tar.gz sway-864b3a9a18f236f92f1898bb44ab977ceaebfd68.tar.zst sway-864b3a9a18f236f92f1898bb44ab977ceaebfd68.zip |
view: associate launch contexts with views
Views now maintain a reference to a launch context which, as a last
resort, is populated at map time with a context associated with its pid.
This opens the possibility of populating it before map via another
source, e.g. xdga-tokens or configuration.
Diffstat (limited to 'sway/tree')
-rw-r--r-- | sway/tree/view.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c index 7482e7a4..31387aaa 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -64,6 +64,8 @@ void view_destroy(struct sway_view *view) { | |||
64 | } | 64 | } |
65 | list_free(view->executed_criteria); | 65 | list_free(view->executed_criteria); |
66 | 66 | ||
67 | view_assign_ctx(view, NULL); | ||
68 | |||
67 | free(view->title_format); | 69 | free(view->title_format); |
68 | 70 | ||
69 | if (view->impl->destroy) { | 71 | if (view->impl->destroy) { |
@@ -534,6 +536,20 @@ static void view_populate_pid(struct sway_view *view) { | |||
534 | view->pid = pid; | 536 | view->pid = pid; |
535 | } | 537 | } |
536 | 538 | ||
539 | void view_assign_ctx(struct sway_view *view, struct launcher_ctx *ctx) { | ||
540 | if (view->ctx) { | ||
541 | // This ctx has been replaced | ||
542 | launcher_ctx_destroy(view->ctx); | ||
543 | view->ctx = NULL; | ||
544 | } | ||
545 | if (ctx == NULL) { | ||
546 | return; | ||
547 | } | ||
548 | launcher_ctx_consume(ctx); | ||
549 | |||
550 | view->ctx = ctx; | ||
551 | } | ||
552 | |||
537 | static struct sway_workspace *select_workspace(struct sway_view *view) { | 553 | static struct sway_workspace *select_workspace(struct sway_view *view) { |
538 | struct sway_seat *seat = input_manager_current_seat(); | 554 | struct sway_seat *seat = input_manager_current_seat(); |
539 | 555 | ||
@@ -569,13 +585,14 @@ static struct sway_workspace *select_workspace(struct sway_view *view) { | |||
569 | } | 585 | } |
570 | list_free(criterias); | 586 | list_free(criterias); |
571 | if (ws) { | 587 | if (ws) { |
572 | remove_workspace_pid(view->pid); | 588 | view_assign_ctx(view, NULL); |
573 | return ws; | 589 | return ws; |
574 | } | 590 | } |
575 | 591 | ||
576 | // Check if there's a PID mapping | 592 | // Check if there's a PID mapping |
577 | ws = workspace_for_pid(view->pid); | 593 | ws = view->ctx ? launcher_ctx_get_workspace(view->ctx) : NULL; |
578 | if (ws) { | 594 | if (ws) { |
595 | view_assign_ctx(view, NULL); | ||
579 | return ws; | 596 | return ws; |
580 | } | 597 | } |
581 | 598 | ||
@@ -718,6 +735,13 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface, | |||
718 | view_populate_pid(view); | 735 | view_populate_pid(view); |
719 | view->container = container_create(view); | 736 | view->container = container_create(view); |
720 | 737 | ||
738 | if (view->ctx == NULL) { | ||
739 | struct launcher_ctx *ctx = launcher_ctx_find_pid(view->pid); | ||
740 | if (ctx != NULL) { | ||
741 | view_assign_ctx(view, ctx); | ||
742 | } | ||
743 | } | ||
744 | |||
721 | // If there is a request to be opened fullscreen on a specific output, try | 745 | // If there is a request to be opened fullscreen on a specific output, try |
722 | // to honor that request. Otherwise, fallback to assigns, pid mappings, | 746 | // to honor that request. Otherwise, fallback to assigns, pid mappings, |
723 | // focused workspace, etc | 747 | // focused workspace, etc |