aboutsummaryrefslogtreecommitdiff
path: root/libindicator/indicator-image-helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'libindicator/indicator-image-helper.c')
-rw-r--r--libindicator/indicator-image-helper.c49
1 files changed, 34 insertions, 15 deletions
diff --git a/libindicator/indicator-image-helper.c b/libindicator/indicator-image-helper.c
index cbbad3d..86d6c25 100644
--- a/libindicator/indicator-image-helper.c
+++ b/libindicator/indicator-image-helper.c
@@ -109,24 +109,41 @@ image_destroyed_cb (GtkImage * image, gpointer user_data)
return;
}
+/* Catch the style changing on the image to make sure
+ we've got the latest. */
+static void
+image_style_change_cb (GtkImage * image, GtkStyle * previous_style, gpointer user_data)
+{
+ refresh_image(image);
+ return;
+}
+
+/* Builds an image with the name and fallbacks and all kinds of fun
+ stuff . */
GtkImage *
indicator_image_helper (const gchar * name)
{
- g_return_val_if_fail(name != NULL, NULL);
- g_return_val_if_fail(name[0] != '\0', NULL);
+ /* Build us an image */
+ GtkImage * image = GTK_IMAGE(gtk_image_new());
+
+ indicator_image_helper_update(image, name);
+
+ return image;
+}
+
+/* Updates and image with all the fun stuff */
+void
+indicator_image_helper_update (GtkImage * image, const gchar * name)
+{
+ g_return_if_fail(name != NULL);
+ g_return_if_fail(name[0] != '\0');
+ g_return_if_fail(image != NULL);
/* Build us a GIcon */
GIcon * icon_names = g_themed_icon_new_with_default_fallbacks(name);
- g_return_val_if_fail(icon_names != NULL, NULL);
-
- /* Build us an image */
- GtkImage * image = GTK_IMAGE(gtk_image_new());
+ g_return_if_fail(icon_names != NULL);
- if (image == NULL) {
- g_error("Unable to create image from pixbuf on icon name '%s'", name);
- g_object_unref(icon_names);
- return NULL;
- }
+ gboolean seen_previously = (g_object_get_data(G_OBJECT(image), INDICATOR_NAMES_DATA) != NULL);
/* Attach our names to the image */
g_object_set_data_full(G_OBJECT(image), INDICATOR_NAMES_DATA, icon_names, g_object_unref);
@@ -135,9 +152,11 @@ indicator_image_helper (const gchar * name)
refresh_image(image);
/* Connect to all changes */
- g_signal_connect(G_OBJECT(gtk_icon_theme_get_default()), "changed", G_CALLBACK(theme_changed_cb), image);
- g_signal_connect(G_OBJECT(image), "destroy", G_CALLBACK(image_destroyed_cb), NULL);
+ if (!seen_previously) {
+ g_signal_connect(G_OBJECT(gtk_icon_theme_get_default()), "changed", G_CALLBACK(theme_changed_cb), image);
+ g_signal_connect(G_OBJECT(image), "destroy", G_CALLBACK(image_destroyed_cb), NULL);
+ g_signal_connect(G_OBJECT(image), "style-set", G_CALLBACK(image_style_change_cb), NULL);
+ }
- /* Return our built image */
- return image;
+ return;
}