aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Ronan Pigott <ronan@rjp.ie>2024-02-07 16:13:25 -0700
committerLibravatar Simon Ser <contact@emersion.fr>2024-02-17 14:27:03 +0100
commitd91779d6471c80fadb30955ad713618740cf649e (patch)
tree9d8f152534983d68a897ae40194c226c84c022e1
parentFix build with wlroots DRM backend disabled (diff)
downloadsway-d91779d6471c80fadb30955ad713618740cf649e.tar.gz
sway-d91779d6471c80fadb30955ad713618740cf649e.tar.zst
sway-d91779d6471c80fadb30955ad713618740cf649e.zip
launcher: track the seat in the launcher ctx
This is a more suitable place to track the requesting seat, since we are able to respond appropriately to destroy notifications. (cherry picked from commit f6d22f8e6886edfeca3ecbb695b02079e81ce360)
-rw-r--r--include/sway/desktop/launcher.h3
-rw-r--r--sway/desktop/launcher.c13
-rw-r--r--sway/xdg_activation_v1.c21
3 files changed, 31 insertions, 6 deletions
diff --git a/include/sway/desktop/launcher.h b/include/sway/desktop/launcher.h
index b7716e82..ad465a9e 100644
--- a/include/sway/desktop/launcher.h
+++ b/include/sway/desktop/launcher.h
@@ -3,12 +3,15 @@
3 3
4#include <stdlib.h> 4#include <stdlib.h>
5#include <wayland-server-core.h> 5#include <wayland-server-core.h>
6#include "sway/input/seat.h"
6 7
7struct launcher_ctx { 8struct launcher_ctx {
8 pid_t pid; 9 pid_t pid;
9 char *fallback_name; 10 char *fallback_name;
10 struct wlr_xdg_activation_token_v1 *token; 11 struct wlr_xdg_activation_token_v1 *token;
11 struct wl_listener token_destroy; 12 struct wl_listener token_destroy;
13 struct sway_seat *seat;
14 struct wl_listener seat_destroy;
12 15
13 bool activated; 16 bool activated;
14 17
diff --git a/sway/desktop/launcher.c b/sway/desktop/launcher.c
index 00a7e38a..4a4255d7 100644
--- a/sway/desktop/launcher.c
+++ b/sway/desktop/launcher.c
@@ -67,6 +67,9 @@ void launcher_ctx_destroy(struct launcher_ctx *ctx) {
67 } 67 }
68 wl_list_remove(&ctx->node_destroy.link); 68 wl_list_remove(&ctx->node_destroy.link);
69 wl_list_remove(&ctx->token_destroy.link); 69 wl_list_remove(&ctx->token_destroy.link);
70 if (ctx->seat) {
71 wl_list_remove(&ctx->seat_destroy.link);
72 }
70 wl_list_remove(&ctx->link); 73 wl_list_remove(&ctx->link);
71 wlr_xdg_activation_token_v1_destroy(ctx->token); 74 wlr_xdg_activation_token_v1_destroy(ctx->token);
72 free(ctx->fallback_name); 75 free(ctx->fallback_name);
@@ -227,6 +230,12 @@ struct launcher_ctx *launcher_ctx_create(struct wlr_xdg_activation_token_v1 *tok
227 return ctx; 230 return ctx;
228} 231}
229 232
233static void launch_ctx_handle_seat_destroy(struct wl_listener *listener, void *data) {
234 struct launcher_ctx *ctx = wl_container_of(listener, ctx, seat_destroy);
235 ctx->seat = NULL;
236 wl_list_remove(&ctx->seat_destroy.link);
237}
238
230// Creates a context with a new token for the internal launcher 239// Creates a context with a new token for the internal launcher
231struct launcher_ctx *launcher_ctx_create_internal(void) { 240struct launcher_ctx *launcher_ctx_create_internal(void) {
232 struct sway_seat *seat = input_manager_current_seat(); 241 struct sway_seat *seat = input_manager_current_seat();
@@ -238,13 +247,15 @@ struct launcher_ctx *launcher_ctx_create_internal(void) {
238 247
239 struct wlr_xdg_activation_token_v1 *token = 248 struct wlr_xdg_activation_token_v1 *token =
240 wlr_xdg_activation_token_v1_create(server.xdg_activation_v1); 249 wlr_xdg_activation_token_v1_create(server.xdg_activation_v1);
241 token->seat = seat->wlr_seat;
242 250
243 struct launcher_ctx *ctx = launcher_ctx_create(token, &ws->node); 251 struct launcher_ctx *ctx = launcher_ctx_create(token, &ws->node);
244 if (!ctx) { 252 if (!ctx) {
245 wlr_xdg_activation_token_v1_destroy(token); 253 wlr_xdg_activation_token_v1_destroy(token);
246 return NULL; 254 return NULL;
247 } 255 }
256 ctx->seat = seat;
257 ctx->seat_destroy.notify = launch_ctx_handle_seat_destroy;
258 wl_signal_add(&seat->wlr_seat->events.destroy, &ctx->seat_destroy);
248 259
249 return ctx; 260 return ctx;
250} 261}
diff --git a/sway/xdg_activation_v1.c b/sway/xdg_activation_v1.c
index c26ee19a..399d81cd 100644
--- a/sway/xdg_activation_v1.c
+++ b/sway/xdg_activation_v1.c
@@ -17,11 +17,15 @@ void xdg_activation_v1_handle_request_activate(struct wl_listener *listener,
17 return; 17 return;
18 } 18 }
19 19
20 struct launcher_ctx *ctx = event->token->data;
21 if (ctx == NULL) {
22 return;
23 }
24
20 if (!xdg_surface->surface->mapped) { 25 if (!xdg_surface->surface->mapped) {
21 // This is a startup notification. If we are tracking it, the data 26 // This is a startup notification. If we are tracking it, the data
22 // field is a launcher_ctx. 27 // field is a launcher_ctx.
23 struct launcher_ctx *ctx = event->token->data; 28 if (ctx->activated) {
24 if (!ctx || ctx->activated) {
25 // This ctx has already been activated and cannot be used again 29 // This ctx has already been activated and cannot be used again
26 // for a startup notification. It will be destroyed 30 // for a startup notification. It will be destroyed
27 return; 31 return;
@@ -32,9 +36,16 @@ void xdg_activation_v1_handle_request_activate(struct wl_listener *listener,
32 return; 36 return;
33 } 37 }
34 38
35 struct wlr_seat *wlr_seat = event->token->seat; 39 // This is an activation request. If this context is internal we have ctx->seat.
36 struct sway_seat *seat = wlr_seat ? wlr_seat->data : NULL; 40 struct sway_seat *seat = ctx->seat;
37 view_request_activate(view, seat); 41 if (!seat) {
42 // Otherwise, use the seat indicated by the launcher client in set_serial
43 seat = ctx->token->seat ? ctx->token->seat->data : NULL;
44 }
45
46 if (seat) {
47 view_request_activate(view, seat);
48 }
38} 49}
39 50
40void xdg_activation_v1_handle_new_token(struct wl_listener *listener, void *data) { 51void xdg_activation_v1_handle_new_token(struct wl_listener *listener, void *data) {