From 923bfe6f1f7f12d103bd8d3586c31cd62d91c8d2 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Wed, 2 Apr 2014 19:53:58 -0500 Subject: [PATCH] Add support for running with a primary client On startup weston now detects the WAYLAND_SERVER_SOCKET environment variable. If found, weston does not create the display like normal, but instead directly adds a client corresponding to the given fd. This, combined with the fullscreen shell, allows a process to spawn weston and use it as a backend. Signed-off-by: Jason Ekstrand --- src/compositor.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/src/compositor.c b/src/compositor.c index 362e959..c293218 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -4080,6 +4080,16 @@ catch_signals(void) sigaction(SIGABRT, &action, NULL); } +static void +handle_primary_client_destroyed(struct wl_listener *listener, void *data) +{ + struct wl_client *client = data; + + weston_log("Primary client died. Closing...\n"); + + wl_display_terminate(wl_client_get_display(client)); +} + int main(int argc, char *argv[]) { int ret = EXIT_SUCCESS; @@ -4091,19 +4101,22 @@ int main(int argc, char *argv[]) *(*backend_init)(struct wl_display *display, int *argc, char *argv[], struct weston_config *config); - int i; + int i, fd; char *backend = NULL; char *option_backend = NULL; char *shell = NULL; char *option_shell = NULL; char *modules, *option_modules = NULL; char *log = NULL; + char *server_socket = NULL, *end; int32_t idle_time = 300; int32_t help = 0; char *socket_name = "wayland-0"; int32_t version = 0; struct weston_config *config; struct weston_config_section *section; + struct wl_client *primary_client; + struct wl_listener primary_client_destroyed; const struct weston_option core_options[] = { { WESTON_OPTION_STRING, "backend", 'B', &option_backend }, @@ -4226,10 +4239,33 @@ int main(int argc, char *argv[]) weston_compositor_log_capabilities(ec); - if (wl_display_add_socket(display, socket_name)) { - weston_log("fatal: failed to add socket: %m\n"); - ret = EXIT_FAILURE; - goto out; + server_socket = getenv("WAYLAND_SERVER_SOCKET"); + if (server_socket) { + weston_log("Running with single client\n"); + fd = strtol(server_socket, &end, 0); + if (*end != '\0') + fd = -1; + } else { + fd = -1; + } + + if (fd != -1) { + primary_client = wl_client_create(display, fd); + if (!primary_client) { + weston_log("fatal: failed to add client: %m\n"); + ret = EXIT_FAILURE; + goto out; + } + primary_client_destroyed.notify = + handle_primary_client_destroyed; + wl_client_add_destroy_listener(primary_client, + &primary_client_destroyed); + } else { + if (wl_display_add_socket(display, socket_name)) { + weston_log("fatal: failed to add socket: %m\n"); + ret = EXIT_FAILURE; + goto out; + } } weston_compositor_wake(ec); -- 2.7.4