[mutter] context: Add setup phase



commit 75f9085ab9f1a9c83a384b15fea1df5fd545bccd
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Tue Mar 2 11:41:34 2021 +0100

    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>

 src/core/meta-context-private.h |  3 +++
 src/core/meta-context.c         | 45 +++++++++++++++++++++++++++++++++++++++++
 src/meta/meta-context.h         |  4 ++++
 src/tests/meta-context-test.c   | 12 +++++++++++
 4 files changed, 64 insertions(+)
---
diff --git a/src/core/meta-context-private.h b/src/core/meta-context-private.h
index 3046476f9f..254403aee7 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 33cc875314..4bd7b78471 100644
--- a/src/core/meta-context.c
+++ b/src/core/meta-context.c
@@ -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",
diff --git a/src/meta/meta-context.h b/src/meta/meta-context.h
index feda6ec901..ffaf8e7183 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 01376b61ee..2a25bdb447 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;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]