[mutter] context: Make context owner of MetaDisplay



commit 68b376a94423d687907ca1335a6c1794e0c96a9d
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Wed Mar 3 15:12:19 2021 +0100

    context: Make context owner of MetaDisplay
    
    It may still be closed from elsewhere, e.g. when being replaced, but the
    reference is owned by MetaContext instead of itself.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1861>

 src/core/display-private.h |  2 +-
 src/core/display.c         | 24 +++++++-----------------
 src/core/meta-context.c    | 25 ++++++++++++++++++++-----
 src/meta/meta-context.h    |  4 ++++
 4 files changed, 32 insertions(+), 23 deletions(-)
---
diff --git a/src/core/display-private.h b/src/core/display-private.h
index 220fd4da03..fc18d6861a 100644
--- a/src/core/display-private.h
+++ b/src/core/display-private.h
@@ -256,7 +256,7 @@ struct _MetaDisplayClass
      (time2) != 0)                                                      \
   )
 
-gboolean meta_display_open (GError **error);
+MetaDisplay * meta_display_new (GError **error);
 
 void meta_display_manage_all_xwindows (MetaDisplay *display);
 void meta_display_unmanage_windows   (MetaDisplay *display,
diff --git a/src/core/display.c b/src/core/display.c
index f19e5cb63a..96be2bb007 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -788,18 +788,8 @@ meta_display_shutdown_x11 (MetaDisplay *display)
   g_clear_object (&display->x11_display);
 }
 
-/**
- * meta_display_open:
- *
- * Opens a new display, sets it up, initialises all the X extensions
- * we will need, and adds it to the list of displays.
- *
- * Returns: %TRUE if the display was opened successfully, and %FALSE
- * otherwise-- that is, if the display doesn't exist or it already
- * has a window manager.
- */
-gboolean
-meta_display_open (GError **error)
+MetaDisplay *
+meta_display_new (GError **error)
 {
   MetaDisplay *display;
   int i;
@@ -905,7 +895,7 @@ meta_display_open (GError **error)
       if (!meta_display_init_x11_display (display, error))
         {
           g_object_unref (display);
-          return FALSE;
+          return NULL;
         }
 
       timestamp = display->x11_display->timestamp;
@@ -923,7 +913,7 @@ meta_display_open (GError **error)
   if (!meta_compositor_do_manage (display->compositor, error))
     {
       g_object_unref (display);
-      return FALSE;
+      return NULL;
     }
 
   if (display->x11_display)
@@ -964,7 +954,7 @@ meta_display_open (GError **error)
   /* Done opening new display */
   display->display_opening = FALSE;
 
-  return TRUE;
+  return display;
 }
 
 static gint
@@ -1077,7 +1067,6 @@ meta_display_close (MetaDisplay *display,
                     guint32      timestamp)
 {
   g_assert (display != NULL);
-  g_assert (display == the_display);
 
   if (display->closing != 0)
     {
@@ -1085,6 +1074,8 @@ meta_display_close (MetaDisplay *display,
       return;
     }
 
+  g_assert (display == the_display);
+
   display->closing += 1;
 
   g_signal_emit (display, display_signals[CLOSING], 0);
@@ -1135,7 +1126,6 @@ meta_display_close (MetaDisplay *display,
   g_clear_object (&display->selection);
   g_clear_object (&display->pad_action_mapper);
 
-  g_object_unref (display);
   the_display = NULL;
 }
 
diff --git a/src/core/meta-context.c b/src/core/meta-context.c
index 787d25d8ec..35bb042be9 100644
--- a/src/core/meta-context.c
+++ b/src/core/meta-context.c
@@ -55,6 +55,7 @@ typedef struct _MetaContextPrivate
   GOptionContext *option_context;
 
   MetaBackend *backend;
+  MetaDisplay *display;
 
   GMainLoop *main_loop;
   GError *termination_error;
@@ -127,6 +128,20 @@ meta_context_get_backend (MetaContext *context)
   return priv->backend;
 }
 
+/**
+ * meta_context_get_display:
+ * @context: The #MetaContext
+ *
+ * Returns: (transfer none): the #MetaDisplay
+ */
+MetaDisplay *
+meta_context_get_display (MetaContext *context)
+{
+  MetaContextPrivate *priv = meta_context_get_instance_private (context);
+
+  return priv->display;
+}
+
 MetaCompositorType
 meta_context_get_compositor_type (MetaContext *context)
 {
@@ -306,7 +321,8 @@ meta_context_start (MetaContext  *context,
     meta_backend_init_wayland (meta_get_backend ());
 #endif
 
-  if (!meta_display_open (error))
+  priv->display = meta_display_new (error);
+  if (!priv->display)
     return FALSE;
 
   priv->main_loop = g_main_loop_new (NULL, FALSE);
@@ -404,7 +420,6 @@ meta_context_finalize (GObject *object)
 {
   MetaContext *context = META_CONTEXT (object);
   MetaContextPrivate *priv = meta_context_get_instance_private (context);
-  MetaDisplay *display;
 #ifdef HAVE_WAYLAND
   MetaWaylandCompositor *compositor;
   MetaCompositorType compositor_type;
@@ -419,9 +434,9 @@ meta_context_finalize (GObject *object)
     meta_wayland_compositor_prepare_shutdown (compositor);
 #endif
 
-  display = meta_get_display ();
-  if (display)
-    meta_display_close (display, META_CURRENT_TIME);
+  if (priv->display)
+    meta_display_close (priv->display, META_CURRENT_TIME);
+  g_clear_object (&priv->display);
 
 #ifdef HAVE_WAYLAND
   compositor_type = meta_context_get_compositor_type (context);
diff --git a/src/meta/meta-context.h b/src/meta/meta-context.h
index aa1437efe3..30ebe82bf7 100644
--- a/src/meta/meta-context.h
+++ b/src/meta/meta-context.h
@@ -25,6 +25,7 @@
 
 #include "meta/common.h"
 #include "meta/meta-enums.h"
+#include "meta/types.h"
 
 #define META_TYPE_CONTEXT (meta_context_get_type ())
 META_EXPORT
@@ -84,4 +85,7 @@ MetaCompositorType meta_context_get_compositor_type (MetaContext *context);
 META_EXPORT
 MetaBackend * meta_context_get_backend (MetaContext *context);
 
+META_EXPORT
+MetaDisplay * meta_context_get_display (MetaContext *context);
+
 #endif /* META_CONTEXT_H */


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