After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 743341 - GtkImage does not correctly reflect icon theme changes.
GtkImage does not correctly reflect icon theme changes.
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Class: GtkStyleContext
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2015-01-22 11:50 UTC by ria.freelander
Modified: 2015-01-27 04:09 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description ria.freelander 2015-01-22 11:50:09 UTC
In docs I see that:

/**
 * gtk_image_new_from_gicon:
 * @icon: an icon
 * @size: (type int): a stock icon size
 * 
 * Creates a #GtkImage displaying an icon from the current icon theme.
 * If the icon name isn’t known, a “broken image” icon will be
 * displayed instead.  If the current icon theme is changed, the icon
 * will be updated appropriately.
 * 
 * Returns: a new #GtkImage displaying the themed icon
 *
 * Since: 2.14
 **/

but icon will be updated only after user interacts with it.
To update icon theme accordingly, I need to use:

g_signal_connect_swapped(gtk_icon_theme_get_default(),"changed",G_CALLBACK(on_theme_changed),img);

static void on_theme_changed(GtkWidget *img, GObject *object)
{
    int size = gtk_image_get_pixel_size(GTK_IMAGE(img));
    GIcon* icon;
    gtk_image_get_gicon(GTK_IMAGE(img),&icon,NULL);
    gtk_image_set_from_gicon(GTK_IMAGE(img),&icon,GTK_ICON_SIZE_INVALID);
    gtk_image_set_pixel_size(GTK_IMAGE(img),size);
}
Comment 1 Benjamin Otte (Company) 2015-01-27 04:09:12 UTC
commit 11d70f1ac30dd491d9d8dac9b9e2c31cee073cc9
Author: Benjamin Otte <otte@redhat.com>
Date:   Tue Jan 27 00:25:05 2015 +0100

    css: Add a -gtk-icon-theme CSS property

    The property is useless to set (it only allows 'initial', 'inherit' and
    'unset' as values), but it is used to track changes to the icon theme.
    And as such, it can ensure that widgets can track when they need to
    reload icons.
                            
    https://bugzilla.gnome.org/show_bug.cgi?id=743341