Skip to content

Commit

Permalink
launcher: fudge the interface a bit
Browse files Browse the repository at this point in the history
We want to create a context before knowing the pid it will match with.
  • Loading branch information
rpigott authored and emersion committed Nov 26, 2022
1 parent 6656850 commit bdeb9f9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/sway/desktop/launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ void launcher_ctx_consume(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
7 changes: 6 additions & 1 deletion sway/commands/exec_always.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) {
}

pid_t pid, child;
struct launcher_ctx *ctx = launcher_ctx_create();
// Fork process
if ((pid = fork()) == 0) {
// Fork child process again
Expand Down Expand Up @@ -92,8 +93,12 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) {
waitpid(pid, NULL, 0);
if (child > 0) {
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 {
launcher_ctx_destroy(ctx);
return cmd_results_new(CMD_FAILURE, "Second fork() failed");
}

Expand Down
7 changes: 2 additions & 5 deletions sway/desktop/launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,11 @@ static void token_handle_destroy(struct wl_listener *listener, void *data) {
launcher_ctx_destroy(ctx);
}

struct launcher_ctx *launcher_ctx_create(pid_t pid) {
sway_log(SWAY_DEBUG, "Recording workspace for process %d", pid);

struct launcher_ctx *launcher_ctx_create() {
struct sway_seat *seat = input_manager_current_seat();
struct sway_workspace *ws = seat_get_focused_workspace(seat);
if (!ws) {
sway_log(SWAY_DEBUG, "Bailing out, no workspace");
sway_log(SWAY_DEBUG, "Failed to create launch context. No workspace.");
return NULL;
}

Expand All @@ -192,7 +190,6 @@ struct launcher_ctx *launcher_ctx_create(pid_t pid) {
ctx->name = strdup(ws->name);
ctx->token = token;
ctx->node = &ws->node;
ctx->pid = pid;

ctx->node_destroy.notify = ctx_handle_node_destroy;
wl_signal_add(&ctx->node->events.destroy, &ctx->node_destroy);
Expand Down

0 comments on commit bdeb9f9

Please sign in to comment.