aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/exec_always.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/exec_always.c')
-rw-r--r--sway/commands/exec_always.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c
index b35065c1..8bc1048c 100644
--- a/sway/commands/exec_always.c
+++ b/sway/commands/exec_always.c
@@ -1,4 +1,3 @@
1#define _POSIX_C_SOURCE 200809L
2#include <stdlib.h> 1#include <stdlib.h>
3#include <stdint.h> 2#include <stdint.h>
4#include <string.h> 3#include <string.h>
@@ -8,6 +7,7 @@
8#include "sway/commands.h" 7#include "sway/commands.h"
9#include "sway/config.h" 8#include "sway/config.h"
10#include "sway/server.h" 9#include "sway/server.h"
10#include "sway/desktop/launcher.h"
11#include "sway/tree/container.h" 11#include "sway/tree/container.h"
12#include "sway/tree/root.h" 12#include "sway/tree/root.h"
13#include "sway/tree/workspace.h" 13#include "sway/tree/workspace.h"
@@ -25,11 +25,22 @@ struct cmd_results *cmd_exec_validate(int argc, char **argv) {
25 return error; 25 return error;
26} 26}
27 27
28static void export_xdga_token(struct launcher_ctx *ctx) {
29 const char *token = launcher_ctx_get_token_name(ctx);
30 setenv("XDG_ACTIVATION_TOKEN", token, 1);
31}
32
33static void export_startup_id(struct launcher_ctx *ctx) {
34 const char *token = launcher_ctx_get_token_name(ctx);
35 setenv("DESKTOP_STARTUP_ID", token, 1);
36}
37
28struct cmd_results *cmd_exec_process(int argc, char **argv) { 38struct cmd_results *cmd_exec_process(int argc, char **argv) {
29 struct cmd_results *error = NULL; 39 struct cmd_results *error = NULL;
30 char *cmd = NULL; 40 char *cmd = NULL;
41 bool no_startup_id = false;
31 if (strcmp(argv[0], "--no-startup-id") == 0) { 42 if (strcmp(argv[0], "--no-startup-id") == 0) {
32 sway_log(SWAY_INFO, "exec switch '--no-startup-id' not supported, ignored."); 43 no_startup_id = true;
33 --argc; ++argv; 44 --argc; ++argv;
34 if ((error = checkarg(argc, argv[-1], EXPECTED_AT_LEAST, 1))) { 45 if ((error = checkarg(argc, argv[-1], EXPECTED_AT_LEAST, 1))) {
35 return error; 46 return error;
@@ -51,6 +62,7 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) {
51 } 62 }
52 63
53 pid_t pid, child; 64 pid_t pid, child;
65 struct launcher_ctx *ctx = launcher_ctx_create_internal();
54 // Fork process 66 // Fork process
55 if ((pid = fork()) == 0) { 67 if ((pid = fork()) == 0) {
56 // Fork child process again 68 // Fork child process again
@@ -63,6 +75,12 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) {
63 close(fd[0]); 75 close(fd[0]);
64 if ((child = fork()) == 0) { 76 if ((child = fork()) == 0) {
65 close(fd[1]); 77 close(fd[1]);
78 if (ctx) {
79 export_xdga_token(ctx);
80 }
81 if (ctx && !no_startup_id) {
82 export_startup_id(ctx);
83 }
66 execlp("sh", "sh", "-c", cmd, (void *)NULL); 84 execlp("sh", "sh", "-c", cmd, (void *)NULL);
67 sway_log_errno(SWAY_ERROR, "execlp failed"); 85 sway_log_errno(SWAY_ERROR, "execlp failed");
68 _exit(1); 86 _exit(1);
@@ -90,8 +108,12 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) {
90 waitpid(pid, NULL, 0); 108 waitpid(pid, NULL, 0);
91 if (child > 0) { 109 if (child > 0) {
92 sway_log(SWAY_DEBUG, "Child process created with pid %d", child); 110 sway_log(SWAY_DEBUG, "Child process created with pid %d", child);
93 root_record_workspace_pid(child); 111 if (ctx != NULL) {
112 sway_log(SWAY_DEBUG, "Recording workspace for process %d", child);
113 ctx->pid = child;
114 }
94 } else { 115 } else {
116 launcher_ctx_destroy(ctx);
95 return cmd_results_new(CMD_FAILURE, "Second fork() failed"); 117 return cmd_results_new(CMD_FAILURE, "Second fork() failed");
96 } 118 }
97 119