[libhandy/msvc] (wip) src/: Remove g_auto*
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy/msvc] (wip) src/: Remove g_auto*
- Date: Wed, 27 Apr 2022 05:03:33 +0000 (UTC)
commit 76b6017c7e66f14664367b4ce21e14a1f6e58fea
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Tue Apr 26 18:19:32 2022 +0800
(wip) src/: Remove g_auto*
This way, the sources will be buildable on Visual Studio.
src/hdy-avatar.c | 307 +++++++++++++++++++++++--------------
src/hdy-carousel-indicator-dots.c | 35 +++--
src/hdy-carousel-indicator-lines.c | 36 +++--
src/hdy-combo-row.c | 64 +++++---
src/hdy-header-bar.c | 4 +-
5 files changed, 282 insertions(+), 164 deletions(-)
---
diff --git a/src/hdy-avatar.c b/src/hdy-avatar.c
index d4e0d01d..f057e0c0 100644
--- a/src/hdy-avatar.c
+++ b/src/hdy-avatar.c
@@ -115,10 +115,11 @@ static GdkPixbuf *
make_round_image (GdkPixbuf *pixbuf,
gdouble size)
{
- g_autoptr (cairo_surface_t) surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, size, size);
- g_autoptr (cairo_t) cr = cairo_create (surface);
+ cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, size, size);
+ cairo_t *cr = cairo_create (surface);
gint width = gdk_pixbuf_get_width (pixbuf);
gint height = gdk_pixbuf_get_height (pixbuf);
+ GdkPixbuf *result;
/* Clip a circle */
cairo_arc (cr, size / 2.0, size / 2.0, size / 2.0, 0, 2 * G_PI);
@@ -128,35 +129,47 @@ make_round_image (GdkPixbuf *pixbuf,
gdk_cairo_set_source_pixbuf (cr, pixbuf, (size - width) / 2, (size - height) / 2);
cairo_paint (cr);
- return gdk_pixbuf_get_from_surface (surface, 0, 0, size, size);
+ result = gdk_pixbuf_get_from_surface (surface, 0, 0, size, size);
+
+ cairo_destroy (cr);
+ cairo_surface_destroy (surface);
+
+ return result;
}
static gchar *
extract_initials_from_text (const gchar *text)
{
GString *initials;
- g_autofree gchar *p = g_utf8_strup (text, -1);
- g_autofree gchar *normalized = g_utf8_normalize (g_strstrip (p), -1, G_NORMALIZE_DEFAULT_COMPOSE);
+ gchar *p = g_utf8_strup (text, -1);
+ gchar *normalized = g_utf8_normalize (g_strstrip (p), -1, G_NORMALIZE_DEFAULT_COMPOSE);
gunichar unichar;
gchar *q = NULL;
+ gchar *result;
- if (normalized == NULL)
- return NULL;
+ if (normalized != NULL) {
+ initials = g_string_new ("");
- initials = g_string_new ("");
+ unichar = g_utf8_get_char (normalized);
+ g_string_append_unichar (initials, unichar);
- unichar = g_utf8_get_char (normalized);
- g_string_append_unichar (initials, unichar);
+ q = g_utf8_strrchr (normalized, -1, ' ');
+ if (q != NULL) {
+ unichar = g_utf8_get_char (g_utf8_next_char (q));
- q = g_utf8_strrchr (normalized, -1, ' ');
- if (q != NULL) {
- unichar = g_utf8_get_char (g_utf8_next_char (q));
+ if (unichar != 0)
+ g_string_append_unichar (initials, unichar);
+ }
- if (unichar != 0)
- g_string_append_unichar (initials, unichar);
+ result = g_string_free (initials, FALSE);
}
+ else
+ result = NULL;
+
+ g_free (normalized);
+ g_free (p);
- return g_string_free (initials, FALSE);
+ return result;
}
static GdkPixbuf *
@@ -219,49 +232,55 @@ load_from_stream_async_cb (GObject *stream,
GAsyncResult *res,
gpointer data)
{
- g_autoptr (GTask) task = data;
+ GTask *task = data;
GdkPixbufLoader *loader = g_task_get_task_data (task);
- g_autoptr (GBytes) bytes = NULL;
+ GBytes *bytes;
GError *error = NULL;
+ gboolean return_error = FALSE;
+ gboolean is_size_zero = FALSE;
bytes = g_input_stream_read_bytes_finish (G_INPUT_STREAM (stream), res, &error);
- if (bytes == NULL) {
- gdk_pixbuf_loader_close (loader, NULL);
- g_task_return_error (task, error);
- return;
- }
+ if (bytes == NULL)
+ return_error = TRUE;
+ else if (g_bytes_get_size (bytes) == 0) {
+ is_size_zero = TRUE;
- if (g_bytes_get_size (bytes) == 0) {
- if (!gdk_pixbuf_loader_close (loader, &error)) {
- g_task_return_error (task, error);
+ if (!gdk_pixbuf_loader_close (loader, &error))
+ return_error = TRUE;
+ }
- return;
+ if (!return_error && !is_size_zero) {
+ if (gdk_pixbuf_loader_write (loader,
+ g_bytes_get_data (bytes, NULL),
+ g_bytes_get_size (bytes),
+ &error)) {
+ g_input_stream_read_bytes_async (G_INPUT_STREAM (stream),
+ LOAD_BUFFER_SIZE,
+ G_PRIORITY_DEFAULT,
+ g_task_get_cancellable (task),
+ load_from_stream_async_cb,
+ g_object_ref (task));
+ } else {
+ return_error = TRUE;
}
+ }
+ if (!return_error && is_size_zero)
g_task_return_pointer (task,
g_object_ref (gdk_pixbuf_loader_get_pixbuf (loader)),
g_object_unref);
- return;
- }
+ if (return_error) {
+ if (!is_size_zero)
+ gdk_pixbuf_loader_close (loader, NULL);
- if (!gdk_pixbuf_loader_write (loader,
- g_bytes_get_data (bytes, NULL),
- g_bytes_get_size (bytes),
- &error)) {
gdk_pixbuf_loader_close (loader, NULL);
g_task_return_error (task, error);
-
- return;
}
- g_input_stream_read_bytes_async (G_INPUT_STREAM (stream),
- LOAD_BUFFER_SIZE,
- G_PRIORITY_DEFAULT,
- g_task_get_cancellable (task),
- load_from_stream_async_cb,
- g_object_ref (task));
+ g_bytes_unref (bytes);
+ g_object_unref (task);
}
static void
@@ -270,24 +289,26 @@ icon_load_async_cb (GLoadableIcon *icon,
GTask *task)
{
GdkPixbufLoader *loader = g_task_get_task_data (task);
- g_autoptr (GInputStream) stream = NULL;
- g_autoptr (GError) error = NULL;
+ GInputStream *stream;
+ GError *error = NULL;
stream = g_loadable_icon_load_finish (icon, res, NULL, &error);
- if (stream == NULL) {
+
+ if (stream != NULL) {
+ g_input_stream_read_bytes_async (stream,
+ LOAD_BUFFER_SIZE,
+ G_PRIORITY_DEFAULT,
+ g_task_get_cancellable (task),
+ load_from_stream_async_cb,
+ task);
+
+ g_object_unref (stream);
+ } else {
gdk_pixbuf_loader_close (loader, NULL);
g_task_return_error (task, g_steal_pointer (&error));
g_object_unref (task);
-
- return;
+ g_clear_error (&error);
}
-
- g_input_stream_read_bytes_async (stream,
- LOAD_BUFFER_SIZE,
- G_PRIORITY_DEFAULT,
- g_task_get_cancellable (task),
- load_from_stream_async_cb,
- task);
}
static GdkPixbuf *
@@ -304,8 +325,8 @@ load_from_gicon_async_for_display_cb (HdyAvatar *self,
GAsyncResult *res,
gpointer *user_data)
{
- g_autoptr (GError) error = NULL;
- g_autoptr (GdkPixbuf) pixbuf = NULL;
+ GError *error = NULL;
+ GdkPixbuf *pixbuf;
pixbuf = load_from_gicon_async_finish (res, &error);
@@ -316,12 +337,14 @@ load_from_gicon_async_for_display_cb (HdyAvatar *self,
g_warning ("Failed to load icon: %s", error->message);
self->loading_error = TRUE;
}
+
+ g_clear_error (&error);
}
self->currently_loading_size = -1;
if (pixbuf) {
- g_autoptr (GdkPixbuf) custom_image = NULL;
+ GdkPixbuf *custom_image = NULL;
GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (self));
gint width = gtk_widget_get_allocated_width (GTK_WIDGET (self));
gint height = gtk_widget_get_allocated_height (GTK_WIDGET (self));
@@ -339,6 +362,11 @@ load_from_gicon_async_for_display_cb (HdyAvatar *self,
g_set_object (&self->round_image, custom_image);
gtk_widget_queue_draw (GTK_WIDGET (self));
+
+ if (custom_image != NULL)
+ g_object_unref (custom_image);
+
+ g_object_unref (pixbuf);
}
}
@@ -348,8 +376,8 @@ load_from_gicon_async_for_export_cb (HdyAvatar *self,
gpointer *user_data)
{
GTask *task = G_TASK (user_data);
- g_autoptr (GError) error = NULL;
- g_autoptr (GdkPixbuf) pixbuf = NULL;
+ GError *error = NULL;
+ GdkPixbuf *pixbuf;
pixbuf = load_from_gicon_async_finish (res, &error);
@@ -362,6 +390,12 @@ load_from_gicon_async_for_export_cb (HdyAvatar *self,
g_task_return_pointer (task,
g_steal_pointer (&pixbuf),
g_object_unref);
+
+ g_clear_error (&error);
+
+ if (pixbuf != NULL)
+ g_object_unref (pixbuf);
+
g_object_unref (task);
}
@@ -435,16 +469,19 @@ static GdkPixbuf *
load_icon_sync (GLoadableIcon *icon,
gint size)
{
- g_autoptr (GError) error = NULL;
- g_autoptr (GInputStream) stream = g_loadable_icon_load (icon, size, NULL, NULL, &error);
- g_autoptr (GdkPixbufLoader) loader = gdk_pixbuf_loader_new ();
- g_autoptr (GdkPixbuf) pixbuf = NULL;
+ GError *error = NULL;
+ GInputStream *stream = g_loadable_icon_load (icon, size, NULL, NULL, &error);
+ GdkPixbufLoader *loader;
+ GdkPixbuf *pixbuf = NULL;
if (error) {
g_warning ("Failed to load icon: %s", error->message);
+
+ g_clear_error (&error);
return NULL;
}
+ loader = gdk_pixbuf_loader_new ();
g_signal_connect (loader, "size-prepared",
G_CALLBACK (size_prepared_cb),
GINT_TO_POINTER (size));
@@ -453,19 +490,23 @@ load_icon_sync (GLoadableIcon *icon,
if (error) {
g_warning ("Failed to load pixbuf from GLoadableIcon: %s", error->message);
- return NULL;
+
+ g_clear_error (&error);
}
- return g_steal_pointer (&pixbuf);
+ g_object_unref (stream);
+ g_object_unref (loader);
+
+ return pixbuf;
}
static void
set_class_color (HdyAvatar *self)
{
GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (self));
- g_autofree GRand *rand = NULL;
- g_autofree gchar *new_class = NULL;
- g_autofree gchar *old_class = g_strdup_printf ("color%d", self->color_class);
+ GRand *rand = NULL;
+ gchar *new_class;
+ gchar *old_class = g_strdup_printf ("color%d", self->color_class);
gtk_style_context_remove_class (context, old_class);
@@ -479,6 +520,12 @@ set_class_color (HdyAvatar *self)
new_class = g_strdup_printf ("color%d", self->color_class);
gtk_style_context_add_class (context, new_class);
+
+ if (rand != NULL)
+ g_rand_free (rand);
+
+ g_free (new_class);
+ g_free (old_class);
}
static void
@@ -502,13 +549,15 @@ clear_pango_layout (HdyAvatar *self)
static void
ensure_pango_layout (HdyAvatar *self)
{
- g_autofree gchar *initials = NULL;
+ gchar *initials;
if (self->layout != NULL || self->text == NULL || strlen (self->text) == 0)
return;
initials = extract_initials_from_text (self->text);
self->layout = gtk_widget_create_pango_layout (GTK_WIDGET (self), initials);
+
+ g_free (initials);
}
static void
@@ -660,10 +709,10 @@ draw_for_size (HdyAvatar *self,
gdouble y = (gdouble)(height - size) / 2.0;
const gchar *icon_name;
GdkRGBA color;
- g_autoptr (GtkIconInfo) icon = NULL;
- g_autoptr (GdkPixbuf) pixbuf = NULL;
- g_autoptr (GError) error = NULL;
- g_autoptr (cairo_surface_t) surface = NULL;
+ GtkIconInfo *icon;
+ GdkPixbuf *pixbuf;
+ GError *error = NULL;
+ cairo_surface_t *surface;
set_class_contrasted (self, size);
@@ -673,6 +722,9 @@ draw_for_size (HdyAvatar *self,
gtk_render_icon_surface (context, cr, surface, x, y);
gtk_render_background (context, cr, x, y, size, size);
gtk_render_frame (context, cr, x, y, size, size);
+
+ cairo_surface_destroy (surface);
+
return;
}
@@ -705,19 +757,25 @@ draw_for_size (HdyAvatar *self,
gtk_style_context_get_color (context, gtk_style_context_get_state (context), &color);
pixbuf = gtk_icon_info_load_symbolic (icon, &color, NULL, NULL, NULL, NULL, &error);
- if (error != NULL) {
+ if (error == NULL) {
+ surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor,
+ gtk_widget_get_window (GTK_WIDGET (self)));
+
+ width = cairo_image_surface_get_width (surface);
+ height = cairo_image_surface_get_height (surface);
+ gtk_render_icon_surface (context, cr, surface,
+ (((gdouble) size - ((gdouble) width / (gdouble) scale_factor)) / 2.0) + x,
+ (((gdouble) size - ((gdouble) height / (gdouble) scale_factor)) / 2.0) + y);
+
+ cairo_surface_destroy (surface);
+ g_object_unref (pixbuf);
+ } else {
g_critical ("Failed to load icon `%s': %s", icon_name, error->message);
- return;
- }
- surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor,
- gtk_widget_get_window (GTK_WIDGET (self)));
+ g_clear_error (&error);
+ }
- width = cairo_image_surface_get_width (surface);
- height = cairo_image_surface_get_height (surface);
- gtk_render_icon_surface (context, cr, surface,
- (((gdouble) size - ((gdouble) width / (gdouble) scale_factor)) / 2.0) + x,
- (((gdouble) size - ((gdouble) height / (gdouble) scale_factor)) / 2.0) + y);
+ g_object_unref (icon);
}
static gboolean
@@ -1138,7 +1196,7 @@ hdy_avatar_set_image_load_func (HdyAvatar *self,
gpointer user_data,
GDestroyNotify destroy)
{
- g_autoptr (HdyAvatarIcon) icon = NULL;
+ HdyAvatarIcon *icon = NULL;
g_return_if_fail (HDY_IS_AVATAR (self));
g_return_if_fail (user_data != NULL || (user_data == NULL && destroy == NULL));
@@ -1156,22 +1214,24 @@ hdy_avatar_set_image_load_func (HdyAvatar *self,
g_set_object (&self->load_func_icon, icon);
/* Don't update the custom avatar when we have a user set GLoadableIcon */
- if (self->icon)
- return;
-
- if (self->load_func_icon) {
- gint scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (self));
+ if (!self->icon) {
+ if (self->load_func_icon) {
+ gint scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (self));
- self->cancellable = g_cancellable_new ();
- self->currently_loading_size = self->size * scale_factor;
- load_icon_async (self,
- self->currently_loading_size,
- self->cancellable,
- (GAsyncReadyCallback) load_from_gicon_async_for_display_cb,
- NULL);
- } else {
- gtk_widget_queue_draw (GTK_WIDGET (self));
+ self->cancellable = g_cancellable_new ();
+ self->currently_loading_size = self->size * scale_factor;
+ load_icon_async (self,
+ self->currently_loading_size,
+ self->cancellable,
+ (GAsyncReadyCallback) load_from_gicon_async_for_display_cb,
+ NULL);
+ } else {
+ gtk_widget_queue_draw (GTK_WIDGET (self));
+ }
}
+
+ if (icon != NULL)
+ g_object_unref (icon);
}
/**
@@ -1236,13 +1296,14 @@ hdy_avatar_draw_to_pixbuf (HdyAvatar *self,
gint size,
gint scale_factor)
{
- g_autoptr (cairo_surface_t) surface = NULL;
- g_autoptr (cairo_t) cr = NULL;
- g_autoptr (GdkPixbuf) custom_image = NULL;
- g_autoptr (GdkPixbuf) pixbuf_from_icon = NULL;
+ cairo_surface_t *surface;
+ cairo_t *cr;
+ GdkPixbuf *custom_image = NULL;
+ GdkPixbuf *pixbuf_from_icon = NULL;
gint scaled_size = size * scale_factor;
GtkStyleContext *context;
GtkAllocation bounds;
+ GdkPixbuf *result;
g_return_val_if_fail (HDY_IS_AVATAR (self), NULL);
g_return_val_if_fail (size > 0, NULL);
@@ -1274,9 +1335,19 @@ hdy_avatar_draw_to_pixbuf (HdyAvatar *self,
draw_for_size (self, cr, custom_image, size, size, scale_factor);
- return gdk_pixbuf_get_from_surface (surface, 0, 0,
- bounds.width * scale_factor,
- bounds.height * scale_factor);
+ result = gdk_pixbuf_get_from_surface (surface, 0, 0,
+ bounds.width * scale_factor,
+ bounds.height * scale_factor);
+
+ if (pixbuf_from_icon != NULL)
+ g_object_unref (pixbuf_from_icon);
+ if (custom_image != NULL)
+ g_object_unref (custom_image);
+
+ cairo_destroy (cr);
+ cairo_surface_destroy (surface);
+
+ return result;
}
/**
@@ -1303,7 +1374,7 @@ hdy_avatar_draw_to_pixbuf_async (HdyAvatar *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
- g_autoptr (GTask) task = NULL;
+ GTask *task;
gint scaled_size = size * scale_factor;
SizeData *data;
@@ -1330,6 +1401,8 @@ hdy_avatar_draw_to_pixbuf_async (HdyAvatar *self,
g_steal_pointer (&task));
else
g_task_return_pointer (task, NULL, NULL);
+
+ g_object_unref (task);
}
/**
@@ -1348,13 +1421,14 @@ hdy_avatar_draw_to_pixbuf_finish (HdyAvatar *self,
GAsyncResult *async_result)
{
GTask *task;
- g_autoptr (GdkPixbuf) pixbuf_from_icon = NULL;
- g_autoptr (GdkPixbuf) custom_image = NULL;
- g_autoptr (cairo_surface_t) surface = NULL;
- g_autoptr (cairo_t) cr = NULL;
+ GdkPixbuf *pixbuf_from_icon;
+ GdkPixbuf *custom_image = NULL;
+ cairo_surface_t *surface = NULL;
+ cairo_t *cr = NULL;
SizeData *data;
GtkStyleContext *context;
GtkAllocation bounds;
+ GdkPixbuf *result;
g_return_val_if_fail (G_IS_TASK (async_result), NULL);
@@ -1381,9 +1455,18 @@ hdy_avatar_draw_to_pixbuf_finish (HdyAvatar *self,
data->size * data->scale_factor);
draw_for_size (self, cr, custom_image, data->size, data->size, data->scale_factor);
- return gdk_pixbuf_get_from_surface (surface, 0, 0,
- bounds.width * data->scale_factor,
- bounds.height * data->scale_factor);
+ result = gdk_pixbuf_get_from_surface (surface, 0, 0,
+ bounds.width * data->scale_factor,
+ bounds.height * data->scale_factor);
+
+ if (custom_image != NULL)
+ g_object_unref (custom_image);
+
+ g_object_unref (pixbuf_from_icon);
+ cairo_destroy (cr);
+ cairo_surface_destroy (surface);
+
+ return result;
}
/**
diff --git a/src/hdy-carousel-indicator-dots.c b/src/hdy-carousel-indicator-dots.c
index a74f977b..018e646b 100644
--- a/src/hdy-carousel-indicator-dots.c
+++ b/src/hdy-carousel-indicator-dots.c
@@ -233,8 +233,8 @@ hdy_carousel_indicator_dots_measure (GtkWidget *widget,
if (orientation == self->orientation) {
gint i, n_points = 0;
gdouble indicator_length, dot_size;
- g_autofree gdouble *points = NULL;
- g_autofree gdouble *sizes = NULL;
+ gdouble *points = NULL;
+ gdouble *sizes;
if (self->carousel)
points = hdy_swipeable_get_snap_points (HDY_SWIPEABLE (self->carousel), &n_points);
@@ -252,6 +252,9 @@ hdy_carousel_indicator_dots_measure (GtkWidget *widget,
indicator_length += dot_size * sizes[i];
size = ceil (indicator_length);
+
+ g_free (sizes);
+ g_free (points);
} else {
size = 2 * DOTS_RADIUS_SELECTED;
}
@@ -296,8 +299,7 @@ hdy_carousel_indicator_dots_draw (GtkWidget *widget,
HdyCarouselIndicatorDots *self = HDY_CAROUSEL_INDICATOR_DOTS (widget);
gint i, n_points;
gdouble position;
- g_autofree gdouble *points = NULL;
- g_autofree gdouble *sizes = NULL;
+ gdouble *points;
if (!self->carousel)
return GDK_EVENT_PROPAGATE;
@@ -305,20 +307,25 @@ hdy_carousel_indicator_dots_draw (GtkWidget *widget,
points = hdy_swipeable_get_snap_points (HDY_SWIPEABLE (self->carousel), &n_points);
position = hdy_carousel_get_position (self->carousel);
- if (n_points < 2)
- return GDK_EVENT_PROPAGATE;
+ if (n_points >= 2) {
+ gdouble *sizes;
+
+ if (self->orientation == GTK_ORIENTATION_HORIZONTAL &&
+ gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+ position = points[n_points - 1] - position;
+
+ sizes = g_new0 (gdouble, n_points);
- if (self->orientation == GTK_ORIENTATION_HORIZONTAL &&
- gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
- position = points[n_points - 1] - position;
+ sizes[0] = points[0] + 1;
+ for (i = 1; i < n_points; i++)
+ sizes[i] = points[i] - points[i - 1];
- sizes = g_new0 (gdouble, n_points);
+ draw_dots (widget, cr, self->orientation, position, sizes, n_points);
- sizes[0] = points[0] + 1;
- for (i = 1; i < n_points; i++)
- sizes[i] = points[i] - points[i - 1];
+ g_free (sizes);
+ }
- draw_dots (widget, cr, self->orientation, position, sizes, n_points);
+ g_free (points);
return GDK_EVENT_PROPAGATE;
}
diff --git a/src/hdy-carousel-indicator-lines.c b/src/hdy-carousel-indicator-lines.c
index c44bd3e9..344b3ba9 100644
--- a/src/hdy-carousel-indicator-lines.c
+++ b/src/hdy-carousel-indicator-lines.c
@@ -231,8 +231,8 @@ hdy_carousel_indicator_lines_measure (GtkWidget *widget,
if (orientation == self->orientation) {
gint i, n_points = 0;
gdouble indicator_length, line_size;
- g_autofree gdouble *points = NULL;
- g_autofree gdouble *sizes = NULL;
+ gdouble *points = NULL;
+ gdouble *sizes;
if (self->carousel)
points = hdy_swipeable_get_snap_points (HDY_SWIPEABLE (self->carousel), &n_points);
@@ -250,6 +250,10 @@ hdy_carousel_indicator_lines_measure (GtkWidget *widget,
indicator_length += line_size * sizes[i];
size = ceil (indicator_length);
+
+ g_free (sizes);
+ g_free (points);
+
} else {
size = LINE_WIDTH;
}
@@ -294,8 +298,7 @@ hdy_carousel_indicator_lines_draw (GtkWidget *widget,
HdyCarouselIndicatorLines *self = HDY_CAROUSEL_INDICATOR_LINES (widget);
gint i, n_points;
gdouble position;
- g_autofree gdouble *points = NULL;
- g_autofree gdouble *sizes = NULL;
+ gdouble *points;
if (!self->carousel)
return GDK_EVENT_PROPAGATE;
@@ -303,20 +306,25 @@ hdy_carousel_indicator_lines_draw (GtkWidget *widget,
points = hdy_swipeable_get_snap_points (HDY_SWIPEABLE (self->carousel), &n_points);
position = hdy_carousel_get_position (self->carousel);
- if (n_points < 2)
- return GDK_EVENT_PROPAGATE;
+ if (n_points >= 2) {
+ gdouble *sizes;
- if (self->orientation == GTK_ORIENTATION_HORIZONTAL &&
- gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
- position = points[n_points - 1] - position;
+ if (self->orientation == GTK_ORIENTATION_HORIZONTAL &&
+ gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+ position = points[n_points - 1] - position;
- sizes = g_new0 (gdouble, n_points);
+ sizes = g_new0 (gdouble, n_points);
- sizes[0] = points[0] + 1;
- for (i = 1; i < n_points; i++)
- sizes[i] = points[i] - points[i - 1];
+ sizes[0] = points[0] + 1;
+ for (i = 1; i < n_points; i++)
+ sizes[i] = points[i] - points[i - 1];
+
+ draw_lines (widget, cr, self->orientation, position, sizes, n_points);
+
+ g_free (sizes);
+ }
- draw_lines (widget, cr, self->orientation, position, sizes, n_points);
+ g_free (points);
return GDK_EVENT_PROPAGATE;
}
diff --git a/src/hdy-combo-row.c b/src/hdy-combo-row.c
index e546f77d..fa3c75b6 100644
--- a/src/hdy-combo-row.c
+++ b/src/hdy-combo-row.c
@@ -87,16 +87,21 @@ create_list_label (gpointer item,
gpointer user_data)
{
HdyComboRowGetName *get_name = (HdyComboRowGetName *) user_data;
- g_autofree gchar *name = get_name->func (item, get_name->func_data);
-
- return g_object_new (GTK_TYPE_LABEL,
- "ellipsize", PANGO_ELLIPSIZE_END,
- "label", name,
- "max-width-chars", 20,
- "valign", GTK_ALIGN_CENTER,
- "visible", TRUE,
- "xalign", 0.0,
- NULL);
+ gchar *name = get_name->func (item, get_name->func_data);
+ GtkWidget *widget;
+
+ widget = g_object_new (GTK_TYPE_LABEL,
+ "ellipsize", PANGO_ELLIPSIZE_END,
+ "label", name,
+ "max-width-chars", 20,
+ "valign", GTK_ALIGN_CENTER,
+ "visible", TRUE,
+ "xalign", 0.0,
+ NULL);
+
+ g_free (name);
+
+ return widget;
}
static GtkWidget *
@@ -104,19 +109,24 @@ create_current_label (gpointer item,
gpointer user_data)
{
HdyComboRowGetName *get_name = (HdyComboRowGetName *) user_data;
- g_autofree gchar *name = NULL;
+ gchar *name = NULL;
+ GtkWidget *widget;
if (get_name->func)
name = get_name->func (item, get_name->func_data);
- return g_object_new (GTK_TYPE_LABEL,
- "ellipsize", PANGO_ELLIPSIZE_END,
- "halign", GTK_ALIGN_END,
- "label", name,
- "valign", GTK_ALIGN_CENTER,
- "visible", TRUE,
- "xalign", 0.0,
- NULL);
+ widget = g_object_new (GTK_TYPE_LABEL,
+ "ellipsize", PANGO_ELLIPSIZE_END,
+ "halign", GTK_ALIGN_END,
+ "label", name,
+ "valign", GTK_ALIGN_CENTER,
+ "visible", TRUE,
+ "xalign", 0.0,
+ NULL);
+
+ g_free (name);
+
+ return widget;
}
static void
@@ -178,8 +188,7 @@ static void
update (HdyComboRow *self)
{
HdyComboRowPrivate *priv = hdy_combo_row_get_instance_private (self);
- g_autoptr(GObject) item = NULL;
- g_autofree gchar *name = NULL;
+ GObject *item;
GtkWidget *widget;
guint n_items = priv->bound_model ? g_list_model_get_n_items (priv->bound_model) : 0;
gint i;
@@ -209,16 +218,22 @@ update (HdyComboRow *self)
item = g_list_model_get_item (priv->bound_model, priv->selected_index);
if (priv->use_subtitle) {
+ gchar *name = NULL;
+
if (priv->get_name != NULL && priv->get_name->func)
name = priv->get_name->func (item, priv->get_name->func_data);
else if (priv->get_name_internal != NULL && priv->get_name_internal->func)
name = priv->get_name_internal->func (item, priv->get_name_internal->func_data);
hdy_action_row_set_subtitle (HDY_ACTION_ROW (self), name);
+
+ g_free (name);
}
else {
widget = priv->create_current_widget_func (item, priv->create_widget_func_data);
gtk_container_add (GTK_CONTAINER (priv->current), widget);
}
+
+ g_object_unref (item);
}
static void
@@ -653,7 +668,7 @@ hdy_combo_row_set_for_enum (HdyComboRow *self,
gpointer user_data,
GDestroyNotify user_data_free_func)
{
- g_autoptr (GListStore) store = g_list_store_new (HDY_TYPE_ENUM_VALUE_OBJECT);
+ GListStore *store = g_list_store_new (HDY_TYPE_ENUM_VALUE_OBJECT);
/* g_autoptr for GEnumClass would require glib > 2.56 */
GEnumClass *enum_class = NULL;
gsize i;
@@ -663,13 +678,16 @@ hdy_combo_row_set_for_enum (HdyComboRow *self,
enum_class = g_type_class_ref (enum_type);
for (i = 0; i < enum_class->n_values; i++)
{
- g_autoptr(HdyEnumValueObject) obj = hdy_enum_value_object_new (&enum_class->values[i]);
+ HdyEnumValueObject *obj = hdy_enum_value_object_new (&enum_class->values[i]);
g_list_store_append (store, obj);
+
+ g_object_unref (obj);
}
hdy_combo_row_bind_name_model (self, G_LIST_MODEL (store), (HdyComboRowGetNameFunc) get_name_func,
user_data, user_data_free_func);
g_type_class_unref (enum_class);
+ g_object_unref (store);
}
/**
diff --git a/src/hdy-header-bar.c b/src/hdy-header-bar.c
index 9d455e16..279623d3 100644
--- a/src/hdy-header-bar.c
+++ b/src/hdy-header-bar.c
@@ -333,13 +333,15 @@ hdy_header_bar_update_window_icon (HdyHeaderBar *self,
pixbuf = hdy_gtk_window_get_icon_for_size (window, scale * 20);
if (pixbuf) {
- g_autoptr (cairo_surface_t) surface =
+ cairo_surface_t *surface =
gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, gtk_widget_get_window (priv->titlebar_icon));
gtk_image_set_from_surface (GTK_IMAGE (priv->titlebar_icon), surface);
g_object_unref (pixbuf);
gtk_widget_show (priv->titlebar_icon);
+ cairo_surface_destroy (surface);
+
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]