wayland: Add a prepare-shutdown signal

This allows moving the xwayland shutdown logic to the xwayland
implementation

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2399>
This commit is contained in:
Bilal Elmoussaoui 2022-06-15 13:12:35 +02:00 committed by Marge Bot
parent f7c55d478a
commit 36f30341ac
4 changed files with 85 additions and 65 deletions

View File

@ -62,6 +62,8 @@ struct _MetaXWaylandManager
guint abstract_fd_watch_id;
guint unix_fd_watch_id;
gulong prepare_shutdown_id;
struct wl_display *wayland_display;
struct wl_client *client;
struct wl_resource *xserver_resource;

View File

@ -61,6 +61,15 @@
#include "backends/native/meta-renderer-native.h"
#endif
enum
{
PREPARE_SHUTDOWN,
N_SIGNALS
};
static guint signals[N_SIGNALS];
static char *_display_name_override;
typedef struct _MetaWaylandCompositorPrivate
@ -431,14 +440,7 @@ meta_wayland_log_func (const char *fmt,
void
meta_wayland_compositor_prepare_shutdown (MetaWaylandCompositor *compositor)
{
#ifdef HAVE_XWAYLAND
MetaX11DisplayPolicy x11_display_policy;
x11_display_policy =
meta_context_get_x11_display_policy (compositor->context);
if (x11_display_policy != META_X11_DISPLAY_POLICY_DISABLED)
meta_xwayland_shutdown (&compositor->xwayland_manager);
#endif
g_signal_emit (compositor, signals[PREPARE_SHUTDOWN], 0, NULL);
if (compositor->wayland_display)
wl_display_destroy_clients (compositor->wayland_display);
@ -492,6 +494,14 @@ meta_wayland_compositor_class_init (MetaWaylandCompositorClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = meta_wayland_compositor_finalize;
signals[PREPARE_SHUTDOWN] =
g_signal_new ("prepare-shutdown",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
}
#ifdef HAVE_XWAYLAND

View File

@ -38,9 +38,6 @@ void
meta_xwayland_setup_xdisplay (MetaXWaylandManager *manager,
Display *xdisplay);
void
meta_xwayland_shutdown (MetaXWaylandManager *manager);
gboolean
meta_xwayland_handle_xevent (XEvent *event);

View File

@ -468,6 +468,7 @@ meta_xwayland_terminate (MetaXWaylandManager *manager)
meta_display_shutdown_x11 (display);
meta_xwayland_stop_xserver (manager);
g_clear_signal_handler (&manager->prepare_shutdown_id, manager->compositor);
}
static int
@ -510,11 +511,13 @@ x_io_error_exit (Display *display,
}
}
#ifdef HAVE_XSETIOERROREXITHANDLER
static void
x_io_error_exit_noop (Display *display,
void *data)
{
}
#endif
void
meta_xwayland_override_display_number (int number)
@ -995,6 +998,63 @@ meta_xwayland_stop_xserver (MetaXWaylandManager *manager)
g_clear_object (&manager->proc);
}
static void
meta_xwayland_connection_release (MetaXWaylandConnection *connection)
{
unlink (connection->lock_file);
g_clear_pointer (&connection->lock_file, g_free);
}
static void
meta_xwayland_shutdown (MetaWaylandCompositor *compositor)
{
MetaXWaylandManager *manager = &compositor->xwayland_manager;
#ifdef HAVE_XSETIOERROREXITHANDLER
MetaDisplay *display = meta_get_display ();
MetaX11Display *x11_display;
#endif
char path[256];
g_cancellable_cancel (manager->xserver_died_cancellable);
XSetIOErrorHandler (x_io_error_noop);
#ifdef HAVE_XSETIOERROREXITHANDLER
x11_display = display->x11_display;
if (x11_display)
{
XSetIOErrorExitHandler (meta_x11_display_get_xdisplay (x11_display),
x_io_error_exit_noop, NULL);
}
#endif
meta_xwayland_terminate (manager);
if (manager->public_connection.name)
{
snprintf (path, sizeof path, "%s%d", X11_TMP_UNIX_PATH,
manager->public_connection.display_index);
unlink (path);
g_clear_pointer (&manager->public_connection.name, g_free);
}
if (manager->private_connection.name)
{
snprintf (path, sizeof path, "%s%d", X11_TMP_UNIX_PATH,
manager->private_connection.display_index);
unlink (path);
g_clear_pointer (&manager->private_connection.name, g_free);
}
meta_xwayland_connection_release (&manager->public_connection);
meta_xwayland_connection_release (&manager->private_connection);
if (manager->auth_file)
{
unlink (manager->auth_file);
g_clear_pointer (&manager->auth_file, g_free);
}
}
gboolean
meta_xwayland_init (MetaXWaylandManager *manager,
MetaWaylandCompositor *compositor,
@ -1057,6 +1117,11 @@ meta_xwayland_init (MetaXWaylandManager *manager,
xdisplay_connection_activity_cb, manager);
}
if (policy != META_X11_DISPLAY_POLICY_DISABLED)
manager->prepare_shutdown_id = g_signal_connect (compositor, "prepare-shutdown",
G_CALLBACK (meta_xwayland_shutdown),
NULL);
return TRUE;
}
@ -1145,60 +1210,6 @@ meta_xwayland_setup_xdisplay (MetaXWaylandManager *manager,
XFixesSetClientDisconnectMode (xdisplay, XFixesClientDisconnectFlagTerminate);
}
static void
meta_xwayland_connection_release (MetaXWaylandConnection *connection)
{
unlink (connection->lock_file);
g_clear_pointer (&connection->lock_file, g_free);
}
void
meta_xwayland_shutdown (MetaXWaylandManager *manager)
{
MetaContext *context =
meta_wayland_compositor_get_context (manager->compositor);
MetaDisplay *display = meta_context_get_display (context);
MetaX11Display *x11_display;
char path[256];
g_cancellable_cancel (manager->xserver_died_cancellable);
XSetIOErrorHandler (x_io_error_noop);
x11_display = display->x11_display;
if (x11_display)
{
XSetIOErrorExitHandler (meta_x11_display_get_xdisplay (x11_display),
x_io_error_exit_noop, NULL);
}
meta_xwayland_terminate (manager);
if (manager->public_connection.name)
{
snprintf (path, sizeof path, "%s%d", X11_TMP_UNIX_PATH,
manager->public_connection.display_index);
unlink (path);
g_clear_pointer (&manager->public_connection.name, g_free);
}
if (manager->private_connection.name)
{
snprintf (path, sizeof path, "%s%d", X11_TMP_UNIX_PATH,
manager->private_connection.display_index);
unlink (path);
g_clear_pointer (&manager->private_connection.name, g_free);
}
meta_xwayland_connection_release (&manager->public_connection);
meta_xwayland_connection_release (&manager->private_connection);
if (manager->auth_file)
{
unlink (manager->auth_file);
g_clear_pointer (&manager->auth_file, g_free);
}
}
static void
meta_xwayland_set_primary_output (MetaX11Display *x11_display)
{