[mutter/wip/carlosg/xwayland-on-demand: 141/143] wayland: Implement on-demand start of Xwayland
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/carlosg/xwayland-on-demand: 141/143] wayland: Implement on-demand start of Xwayland
- Date: Fri, 19 Jul 2019 22:42:48 +0000 (UTC)
commit eaea8b4f95bb7804ecaae416eee43cb8ef6bab7f
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri May 24 21:36:50 2019 +0200
wayland: Implement on-demand start of Xwayland
The Xwayland manager now has 4 distinct phases:
- Init and shutdown (Happening together with the compositor itself)
- Start and stop
In these last 2 phases, handle orderly initialization and shutdown
of Xwayland. On initialization We will simply find out what is a
proper display name, and set up the envvar and socket so that clients
think there is a X server.
Whenever we detect data on this socket, we enter the start phase
that will launch Xwayland, and plunge the socket directly to it.
In this phase we now also set up the MetaX11Display.
The stop phase is pretty much the opposite, we will shutdown the
MetaX11Display and all related data, terminate the Xwayland
process, and restore the listening sockets. This phase happens
on a timeout whenever the last known X11 MetaWindow is gone. If no
new X clients come back in this timeout, the X server will be
eventually terminated.
The shutdown phase happens on compositor shutdown and is completely
uninteresting. Some bits there moved into the stop phase as might
happen over and over.
This is all controlled by META_DISPLAY_POLICY_ON_DEMAND and
the "autostart-xwayland" experimental setting.
src/core/display.c | 12 ++--
src/wayland/meta-wayland-private.h | 1 +
src/wayland/meta-xwayland.c | 118 +++++++++++++++++++++++++++++++------
3 files changed, 109 insertions(+), 22 deletions(-)
---
diff --git a/src/core/display.c b/src/core/display.c
index 37ef364e3..80acd114c 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -49,6 +49,7 @@
#include "backends/x11/meta-backend-x11.h"
#include "backends/x11/cm/meta-backend-x11-cm.h"
#include "clutter/x11/clutter-x11.h"
+#include "compositor/compositor-private.h"
#include "core/bell.h"
#include "core/boxes-private.h"
#include "core/display-private.h"
@@ -643,12 +644,15 @@ meta_display_init_x11 (MetaDisplay *display,
display->x11_display = x11_display;
g_signal_emit (display, display_signals[X11_DISPLAY_OPENED], 0);
- meta_x11_display_create_guard_window (x11_display);
- if (!display->display_opening)
- meta_display_manage_all_xwindows (display);
+ if (meta_get_x11_display_policy () == META_DISPLAY_POLICY_ON_DEMAND)
+ {
+ meta_x11_display_create_guard_window (x11_display);
+ if (!display->display_opening)
+ meta_display_manage_all_xwindows (display);
- meta_compositor_redirect_x11_windows (display->compositor);
+ meta_compositor_redirect_x11_windows (display->compositor);
+ }
return TRUE;
}
diff --git a/src/wayland/meta-wayland-private.h b/src/wayland/meta-wayland-private.h
index 6acbafc1f..9b99674e0 100644
--- a/src/wayland/meta-wayland-private.h
+++ b/src/wayland/meta-wayland-private.h
@@ -48,6 +48,7 @@ typedef struct
char *lock_file;
int abstract_fd;
int unix_fd;
+ guint xserver_grace_period_id;
struct wl_display *wayland_display;
struct wl_client *client;
struct wl_resource *xserver_resource;
diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c
index c47dc9cb5..0b96fe70a 100644
--- a/src/wayland/meta-xwayland.c
+++ b/src/wayland/meta-xwayland.c
@@ -41,6 +41,7 @@
#include "compositor/meta-surface-actor-wayland.h"
#include "compositor/meta-window-actor-private.h"
+#include "core/main-private.h"
#include "meta/main.h"
#include "wayland/meta-wayland-actor-surface.h"
@@ -70,6 +71,8 @@ G_DEFINE_TYPE (MetaWaylandSurfaceRoleXWayland,
static int display_number_override = -1;
+static void meta_xwayland_stop_xserver (MetaXWaylandManager *manager);
+
void
meta_xwayland_associate_window_with_surface (MetaWindow *window,
MetaWaylandSurface *surface)
@@ -368,24 +371,45 @@ xserver_died (GObject *source,
g_warning ("Failed to finish waiting for Xwayland: %s", error->message);
}
else if (!g_subprocess_get_successful (proc))
- g_warning ("X Wayland crashed; exiting");
- else
+ g_warning ("X Wayland process exited");
+
+ if (meta_get_x11_display_policy () == META_DISPLAY_POLICY_MANDATORY)
{
- /* For now we simply abort if we see the server exit.
- *
- * In the future X will only be loaded lazily for legacy X support
- * but for now it's a hard requirement. */
- g_warning ("Spurious exit of X Wayland server");
+ meta_exit (META_EXIT_ERROR);
+ }
+ else if (meta_get_x11_display_policy () == META_DISPLAY_POLICY_ON_DEMAND)
+ {
+ MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
+ MetaDisplay *display = meta_get_display ();
+
+ if (display->x11_display)
+ meta_display_shutdown_x11 (display);
+
+ if (!meta_xwayland_init (&compositor->xwayland_manager,
+ compositor->wayland_display))
+ g_warning ("Failed to init X sockets");
}
+}
+
+static gboolean
+shutdown_xwayland_cb (gpointer data)
+{
+ MetaXWaylandManager *manager = data;
- meta_exit (META_EXIT_ERROR);
+ g_debug ("Shutting down Xwayland");
+ manager->xserver_grace_period_id = 0;
+ meta_display_shutdown_x11 (meta_get_display ());
+ meta_xwayland_stop_xserver (manager);
+ return G_SOURCE_REMOVE;
}
static int
x_io_error (Display *display)
{
g_warning ("Connection to xwayland lost");
- meta_exit (META_EXIT_ERROR);
+
+ if (meta_get_x11_display_policy () == META_DISPLAY_POLICY_MANDATORY)
+ meta_exit (META_EXIT_ERROR);
return 0;
}
@@ -552,6 +576,7 @@ on_displayfd_ready (int fd,
gpointer user_data)
{
MetaXWaylandManager *manager = user_data;
+ MetaDisplay *display = meta_get_display ();
/* The server writes its display name to the displayfd
* socket when it's ready. We don't care about the data
@@ -559,6 +584,9 @@ on_displayfd_ready (int fd,
* that means it's ready. */
xserver_finished_init (manager);
+ if (meta_get_x11_display_policy () == META_DISPLAY_POLICY_ON_DEMAND)
+ meta_display_init_x11 (display, NULL);
+
return G_SOURCE_REMOVE;
}
@@ -636,6 +664,19 @@ meta_xwayland_start_xserver (MetaXWaylandManager *manager)
return TRUE;
}
+static gboolean
+xdisplay_connection_activity_cb (gint fd,
+ GIOCondition cond,
+ gpointer user_data)
+{
+ MetaXWaylandManager *manager = user_data;
+
+ if (!meta_xwayland_start_xserver (manager))
+ g_critical ("Could not start Xserver");
+
+ return G_SOURCE_REMOVE;
+}
+
static void
window_unmanaged_cb (MetaWindow *window,
MetaXWaylandManager *manager)
@@ -644,6 +685,12 @@ window_unmanaged_cb (MetaWindow *window,
g_signal_handlers_disconnect_by_func (window,
window_unmanaged_cb,
manager);
+ if (!manager->x11_windows)
+ {
+ g_debug ("All X11 windows gone, setting shutdown timeout");
+ manager->xserver_grace_period_id =
+ g_timeout_add_seconds (10, shutdown_xwayland_cb, manager);
+ }
}
static void
@@ -657,21 +704,62 @@ window_created_cb (MetaDisplay *display,
manager->x11_windows = g_list_prepend (manager->x11_windows, window);
g_signal_connect (window, "unmanaged",
G_CALLBACK (window_unmanaged_cb), manager);
+ if (manager->xserver_grace_period_id)
+ {
+ g_source_remove (manager->xserver_grace_period_id);
+ manager->xserver_grace_period_id = 0;
+ }
}
}
+static void
+meta_xwayland_stop_xserver (MetaXWaylandManager *manager)
+{
+ if (manager->proc)
+ g_subprocess_send_signal (manager->proc, SIGTERM);
+ g_signal_handlers_disconnect_by_func (meta_get_display (),
+ window_created_cb,
+ manager);
+ g_clear_object (&manager->xserver_died_cancellable);
+ g_clear_object (&manager->proc);
+}
+
gboolean
meta_xwayland_init (MetaXWaylandManager *manager,
struct wl_display *wl_display)
{
- if (!choose_xdisplay (manager))
- return FALSE;
+ MetaDisplayPolicy policy;
+ gboolean fatal;
+
+ if (!manager->display_name)
+ {
+ if (!choose_xdisplay (manager))
+ return FALSE;
+ }
+ else
+ {
+ if (!open_display_sockets (manager, manager->display_index, &fatal))
+ return FALSE;
+ }
if (!prepare_auth_file (manager))
return FALSE;
manager->wayland_display = wl_display;
- return meta_xwayland_start_xserver (manager);
+ policy = meta_get_x11_display_policy ();
+
+ if (policy == META_DISPLAY_POLICY_MANDATORY)
+ {
+ return meta_xwayland_start_xserver (manager);
+ }
+ else if (policy == META_DISPLAY_POLICY_ON_DEMAND)
+ {
+ g_unix_fd_add (manager->abstract_fd, G_IO_IN,
+ xdisplay_connection_activity_cb, manager);
+ return TRUE;
+ }
+
+ return FALSE;
}
static void
@@ -710,13 +798,7 @@ meta_xwayland_shutdown (MetaXWaylandManager *manager)
{
char path[256];
- g_signal_handlers_disconnect_by_func (meta_get_display (),
- window_created_cb,
- manager);
-
g_cancellable_cancel (manager->xserver_died_cancellable);
- g_clear_object (&manager->proc);
- g_clear_object (&manager->xserver_died_cancellable);
snprintf (path, sizeof path, "/tmp/.X11-unix/X%d", manager->display_index);
unlink (path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]