1
0
Fork 0

restart: Make API that needs context take a context

This allows avoiding looking up old singletons.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2446>
This commit is contained in:
Jonas Ådahl 2022-05-30 23:06:00 +02:00 committed by Marge Bot
parent 81860229ba
commit f772b4cde6
3 changed files with 23 additions and 13 deletions

View file

@ -1003,7 +1003,7 @@ meta_compositor_real_after_paint (MetaCompositor *compositor,
a wayland compositor but in that case we shouldn't get here
since we don't enable robustness in that case. */
g_assert (!meta_is_wayland_compositor ());
meta_restart (NULL);
meta_restart (NULL, meta_display_get_context (priv->display));
break;
}

View file

@ -56,11 +56,11 @@ meta_set_is_restart (gboolean whether)
}
static void
restart_check_ready (void)
restart_check_ready (MetaContext *context)
{
if (restart_helper_started && restart_message_shown)
{
MetaDisplay *display = meta_get_display ();
MetaDisplay *display = meta_context_get_display (context);
if (!meta_display_request_restart (display))
meta_display_show_restart_message (display, NULL);
@ -72,6 +72,7 @@ restart_helper_read_line_callback (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
MetaContext *context = user_data;
GError *error = NULL;
gsize length;
char *line = g_data_input_stream_read_line_finish_utf8 (G_DATA_INPUT_STREAM (source_object),
@ -89,14 +90,16 @@ restart_helper_read_line_callback (GObject *source_object,
g_object_unref (source_object);
restart_helper_started = TRUE;
restart_check_ready ();
restart_check_ready (context);
}
static gboolean
restart_message_painted (gpointer data)
restart_message_painted (gpointer user_data)
{
MetaContext *context = user_data;
restart_message_shown = TRUE;
restart_check_ready ();
restart_check_ready (context);
return FALSE;
}
@ -113,6 +116,7 @@ child_setup (gpointer user_data)
/**
* meta_restart:
* @message: (allow-none): message to display to the user, or %NULL
* @context: a #MetaContext
*
* Starts the process of restarting the compositor. Note that Mutter's
* involvement here is to make the restart visually smooth for the
@ -123,9 +127,10 @@ child_setup (gpointer user_data)
* reexec the compositor.
*/
void
meta_restart (const char *message)
meta_restart (const char *message,
MetaContext *context)
{
MetaDisplay *display = meta_get_display();
MetaDisplay *display;
GInputStream *unix_stream;
GDataInputStream *data_stream;
GError *error = NULL;
@ -135,19 +140,23 @@ meta_restart (const char *message)
MUTTER_LIBEXECDIR "/mutter-restart-helper", NULL
};
g_return_if_fail (META_IS_CONTEXT (context));
display = meta_context_get_display (context);
if (message && meta_display_show_restart_message (display, message))
{
/* Wait until the stage was painted */
clutter_threads_add_repaint_func_full (CLUTTER_REPAINT_FLAGS_POST_PAINT,
restart_message_painted,
NULL, NULL);
context, NULL);
}
else
{
/* Can't show the message, show the message as soon as the
* restart helper starts
*/
restart_message_painted (NULL);
restart_message_painted (context);
}
/* We also need to wait for the restart helper to get its
@ -174,7 +183,7 @@ meta_restart (const char *message)
g_data_input_stream_read_line_async (data_stream, G_PRIORITY_DEFAULT,
NULL, restart_helper_read_line_callback,
NULL);
context);
return;
@ -184,7 +193,7 @@ meta_restart (const char *message)
* will be destroyed and recreated, but otherwise it will work fine.
*/
restart_helper_started = TRUE;
restart_check_ready ();
restart_check_ready (context);
return;
}

View file

@ -27,7 +27,8 @@
#include <meta/common.h>
META_EXPORT
void meta_restart (const char *message);
void meta_restart (const char *message,
MetaContext *context);
META_EXPORT
gboolean meta_is_restart (void);