[mutter] wayland: Make MetaWaylandOutput a GObject



commit dc99af40f384a204c40cba96683fdb2c7df82b07
Author: Jonas Ådahl <jadahl gmail com>
Date:   Fri Apr 17 17:17:46 2015 +0800

    wayland: Make MetaWaylandOutput a GObject
    
    This way we can later add signals to it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=744453

 src/wayland/meta-wayland-outputs.c |   63 ++++++++++++++++++++++++++---------
 src/wayland/meta-wayland-outputs.h |   23 ++++++++++++-
 2 files changed, 68 insertions(+), 18 deletions(-)
---
diff --git a/src/wayland/meta-wayland-outputs.c b/src/wayland/meta-wayland-outputs.c
index 0c349ef..6c59303 100644
--- a/src/wayland/meta-wayland-outputs.c
+++ b/src/wayland/meta-wayland-outputs.c
@@ -31,6 +31,8 @@
 
 #include <string.h>
 
+G_DEFINE_TYPE (MetaWaylandOutput, meta_wayland_output, G_TYPE_OBJECT)
+
 static void
 output_resource_destroy (struct wl_resource *res)
 {
@@ -99,16 +101,8 @@ static void
 wayland_output_destroy_notify (gpointer data)
 {
   MetaWaylandOutput *wayland_output = data;
-  GList *resources;
-
-  /* Make sure the destructors don't mess with the list */
-  resources = wayland_output->resources;
-  wayland_output->resources = NULL;
 
-  wl_global_destroy (wayland_output->global);
-  g_list_free (resources);
-
-  g_slice_free (MetaWaylandOutput, wayland_output);
+  g_object_unref (wayland_output);
 }
 
 static inline enum wl_output_transform
@@ -165,6 +159,20 @@ wayland_output_update_for_output (MetaWaylandOutput *wayland_output,
   wayland_output->transform = wl_transform;
 }
 
+static MetaWaylandOutput *
+meta_wayland_output_new (MetaWaylandCompositor *compositor)
+{
+  MetaWaylandOutput *wayland_output;
+
+  wayland_output = g_object_new (META_TYPE_WAYLAND_OUTPUT, NULL);
+  wayland_output->global = wl_global_create (compositor->wayland_display,
+                                             &wl_output_interface,
+                                             META_WL_OUTPUT_VERSION,
+                                             wayland_output, bind_output);
+
+  return wayland_output;
+}
+
 static GHashTable *
 meta_wayland_compositor_update_outputs (MetaWaylandCompositor *compositor,
                                         MetaMonitorManager    *monitors)
@@ -191,13 +199,7 @@ meta_wayland_compositor_update_outputs (MetaWaylandCompositor *compositor,
           g_hash_table_steal (compositor->outputs, GSIZE_TO_POINTER (info->winsys_id));
         }
       else
-        {
-          wayland_output = g_slice_new0 (MetaWaylandOutput);
-          wayland_output->global = wl_global_create (compositor->wayland_display,
-                                                     &wl_output_interface,
-                                                    META_WL_OUTPUT_VERSION,
-                                                     wayland_output, bind_output);
-        }
+        wayland_output = meta_wayland_output_new (compositor);
 
       wayland_output_update_for_output (wayland_output, info);
       g_hash_table_insert (new_table, GSIZE_TO_POINTER (info->winsys_id), wayland_output);
@@ -214,6 +216,35 @@ on_monitors_changed (MetaMonitorManager    *monitors,
   compositor->outputs = meta_wayland_compositor_update_outputs (compositor, monitors);
 }
 
+static void
+meta_wayland_output_init (MetaWaylandOutput *wayland_output)
+{
+}
+
+static void
+meta_wayland_output_finalize (GObject *object)
+{
+  MetaWaylandOutput *wayland_output = META_WAYLAND_OUTPUT (object);
+  GList *resources;
+
+  /* Make sure the destructors don't mess with the list */
+  resources = wayland_output->resources;
+  wayland_output->resources = NULL;
+
+  wl_global_destroy (wayland_output->global);
+  g_list_free (resources);
+
+  G_OBJECT_CLASS (meta_wayland_output_parent_class)->finalize (object);
+}
+
+static void
+meta_wayland_output_class_init (MetaWaylandOutputClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = meta_wayland_output_finalize;
+}
+
 void
 meta_wayland_outputs_init (MetaWaylandCompositor *compositor)
 {
diff --git a/src/wayland/meta-wayland-outputs.h b/src/wayland/meta-wayland-outputs.h
index 8a6db27..94a739d 100644
--- a/src/wayland/meta-wayland-outputs.h
+++ b/src/wayland/meta-wayland-outputs.h
@@ -28,15 +28,34 @@
 #include "backends/meta-monitor-manager-private.h"
 #include "meta-wayland-private.h"
 
-typedef struct
+#define META_TYPE_WAYLAND_OUTPUT            (meta_wayland_output_get_type ())
+#define META_WAYLAND_OUTPUT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_WAYLAND_OUTPUT, 
MetaWaylandOutput))
+#define META_WAYLAND_OUTPUT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  META_TYPE_WAYLAND_OUTPUT, 
MetaWaylandOutputClass))
+#define META_IS_WAYLAND_OUTPUT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_WAYLAND_OUTPUT))
+#define META_IS_WAYLAND_OUTPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  META_TYPE_WAYLAND_OUTPUT))
+#define META_WAYLAND_OUTPUT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  META_TYPE_WAYLAND_OUTPUT, 
MetaWaylandOutputClass))
+
+typedef struct _MetaWaylandOutput       MetaWaylandOutput;
+typedef struct _MetaWaylandOutputClass  MetaWaylandOutputClass;
+
+struct _MetaWaylandOutput
 {
+  GObject                   parent;
+
   MetaMonitorInfo          *monitor_info;
   struct wl_global         *global;
   int                       x, y;
   enum wl_output_transform  transform;
 
   GList                    *resources;
-} MetaWaylandOutput;
+};
+
+struct _MetaWaylandOutputClass
+{
+  GObjectClass parent_class;
+};
+
+GType meta_wayland_output_get_type (void) G_GNUC_CONST;
 
 void meta_wayland_outputs_init (MetaWaylandCompositor *compositor);
 


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