2019-03-06 00:32:24 +01:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <errno.h>
|
2017-08-19 17:59:31 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
2017-08-19 17:59:31 +02:00
|
|
|
#include <sys/socket.h>
|
2017-08-23 23:19:15 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
2017-08-19 17:59:31 +02:00
|
|
|
#include <time.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <unistd.h>
|
2019-07-27 10:53:54 +02:00
|
|
|
#include <wayland-server-core.h>
|
2018-02-12 09:12:31 +01:00
|
|
|
#include <wlr/util/log.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <wlr/xwayland.h>
|
2017-08-20 07:59:03 +02:00
|
|
|
#include "sockets.h"
|
2018-02-12 21:29:23 +01:00
|
|
|
#include "util/signal.h"
|
2018-03-03 17:03:19 +01:00
|
|
|
#include "xwayland/xwm.h"
|
2017-08-19 17:59:31 +02:00
|
|
|
|
2017-11-02 16:49:22 +01:00
|
|
|
struct wlr_xwayland_cursor {
|
|
|
|
uint8_t *pixels;
|
|
|
|
uint32_t stride;
|
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
|
|
|
int32_t hotspot_x;
|
|
|
|
int32_t hotspot_y;
|
|
|
|
};
|
|
|
|
|
2017-08-19 17:59:31 +02:00
|
|
|
static void safe_close(int fd) {
|
|
|
|
if (fd >= 0) {
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-20 19:50:28 +02:00
|
|
|
static int fill_arg(char ***argv, const char *fmt, ...) {
|
|
|
|
int len;
|
|
|
|
char **cur_arg = *argv;
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
len = vsnprintf(NULL, 0, fmt, args) + 1;
|
|
|
|
va_end(args);
|
|
|
|
while (*cur_arg) {
|
|
|
|
cur_arg++;
|
|
|
|
}
|
|
|
|
*cur_arg = malloc(len);
|
|
|
|
if (!*cur_arg) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*argv = cur_arg;
|
|
|
|
va_start(args, fmt);
|
|
|
|
len = vsnprintf(*cur_arg, len, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2019-02-19 16:38:45 +01:00
|
|
|
_Noreturn static void exec_xwayland(struct wlr_xwayland *wlr_xwayland) {
|
|
|
|
if (!set_cloexec(wlr_xwayland->x_fd[0], false) ||
|
|
|
|
!set_cloexec(wlr_xwayland->x_fd[1], false) ||
|
|
|
|
!set_cloexec(wlr_xwayland->wm_fd[1], false) ||
|
|
|
|
!set_cloexec(wlr_xwayland->wl_fd[1], false)) {
|
2017-08-26 18:10:57 +02:00
|
|
|
_exit(EXIT_FAILURE);
|
2017-08-19 17:59:31 +02:00
|
|
|
}
|
|
|
|
|
2017-08-19 23:09:59 +02:00
|
|
|
/* Make Xwayland signal us when it's ready */
|
|
|
|
signal(SIGUSR1, SIG_IGN);
|
|
|
|
|
2017-08-20 19:50:28 +02:00
|
|
|
char *argv[] = {
|
|
|
|
"Xwayland", NULL /* display, e.g. :1 */,
|
|
|
|
"-rootless", "-terminate",
|
|
|
|
"-listen", NULL /* x_fd[0] */,
|
|
|
|
"-listen", NULL /* x_fd[1] */,
|
|
|
|
"-wm", NULL /* wm_fd[1] */,
|
2019-02-19 16:38:45 +01:00
|
|
|
NULL,
|
|
|
|
};
|
2017-08-20 19:50:28 +02:00
|
|
|
char **cur_arg = argv;
|
|
|
|
|
|
|
|
if (fill_arg(&cur_arg, ":%d", wlr_xwayland->display) < 0 ||
|
|
|
|
fill_arg(&cur_arg, "%d", wlr_xwayland->x_fd[0]) < 0 ||
|
|
|
|
fill_arg(&cur_arg, "%d", wlr_xwayland->x_fd[1]) < 0 ||
|
|
|
|
fill_arg(&cur_arg, "%d", wlr_xwayland->wm_fd[1]) < 0) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log_errno(WLR_ERROR, "alloc/print failure");
|
2017-08-26 18:10:57 +02:00
|
|
|
_exit(EXIT_FAILURE);
|
2017-08-19 17:59:31 +02:00
|
|
|
}
|
|
|
|
|
2017-08-20 19:50:28 +02:00
|
|
|
char wayland_socket_str[16];
|
|
|
|
snprintf(wayland_socket_str, sizeof(wayland_socket_str), "%d", wlr_xwayland->wl_fd[1]);
|
|
|
|
setenv("WAYLAND_SOCKET", wayland_socket_str, true);
|
2017-08-19 17:59:31 +02:00
|
|
|
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_INFO, "WAYLAND_SOCKET=%d Xwayland :%d -rootless -terminate -listen %d -listen %d -wm %d",
|
2017-08-23 23:19:15 +02:00
|
|
|
wlr_xwayland->wl_fd[1], wlr_xwayland->display, wlr_xwayland->x_fd[0],
|
|
|
|
wlr_xwayland->x_fd[1], wlr_xwayland->wm_fd[1]);
|
2017-08-19 17:59:31 +02:00
|
|
|
|
2018-09-01 12:45:18 +02:00
|
|
|
// Closes stdout/stderr depending on log verbosity
|
|
|
|
enum wlr_log_importance verbosity = wlr_log_get_verbosity();
|
2019-03-06 00:32:24 +01:00
|
|
|
int devnull = open("/dev/null", O_WRONLY | O_CREAT | O_CLOEXEC, 0666);
|
2018-09-01 12:45:18 +02:00
|
|
|
if (devnull < 0) {
|
|
|
|
wlr_log_errno(WLR_ERROR, "XWayland: failed to open /dev/null");
|
|
|
|
_exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if (verbosity < WLR_INFO) {
|
|
|
|
dup2(devnull, STDOUT_FILENO);
|
|
|
|
}
|
|
|
|
if (verbosity < WLR_ERROR) {
|
|
|
|
dup2(devnull, STDERR_FILENO);
|
|
|
|
}
|
2017-08-19 21:25:26 +02:00
|
|
|
|
2018-09-01 12:45:18 +02:00
|
|
|
// This returns if and only if the call fails
|
2017-08-20 19:50:28 +02:00
|
|
|
execvp("Xwayland", argv);
|
2018-09-01 12:45:18 +02:00
|
|
|
|
|
|
|
wlr_log_errno(WLR_ERROR, "failed to exec Xwayland");
|
|
|
|
close(devnull);
|
|
|
|
_exit(EXIT_FAILURE);
|
2017-08-19 17:59:31 +02:00
|
|
|
}
|
|
|
|
|
2018-05-06 20:23:10 +02:00
|
|
|
static void xwayland_finish_server(struct wlr_xwayland *wlr_xwayland) {
|
2017-08-23 23:19:15 +02:00
|
|
|
if (!wlr_xwayland || wlr_xwayland->display == -1) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-08 00:59:37 +01:00
|
|
|
|
2018-05-10 01:44:17 +02:00
|
|
|
if (wlr_xwayland->x_fd_read_event[0]) {
|
|
|
|
wl_event_source_remove(wlr_xwayland->x_fd_read_event[0]);
|
|
|
|
wl_event_source_remove(wlr_xwayland->x_fd_read_event[1]);
|
|
|
|
|
|
|
|
wlr_xwayland->x_fd_read_event[0] = wlr_xwayland->x_fd_read_event[1] = NULL;
|
|
|
|
}
|
|
|
|
|
2017-12-08 01:38:45 +01:00
|
|
|
if (wlr_xwayland->cursor != NULL) {
|
|
|
|
free(wlr_xwayland->cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
xwm_destroy(wlr_xwayland->xwm);
|
|
|
|
|
2017-08-19 17:59:31 +02:00
|
|
|
if (wlr_xwayland->client) {
|
2017-12-08 01:38:45 +01:00
|
|
|
wl_list_remove(&wlr_xwayland->client_destroy.link);
|
2017-08-19 17:59:31 +02:00
|
|
|
wl_client_destroy(wlr_xwayland->client);
|
|
|
|
}
|
2017-08-19 23:09:59 +02:00
|
|
|
if (wlr_xwayland->sigusr1_source) {
|
|
|
|
wl_event_source_remove(wlr_xwayland->sigusr1_source);
|
|
|
|
}
|
|
|
|
|
2017-08-19 17:59:31 +02:00
|
|
|
safe_close(wlr_xwayland->wl_fd[0]);
|
|
|
|
safe_close(wlr_xwayland->wl_fd[1]);
|
|
|
|
safe_close(wlr_xwayland->wm_fd[0]);
|
|
|
|
safe_close(wlr_xwayland->wm_fd[1]);
|
2018-05-08 22:22:35 +02:00
|
|
|
memset(wlr_xwayland, 0, offsetof(struct wlr_xwayland, display));
|
|
|
|
wlr_xwayland->wl_fd[0] = wlr_xwayland->wl_fd[1] = -1;
|
|
|
|
wlr_xwayland->wm_fd[0] = wlr_xwayland->wm_fd[1] = -1;
|
|
|
|
|
2018-05-06 20:23:10 +02:00
|
|
|
/* We do not kill the Xwayland process, it dies to broken pipe
|
|
|
|
* after we close our side of the wm/wl fds. This is more reliable
|
|
|
|
* than trying to kill something that might no longer be Xwayland.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xwayland_finish_display(struct wlr_xwayland *wlr_xwayland) {
|
2018-05-10 01:44:17 +02:00
|
|
|
if (!wlr_xwayland || wlr_xwayland->display == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-06 20:23:10 +02:00
|
|
|
safe_close(wlr_xwayland->x_fd[0]);
|
|
|
|
safe_close(wlr_xwayland->x_fd[1]);
|
2018-05-08 22:22:35 +02:00
|
|
|
wlr_xwayland->x_fd[0] = wlr_xwayland->x_fd[1] = -1;
|
2017-08-19 17:59:31 +02:00
|
|
|
|
2017-12-08 00:59:37 +01:00
|
|
|
wl_list_remove(&wlr_xwayland->display_destroy.link);
|
|
|
|
|
2017-08-20 07:59:03 +02:00
|
|
|
unlink_display_sockets(wlr_xwayland->display);
|
2017-08-23 23:19:15 +02:00
|
|
|
wlr_xwayland->display = -1;
|
2019-03-02 15:14:23 +01:00
|
|
|
wlr_xwayland->display_name[0] = '\0';
|
2017-08-19 17:59:31 +02:00
|
|
|
}
|
|
|
|
|
2018-05-06 20:23:10 +02:00
|
|
|
static bool xwayland_start_server(struct wlr_xwayland *wlr_xwayland);
|
|
|
|
static bool xwayland_start_server_lazy(struct wlr_xwayland *wlr_xwayland);
|
|
|
|
|
2017-12-08 01:38:45 +01:00
|
|
|
static void handle_client_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_xwayland *wlr_xwayland =
|
|
|
|
wl_container_of(listener, wlr_xwayland, client_destroy);
|
|
|
|
|
2018-05-07 00:43:26 +02:00
|
|
|
if (wlr_xwayland->sigusr1_source) {
|
|
|
|
// Xwayland failed to start, let the sigusr1 handler deal with it
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-08 10:58:36 +01:00
|
|
|
// Don't call client destroy: it's being destroyed already
|
2017-12-08 01:38:45 +01:00
|
|
|
wlr_xwayland->client = NULL;
|
|
|
|
wl_list_remove(&wlr_xwayland->client_destroy.link);
|
2017-12-08 10:58:36 +01:00
|
|
|
|
2018-05-06 20:23:10 +02:00
|
|
|
xwayland_finish_server(wlr_xwayland);
|
2017-12-08 01:38:45 +01:00
|
|
|
|
2018-05-07 00:43:26 +02:00
|
|
|
if (time(NULL) - wlr_xwayland->server_start > 5) {
|
|
|
|
if (wlr_xwayland->lazy) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_INFO, "Restarting Xwayland (lazy)");
|
2018-05-07 00:43:26 +02:00
|
|
|
xwayland_start_server_lazy(wlr_xwayland);
|
|
|
|
} else {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_INFO, "Restarting Xwayland");
|
2018-05-07 00:43:26 +02:00
|
|
|
xwayland_start_server(wlr_xwayland);
|
|
|
|
}
|
2017-12-08 01:38:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 00:59:37 +01:00
|
|
|
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_xwayland *wlr_xwayland =
|
|
|
|
wl_container_of(listener, wlr_xwayland, display_destroy);
|
2017-12-08 10:58:36 +01:00
|
|
|
|
|
|
|
// Don't call client destroy: the display is being destroyed, it's too late
|
|
|
|
if (wlr_xwayland->client) {
|
|
|
|
wlr_xwayland->client = NULL;
|
|
|
|
wl_list_remove(&wlr_xwayland->client_destroy.link);
|
|
|
|
}
|
|
|
|
|
2017-12-08 00:59:37 +01:00
|
|
|
wlr_xwayland_destroy(wlr_xwayland);
|
|
|
|
}
|
|
|
|
|
2017-08-19 23:09:59 +02:00
|
|
|
static int xserver_handle_ready(int signal_number, void *data) {
|
|
|
|
struct wlr_xwayland *wlr_xwayland = data;
|
|
|
|
|
2017-08-26 18:10:57 +02:00
|
|
|
int stat_val = -1;
|
|
|
|
while (waitpid(wlr_xwayland->pid, &stat_val, 0) < 0) {
|
|
|
|
if (errno == EINTR) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log_errno(WLR_ERROR, "waitpid for Xwayland fork failed");
|
2017-08-26 18:10:57 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (stat_val) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "Xwayland startup failed, not setting up xwm");
|
2017-08-26 18:10:57 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG, "Xserver is ready");
|
2017-08-19 23:09:59 +02:00
|
|
|
|
|
|
|
wlr_xwayland->xwm = xwm_create(wlr_xwayland);
|
|
|
|
if (!wlr_xwayland->xwm) {
|
2018-05-06 20:23:10 +02:00
|
|
|
xwayland_finish_server(wlr_xwayland);
|
2017-08-19 23:09:59 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-11-22 14:23:23 +01:00
|
|
|
if (wlr_xwayland->seat) {
|
|
|
|
xwm_set_seat(wlr_xwayland->xwm, wlr_xwayland->seat);
|
|
|
|
}
|
|
|
|
|
2017-08-20 07:47:38 +02:00
|
|
|
wl_event_source_remove(wlr_xwayland->sigusr1_source);
|
|
|
|
wlr_xwayland->sigusr1_source = NULL;
|
|
|
|
|
2017-11-02 16:49:22 +01:00
|
|
|
if (wlr_xwayland->cursor != NULL) {
|
|
|
|
struct wlr_xwayland_cursor *cur = wlr_xwayland->cursor;
|
|
|
|
xwm_set_cursor(wlr_xwayland->xwm, cur->pixels, cur->stride, cur->width,
|
|
|
|
cur->height, cur->hotspot_x, cur->hotspot_y);
|
|
|
|
free(cur);
|
|
|
|
wlr_xwayland->cursor = NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-19 23:09:59 +02:00
|
|
|
|
2018-02-12 09:12:31 +01:00
|
|
|
wlr_signal_emit_safe(&wlr_xwayland->events.ready, wlr_xwayland);
|
2017-12-29 20:50:50 +01:00
|
|
|
/* ready is a one-shot signal, fire and forget */
|
|
|
|
wl_signal_init(&wlr_xwayland->events.ready);
|
2017-11-12 22:01:31 +01:00
|
|
|
|
2017-08-20 19:50:28 +02:00
|
|
|
return 1; /* wayland event loop dispatcher's count */
|
2017-08-19 23:09:59 +02:00
|
|
|
}
|
|
|
|
|
2018-05-06 20:23:10 +02:00
|
|
|
static int xwayland_socket_connected(int fd, uint32_t mask, void* data){
|
|
|
|
struct wlr_xwayland *wlr_xwayland = data;
|
|
|
|
|
|
|
|
wl_event_source_remove(wlr_xwayland->x_fd_read_event[0]);
|
|
|
|
wl_event_source_remove(wlr_xwayland->x_fd_read_event[1]);
|
|
|
|
|
2018-05-07 00:48:02 +02:00
|
|
|
wlr_xwayland->x_fd_read_event[0] = wlr_xwayland->x_fd_read_event[1] = NULL;
|
|
|
|
|
2018-05-06 20:23:10 +02:00
|
|
|
xwayland_start_server(wlr_xwayland);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool xwayland_start_display(struct wlr_xwayland *wlr_xwayland,
|
2018-05-19 13:39:51 +02:00
|
|
|
struct wl_display *wl_display) {
|
2017-08-19 17:59:31 +02:00
|
|
|
|
2017-12-08 00:59:37 +01:00
|
|
|
wlr_xwayland->display_destroy.notify = handle_display_destroy;
|
|
|
|
wl_display_add_destroy_listener(wl_display, &wlr_xwayland->display_destroy);
|
|
|
|
|
2017-08-19 17:59:31 +02:00
|
|
|
wlr_xwayland->display = open_display_sockets(wlr_xwayland->x_fd);
|
|
|
|
if (wlr_xwayland->display < 0) {
|
2018-05-06 20:23:10 +02:00
|
|
|
xwayland_finish_display(wlr_xwayland);
|
2017-08-19 17:59:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-05-06 20:23:10 +02:00
|
|
|
|
2019-03-02 15:14:23 +01:00
|
|
|
snprintf(wlr_xwayland->display_name, sizeof(wlr_xwayland->display_name),
|
|
|
|
":%d", wlr_xwayland->display);
|
2018-05-06 20:23:10 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool xwayland_start_server(struct wlr_xwayland *wlr_xwayland) {
|
2019-02-19 16:38:45 +01:00
|
|
|
if (socketpair(AF_UNIX, SOCK_STREAM, 0, wlr_xwayland->wl_fd) != 0 ||
|
|
|
|
socketpair(AF_UNIX, SOCK_STREAM, 0, wlr_xwayland->wm_fd) != 0) {
|
|
|
|
wlr_log_errno(WLR_ERROR, "socketpair failed");
|
2018-05-06 20:23:10 +02:00
|
|
|
xwayland_finish_server(wlr_xwayland);
|
2017-08-19 17:59:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-02-19 16:38:45 +01:00
|
|
|
if (!set_cloexec(wlr_xwayland->wl_fd[0], true) ||
|
|
|
|
!set_cloexec(wlr_xwayland->wl_fd[1], true) ||
|
|
|
|
!set_cloexec(wlr_xwayland->wm_fd[0], true) ||
|
|
|
|
!set_cloexec(wlr_xwayland->wm_fd[1], true)) {
|
|
|
|
xwayland_finish_server(wlr_xwayland);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-26 18:10:57 +02:00
|
|
|
wlr_xwayland->server_start = time(NULL);
|
|
|
|
|
2019-02-19 16:38:45 +01:00
|
|
|
wlr_xwayland->client =
|
|
|
|
wl_client_create(wlr_xwayland->wl_display, wlr_xwayland->wl_fd[0]);
|
|
|
|
if (!wlr_xwayland->client) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log_errno(WLR_ERROR, "wl_client_create failed");
|
2018-05-06 20:23:10 +02:00
|
|
|
xwayland_finish_server(wlr_xwayland);
|
2017-08-26 18:10:57 +02:00
|
|
|
return false;
|
2017-08-19 17:59:31 +02:00
|
|
|
}
|
2017-10-04 06:42:10 +02:00
|
|
|
|
2017-08-26 18:10:57 +02:00
|
|
|
wlr_xwayland->wl_fd[0] = -1; /* not ours anymore */
|
|
|
|
|
2017-12-08 01:38:45 +01:00
|
|
|
wlr_xwayland->client_destroy.notify = handle_client_destroy;
|
2017-12-08 00:59:37 +01:00
|
|
|
wl_client_add_destroy_listener(wlr_xwayland->client,
|
2017-12-08 01:38:45 +01:00
|
|
|
&wlr_xwayland->client_destroy);
|
2017-08-26 18:10:57 +02:00
|
|
|
|
2018-05-06 20:23:10 +02:00
|
|
|
struct wl_event_loop *loop = wl_display_get_event_loop(wlr_xwayland->wl_display);
|
2017-12-08 00:59:37 +01:00
|
|
|
wlr_xwayland->sigusr1_source = wl_event_loop_add_signal(loop, SIGUSR1,
|
|
|
|
xserver_handle_ready, wlr_xwayland);
|
2017-08-19 17:59:31 +02:00
|
|
|
|
2019-02-19 16:38:45 +01:00
|
|
|
wlr_xwayland->pid = fork();
|
|
|
|
if (wlr_xwayland->pid < 0) {
|
|
|
|
wlr_log_errno(WLR_ERROR, "fork failed");
|
|
|
|
xwayland_finish_server(wlr_xwayland);
|
|
|
|
return false;
|
|
|
|
} else if (wlr_xwayland->pid == 0) {
|
2017-08-26 18:10:57 +02:00
|
|
|
/* Double-fork, but we need to forward SIGUSR1 once Xserver(1)
|
|
|
|
* is ready, or error if there was one. */
|
2019-02-19 16:38:45 +01:00
|
|
|
pid_t ppid = getppid();
|
2017-08-26 18:10:57 +02:00
|
|
|
sigset_t sigset;
|
|
|
|
sigemptyset(&sigset);
|
|
|
|
sigaddset(&sigset, SIGUSR1);
|
|
|
|
sigaddset(&sigset, SIGCHLD);
|
|
|
|
sigprocmask(SIG_BLOCK, &sigset, NULL);
|
2019-02-19 16:38:45 +01:00
|
|
|
|
|
|
|
pid_t pid = fork();
|
2017-08-26 18:10:57 +02:00
|
|
|
if (pid < 0) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log_errno(WLR_ERROR, "second fork failed");
|
2017-08-26 18:10:57 +02:00
|
|
|
_exit(EXIT_FAILURE);
|
2019-02-19 16:38:45 +01:00
|
|
|
} else if (pid == 0) {
|
|
|
|
exec_xwayland(wlr_xwayland);
|
2017-08-26 18:10:57 +02:00
|
|
|
}
|
2019-02-19 16:38:45 +01:00
|
|
|
|
|
|
|
int sig;
|
2017-08-26 18:10:57 +02:00
|
|
|
sigwait(&sigset, &sig);
|
|
|
|
kill(ppid, SIGUSR1);
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_DEBUG, "sent SIGUSR1 to process %d", ppid);
|
2017-08-26 18:10:57 +02:00
|
|
|
if (sig == SIGCHLD) {
|
|
|
|
waitpid(pid, NULL, 0);
|
|
|
|
_exit(EXIT_FAILURE);
|
|
|
|
}
|
2019-02-19 16:38:45 +01:00
|
|
|
|
2017-08-26 18:10:57 +02:00
|
|
|
_exit(EXIT_SUCCESS);
|
|
|
|
}
|
2017-08-19 17:59:31 +02:00
|
|
|
|
|
|
|
/* close child fds */
|
2018-05-06 20:23:10 +02:00
|
|
|
/* remain managing x sockets for lazy start */
|
2017-08-19 17:59:31 +02:00
|
|
|
close(wlr_xwayland->wl_fd[1]);
|
|
|
|
close(wlr_xwayland->wm_fd[1]);
|
|
|
|
wlr_xwayland->wl_fd[1] = wlr_xwayland->wm_fd[1] = -1;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-08-20 07:59:03 +02:00
|
|
|
|
2018-05-06 20:23:10 +02:00
|
|
|
static bool xwayland_start_server_lazy(struct wlr_xwayland *wlr_xwayland) {
|
|
|
|
struct wl_event_loop *loop = wl_display_get_event_loop(wlr_xwayland->wl_display);
|
|
|
|
wlr_xwayland->x_fd_read_event[0] =
|
|
|
|
wl_event_loop_add_fd(loop, wlr_xwayland->x_fd[0], WL_EVENT_READABLE,
|
|
|
|
xwayland_socket_connected, wlr_xwayland);
|
|
|
|
wlr_xwayland->x_fd_read_event[1] =
|
|
|
|
wl_event_loop_add_fd(loop, wlr_xwayland->x_fd[1], WL_EVENT_READABLE,
|
|
|
|
xwayland_socket_connected, wlr_xwayland);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-20 07:59:03 +02:00
|
|
|
void wlr_xwayland_destroy(struct wlr_xwayland *wlr_xwayland) {
|
2018-09-08 13:00:56 +02:00
|
|
|
if (!wlr_xwayland) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-29 20:50:50 +01:00
|
|
|
wlr_xwayland_set_seat(wlr_xwayland, NULL);
|
2018-05-06 20:23:10 +02:00
|
|
|
xwayland_finish_server(wlr_xwayland);
|
|
|
|
xwayland_finish_display(wlr_xwayland);
|
2017-08-20 07:59:03 +02:00
|
|
|
free(wlr_xwayland);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display,
|
2018-05-06 20:23:10 +02:00
|
|
|
struct wlr_compositor *compositor, bool lazy) {
|
2017-08-20 07:59:03 +02:00
|
|
|
struct wlr_xwayland *wlr_xwayland = calloc(1, sizeof(struct wlr_xwayland));
|
2018-05-08 22:22:35 +02:00
|
|
|
if (!wlr_xwayland) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-05-06 20:23:10 +02:00
|
|
|
|
|
|
|
wlr_xwayland->wl_display = wl_display;
|
|
|
|
wlr_xwayland->compositor = compositor;
|
|
|
|
wlr_xwayland->lazy = lazy;
|
|
|
|
|
|
|
|
wlr_xwayland->x_fd[0] = wlr_xwayland->x_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;
|
2017-12-29 20:50:50 +01:00
|
|
|
|
|
|
|
wl_signal_init(&wlr_xwayland->events.new_surface);
|
|
|
|
wl_signal_init(&wlr_xwayland->events.ready);
|
2018-05-06 20:23:10 +02:00
|
|
|
|
2018-05-19 13:39:51 +02:00
|
|
|
if (!xwayland_start_display(wlr_xwayland, wl_display)) {
|
2018-05-06 20:23:10 +02:00
|
|
|
goto error_alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wlr_xwayland->lazy) {
|
|
|
|
if (!xwayland_start_server_lazy(wlr_xwayland)) {
|
|
|
|
goto error_display;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!xwayland_start_server(wlr_xwayland)) {
|
|
|
|
goto error_display;
|
|
|
|
}
|
2017-08-20 07:59:03 +02:00
|
|
|
}
|
2018-05-06 20:23:10 +02:00
|
|
|
|
|
|
|
return wlr_xwayland;
|
|
|
|
|
|
|
|
error_display:
|
|
|
|
xwayland_finish_display(wlr_xwayland);
|
|
|
|
|
|
|
|
error_alloc:
|
2017-08-20 07:59:03 +02:00
|
|
|
free(wlr_xwayland);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-11-02 16:49:22 +01:00
|
|
|
|
|
|
|
void wlr_xwayland_set_cursor(struct wlr_xwayland *wlr_xwayland,
|
|
|
|
uint8_t *pixels, uint32_t stride, uint32_t width, uint32_t height,
|
|
|
|
int32_t hotspot_x, int32_t hotspot_y) {
|
|
|
|
if (wlr_xwayland->xwm != NULL) {
|
|
|
|
xwm_set_cursor(wlr_xwayland->xwm, pixels, stride, width, height,
|
|
|
|
hotspot_x, hotspot_y);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(wlr_xwayland->cursor);
|
|
|
|
|
|
|
|
wlr_xwayland->cursor = calloc(1, sizeof(struct wlr_xwayland_cursor));
|
|
|
|
if (wlr_xwayland->cursor == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wlr_xwayland->cursor->pixels = pixels;
|
|
|
|
wlr_xwayland->cursor->stride = stride;
|
|
|
|
wlr_xwayland->cursor->width = width;
|
|
|
|
wlr_xwayland->cursor->height = height;
|
|
|
|
wlr_xwayland->cursor->hotspot_x = hotspot_x;
|
|
|
|
wlr_xwayland->cursor->hotspot_y = hotspot_y;
|
|
|
|
}
|
2017-11-22 14:10:06 +01:00
|
|
|
|
2018-04-26 00:51:00 +02:00
|
|
|
static void xwayland_handle_seat_destroy(struct wl_listener *listener,
|
2017-12-29 17:55:16 +01:00
|
|
|
void *data) {
|
|
|
|
struct wlr_xwayland *xwayland =
|
|
|
|
wl_container_of(listener, xwayland, seat_destroy);
|
|
|
|
|
|
|
|
wlr_xwayland_set_seat(xwayland, NULL);
|
|
|
|
}
|
|
|
|
|
2017-11-22 14:10:06 +01:00
|
|
|
void wlr_xwayland_set_seat(struct wlr_xwayland *xwayland,
|
|
|
|
struct wlr_seat *seat) {
|
2017-12-29 17:55:16 +01:00
|
|
|
if (xwayland->seat) {
|
|
|
|
wl_list_remove(&xwayland->seat_destroy.link);
|
|
|
|
}
|
|
|
|
|
2017-11-22 14:23:23 +01:00
|
|
|
xwayland->seat = seat;
|
|
|
|
|
|
|
|
if (xwayland->xwm) {
|
|
|
|
xwm_set_seat(xwayland->xwm, seat);
|
|
|
|
}
|
2017-12-29 17:55:16 +01:00
|
|
|
|
|
|
|
if (seat == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-26 00:51:00 +02:00
|
|
|
xwayland->seat_destroy.notify = xwayland_handle_seat_destroy;
|
2017-12-29 17:55:16 +01:00
|
|
|
wl_signal_add(&seat->events.destroy, &xwayland->seat_destroy);
|
2017-11-22 14:10:06 +01:00
|
|
|
}
|