From 42855b69e7b37e229e6a8a6c4fb129c94141e899 Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Wed, 17 Mar 2021 15:44:45 +0100 Subject: [PATCH] xwayland: Mark our X11 connection terminatable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The connection to the Xserver for the X11 window manager part of mutter even on Wayland may prevent the Xserver from shutting down. Currently, what mutter does is to check the X11 clients still connected to Xwayland using the XRes extension, with a list of X11 clients that can be safely ignored (typically the GNOME XSettings daemon, the IBus daemon, pulseaudio and even mutter window manager itself). When there is just those known clients remaining, mutter would kill Xwayland automatically. But that's racy, because between the time mutter checks with Xwayland the remaining clients and the time it actually kills the process, a new X11 client might have come along and won't be able to connect to Xwayland that mutter is just about to kill. Because of that, the feature “autoclose-xwayland” is marked as an experimental feature in mutter and not enabled by default. Thankfully, the Xserver has all it takes to manage that already, and is even capable of terminating itself once all X11 clients are gone (the -terminate option on the command line). With XFixes version 6, the X11 clients can declare themselves "terminatable", so that the Xserver could simply ignore those X11 clients when checking the remaining clients and terminate itself automatically. Use that mechanism to declare mutter's own connection to the Xserver as "terminatable" when Xwayland is started on demand so that it won't hold Xwayland alive for the sole purpose of mutter itself. Part-of: --- config.h.meson | 3 +++ meson.build | 13 ++++++++++++- src/wayland/meta-xwayland.c | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/config.h.meson b/config.h.meson index b7ca736df..4939d2a73 100644 --- a/config.h.meson +++ b/config.h.meson @@ -91,3 +91,6 @@ /* List of executable names to ignore when terminating Xwayland */ #mesondefine XWAYLAND_IGNORE_EXECUTABLES + +/* Whether the Xwayland -terminate supports a delay */ +#mesondefine HAVE_XWAYLAND_TERMINATE_DELAY diff --git a/meson.build b/meson.build index 4334b8e6a..8f615bd66 100644 --- a/meson.build +++ b/meson.build @@ -28,7 +28,7 @@ json_glib_req = '>= 0.12.0' upower_glib_req = '>= 0.99.0' xcomposite_req = '>= 0.4' xkbcommon_req = '>= 0.4.3' -xfixes_req = '>= 3' +xfixes_req = '>= 6' xi_req = '>= 1.7.4' xrandr_req = '>= 1.5.0' libstartup_notification_req = '>= 0.7' @@ -457,6 +457,7 @@ endif have_xwayland_initfd = false have_xwayland_listenfd = false +have_xwayland_terminate_delay = false if have_wayland xwayland_dep = dependency('xwayland', required: false) @@ -509,6 +510,15 @@ if have_wayland if (have_xwayland_listenfd) cdata.set('HAVE_XWAYLAND_LISTENFD', 1) endif + + # For Xwayland -listenfd usage + if xwayland_dep.found() + have_xwayland_terminate_delay = xwayland_dep.get_pkgconfig_variable('have_terminate_delay') == 'true' + endif + + if (have_xwayland_terminate_delay) + cdata.set('HAVE_XWAYLAND_TERMINATE_DELAY', 1) + endif endif have_xsetioerrorexithandler = false @@ -593,6 +603,7 @@ summary('Profiler', have_profiler, section: 'Options') summary('Xwayland initfd', have_xwayland_initfd, section: 'Options') summary('Xwayland listenfd', have_xwayland_listenfd, section: 'Options') summary('Safe X11 I/O errors', have_xsetioerrorexithandler, section: 'Options') +summary('Xwayland terminate delay', have_xwayland_terminate_delay, section: 'Options') summary('Enabled', have_tests, section: 'Tests') summary('Core tests', have_core_tests, section: 'Tests') diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c index 77fb366ea..5613f386d 100644 --- a/src/wayland/meta-xwayland.c +++ b/src/wayland/meta-xwayland.c @@ -40,6 +40,7 @@ #endif #include #include +#include #include #include @@ -1305,6 +1306,8 @@ meta_xwayland_setup_xdisplay (MetaXWaylandManager *manager, XSetIOErrorExitHandler (xdisplay, x_io_error_exit, manager); #endif + XFixesSetClientDisconnectMode (xdisplay, XFixesClientDisconnectFlagTerminate); + add_local_user_to_xhost (xdisplay); }