launcher: fudge the interface a bit

We want to create a context before knowing the pid it will match with.

(cherry picked from commit bdeb9f9565)
This commit is contained in:
Ronan Pigott 2022-11-16 15:50:34 -07:00 committed by Simon Ser
parent 66be031f6c
commit ee9266cf8c
3 changed files with 9 additions and 7 deletions

View file

@ -23,6 +23,6 @@ void launcher_ctx_consume(struct launcher_ctx *ctx);
void launcher_ctx_destroy(struct launcher_ctx *ctx); void launcher_ctx_destroy(struct launcher_ctx *ctx);
struct launcher_ctx *launcher_ctx_create(pid_t pid); struct launcher_ctx *launcher_ctx_create(void);
#endif #endif

View file

@ -53,6 +53,7 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) {
} }
pid_t pid, child; pid_t pid, child;
struct launcher_ctx *ctx = launcher_ctx_create();
// Fork process // Fork process
if ((pid = fork()) == 0) { if ((pid = fork()) == 0) {
// Fork child process again // Fork child process again
@ -92,8 +93,12 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) {
waitpid(pid, NULL, 0); waitpid(pid, NULL, 0);
if (child > 0) { if (child > 0) {
sway_log(SWAY_DEBUG, "Child process created with pid %d", child); sway_log(SWAY_DEBUG, "Child process created with pid %d", child);
launcher_ctx_create(child); if (ctx != NULL) {
sway_log(SWAY_DEBUG, "Recording workspace for process %d", child);
ctx->pid = child;
}
} else { } else {
launcher_ctx_destroy(ctx);
return cmd_results_new(CMD_FAILURE, "Second fork() failed"); return cmd_results_new(CMD_FAILURE, "Second fork() failed");
} }

View file

@ -175,13 +175,11 @@ static void token_handle_destroy(struct wl_listener *listener, void *data) {
launcher_ctx_destroy(ctx); launcher_ctx_destroy(ctx);
} }
struct launcher_ctx *launcher_ctx_create(pid_t pid) { struct launcher_ctx *launcher_ctx_create() {
sway_log(SWAY_DEBUG, "Recording workspace for process %d", pid);
struct sway_seat *seat = input_manager_current_seat(); struct sway_seat *seat = input_manager_current_seat();
struct sway_workspace *ws = seat_get_focused_workspace(seat); struct sway_workspace *ws = seat_get_focused_workspace(seat);
if (!ws) { if (!ws) {
sway_log(SWAY_DEBUG, "Bailing out, no workspace"); sway_log(SWAY_DEBUG, "Failed to create launch context. No workspace.");
return NULL; return NULL;
} }
@ -192,7 +190,6 @@ struct launcher_ctx *launcher_ctx_create(pid_t pid) {
ctx->name = strdup(ws->name); ctx->name = strdup(ws->name);
ctx->token = token; ctx->token = token;
ctx->node = &ws->node; ctx->node = &ws->node;
ctx->pid = pid;
ctx->node_destroy.notify = ctx_handle_node_destroy; ctx->node_destroy.notify = ctx_handle_node_destroy;
wl_signal_add(&ctx->node->events.destroy, &ctx->node_destroy); wl_signal_add(&ctx->node->events.destroy, &ctx->node_destroy);