Run startup command after xwayland is ready

master
Drew DeVault 7 years ago
parent 51ef12f128
commit a317ecdab8

@ -29,6 +29,7 @@ struct wlr_xwayland {
struct wlr_xwayland_cursor *cursor; struct wlr_xwayland_cursor *cursor;
struct { struct {
struct wl_signal ready;
struct wl_signal new_surface; struct wl_signal new_surface;
} events; } events;

@ -12,6 +12,18 @@
struct roots_server server = { 0 }; struct roots_server server = { 0 };
static void ready(struct wl_listener *listener, void *data) {
if (server.config->startup_cmd != NULL) {
const char *cmd = server.config->startup_cmd;
pid_t pid = fork();
if (pid < 0) {
wlr_log(L_ERROR, "cannot execute binding command: fork() failed");
} else if (pid == 0) {
execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL);
}
}
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
assert(server.config = roots_config_create_from_args(argc, argv)); assert(server.config = roots_config_create_from_args(argc, argv));
assert(server.wl_display = wl_display_create()); assert(server.wl_display = wl_display_create());
@ -43,17 +55,12 @@ int main(int argc, char **argv) {
} }
setenv("WAYLAND_DISPLAY", socket, true); setenv("WAYLAND_DISPLAY", socket, true);
#ifndef HAS_XWAYLAND
if (server.config->startup_cmd != NULL) { ready(NULL, NULL);
const char *cmd = server.config->startup_cmd; #else
pid_t pid = fork(); struct wl_listener xwayland_ready = { .notify = ready };
if (pid < 0) { wl_signal_add(&server.desktop->xwayland->events.ready, &xwayland_ready);
wlr_log(L_ERROR, "cannot execute binding command: fork() failed"); #endif
return 1;
} else if (pid == 0) {
execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL);
}
}
wl_display_run(server.wl_display); wl_display_run(server.wl_display);
wlr_backend_destroy(server.backend); wlr_backend_destroy(server.backend);

@ -211,6 +211,8 @@ static int xserver_handle_ready(int signal_number, void *data) {
snprintf(display_name, sizeof(display_name), ":%d", wlr_xwayland->display); snprintf(display_name, sizeof(display_name), ":%d", wlr_xwayland->display);
setenv("DISPLAY", display_name, true); setenv("DISPLAY", display_name, true);
wl_signal_emit(&wlr_xwayland->events.ready, wlr_xwayland);
return 1; /* wayland event loop dispatcher's count */ return 1; /* wayland event loop dispatcher's count */
} }
@ -223,6 +225,7 @@ static bool wlr_xwayland_init(struct wlr_xwayland *wlr_xwayland,
wlr_xwayland->wl_fd[0] = wlr_xwayland->wl_fd[1] = -1; wlr_xwayland->wl_fd[0] = wlr_xwayland->wl_fd[1] = -1;
wlr_xwayland->wm_fd[0] = wlr_xwayland->wm_fd[1] = -1; wlr_xwayland->wm_fd[0] = wlr_xwayland->wm_fd[1] = -1;
wl_signal_init(&wlr_xwayland->events.new_surface); wl_signal_init(&wlr_xwayland->events.new_surface);
wl_signal_init(&wlr_xwayland->events.ready);
wlr_xwayland->display = open_display_sockets(wlr_xwayland->x_fd); wlr_xwayland->display = open_display_sockets(wlr_xwayland->x_fd);
if (wlr_xwayland->display < 0) { if (wlr_xwayland->display < 0) {

Loading…
Cancel
Save