diff options
author | 2022-11-16 15:50:34 -0700 | |
---|---|---|
committer | 2022-11-26 09:48:58 +0100 | |
commit | bdeb9f95651f6c99cc2f4cfb59020ddee202cf36 (patch) | |
tree | a3c27179887ff4a8b88e08b65e55e8fd838f46f7 | |
parent | launcher: initialize launcher_ctxs once on startup (diff) | |
download | sway-bdeb9f95651f6c99cc2f4cfb59020ddee202cf36.tar.gz sway-bdeb9f95651f6c99cc2f4cfb59020ddee202cf36.tar.zst sway-bdeb9f95651f6c99cc2f4cfb59020ddee202cf36.zip |
launcher: fudge the interface a bit
We want to create a context before knowing the pid it will match with.
-rw-r--r-- | include/sway/desktop/launcher.h | 2 | ||||
-rw-r--r-- | sway/commands/exec_always.c | 7 | ||||
-rw-r--r-- | sway/desktop/launcher.c | 7 |
3 files changed, 9 insertions, 7 deletions
diff --git a/include/sway/desktop/launcher.h b/include/sway/desktop/launcher.h index 09b27eb9..91915604 100644 --- a/include/sway/desktop/launcher.h +++ b/include/sway/desktop/launcher.h | |||
@@ -23,6 +23,6 @@ void launcher_ctx_consume(struct launcher_ctx *ctx); | |||
23 | 23 | ||
24 | void launcher_ctx_destroy(struct launcher_ctx *ctx); | 24 | void launcher_ctx_destroy(struct launcher_ctx *ctx); |
25 | 25 | ||
26 | struct launcher_ctx *launcher_ctx_create(pid_t pid); | 26 | struct launcher_ctx *launcher_ctx_create(void); |
27 | 27 | ||
28 | #endif | 28 | #endif |
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index 0d3254ae..13deb9e3 100644 --- a/sway/commands/exec_always.c +++ b/sway/commands/exec_always.c | |||
@@ -53,6 +53,7 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) { | |||
53 | } | 53 | } |
54 | 54 | ||
55 | pid_t pid, child; | 55 | pid_t pid, child; |
56 | struct launcher_ctx *ctx = launcher_ctx_create(); | ||
56 | // Fork process | 57 | // Fork process |
57 | if ((pid = fork()) == 0) { | 58 | if ((pid = fork()) == 0) { |
58 | // Fork child process again | 59 | // Fork child process again |
@@ -92,8 +93,12 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) { | |||
92 | waitpid(pid, NULL, 0); | 93 | waitpid(pid, NULL, 0); |
93 | if (child > 0) { | 94 | if (child > 0) { |
94 | sway_log(SWAY_DEBUG, "Child process created with pid %d", child); | 95 | sway_log(SWAY_DEBUG, "Child process created with pid %d", child); |
95 | launcher_ctx_create(child); | 96 | if (ctx != NULL) { |
97 | sway_log(SWAY_DEBUG, "Recording workspace for process %d", child); | ||
98 | ctx->pid = child; | ||
99 | } | ||
96 | } else { | 100 | } else { |
101 | launcher_ctx_destroy(ctx); | ||
97 | return cmd_results_new(CMD_FAILURE, "Second fork() failed"); | 102 | return cmd_results_new(CMD_FAILURE, "Second fork() failed"); |
98 | } | 103 | } |
99 | 104 | ||
diff --git a/sway/desktop/launcher.c b/sway/desktop/launcher.c index 89a93384..b983dcb0 100644 --- a/sway/desktop/launcher.c +++ b/sway/desktop/launcher.c | |||
@@ -175,13 +175,11 @@ static void token_handle_destroy(struct wl_listener *listener, void *data) { | |||
175 | launcher_ctx_destroy(ctx); | 175 | launcher_ctx_destroy(ctx); |
176 | } | 176 | } |
177 | 177 | ||
178 | struct launcher_ctx *launcher_ctx_create(pid_t pid) { | 178 | struct launcher_ctx *launcher_ctx_create() { |
179 | sway_log(SWAY_DEBUG, "Recording workspace for process %d", pid); | ||
180 | |||
181 | struct sway_seat *seat = input_manager_current_seat(); | 179 | struct sway_seat *seat = input_manager_current_seat(); |
182 | struct sway_workspace *ws = seat_get_focused_workspace(seat); | 180 | struct sway_workspace *ws = seat_get_focused_workspace(seat); |
183 | if (!ws) { | 181 | if (!ws) { |
184 | sway_log(SWAY_DEBUG, "Bailing out, no workspace"); | 182 | sway_log(SWAY_DEBUG, "Failed to create launch context. No workspace."); |
185 | return NULL; | 183 | return NULL; |
186 | } | 184 | } |
187 | 185 | ||
@@ -192,7 +190,6 @@ struct launcher_ctx *launcher_ctx_create(pid_t pid) { | |||
192 | ctx->name = strdup(ws->name); | 190 | ctx->name = strdup(ws->name); |
193 | ctx->token = token; | 191 | ctx->token = token; |
194 | ctx->node = &ws->node; | 192 | ctx->node = &ws->node; |
195 | ctx->pid = pid; | ||
196 | 193 | ||
197 | ctx->node_destroy.notify = ctx_handle_node_destroy; | 194 | ctx->node_destroy.notify = ctx_handle_node_destroy; |
198 | wl_signal_add(&ctx->node->events.destroy, &ctx->node_destroy); | 195 | wl_signal_add(&ctx->node->events.destroy, &ctx->node_destroy); |