From 920637abef35f4d26a2991b12aac830eb26ec8c4 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Wed, 3 Nov 2010 12:18:48 +0100 Subject: [PATCH] GtkStyle: Listen to context changes. This way the GtkStyle is updated to the latest style info, actually emitting ::style-set must be performed after invalidating the style context. --- gtk/gtkstyle.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c index 5b0721e1f0..6c4530261b 100644 --- a/gtk/gtkstyle.c +++ b/gtk/gtkstyle.c @@ -79,6 +79,7 @@ typedef struct _GtkStylePrivate GtkStylePrivate; struct _GtkStylePrivate { GSList *color_hashes; GtkStyleContext *context; + gulong context_changed_id; }; enum { @@ -610,7 +611,12 @@ gtk_style_finalize (GObject *object) g_object_unref (style->rc_style); if (priv->context) - g_object_unref (priv->context); + { + if (priv->context_changed_id) + g_signal_handler_disconnect (priv->context, priv->context_changed_id); + + g_object_unref (priv->context); + } G_OBJECT_CLASS (gtk_style_parent_class)->finalize (object); } @@ -735,6 +741,13 @@ gtk_style_update_from_context (GtkStyle *style) } } +static void +style_context_changed (GtkStyleContext *context, + gpointer user_data) +{ + gtk_style_update_from_context (GTK_STYLE (user_data)); +} + static void gtk_style_constructed (GObject *object) { @@ -746,7 +759,8 @@ gtk_style_constructed (GObject *object) { gtk_style_update_from_context (GTK_STYLE (object)); - /* FIXME: Listen to context changes */ + priv->context_changed_id = g_signal_connect (priv->context, "changed", + G_CALLBACK (style_context_changed), object); } }