Add way to pass construct time options to plugin

This is needed to allow tests to manipulate the behavior of the test
shell plugin during startup. Since the plugin is created and started
when the MetaDisplay is created, it needs to be handled via MetaContext,
by setting the options after creating the context, but before starting.

For simplicity reasons, make the options an opaque GVariant, passed via
a an `"options"` property when the plugin object is created, if the
passed options is non-NULL. Only passing the options when non-NULL
allows for backward compatibility.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4152>
This commit is contained in:
Jonas Ådahl 2024-11-29 12:42:11 +01:00 committed by Marge Bot
parent 03c36f94bb
commit a23d08c754
8 changed files with 40 additions and 6 deletions

View File

@ -91,6 +91,7 @@ void meta_compositor_grab_end (MetaCompositor *compositor);
void meta_compositor_destroy (MetaCompositor *compositor);
gboolean meta_compositor_manage (MetaCompositor *compositor,
GVariant *plugin_options,
GError **error);
void meta_compositor_unmanage (MetaCompositor *compositor);

View File

@ -319,6 +319,7 @@ meta_compositor_create_view (MetaCompositor *compositor,
gboolean
meta_compositor_manage (MetaCompositor *compositor,
GVariant *plugin_options,
GError **error)
{
MetaCompositorPrivate *priv =
@ -346,7 +347,7 @@ meta_compositor_manage (MetaCompositor *compositor,
if (!META_COMPOSITOR_GET_CLASS (compositor)->manage (compositor, error))
return FALSE;
priv->plugin_mgr = meta_plugin_manager_new (compositor);
priv->plugin_mgr = meta_plugin_manager_new (compositor, plugin_options);
meta_plugin_manager_start (priv->plugin_mgr);
return TRUE;

View File

@ -113,7 +113,8 @@ on_prepare_shutdown (MetaContext *context,
}
MetaPluginManager *
meta_plugin_manager_new (MetaCompositor *compositor)
meta_plugin_manager_new (MetaCompositor *compositor,
GVariant *plugin_options)
{
MetaBackend *backend = meta_compositor_get_backend (compositor);
MetaMonitorManager *monitor_manager =
@ -123,10 +124,21 @@ meta_plugin_manager_new (MetaCompositor *compositor)
MetaDisplay *display;
MetaContext *context;
if (plugin_options)
{
plugin = g_object_new (plugin_type,
"options", plugin_options,
NULL);
}
else
{
plugin = g_object_new (plugin_type, NULL);
}
plugin_mgr = g_new0 (MetaPluginManager, 1);
plugin_mgr->state = PLUGIN_MANAGER_STATE_STARTING;
plugin_mgr->compositor = compositor;
plugin_mgr->plugin = plugin = g_object_new (plugin_type, NULL);
plugin_mgr->plugin = plugin;
_meta_plugin_set_compositor (plugin, compositor);

View File

@ -42,7 +42,8 @@ typedef enum
*/
typedef struct MetaPluginManager MetaPluginManager;
MetaPluginManager * meta_plugin_manager_new (MetaCompositor *compositor);
MetaPluginManager * meta_plugin_manager_new (MetaCompositor *compositor,
GVariant *plugin_options);
void meta_plugin_manager_start (MetaPluginManager *plugin_mgr);

View File

@ -189,6 +189,7 @@ struct _MetaDisplayClass
)
MetaDisplay * meta_display_new (MetaContext *context,
GVariant *plugin_options,
GError **error);
#ifdef HAVE_X11_CLIENT

View File

@ -938,6 +938,7 @@ meta_display_shutdown_x11 (MetaDisplay *display)
MetaDisplay *
meta_display_new (MetaContext *context,
GVariant *plugin_options,
GError **error)
{
MetaBackend *backend = meta_context_get_backend (context);
@ -1063,7 +1064,7 @@ meta_display_new (MetaContext *context,
display->last_focus_time = timestamp;
display->last_user_time = timestamp;
if (!meta_compositor_manage (display->compositor, error))
if (!meta_compositor_manage (display->compositor, plugin_options, error))
{
g_object_unref (display);
return NULL;

View File

@ -91,3 +91,7 @@ void meta_context_set_trace_file (MetaContext *context,
#endif
MetaSessionManager * meta_context_get_session_manager (MetaContext *context);
META_EXPORT_TEST
void meta_context_set_plugin_options (MetaContext *context,
GVariant *plugin_options);

View File

@ -78,6 +78,7 @@ typedef struct _MetaContextPrivate
char *nick;
char *plugin_name;
GType plugin_gtype;
GVariant *plugin_options;
char *gnome_wm_keybindings;
gboolean unsafe_mode;
@ -185,6 +186,15 @@ meta_context_set_plugin_name (MetaContext *context,
priv->plugin_name = g_strdup (plugin_name);
}
void
meta_context_set_plugin_options (MetaContext *context,
GVariant *plugin_options)
{
MetaContextPrivate *priv = meta_context_get_instance_private (context);
priv->plugin_options = g_variant_ref (plugin_options);
}
void
meta_context_set_gnome_wm_keybindings (MetaContext *context,
const char *wm_keybindings)
@ -510,6 +520,7 @@ meta_context_start (MetaContext *context,
GError **error)
{
MetaContextPrivate *priv = meta_context_get_instance_private (context);
g_autoptr (GVariant) plugin_options = NULL;
g_return_val_if_fail (META_IS_CONTEXT (context), FALSE);
@ -523,7 +534,8 @@ meta_context_start (MetaContext *context,
priv->wayland_compositor = meta_wayland_compositor_new (context);
#endif
priv->display = meta_display_new (context, error);
plugin_options = g_steal_pointer (&priv->plugin_options),
priv->display = meta_display_new (context, plugin_options, error);
if (!priv->display)
{
priv->state = META_CONTEXT_STATE_TERMINATED;
@ -882,6 +894,7 @@ meta_context_finalize (GObject *object)
g_clear_pointer (&priv->trace_file, g_free);
#endif
g_clear_pointer (&priv->plugin_options, g_variant_unref);
g_clear_pointer (&priv->gnome_wm_keybindings, g_free);
g_clear_pointer (&priv->plugin_name, g_free);
g_clear_pointer (&priv->name, g_free);