[mutter/wip/nielsdg/meta-plugin-derivable] MetaPlugin: use G_DECLARE_DERIVABLE_TYPE.



commit 8e0d31892a1a1bc1e1809655274273f3548b5b90
Author: Niels De Graef <Niels DeGraef barco com>
Date:   Tue Oct 30 11:19:36 2018 +0100

    MetaPlugin: use G_DECLARE_DERIVABLE_TYPE.
    
    It cuts out some of the GObject boilerplate, and gives us g_autoptr()
    support for free.

 src/compositor/meta-plugin.c | 19 ++++++++-----------
 src/meta/meta-plugin.h       | 20 +++-----------------
 2 files changed, 11 insertions(+), 28 deletions(-)
---
diff --git a/src/compositor/meta-plugin.c b/src/compositor/meta-plugin.c
index c613a5020..42aba237c 100644
--- a/src/compositor/meta-plugin.c
+++ b/src/compositor/meta-plugin.c
@@ -41,16 +41,14 @@
 #include "meta-window-actor-private.h"
 #include "meta-monitor-manager-private.h"
 
-struct _MetaPluginPrivate
+
+typedef struct
 {
   MetaCompositor *compositor;
-};
+} MetaPluginPrivate;
 
 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaPlugin, meta_plugin, G_TYPE_OBJECT);
 
-#define META_PLUGIN_GET_PRIVATE(obj) \
-(G_TYPE_INSTANCE_GET_PRIVATE ((obj), META_TYPE_PLUGIN, MetaPluginPrivate))
-
 static void
 meta_plugin_class_init (MetaPluginClass *klass)
 {
@@ -59,7 +57,6 @@ meta_plugin_class_init (MetaPluginClass *klass)
 static void
 meta_plugin_init (MetaPlugin *self)
 {
-  self->priv = META_PLUGIN_GET_PRIVATE (self);
 }
 
 const MetaPluginInfo *
@@ -88,7 +85,7 @@ _meta_plugin_xevent_filter (MetaPlugin *plugin,
 void
 meta_plugin_switch_workspace_completed (MetaPlugin *plugin)
 {
-  MetaPluginPrivate *priv = META_PLUGIN (plugin)->priv;
+  MetaPluginPrivate *priv = meta_plugin_get_instance_private (plugin);
 
   meta_switch_workspace_completed (priv->compositor);
 }
@@ -162,7 +159,7 @@ meta_plugin_begin_modal (MetaPlugin       *plugin,
                          MetaModalOptions  options,
                          guint32           timestamp)
 {
-  MetaPluginPrivate *priv = META_PLUGIN (plugin)->priv;
+  MetaPluginPrivate *priv = meta_plugin_get_instance_private (plugin);
 
   return meta_begin_modal_for_plugin (priv->compositor, plugin,
                                       options, timestamp);
@@ -183,7 +180,7 @@ void
 meta_plugin_end_modal (MetaPlugin *plugin,
                        guint32     timestamp)
 {
-  MetaPluginPrivate *priv = META_PLUGIN (plugin)->priv;
+  MetaPluginPrivate *priv = meta_plugin_get_instance_private (plugin);
 
   meta_end_modal_for_plugin (priv->compositor, plugin, timestamp);
 }
@@ -199,7 +196,7 @@ meta_plugin_end_modal (MetaPlugin *plugin,
 MetaDisplay *
 meta_plugin_get_display (MetaPlugin *plugin)
 {
-  MetaPluginPrivate *priv = META_PLUGIN (plugin)->priv;
+  MetaPluginPrivate *priv = meta_plugin_get_instance_private (plugin);
 
   return priv->compositor->display;
 }
@@ -207,7 +204,7 @@ meta_plugin_get_display (MetaPlugin *plugin)
 void
 _meta_plugin_set_compositor (MetaPlugin *plugin, MetaCompositor *compositor)
 {
-  MetaPluginPrivate *priv = META_PLUGIN (plugin)->priv;
+  MetaPluginPrivate *priv = meta_plugin_get_instance_private (plugin);
 
   priv->compositor = compositor;
 }
diff --git a/src/meta/meta-plugin.h b/src/meta/meta-plugin.h
index 82382cd1d..a9b32def8 100644
--- a/src/meta/meta-plugin.h
+++ b/src/meta/meta-plugin.h
@@ -33,25 +33,11 @@
 #include <X11/extensions/Xfixes.h>
 #include <gmodule.h>
 
-#define META_TYPE_PLUGIN            (meta_plugin_get_type ())
-#define META_PLUGIN(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_PLUGIN, MetaPlugin))
-#define META_PLUGIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  META_TYPE_PLUGIN, MetaPluginClass))
-#define META_IS_PLUGIN(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), META_TYPE_PLUGIN))
-#define META_IS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  META_TYPE_PLUGIN))
-#define META_PLUGIN_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  META_TYPE_PLUGIN, MetaPluginClass))
-
-typedef struct _MetaPlugin        MetaPlugin;
-typedef struct _MetaPluginClass   MetaPluginClass;
+#define META_TYPE_PLUGIN (meta_plugin_get_type ())
+G_DECLARE_DERIVABLE_TYPE (MetaPlugin, meta_plugin, META, PLUGIN, GObject)
+
 typedef struct _MetaPluginVersion MetaPluginVersion;
 typedef struct _MetaPluginInfo    MetaPluginInfo;
-typedef struct _MetaPluginPrivate MetaPluginPrivate;
-
-struct _MetaPlugin
-{
-  GObject parent;
-
-  MetaPluginPrivate *priv;
-};
 
 /**
  * MetaPluginClass:


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