Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
xwayland: add option to disable WM
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed May 19, 2020
1 parent 75a6cbf commit 74c821e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
8 changes: 7 additions & 1 deletion include/wlr/xwayland.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct wlr_xwayland_server {
int x_fd[2];
struct wl_event_source *x_fd_read_event[2];
bool lazy;
bool enable_wm;

struct wl_display *wl_display;

Expand All @@ -48,6 +49,11 @@ struct wlr_xwayland_server {
void *data;
};

struct wlr_xwayland_server_options {
bool lazy;
bool enable_wm;
};

struct wlr_xwayland_server_ready_event {
struct wlr_xwayland_server *server;
int wm_fd;
Expand Down Expand Up @@ -214,7 +220,7 @@ struct wlr_xwayland_resize_event {
};

struct wlr_xwayland_server *wlr_xwayland_server_create(
struct wl_display *display, bool lazy);
struct wl_display *display, struct wlr_xwayland_server_options *options);
void wlr_xwayland_server_destroy(struct wlr_xwayland_server *server);

/** Create an Xwayland server and XWM.
Expand Down
47 changes: 36 additions & 11 deletions xwayland/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ static int fill_arg(char ***argv, const char *fmt, ...) {
noreturn static void exec_xwayland(struct wlr_xwayland_server *server) {
if (!set_cloexec(server->x_fd[0], false) ||
!set_cloexec(server->x_fd[1], false) ||
!set_cloexec(server->wm_fd[1], false) ||
!set_cloexec(server->wl_fd[1], false)) {
wlr_log(WLR_ERROR, "Failed to unset CLOEXEC on FD");
_exit(EXIT_FAILURE);
}
if (server->enable_wm && !set_cloexec(server->wm_fd[1], false)) {
wlr_log(WLR_ERROR, "Failed to unset CLOEXEC on FD");
_exit(EXIT_FAILURE);
}

Expand All @@ -67,11 +71,19 @@ noreturn static void exec_xwayland(struct wlr_xwayland_server *server) {

if (fill_arg(&cur_arg, ":%d", server->display) < 0 ||
fill_arg(&cur_arg, "%d", server->x_fd[0]) < 0 ||
fill_arg(&cur_arg, "%d", server->x_fd[1]) < 0 ||
fill_arg(&cur_arg, "%d", server->wm_fd[1]) < 0) {
fill_arg(&cur_arg, "%d", server->x_fd[1]) < 0) {
wlr_log_errno(WLR_ERROR, "alloc/print failure");
_exit(EXIT_FAILURE);
}
if (server->enable_wm) {
if (fill_arg(&cur_arg, "%d", server->wm_fd[1]) < 0) {
wlr_log_errno(WLR_ERROR, "alloc/print failure");
_exit(EXIT_FAILURE);
}
} else {
cur_arg++;
*cur_arg = NULL;
}

char wayland_socket_str[16];
snprintf(wayland_socket_str, sizeof(wayland_socket_str), "%d", server->wl_fd[1]);
Expand Down Expand Up @@ -249,19 +261,30 @@ static bool server_start_display(struct wlr_xwayland_server *server,
}

static bool server_start(struct wlr_xwayland_server *server) {
if (socketpair(AF_UNIX, SOCK_STREAM, 0, server->wl_fd) != 0 ||
socketpair(AF_UNIX, SOCK_STREAM, 0, server->wm_fd) != 0) {
if (socketpair(AF_UNIX, SOCK_STREAM, 0, server->wl_fd) != 0) {
wlr_log_errno(WLR_ERROR, "socketpair failed");
server_finish_process(server);
return false;
}
if (!set_cloexec(server->wl_fd[0], true) ||
!set_cloexec(server->wl_fd[1], true) ||
!set_cloexec(server->wm_fd[0], true) ||
!set_cloexec(server->wm_fd[1], true)) {
!set_cloexec(server->wl_fd[1], true)) {
wlr_log(WLR_ERROR, "Failed to set O_CLOEXEC on socket");
server_finish_process(server);
return false;
}
if (server->enable_wm) {
if (socketpair(AF_UNIX, SOCK_STREAM, 0, server->wm_fd) != 0) {
wlr_log_errno(WLR_ERROR, "socketpair failed");
server_finish_process(server);
return false;
}
if (!set_cloexec(server->wm_fd[0], true) ||
!set_cloexec(server->wm_fd[1], true)) {
wlr_log(WLR_ERROR, "Failed to set O_CLOEXEC on socket");
server_finish_process(server);
return false;
}
}

server->server_start = time(NULL);

Expand Down Expand Up @@ -319,7 +342,7 @@ static bool server_start(struct wlr_xwayland_server *server) {
/* close child fds */
/* remain managing x sockets for lazy start */
close(server->wl_fd[1]);
close(server->wm_fd[1]);
safe_close(server->wm_fd[1]);
server->wl_fd[1] = server->wm_fd[1] = -1;

return true;
Expand Down Expand Up @@ -359,15 +382,17 @@ void wlr_xwayland_server_destroy(struct wlr_xwayland_server *server) {
}

struct wlr_xwayland_server *wlr_xwayland_server_create(
struct wl_display *wl_display, bool lazy) {
struct wl_display *wl_display,
struct wlr_xwayland_server_options *options) {
struct wlr_xwayland_server *server =
calloc(1, sizeof(struct wlr_xwayland_server));
if (!server) {
return NULL;
}

server->wl_display = wl_display;
server->lazy = lazy;
server->lazy = options->lazy;
server->enable_wm = options->enable_wm;

server->x_fd[0] = server->x_fd[1] = -1;
server->wl_fd[0] = server->wl_fd[1] = -1;
Expand Down
6 changes: 5 additions & 1 deletion xwayland/xwayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display,
wl_signal_init(&xwayland->events.new_surface);
wl_signal_init(&xwayland->events.ready);

xwayland->server = wlr_xwayland_server_create(wl_display, lazy);
struct wlr_xwayland_server_options options = {
.lazy = lazy,
.enable_wm = true,
};
xwayland->server = wlr_xwayland_server_create(wl_display, &options);
if (xwayland->server == NULL) {
free(xwayland->server);
return NULL;
Expand Down

0 comments on commit 74c821e

Please sign in to comment.