diff --git a/src/core/meta-context-private.h b/src/core/meta-context-private.h index 3046476f9..254403aee 100644 --- a/src/core/meta-context-private.h +++ b/src/core/meta-context-private.h @@ -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); }; diff --git a/src/core/meta-context.c b/src/core/meta-context.c index 33cc87531..4bd7b7847 100644 --- a/src/core/meta-context.c +++ b/src/core/meta-context.c @@ -24,6 +24,7 @@ #include +#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", diff --git a/src/meta/meta-context.h b/src/meta/meta-context.h index feda6ec90..ffaf8e718 100644 --- a/src/meta/meta-context.h +++ b/src/meta/meta-context.h @@ -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 */ diff --git a/src/tests/meta-context-test.c b/src/tests/meta-context-test.c index 01376b61e..2a25bdb44 100644 --- a/src/tests/meta-context-test.c +++ b/src/tests/meta-context-test.c @@ -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; }