context: Add way to set plugin GType instead of name

Will be used by gnome-shell.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1861>
This commit is contained in:
Jonas Ådahl 2021-03-03 13:55:32 +01:00
parent fe0ce2814e
commit d76743736f
2 changed files with 25 additions and 2 deletions

View File

@ -50,6 +50,7 @@ typedef struct _MetaContextPrivate
{ {
char *name; char *name;
char *plugin_name; char *plugin_name;
GType plugin_gtype;
GOptionContext *option_context; GOptionContext *option_context;
@ -71,12 +72,25 @@ meta_context_add_option_entries (MetaContext *context,
translation_domain); translation_domain);
} }
void
meta_context_set_plugin_gtype (MetaContext *context,
GType plugin_gtype)
{
MetaContextPrivate *priv = meta_context_get_instance_private (context);
g_return_if_fail (!priv->plugin_name);
priv->plugin_gtype = plugin_gtype;
}
void void
meta_context_set_plugin_name (MetaContext *context, meta_context_set_plugin_name (MetaContext *context,
const char *plugin_name) const char *plugin_name)
{ {
MetaContextPrivate *priv = meta_context_get_instance_private (context); MetaContextPrivate *priv = meta_context_get_instance_private (context);
g_return_if_fail (priv->plugin_gtype == G_TYPE_NONE);
priv->plugin_name = g_strdup (plugin_name); priv->plugin_name = g_strdup (plugin_name);
} }
@ -216,7 +230,7 @@ meta_context_setup (MetaContext *context,
MetaContextPrivate *priv = meta_context_get_instance_private (context); MetaContextPrivate *priv = meta_context_get_instance_private (context);
MetaCompositorType compositor_type; MetaCompositorType compositor_type;
if (!priv->plugin_name) if (!priv->plugin_name && priv->plugin_gtype == G_TYPE_NONE)
{ {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"No compositor plugin set"); "No compositor plugin set");
@ -233,7 +247,10 @@ meta_context_setup (MetaContext *context,
priv->name, VERSION, priv->name, VERSION,
compositor_type_to_description (compositor_type)); compositor_type_to_description (compositor_type));
if (priv->plugin_name)
meta_plugin_manager_load (priv->plugin_name); meta_plugin_manager_load (priv->plugin_name);
else
meta_plugin_manager_set_plugin_type (priv->plugin_gtype);
init_introspection (context); init_introspection (context);
@ -438,6 +455,8 @@ meta_context_init (MetaContext *context)
g_assert (!_context_temporary); g_assert (!_context_temporary);
_context_temporary = context; _context_temporary = context;
priv->plugin_gtype = G_TYPE_NONE;
if (!setlocale (LC_ALL, "")) if (!setlocale (LC_ALL, ""))
g_warning ("Locale not understood by C library"); g_warning ("Locale not understood by C library");
bindtextdomain (GETTEXT_PACKAGE, MUTTER_LOCALEDIR); bindtextdomain (GETTEXT_PACKAGE, MUTTER_LOCALEDIR);

View File

@ -38,6 +38,10 @@ void meta_context_add_option_entries (MetaContext *context,
const GOptionEntry *entries, const GOptionEntry *entries,
const char *translation_domain); const char *translation_domain);
META_EXPORT
void meta_context_set_plugin_gtype (MetaContext *context,
GType plugin_gtype);
META_EXPORT META_EXPORT
void meta_context_set_plugin_name (MetaContext *context, void meta_context_set_plugin_name (MetaContext *context,
const char *plugin_name); const char *plugin_name);