context: Add setup phase

During this phase, the backend is created and configured. Currently only
configured, but will gain more logic that currently main.c does with
various helpers.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1861>
This commit is contained in:
Jonas Ådahl 2021-03-02 11:41:34 +01:00
parent df8074c636
commit 75f9085ab9
4 changed files with 64 additions and 0 deletions

View File

@ -36,6 +36,9 @@ struct _MetaContextClass
MetaCompositorType (* get_compositor_type) (MetaContext *context);
gboolean (* setup) (MetaContext *context,
GError **error);
MetaBackend * (* create_backend) (MetaContext *context,
GError **error);
};

View File

@ -24,6 +24,7 @@
#include <locale.h>
#include "backends/meta-backend-private.h"
#include "core/util-private.h"
enum
@ -75,6 +76,41 @@ meta_context_configure (MetaContext *context,
return TRUE;
}
static const char *
compositor_type_to_description (MetaCompositorType compositor_type)
{
switch (compositor_type)
{
case META_COMPOSITOR_TYPE_WAYLAND:
return "Wayland display server";
case META_COMPOSITOR_TYPE_X11:
return "X11 window and compositing manager";
}
g_assert_not_reached ();
}
static gboolean
meta_context_real_setup (MetaContext *context,
GError **error)
{
return !!META_CONTEXT_GET_CLASS (context)->create_backend (context, error);
}
gboolean
meta_context_setup (MetaContext *context,
GError **error)
{
MetaContextPrivate *priv = meta_context_get_instance_private (context);
MetaCompositorType compositor_type;
compositor_type = meta_context_get_compositor_type (context);
g_message ("Running %s (using mutter %s) as a %s",
priv->name, VERSION,
compositor_type_to_description (compositor_type));
return META_CONTEXT_GET_CLASS (context)->setup (context, error);
}
static void
meta_context_get_property (GObject *object,
guint prop_id,
@ -120,6 +156,13 @@ meta_context_finalize (GObject *object)
{
MetaContext *context = META_CONTEXT (object);
MetaContextPrivate *priv = meta_context_get_instance_private (context);
MetaBackend *backend;
backend = meta_get_backend ();
if (backend)
meta_backend_prepare_shutdown (backend);
meta_release_backend ();
g_clear_pointer (&priv->name, g_free);
@ -135,6 +178,8 @@ meta_context_class_init (MetaContextClass *klass)
object_class->set_property = meta_context_set_property;
object_class->finalize = meta_context_finalize;
klass->setup = meta_context_real_setup;
obj_props[PROP_NAME] =
g_param_spec_string ("name",
"name",

View File

@ -35,4 +35,8 @@ gboolean meta_context_configure (MetaContext *context,
char ***argv,
GError **error);
META_EXPORT
gboolean meta_context_setup (MetaContext *context,
GError **error);
#endif /* META_CONTEXT_H */

View File

@ -66,6 +66,17 @@ meta_context_test_get_compositor_type (MetaContext *context)
return META_COMPOSITOR_TYPE_WAYLAND;
}
static gboolean
meta_context_test_setup (MetaContext *context,
GError **error)
{
if (!META_CONTEXT_CLASS (meta_context_test_parent_class)->setup (context,
error))
return FALSE;
return TRUE;
}
static MetaBackend *
create_nested_backend (MetaContext *context,
GError **error)
@ -126,6 +137,7 @@ meta_context_test_class_init (MetaContextTestClass *klass)
context_class->configure = meta_context_test_configure;
context_class->get_compositor_type = meta_context_test_get_compositor_type;
context_class->setup = meta_context_test_setup;
context_class->create_backend = meta_context_test_create_backend;
}