[gnome-panel] libgnome-panel: redo gp_applet_get_size_hints



commit 3b548d825dc499586e3f5f08e29c0e59db14153c
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Tue Nov 1 18:42:08 2016 +0200

    libgnome-panel: redo gp_applet_get_size_hints

 .../libpanel-applet-private/gp-applet-frame.c      |   20 ++-----------
 libgnome-panel/gp-applet-private.h                 |    3 +-
 libgnome-panel/gp-applet.c                         |   29 ++++++++++++++++---
 3 files changed, 29 insertions(+), 23 deletions(-)
---
diff --git a/gnome-panel/libpanel-applet-private/gp-applet-frame.c 
b/gnome-panel/libpanel-applet-private/gp-applet-frame.c
index ab0712e..01db82f 100644
--- a/gnome-panel/libpanel-applet-private/gp-applet-frame.c
+++ b/gnome-panel/libpanel-applet-private/gp-applet-frame.c
@@ -119,27 +119,13 @@ static void
 update_size_hints (PanelAppletFrame *applet_frame)
 {
   GpAppletFrame *frame;
-  GArray *array;
+  guint n_elements;
   gint *size_hints;
-  guint i;
 
   frame = GP_APPLET_FRAME (applet_frame);
-  array = gp_applet_get_size_hints (frame->applet);
 
-  if (!array || array->len == 0)
-    {
-      _panel_applet_frame_update_size_hints (applet_frame, NULL, 0);
-      return;
-    }
-
-  size_hints = g_new (gint, array->len);
-
-  for (i = 0; i < array->len; i++)
-    {
-      size_hints[i] = g_array_index (array, gint, i);
-    }
-
-  _panel_applet_frame_update_size_hints (applet_frame, size_hints, array->len);
+  size_hints = gp_applet_get_size_hints (frame->applet, &n_elements);
+  _panel_applet_frame_update_size_hints (applet_frame, size_hints, n_elements);
 }
 
 static void
diff --git a/libgnome-panel/gp-applet-private.h b/libgnome-panel/gp-applet-private.h
index 6f4f2c8..61a2e5f 100644
--- a/libgnome-panel/gp-applet-private.h
+++ b/libgnome-panel/gp-applet-private.h
@@ -38,7 +38,8 @@ void           gp_applet_set_position    (GpApplet        *applet,
 
 GpAppletFlags  gp_applet_get_flags       (GpApplet        *applet);
 
-GArray        *gp_applet_get_size_hints  (GpApplet        *applet);
+gint          *gp_applet_get_size_hints  (GpApplet        *applet,
+                                          guint           *n_elements);
 
 GtkWidget     *gp_applet_get_menu        (GpApplet        *applet);
 
diff --git a/libgnome-panel/gp-applet.c b/libgnome-panel/gp-applet.c
index a7c929e..799c43d 100644
--- a/libgnome-panel/gp-applet.c
+++ b/libgnome-panel/gp-applet.c
@@ -668,20 +668,39 @@ gp_applet_set_flags (GpApplet      *applet,
 /**
  * gp_applet_get_size_hints:
  * @applet: a #GpApplet
+ * @n_elements: (out): return location for the length of the returned array
  *
- * Retrieves the #GArray with size hints.
+ * Returns array with size hints.
  *
- * Returns: (transfer none): a pointer to a #GArray, or %NULL.
+ * Returns: (transfer full) (array length=n_elements): a newly allocated
+ *     array, or %NULL.
  */
-GArray *
-gp_applet_get_size_hints (GpApplet *applet)
+gint *
+gp_applet_get_size_hints (GpApplet *applet,
+                          guint    *n_elements)
 {
   GpAppletPrivate *priv;
+  gint *size_hints;
+  guint i;
 
   g_return_val_if_fail (GP_IS_APPLET (applet), NULL);
+  g_return_val_if_fail (n_elements != NULL, NULL);
+
   priv = gp_applet_get_instance_private (applet);
 
-  return priv->size_hints;
+  if (!priv->size_hints || priv->size_hints->len == 0)
+    {
+      *n_elements = 0;
+      return NULL;
+    }
+
+  *n_elements = priv->size_hints->len;
+  size_hints = g_new0 (gint, priv->size_hints->len);
+
+  for (i = 0; i < priv->size_hints->len; i++)
+    size_hints[i] = g_array_index (priv->size_hints, gint, i);
+
+  return size_hints;
 }
 
 /**


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