[mutter] Make MetaRectangle a boxed type



commit 11a8ab47fa83b6c8845e9a8241c2f1017d05bef8
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Thu Jul 1 20:22:58 2010 -0400

    Make MetaRectangle a boxed type
    
    Export a boxed type for MetaRectangle; this is mostly of interest
    because GdkRectangle has been turned into a typedef for
    cairo_rectangle_int_t which causes massive problems for using it from
    gobject-introspection based language bindings.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=623335

 src/core/boxes.c    |   29 +++++++++++++++++++++++++++++
 src/include/boxes.h |    9 ++++++++-
 2 files changed, 37 insertions(+), 1 deletions(-)
---
diff --git a/src/core/boxes.c b/src/core/boxes.c
index bc596bd..700ff85 100644
--- a/src/core/boxes.c
+++ b/src/core/boxes.c
@@ -30,6 +30,35 @@
 #include "util.h"
 #include <X11/Xutil.h>  /* Just for the definition of the various gravities */
 
+/* It would make sense to use GSlice here, but until we clean up the
+ * rest of this file and the internal API to use these functions, we
+ * leave it using g_malloc()/g_free() for consistency.
+ */
+
+MetaRectangle *
+meta_rectangle_copy (const MetaRectangle *rect)
+{
+  return g_memdup (rect, sizeof (MetaRectangle));
+}
+
+void
+meta_rectangle_free (MetaRectangle *rect)
+{
+  g_free (rect);
+}
+
+GType
+meta_rectangle_get_type (void)
+{
+  static GType type_id = 0;
+
+  if (!type_id)
+    type_id = g_boxed_type_register_static (g_intern_static_string ("MetaRectangle"),
+					    (GBoxedCopyFunc) meta_rectangle_copy,
+					    (GBoxedFreeFunc) meta_rectangle_free);
+  return type_id;
+}
+
 char*
 meta_rectangle_to_string (const MetaRectangle *rect,
                           char                *output)
diff --git a/src/include/boxes.h b/src/include/boxes.h
index 11fd8bd..e38b546 100644
--- a/src/include/boxes.h
+++ b/src/include/boxes.h
@@ -24,9 +24,11 @@
 #ifndef META_BOXES_H
 #define META_BOXES_H
 
-#include <glib.h>
+#include <glib-object.h>
 #include "common.h"
 
+#define META_TYPE_RECTANGLE            (meta_rectangle_get_type ())
+
 typedef struct _MetaRectangle MetaRectangle;
 struct _MetaRectangle
 {
@@ -70,6 +72,11 @@ struct _MetaEdge
   MetaEdgeType  edge_type;
 };
 
+GType meta_rectangle_get_type (void);
+
+MetaRectangle *meta_rectangle_copy (const MetaRectangle *rect);
+void           meta_rectangle_free (MetaRectangle       *rect);
+
 /* Output functions -- note that the output buffer had better be big enough:
  *   rect_to_string:   RECT_LENGTH
  *   region_to_string: (RECT_LENGTH+strlen(separator_string)) *



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