diff options
Diffstat (limited to 'sway/commands/exec_always.c')
-rw-r--r-- | sway/commands/exec_always.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index fce337d5..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> |
@@ -7,6 +6,8 @@ | |||
7 | #include <signal.h> | 6 | #include <signal.h> |
8 | #include "sway/commands.h" | 7 | #include "sway/commands.h" |
9 | #include "sway/config.h" | 8 | #include "sway/config.h" |
9 | #include "sway/server.h" | ||
10 | #include "sway/desktop/launcher.h" | ||
10 | #include "sway/tree/container.h" | 11 | #include "sway/tree/container.h" |
11 | #include "sway/tree/root.h" | 12 | #include "sway/tree/root.h" |
12 | #include "sway/tree/workspace.h" | 13 | #include "sway/tree/workspace.h" |
@@ -24,11 +25,22 @@ struct cmd_results *cmd_exec_validate(int argc, char **argv) { | |||
24 | return error; | 25 | return error; |
25 | } | 26 | } |
26 | 27 | ||
28 | static 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 | |||
33 | static 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 | |||
27 | struct cmd_results *cmd_exec_process(int argc, char **argv) { | 38 | struct cmd_results *cmd_exec_process(int argc, char **argv) { |
28 | struct cmd_results *error = NULL; | 39 | struct cmd_results *error = NULL; |
29 | char *cmd = NULL; | 40 | char *cmd = NULL; |
41 | bool no_startup_id = false; | ||
30 | if (strcmp(argv[0], "--no-startup-id") == 0) { | 42 | if (strcmp(argv[0], "--no-startup-id") == 0) { |
31 | sway_log(SWAY_INFO, "exec switch '--no-startup-id' not supported, ignored."); | 43 | no_startup_id = true; |
32 | --argc; ++argv; | 44 | --argc; ++argv; |
33 | if ((error = checkarg(argc, argv[-1], EXPECTED_AT_LEAST, 1))) { | 45 | if ((error = checkarg(argc, argv[-1], EXPECTED_AT_LEAST, 1))) { |
34 | return error; | 46 | return error; |
@@ -50,9 +62,11 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) { | |||
50 | } | 62 | } |
51 | 63 | ||
52 | pid_t pid, child; | 64 | pid_t pid, child; |
65 | struct launcher_ctx *ctx = launcher_ctx_create_internal(); | ||
53 | // Fork process | 66 | // Fork process |
54 | if ((pid = fork()) == 0) { | 67 | if ((pid = fork()) == 0) { |
55 | // Fork child process again | 68 | // Fork child process again |
69 | restore_nofile_limit(); | ||
56 | setsid(); | 70 | setsid(); |
57 | sigset_t set; | 71 | sigset_t set; |
58 | sigemptyset(&set); | 72 | sigemptyset(&set); |
@@ -61,6 +75,12 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) { | |||
61 | close(fd[0]); | 75 | close(fd[0]); |
62 | if ((child = fork()) == 0) { | 76 | if ((child = fork()) == 0) { |
63 | 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 | } | ||
64 | execlp("sh", "sh", "-c", cmd, (void *)NULL); | 84 | execlp("sh", "sh", "-c", cmd, (void *)NULL); |
65 | sway_log_errno(SWAY_ERROR, "execlp failed"); | 85 | sway_log_errno(SWAY_ERROR, "execlp failed"); |
66 | _exit(1); | 86 | _exit(1); |
@@ -88,8 +108,12 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) { | |||
88 | waitpid(pid, NULL, 0); | 108 | waitpid(pid, NULL, 0); |
89 | if (child > 0) { | 109 | if (child > 0) { |
90 | sway_log(SWAY_DEBUG, "Child process created with pid %d", child); | 110 | sway_log(SWAY_DEBUG, "Child process created with pid %d", child); |
91 | 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 | } | ||
92 | } else { | 115 | } else { |
116 | launcher_ctx_destroy(ctx); | ||
93 | return cmd_results_new(CMD_FAILURE, "Second fork() failed"); | 117 | return cmd_results_new(CMD_FAILURE, "Second fork() failed"); |
94 | } | 118 | } |
95 | 119 | ||