weston_LDFLAGS = -export-dynamic
weston_CPPFLAGS = $(AM_CPPFLAGS) -DIN_WESTON \
- -DMODULEDIR='"$(moduledir)"'
+ -DMODULEDIR='"$(moduledir)"' \
+ -DXSERVER_PATH='"@XSERVER_PATH@"'
weston_CFLAGS = $(AM_CFLAGS) $(COMPOSITOR_CFLAGS) $(LIBUNWIND_CFLAGS)
weston_LDADD = $(COMPOSITOR_LIBS) $(LIBUNWIND_LIBS) \
$(DLOPEN_LIBS) $(LIBINPUT_BACKEND_LIBS) \
weston_SOURCES = \
compositor/main.c \
compositor/weston-screenshooter.c \
- compositor/text-backend.c
+ compositor/text-backend.c \
+ compositor/xwayland.c
# Track this dependency explicitly instead of using BUILT_SOURCES. We
# add BUILT_SOURCES to CLEANFILES, but we want to keep git-version.h
if ENABLE_XWAYLAND
-module_LTLIBRARIES += xwayland.la
+libweston_module_LTLIBRARIES += xwayland.la
xwayland_la_CPPFLAGS = \
-I$(top_builddir)/protocol \
-I$(top_builddir)/xwayland \
-DDATADIR='"$(datadir)"' \
-DMODULEDIR='"$(moduledir)"' \
- -DLIBEXECDIR='"$(libexecdir)"' \
- -DXSERVER_PATH='"@XSERVER_PATH@"'
+ -DLIBEXECDIR='"$(libexecdir)"'
xwayland_la_LDFLAGS = -module -avoid-version
xwayland_la_LIBADD = \
xwayland/hash.c \
xwayland/hash.h \
shared/helpers.h
+
+libwestoninclude_HEADERS += xwayland/xwayland-api.h
+
endif
while (*p) {
end = strchrnul(p, ',');
snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
- module_init = wet_load_module(buffer, "module_init");
- if (!module_init)
- return -1;
- if (module_init(ec, argc, argv) < 0)
- return -1;
+
+ if (strstr(buffer, "xwayland.so")) {
+ if (wet_load_xwayland(ec) < 0)
+ return -1;
+ } else {
+ module_init = wet_load_module(buffer, "module_init");
+ if (!module_init)
+ return -1;
+ if (module_init(ec, argc, argv) < 0)
+ return -1;
+ }
p = end;
while (*p == ',')
p++;
void *
wet_load_module(const char *name, const char *entrypoint);
+int
+wet_load_xwayland(struct weston_compositor *comp);
+
#ifdef __cplusplus
}
#endif
--- /dev/null
+/*
+ * Copyright © 2011 Intel Corporation
+ * Copyright © 2016 Giulio Camuffo
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <signal.h>
+#include <sys/socket.h>
+
+#include "compositor.h"
+#include "compositor/weston.h"
+#include "xwayland/xwayland-api.h"
+#include "shared/helpers.h"
+
+struct wet_xwayland {
+ struct weston_compositor *compositor;
+ const struct weston_xwayland_api *api;
+ struct weston_xwayland *xwayland;
+ struct wl_event_source *sigusr1_source;
+ struct wl_client *client;
+ int wm_fd;
+ struct weston_process process;
+};
+
+static int
+handle_sigusr1(int signal_number, void *data)
+{
+ struct wet_xwayland *wxw = data;
+
+ /* We'd be safer if we actually had the struct
+ * signalfd_siginfo from the signalfd data and could verify
+ * this came from Xwayland.*/
+ wxw->api->xserver_loaded(wxw->xwayland, wxw->client, wxw->wm_fd);
+ wl_event_source_remove(wxw->sigusr1_source);
+
+ return 1;
+}
+
+static pid_t
+spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd)
+{
+ struct wet_xwayland *wxw = user_data;
+ pid_t pid;
+ char s[8], abstract_fd_str[8], unix_fd_str[8], wm_fd_str[8];
+ int sv[2], wm[2], fd;
+ char *xserver = NULL;
+ struct weston_config *config = wet_get_config(wxw->compositor);
+ struct weston_config_section *section;
+
+ if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) {
+ weston_log("wl connection socketpair failed\n");
+ return 1;
+ }
+
+ if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, wm) < 0) {
+ weston_log("X wm connection socketpair failed\n");
+ return 1;
+ }
+
+ pid = fork();
+ switch (pid) {
+ case 0:
+ /* SOCK_CLOEXEC closes both ends, so we need to unset
+ * the flag on the client fd. */
+ fd = dup(sv[1]);
+ if (fd < 0)
+ goto fail;
+ snprintf(s, sizeof s, "%d", fd);
+ setenv("WAYLAND_SOCKET", s, 1);
+
+ fd = dup(abstract_fd);
+ if (fd < 0)
+ goto fail;
+ snprintf(abstract_fd_str, sizeof abstract_fd_str, "%d", fd);
+ fd = dup(unix_fd);
+ if (fd < 0)
+ goto fail;
+ snprintf(unix_fd_str, sizeof unix_fd_str, "%d", fd);
+ fd = dup(wm[1]);
+ if (fd < 0)
+ goto fail;
+ snprintf(wm_fd_str, sizeof wm_fd_str, "%d", fd);
+
+ section = weston_config_get_section(config,
+ "xwayland", NULL, NULL);
+ weston_config_section_get_string(section, "path",
+ &xserver, XSERVER_PATH);
+
+ /* Ignore SIGUSR1 in the child, which will make the X
+ * server send SIGUSR1 to the parent (weston) when
+ * it's done with initialization. During
+ * initialization the X server will round trip and
+ * block on the wayland compositor, so avoid making
+ * blocking requests (like xcb_connect_to_fd) until
+ * it's done with that. */
+ signal(SIGUSR1, SIG_IGN);
+
+ if (execl(xserver,
+ xserver,
+ display,
+ "-rootless",
+ "-listen", abstract_fd_str,
+ "-listen", unix_fd_str,
+ "-wm", wm_fd_str,
+ "-terminate",
+ NULL) < 0)
+ weston_log("exec of '%s %s -rootless "
+ "-listen %s -listen %s -wm %s "
+ "-terminate' failed: %m\n",
+ xserver, display,
+ abstract_fd_str, unix_fd_str, wm_fd_str);
+ fail:
+ _exit(EXIT_FAILURE);
+
+ default:
+ close(sv[1]);
+ wxw->client = wl_client_create(wxw->compositor->wl_display, sv[0]);
+
+ close(wm[1]);
+ wxw->wm_fd = wm[0];
+
+ wxw->process.pid = pid;
+ weston_watch_process(&wxw->process);
+ break;
+
+ case -1:
+ weston_log( "failed to fork\n");
+ break;
+ }
+
+ return pid;
+}
+
+static void
+xserver_cleanup(struct weston_process *process, int status)
+{
+ struct wet_xwayland *wxw =
+ container_of(process, struct wet_xwayland, process);
+ struct wl_event_loop *loop =
+ wl_display_get_event_loop(wxw->compositor->wl_display);
+
+ wxw->api->xserver_exited(wxw->xwayland, status);
+ wxw->sigusr1_source = wl_event_loop_add_signal(loop, SIGUSR1,
+ handle_sigusr1, wxw);
+ wxw->client = NULL;
+}
+
+int
+wet_load_xwayland(struct weston_compositor *comp)
+{
+ const struct weston_xwayland_api *api;
+ struct weston_xwayland *xwayland;
+ struct wet_xwayland *wxw;
+ struct wl_event_loop *loop;
+
+ if (weston_compositor_load_xwayland(comp) < 0)
+ return -1;
+
+ api = weston_xwayland_get_api(comp);
+ if (!api) {
+ weston_log("Failed to get the xwayland module API.\n");
+ return -1;
+ }
+
+ xwayland = api->get(comp);
+ if (!xwayland) {
+ weston_log("Failed to get the xwayland object.\n");
+ return -1;
+ }
+
+ wxw = zalloc(sizeof *wxw);
+ if (!wxw)
+ return -1;
+
+ wxw->compositor = comp;
+ wxw->api = api;
+ wxw->xwayland = xwayland;
+ wxw->process.cleanup = xserver_cleanup;
+ if (api->listen(xwayland, wxw, spawn_xserver) < 0)
+ return -1;
+
+ loop = wl_display_get_event_loop(comp->wl_display);
+ wxw->sigusr1_source = wl_event_loop_add_signal(loop, SIGUSR1,
+ handle_sigusr1, wxw);
+
+ return 0;
+}
return backend_init(compositor, config_base);
}
+
+WL_EXPORT int
+weston_compositor_load_xwayland(struct weston_compositor *compositor)
+{
+ int (*module_init)(struct weston_compositor *ec,
+ int *argc, char *argv[]);
+ int argc = 0;
+
+ module_init = weston_load_module("xwayland.so", "module_init");
+ if (!module_init)
+ return -1;
+ if (module_init(compositor, &argc, NULL) < 0)
+ return -1;
+ return 0;
+}
weston_seat_set_keyboard_focus(struct weston_seat *seat,
struct weston_surface *surface);
+int
+weston_compositor_load_xwayland(struct weston_compositor *compositor);
+
#ifdef __cplusplus
}
#endif
#include <signal.h>
#include "xwayland.h"
+#include "xwayland-api.h"
#include "shared/helpers.h"
#include "compositor/weston.h"
static int
-handle_sigusr1(int signal_number, void *data)
-{
- struct weston_xserver *wxs = data;
-
- /* We'd be safer if we actually had the struct
- * signalfd_siginfo from the signalfd data and could verify
- * this came from Xwayland.*/
- wxs->wm = weston_wm_create(wxs, wxs->wm_fd);
- wl_event_source_remove(wxs->sigusr1_source);
-
- return 1;
-}
-
-static int
weston_xserver_handle_event(int listen_fd, uint32_t mask, void *data)
{
struct weston_xserver *wxs = data;
- char display[8], s[8], abstract_fd[8], unix_fd[8], wm_fd[8];
- int sv[2], wm[2], fd;
- char *xserver = NULL;
- struct weston_config *config = wet_get_config(wxs->compositor);
- struct weston_config_section *section;
-
- if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, sv) < 0) {
- weston_log("wl connection socketpair failed\n");
- return 1;
- }
+ char display[8];
+
+ snprintf(display, sizeof display, ":%d", wxs->display);
- if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, wm) < 0) {
- weston_log("X wm connection socketpair failed\n");
+ wxs->pid = wxs->spawn_func(wxs->user_data, display, wxs->abstract_fd, wxs->unix_fd);
+ if (wxs->pid == -1) {
+ weston_log("Failed to spawn the Xwayland server\n");
return 1;
}
- wxs->process.pid = fork();
- switch (wxs->process.pid) {
- case 0:
- /* SOCK_CLOEXEC closes both ends, so we need to unset
- * the flag on the client fd. */
- fd = dup(sv[1]);
- if (fd < 0)
- goto fail;
- snprintf(s, sizeof s, "%d", fd);
- setenv("WAYLAND_SOCKET", s, 1);
-
- snprintf(display, sizeof display, ":%d", wxs->display);
-
- fd = dup(wxs->abstract_fd);
- if (fd < 0)
- goto fail;
- snprintf(abstract_fd, sizeof abstract_fd, "%d", fd);
- fd = dup(wxs->unix_fd);
- if (fd < 0)
- goto fail;
- snprintf(unix_fd, sizeof unix_fd, "%d", fd);
- fd = dup(wm[1]);
- if (fd < 0)
- goto fail;
- snprintf(wm_fd, sizeof wm_fd, "%d", fd);
-
- section = weston_config_get_section(config,
- "xwayland", NULL, NULL);
- weston_config_section_get_string(section, "path",
- &xserver, XSERVER_PATH);
-
- /* Ignore SIGUSR1 in the child, which will make the X
- * server send SIGUSR1 to the parent (weston) when
- * it's done with initialization. During
- * initialization the X server will round trip and
- * block on the wayland compositor, so avoid making
- * blocking requests (like xcb_connect_to_fd) until
- * it's done with that. */
- signal(SIGUSR1, SIG_IGN);
-
- if (execl(xserver,
- xserver,
- display,
- "-rootless",
- "-listen", abstract_fd,
- "-listen", unix_fd,
- "-wm", wm_fd,
- "-terminate",
- NULL) < 0)
- weston_log("exec of '%s %s -rootless "
- "-listen %s -listen %s -wm %s "
- "-terminate' failed: %m\n",
- xserver, display,
- abstract_fd, unix_fd, wm_fd);
- fail:
- _exit(EXIT_FAILURE);
-
- default:
- weston_log("forked X server, pid %d\n", wxs->process.pid);
-
- close(sv[1]);
- wxs->client = wl_client_create(wxs->wl_display, sv[0]);
-
- close(wm[1]);
- wxs->wm_fd = wm[0];
-
- weston_watch_process(&wxs->process);
-
- wl_event_source_remove(wxs->abstract_source);
- wl_event_source_remove(wxs->unix_source);
- break;
-
- case -1:
- weston_log( "failed to fork\n");
- break;
- }
+ weston_log("Spawned Xwayland server, pid %d\n", wxs->pid);
+ wl_event_source_remove(wxs->abstract_source);
+ wl_event_source_remove(wxs->unix_source);
return 1;
}
unlink(path);
snprintf(path, sizeof path, "/tmp/.X11-unix/X%d", wxs->display);
unlink(path);
- if (wxs->process.pid == 0) {
+ if (wxs->pid == 0) {
wl_event_source_remove(wxs->abstract_source);
wl_event_source_remove(wxs->unix_source);
}
wxs->loop = NULL;
}
-static void
-weston_xserver_cleanup(struct weston_process *process, int status)
-{
- struct weston_xserver *wxs =
- container_of(process, struct weston_xserver, process);
-
- wxs->process.pid = 0;
- wxs->client = NULL;
- wxs->resource = NULL;
-
- wxs->abstract_source =
- wl_event_loop_add_fd(wxs->loop, wxs->abstract_fd,
- WL_EVENT_READABLE,
- weston_xserver_handle_event, wxs);
-
- wxs->unix_source =
- wl_event_loop_add_fd(wxs->loop, wxs->unix_fd,
- WL_EVENT_READABLE,
- weston_xserver_handle_event, wxs);
-
- if (wxs->wm) {
- weston_log("xserver exited, code %d\n", status);
- weston_wm_destroy(wxs->wm);
- wxs->wm = NULL;
- } else {
- /* If the X server crashes before it binds to the
- * xserver interface, shut down and don't try
- * again. */
- weston_log("xserver crashing too fast: %d\n", status);
- weston_xserver_shutdown(wxs);
- }
-}
-
static int
bind_to_abstract_socket(int display)
{
free(wxs);
}
-WL_EXPORT int
-module_init(struct weston_compositor *compositor,
- int *argc, char *argv[])
-
+static struct weston_xwayland *
+weston_xwayland_get(struct weston_compositor *compositor)
{
- struct wl_display *display = compositor->wl_display;
+ struct wl_listener *listener;
struct weston_xserver *wxs;
- char lockfile[256], display_name[8];
- wxs = zalloc(sizeof *wxs);
- if (wxs == NULL)
- return -1;
- wxs->process.cleanup = weston_xserver_cleanup;
- wxs->wl_display = display;
- wxs->compositor = compositor;
+ listener = wl_signal_get(&compositor->destroy_signal,
+ weston_xserver_destroy);
+ if (!listener)
+ return NULL;
- wxs->display = 0;
+ wxs = wl_container_of(listener, wxs, destroy_listener);
+ return (struct weston_xwayland *)wxs;
+}
- retry:
+static int
+weston_xwayland_listen(struct weston_xwayland *xwayland, void *user_data,
+ weston_xwayland_spawn_xserver_func_t spawn_func)
+{
+ struct weston_xserver *wxs = (struct weston_xserver *)xwayland;
+ char lockfile[256], display_name[8];
+
+ wxs->user_data = user_data;
+ wxs->spawn_func = spawn_func;
+
+retry:
if (create_lockfile(wxs->display, lockfile, sizeof lockfile) < 0) {
if (errno == EAGAIN) {
goto retry;
weston_log("xserver listening on display %s\n", display_name);
setenv("DISPLAY", display_name, 1);
- wxs->loop = wl_display_get_event_loop(display);
+ wxs->loop = wl_display_get_event_loop(wxs->wl_display);
+ wxs->abstract_source =
+ wl_event_loop_add_fd(wxs->loop, wxs->abstract_fd,
+ WL_EVENT_READABLE,
+ weston_xserver_handle_event, wxs);
+ wxs->unix_source =
+ wl_event_loop_add_fd(wxs->loop, wxs->unix_fd,
+ WL_EVENT_READABLE,
+ weston_xserver_handle_event, wxs);
+
+ return 0;
+}
+
+static void
+weston_xwayland_xserver_loaded(struct weston_xwayland *xwayland,
+ struct wl_client *client, int wm_fd)
+{
+ struct weston_xserver *wxs = (struct weston_xserver *)xwayland;
+ wxs->wm = weston_wm_create(wxs, wm_fd);
+ wxs->client = client;
+}
+
+static void
+weston_xwayland_xserver_exited(struct weston_xwayland *xwayland,
+ int exit_status)
+{
+ struct weston_xserver *wxs = (struct weston_xserver *)xwayland;
+
+ wxs->pid = 0;
+ wxs->client = NULL;
+
wxs->abstract_source =
wl_event_loop_add_fd(wxs->loop, wxs->abstract_fd,
WL_EVENT_READABLE,
WL_EVENT_READABLE,
weston_xserver_handle_event, wxs);
- wxs->sigusr1_source = wl_event_loop_add_signal(wxs->loop, SIGUSR1,
- handle_sigusr1, wxs);
+ if (wxs->wm) {
+ weston_log("xserver exited, code %d\n", exit_status);
+ weston_wm_destroy(wxs->wm);
+ wxs->wm = NULL;
+ } else {
+ /* If the X server crashes before it binds to the
+ * xserver interface, shut down and don't try
+ * again. */
+ weston_log("xserver crashing too fast: %d\n", exit_status);
+ weston_xserver_shutdown(wxs);
+ }
+}
+
+const struct weston_xwayland_api api = {
+ weston_xwayland_get,
+ weston_xwayland_listen,
+ weston_xwayland_xserver_loaded,
+ weston_xwayland_xserver_exited,
+};
+
+WL_EXPORT int
+module_init(struct weston_compositor *compositor,
+ int *argc, char *argv[])
+
+{
+ struct wl_display *display = compositor->wl_display;
+ struct weston_xserver *wxs;
+ int ret;
+
+ wxs = zalloc(sizeof *wxs);
+ if (wxs == NULL)
+ return -1;
+ wxs->wl_display = display;
+ wxs->compositor = compositor;
+
+ ret = weston_plugin_api_register(compositor, WESTON_XWAYLAND_API_NAME,
+ &api, sizeof(api));
+ if (ret < 0) {
+ weston_log("Failed to register the xwayland module API.\n");
+ free(wxs);
+ return -1;
+ }
+
wxs->destroy_listener.notify = weston_xserver_destroy;
wl_signal_add(&compositor->destroy_signal, &wxs->destroy_listener);
--- /dev/null
+/*
+ * Copyright © 2016 Giulio Camuffo
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef XWAYLAND_API_H
+#define XWAYLAND_API_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <unistd.h>
+
+#include "plugin-registry.h"
+
+struct weston_compositor;
+struct weston_xwayland;
+
+#define WESTON_XWAYLAND_API_NAME "weston_xwayland_v1"
+
+typedef pid_t
+(*weston_xwayland_spawn_xserver_func_t)(
+ void *user_data, const char *display, int abstract_fd, int unix_fd);
+
+/** The libweston Xwayland API
+ *
+ * This API allows to control the Xwayland libweston module.
+ * The module must be loaded at runtime with \a weston_compositor_load_xwayland,
+ * after which the API can be retrieved by using \a weston_xwayland_get_api.
+ */
+struct weston_xwayland_api {
+ /** Retrieve the Xwayland context object.
+ *
+ * Note that this function does not create a new object, but returns
+ * always the same object per compositor instance.
+ * This function cannot fail, if this API object is valid.
+ *
+ * \param compositor The compositor instance.
+ */
+ struct weston_xwayland *
+ (*get)(struct weston_compositor *compositor);
+
+ /** Listen for X connections.
+ *
+ * This function tells the Xwayland module to start create a X socket
+ * and to listen for client connections. When one such connection is
+ * detected the given \a spawn_func callback will be called to start
+ * the Xwayland process.
+ *
+ * \param xwayland The Xwayland context object.
+ * \param user_data The user data pointer to be passed to \a spawn_func.
+ * \param spawn_func The callback function called to start the Xwayland
+ * server process.
+ *
+ * \return 0 on success, a negative number otherwise.
+ */
+ int
+ (*listen)(struct weston_xwayland *xwayland, void *user_data,
+ weston_xwayland_spawn_xserver_func_t spawn_func);
+
+ /** Notify the Xwayland module the Xwayland server is loaded.
+ *
+ * After the Xwayland server process has been spawned it will notify
+ * the parent that is has finished the initialization by sending a
+ * SIGUSR1 signal.
+ * The caller should listen for that signal and call this function
+ * when it is received.
+ *
+ * \param xwayland The Xwayland context object.
+ * \param client The wl_client object representing the connection of
+ * the Xwayland server process.
+ * \param wm_fd The file descriptor for the wm.
+ */
+ void
+ (*xserver_loaded)(struct weston_xwayland *xwayland,
+ struct wl_client *client, int wm_fd);
+
+ /** Notify the Xwayland module the Xwayland server has exited.
+ *
+ * Whenever the Xwayland server process quits this function should be
+ * called.
+ * The Xwayland module will keep listening for X connections on the
+ * socket, and may call the spawn function again.
+ *
+ * \param xwayland The Xwayland context object.
+ * \param exit_status The exit status of the Xwayland server process.
+ */
+ void
+ (*xserver_exited)(struct weston_xwayland *xwayland, int exit_status);
+};
+
+/** Retrieve the API object for the libweston Xwayland module.
+ *
+ * The module must have been previously loaded by calling
+ * \a weston_compositor_load_xwayland.
+ *
+ * \param compositor The compositor instance.
+ */
+static inline const struct weston_xwayland_api *
+weston_xwayland_get_api(struct weston_compositor *compositor)
+{
+ const void *api;
+ api = weston_plugin_api_get(compositor, WESTON_XWAYLAND_API_NAME,
+ sizeof(struct weston_xwayland_api));
+ /* The cast is necessary to use this function in C++ code */
+ return (const struct weston_xwayland_api *)api;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
#include "compositor.h"
#include "compositor/weston.h"
+#include "xwayland-api.h"
#define SEND_EVENT_MASK (0x80)
#define EVENT_TYPE(event) ((event)->response_type & ~SEND_EVENT_MASK)
struct weston_xserver {
struct wl_display *wl_display;
struct wl_event_loop *loop;
- struct wl_event_source *sigchld_source;
int abstract_fd;
struct wl_event_source *abstract_source;
int unix_fd;
struct wl_event_source *unix_source;
- int wm_fd;
int display;
- struct wl_event_source *sigusr1_source;
- struct weston_process process;
- struct wl_resource *resource;
+ pid_t pid;
struct wl_client *client;
struct weston_compositor *compositor;
struct weston_wm *wm;
struct wl_listener destroy_listener;
+ weston_xwayland_spawn_xserver_func_t spawn_func;
+ void *user_data;
};
struct weston_wm {