diff options
author | Ronan Pigott <ronan@rjp.ie> | 2022-11-16 15:50:34 -0700 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2022-11-26 10:29:59 +0100 |
commit | 5794a223ce9c22cee11a395bd0aa9477939becde (patch) | |
tree | bde976da20d3fa63e9ff24e592c0dccfcd32f187 /sway/desktop/launcher.c | |
parent | launcher: rename pid_workspace to launcher_ctx (diff) | |
download | sway-5794a223ce9c22cee11a395bd0aa9477939becde.tar.gz sway-5794a223ce9c22cee11a395bd0aa9477939becde.tar.zst sway-5794a223ce9c22cee11a395bd0aa9477939becde.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.
(cherry picked from commit 864b3a9a18f236f92f1898bb44ab977ceaebfd68)
Diffstat (limited to 'sway/desktop/launcher.c')
-rw-r--r-- | sway/desktop/launcher.c | 50 |
1 files changed, 16 insertions, 34 deletions
diff --git a/sway/desktop/launcher.c b/sway/desktop/launcher.c index 337ca975..810a04ef 100644 --- a/sway/desktop/launcher.c +++ b/sway/desktop/launcher.c | |||
@@ -13,18 +13,6 @@ | |||
13 | 13 | ||
14 | static struct wl_list launcher_ctxs; | 14 | static struct wl_list launcher_ctxs; |
15 | 15 | ||
16 | struct launcher_ctx { | ||
17 | pid_t pid; | ||
18 | char *name; | ||
19 | struct wlr_xdg_activation_token_v1 *token; | ||
20 | struct wl_listener token_destroy; | ||
21 | |||
22 | struct sway_node *node; | ||
23 | struct wl_listener node_destroy; | ||
24 | |||
25 | struct wl_list link; | ||
26 | }; | ||
27 | |||
28 | /** | 16 | /** |
29 | * Get the pid of a parent process given the pid of a child process. | 17 | * Get the pid of a parent process given the pid of a child process. |
30 | * | 18 | * |
@@ -59,7 +47,20 @@ static pid_t get_parent_pid(pid_t child) { | |||
59 | return -1; | 47 | return -1; |
60 | } | 48 | } |
61 | 49 | ||
62 | static void launcher_ctx_destroy(struct launcher_ctx *ctx) { | 50 | void launcher_ctx_consume(struct launcher_ctx *ctx) { |
51 | // The view is now responsible for destroying this ctx | ||
52 | wl_list_remove(&ctx->token_destroy.link); | ||
53 | wl_list_init(&ctx->token_destroy.link); | ||
54 | |||
55 | wlr_xdg_activation_token_v1_destroy(ctx->token); | ||
56 | ctx->token = NULL; | ||
57 | |||
58 | // Prevent additional matches | ||
59 | wl_list_remove(&ctx->link); | ||
60 | wl_list_init(&ctx->link); | ||
61 | } | ||
62 | |||
63 | void launcher_ctx_destroy(struct launcher_ctx *ctx) { | ||
63 | if (ctx == NULL) { | 64 | if (ctx == NULL) { |
64 | return; | 65 | return; |
65 | } | 66 | } |
@@ -71,7 +72,7 @@ static void launcher_ctx_destroy(struct launcher_ctx *ctx) { | |||
71 | free(ctx); | 72 | free(ctx); |
72 | } | 73 | } |
73 | 74 | ||
74 | static struct launcher_ctx *launcher_ctx_find_pid(pid_t pid) { | 75 | struct launcher_ctx *launcher_ctx_find_pid(pid_t pid) { |
75 | if (!launcher_ctxs.prev && !launcher_ctxs.next) { | 76 | if (!launcher_ctxs.prev && !launcher_ctxs.next) { |
76 | wl_list_init(&launcher_ctxs); | 77 | wl_list_init(&launcher_ctxs); |
77 | return NULL; | 78 | return NULL; |
@@ -97,7 +98,7 @@ static struct launcher_ctx *launcher_ctx_find_pid(pid_t pid) { | |||
97 | return ctx; | 98 | return ctx; |
98 | } | 99 | } |
99 | 100 | ||
100 | static struct sway_workspace *launcher_ctx_get_workspace( | 101 | struct sway_workspace *launcher_ctx_get_workspace( |
101 | struct launcher_ctx *ctx) { | 102 | struct launcher_ctx *ctx) { |
102 | struct sway_workspace *ws = NULL; | 103 | struct sway_workspace *ws = NULL; |
103 | struct sway_output *output = NULL; | 104 | struct sway_output *output = NULL; |
@@ -135,16 +136,6 @@ static struct sway_workspace *launcher_ctx_get_workspace( | |||
135 | return ws; | 136 | return ws; |
136 | } | 137 | } |
137 | 138 | ||
138 | struct sway_workspace *workspace_for_pid(pid_t pid) { | ||
139 | struct launcher_ctx *ctx = launcher_ctx_find_pid(pid); | ||
140 | if (ctx == NULL) { | ||
141 | return NULL; | ||
142 | } | ||
143 | struct sway_workspace *ws = launcher_ctx_get_workspace(ctx); | ||
144 | launcher_ctx_destroy(ctx); | ||
145 | return ws; | ||
146 | } | ||
147 | |||
148 | static void ctx_handle_node_destroy(struct wl_listener *listener, void *data) { | 139 | static void ctx_handle_node_destroy(struct wl_listener *listener, void *data) { |
149 | struct launcher_ctx *ctx = wl_container_of(listener, ctx, node_destroy); | 140 | struct launcher_ctx *ctx = wl_container_of(listener, ctx, node_destroy); |
150 | switch (ctx->node->type) { | 141 | switch (ctx->node->type) { |
@@ -217,12 +208,3 @@ void launcher_ctx_create(pid_t pid) { | |||
217 | 208 | ||
218 | wl_list_insert(&launcher_ctxs, &ctx->link); | 209 | wl_list_insert(&launcher_ctxs, &ctx->link); |
219 | } | 210 | } |
220 | |||
221 | void remove_workspace_pid(pid_t pid) { | ||
222 | if (!launcher_ctxs.prev || !launcher_ctxs.next) { | ||
223 | return; | ||
224 | } | ||
225 | |||
226 | struct launcher_ctx *ctx = launcher_ctx_find_pid(pid); | ||
227 | launcher_ctx_destroy(ctx); | ||
228 | } | ||