aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Ronan Pigott <ronan@rjp.ie>2022-11-18 20:05:24 -0700
committerLibravatar Simon Ser <contact@emersion.fr>2022-11-26 10:29:59 +0100
commit97423ca9c79b4aa273b5d156299bc6a7c8428dc0 (patch)
tree6392bca40f386ab8a8b022109d9c393fcf9a43f6
parentlauncher: fudge the interface a bit (diff)
downloadsway-97423ca9c79b4aa273b5d156299bc6a7c8428dc0.tar.gz
sway-97423ca9c79b4aa273b5d156299bc6a7c8428dc0.tar.zst
sway-97423ca9c79b4aa273b5d156299bc6a7c8428dc0.zip
launcher: export xdga tokens and use them for workspace matching
(cherry picked from commit 30ad4dc4a5a41ce7c7aa85096a6e18f374172983)
-rw-r--r--include/sway/desktop/launcher.h4
-rw-r--r--sway/commands/exec_always.c8
-rw-r--r--sway/desktop/launcher.c10
-rw-r--r--sway/xdg_activation_v1.c18
4 files changed, 38 insertions, 2 deletions
diff --git a/include/sway/desktop/launcher.h b/include/sway/desktop/launcher.h
index 91915604..3b577f74 100644
--- a/include/sway/desktop/launcher.h
+++ b/include/sway/desktop/launcher.h
@@ -9,6 +9,8 @@ struct launcher_ctx {
9 struct wlr_xdg_activation_token_v1 *token; 9 struct wlr_xdg_activation_token_v1 *token;
10 struct wl_listener token_destroy; 10 struct wl_listener token_destroy;
11 11
12 bool activated;
13
12 struct sway_node *node; 14 struct sway_node *node;
13 struct wl_listener node_destroy; 15 struct wl_listener node_destroy;
14 16
@@ -25,4 +27,6 @@ void launcher_ctx_destroy(struct launcher_ctx *ctx);
25 27
26struct launcher_ctx *launcher_ctx_create(void); 28struct launcher_ctx *launcher_ctx_create(void);
27 29
30const char *launcher_ctx_get_token_name(struct launcher_ctx *ctx);
31
28#endif 32#endif
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c
index 13deb9e3..2dfba7ff 100644
--- a/sway/commands/exec_always.c
+++ b/sway/commands/exec_always.c
@@ -27,6 +27,11 @@ struct cmd_results *cmd_exec_validate(int argc, char **argv) {
27 return error; 27 return error;
28} 28}
29 29
30static void export_xdga_token(struct launcher_ctx *ctx) {
31 const char *token = launcher_ctx_get_token_name(ctx);
32 setenv("XDG_ACTIVATION_TOKEN", token, 1);
33}
34
30struct cmd_results *cmd_exec_process(int argc, char **argv) { 35struct cmd_results *cmd_exec_process(int argc, char **argv) {
31 struct cmd_results *error = NULL; 36 struct cmd_results *error = NULL;
32 char *cmd = NULL; 37 char *cmd = NULL;
@@ -66,6 +71,9 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) {
66 close(fd[0]); 71 close(fd[0]);
67 if ((child = fork()) == 0) { 72 if ((child = fork()) == 0) {
68 close(fd[1]); 73 close(fd[1]);
74 if (ctx) {
75 export_xdga_token(ctx);
76 }
69 execlp("sh", "sh", "-c", cmd, (void *)NULL); 77 execlp("sh", "sh", "-c", cmd, (void *)NULL);
70 sway_log_errno(SWAY_ERROR, "execlp failed"); 78 sway_log_errno(SWAY_ERROR, "execlp failed");
71 _exit(1); 79 _exit(1);
diff --git a/sway/desktop/launcher.c b/sway/desktop/launcher.c
index b983dcb0..48e5d24c 100644
--- a/sway/desktop/launcher.c
+++ b/sway/desktop/launcher.c
@@ -50,7 +50,10 @@ void launcher_ctx_consume(struct launcher_ctx *ctx) {
50 wl_list_remove(&ctx->token_destroy.link); 50 wl_list_remove(&ctx->token_destroy.link);
51 wl_list_init(&ctx->token_destroy.link); 51 wl_list_init(&ctx->token_destroy.link);
52 52
53 wlr_xdg_activation_token_v1_destroy(ctx->token); 53 if (!ctx->activated) {
54 // An unactivated token hasn't been destroyed yet
55 wlr_xdg_activation_token_v1_destroy(ctx->token);
56 }
54 ctx->token = NULL; 57 ctx->token = NULL;
55 58
56 // Prevent additional matches 59 // Prevent additional matches
@@ -201,3 +204,8 @@ struct launcher_ctx *launcher_ctx_create() {
201 wl_list_insert(&server.pending_launcher_ctxs, &ctx->link); 204 wl_list_insert(&server.pending_launcher_ctxs, &ctx->link);
202 return ctx; 205 return ctx;
203} 206}
207
208const char *launcher_ctx_get_token_name(struct launcher_ctx *ctx) {
209 const char *token = wlr_xdg_activation_token_v1_get_name(ctx->token);
210 return token;
211}
diff --git a/sway/xdg_activation_v1.c b/sway/xdg_activation_v1.c
index 99e7f9b5..2b94136c 100644
--- a/sway/xdg_activation_v1.c
+++ b/sway/xdg_activation_v1.c
@@ -1,4 +1,5 @@
1#include <wlr/types/wlr_xdg_activation_v1.h> 1#include <wlr/types/wlr_xdg_activation_v1.h>
2#include "sway/desktop/launcher.h"
2#include "sway/tree/view.h" 3#include "sway/tree/view.h"
3 4
4void xdg_activation_v1_handle_request_activate(struct wl_listener *listener, 5void xdg_activation_v1_handle_request_activate(struct wl_listener *listener,
@@ -15,7 +16,22 @@ void xdg_activation_v1_handle_request_activate(struct wl_listener *listener,
15 return; 16 return;
16 } 17 }
17 struct sway_view *view = xdg_surface->data; 18 struct sway_view *view = xdg_surface->data;
18 if (!xdg_surface->mapped || view == NULL) { 19 if (view == NULL) {
20 return;
21 }
22
23 if (!xdg_surface->mapped) {
24 // This is a startup notification. If we are tracking it, the data
25 // field is a launcher_ctx.
26 struct launcher_ctx *ctx = event->token->data;
27 if (!ctx || ctx->activated) {
28 // This ctx has already been activated and cannot be used again
29 // for a startup notification. It will be destroyed
30 return;
31 } else {
32 ctx->activated = true;
33 view_assign_ctx(view, ctx);
34 }
19 return; 35 return;
20 } 36 }
21 37