Skip to content

Commit

Permalink
launcher: initialize launcher_ctxs once on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
rpigott authored and emersion committed Nov 26, 2022
1 parent 864b3a9 commit 6656850
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 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);

void launcher_ctx_create(pid_t pid);
struct launcher_ctx *launcher_ctx_create(pid_t pid);

#endif
2 changes: 2 additions & 0 deletions include/sway/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ struct sway_server {
struct wlr_xdg_activation_v1 *xdg_activation_v1;
struct wl_listener xdg_activation_v1_request_activate;

struct wl_list pending_launcher_ctxs; // launcher_ctx::link

// The timeout for transactions, after which a transaction is applied
// regardless of readiness.
size_t txn_timeout_ms;
Expand Down
1 change: 1 addition & 0 deletions sway/commands/exec_always.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "sway/config.h"
#include "sway/server.h"
#include "sway/desktop/launcher.h"
#include "sway/server.h"
#include "sway/tree/container.h"
#include "sway/tree/root.h"
#include "sway/tree/workspace.h"
Expand Down
18 changes: 7 additions & 11 deletions sway/desktop/launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include "sway/tree/root.h"
#include "log.h"

static struct wl_list launcher_ctxs;

/**
* Get the pid of a parent process given the pid of a child process.
*
Expand Down Expand Up @@ -73,8 +71,7 @@ void launcher_ctx_destroy(struct launcher_ctx *ctx) {
}

struct launcher_ctx *launcher_ctx_find_pid(pid_t pid) {
if (!launcher_ctxs.prev && !launcher_ctxs.next) {
wl_list_init(&launcher_ctxs);
if (wl_list_empty(&server.pending_launcher_ctxs)) {
return NULL;
}

Expand All @@ -83,7 +80,7 @@ struct launcher_ctx *launcher_ctx_find_pid(pid_t pid) {

do {
struct launcher_ctx *_ctx = NULL;
wl_list_for_each(_ctx, &launcher_ctxs, link) {
wl_list_for_each(_ctx, &server.pending_launcher_ctxs, link) {
if (pid == _ctx->pid) {
ctx = _ctx;
sway_log(SWAY_DEBUG,
Expand Down Expand Up @@ -178,17 +175,14 @@ static void token_handle_destroy(struct wl_listener *listener, void *data) {
launcher_ctx_destroy(ctx);
}

void launcher_ctx_create(pid_t pid) {
struct launcher_ctx *launcher_ctx_create(pid_t pid) {
sway_log(SWAY_DEBUG, "Recording workspace for process %d", pid);
if (!launcher_ctxs.prev && !launcher_ctxs.next) {
wl_list_init(&launcher_ctxs);
}

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");
return;
return NULL;
}

struct launcher_ctx *ctx = calloc(1, sizeof(struct launcher_ctx));
Expand All @@ -206,5 +200,7 @@ void launcher_ctx_create(pid_t pid) {
ctx->token_destroy.notify = token_handle_destroy;
wl_signal_add(&token->events.destroy, &ctx->token_destroy);

wl_list_insert(&launcher_ctxs, &ctx->link);
wl_list_init(&ctx->link);
wl_list_insert(&server.pending_launcher_ctxs, &ctx->link);
return ctx;
}
2 changes: 2 additions & 0 deletions sway/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ bool server_init(struct sway_server *server) {
wl_signal_add(&server->xdg_activation_v1->events.request_activate,
&server->xdg_activation_v1_request_activate);

wl_list_init(&server->pending_launcher_ctxs);

// Avoid using "wayland-0" as display socket
char name_candidate[16];
for (unsigned int i = 1; i <= 32; ++i) {
Expand Down

0 comments on commit 6656850

Please sign in to comment.