From e1d74f7c71122fe0637cbe1e97d96adbb8602033 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 2 Dec 2015 03:28:36 +0100 Subject: [PATCH] window: Listen to icon theme changes on CSS No need to connect a signal handler to the icon theme, we get notified via CSS. --- gtk/gtkwindow.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 39e09da026..8c00efe252 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -492,8 +492,7 @@ static void gtk_window_set_default_size_internal (GtkWindow *window, gint height, gboolean is_geometry); -static void update_themed_icon (GtkIconTheme *theme, - GtkWindow *window); +static void update_themed_icon (GtkWindow *window); static GList *icon_list_from_theme (GtkWindow *window, const gchar *name); static void gtk_window_realize_icon (GtkWindow *window); @@ -531,6 +530,7 @@ static void gtk_window_get_preferred_height_for_width (GtkWidget *widget, gint width, gint *minimum_size, gint *natural_size); +static void gtk_window_style_updated (GtkWidget *widget); static void gtk_window_state_flags_changed (GtkWidget *widget, GtkStateFlags previous_state); @@ -710,6 +710,7 @@ gtk_window_class_init (GtkWindowClass *klass) widget_class->get_preferred_height = gtk_window_get_preferred_height; widget_class->get_preferred_height_for_width = gtk_window_get_preferred_height_for_width; widget_class->state_flags_changed = gtk_window_state_flags_changed; + widget_class->style_updated = gtk_window_style_updated; container_class->remove = gtk_window_remove; container_class->check_resize = gtk_window_check_resize; @@ -4513,15 +4514,7 @@ gtk_window_realize_icon (GtkWindow *window) if (info->using_themed_icon) { - GtkIconTheme *icon_theme; - g_list_free_full (icon_list, g_object_unref); - - icon_theme = gtk_css_icon_theme_value_get_icon_theme - (_gtk_style_context_peek_property (gtk_widget_get_style_context (GTK_WIDGET (window)), - GTK_CSS_PROPERTY_ICON_THEME)); - g_signal_connect (icon_theme, "changed", - G_CALLBACK (update_themed_icon), window); } } @@ -4602,17 +4595,6 @@ gtk_window_unrealize_icon (GtkWindow *window) if (info == NULL) return; - if (info->using_themed_icon) - { - GtkIconTheme *icon_theme; - - icon_theme = gtk_css_icon_theme_value_get_icon_theme - (_gtk_style_context_peek_property (gtk_widget_get_style_context (GTK_WIDGET (window)), - GTK_CSS_PROPERTY_ICON_THEME)); - - g_signal_handlers_disconnect_by_func (icon_theme, update_themed_icon, window); - } - /* We don't clear the properties on the window, just figure the * window is going away. */ @@ -4753,8 +4735,7 @@ gtk_window_set_icon (GtkWindow *window, static void -update_themed_icon (GtkIconTheme *icon_theme, - GtkWindow *window) +update_themed_icon (GtkWindow *window) { g_object_notify_by_pspec (G_OBJECT (window), window_props[PROP_ICON_NAME]); @@ -4798,7 +4779,7 @@ gtk_window_set_icon_name (GtkWindow *window, g_list_free_full (info->icon_list, g_object_unref); info->icon_list = NULL; - update_themed_icon (NULL, window); + update_themed_icon (window); g_object_notify_by_pspec (G_OBJECT (window), window_props[PROP_ICON_NAME]); } @@ -8761,6 +8742,17 @@ gtk_window_state_flags_changed (GtkWidget *widget, gtk_css_node_set_state (priv->decoration_node, state); } +static void +gtk_window_style_updated (GtkWidget *widget) +{ + const GtkBitmask *changes = _gtk_style_context_get_changes (gtk_widget_get_style_context (widget)); + + GTK_WIDGET_CLASS (gtk_window_parent_class)->style_updated (widget); + + if (changes == NULL || _gtk_bitmask_get (changes, GTK_CSS_PROPERTY_ICON_THEME)) + update_themed_icon (GTK_WINDOW (widget)); +} + /** * _gtk_window_unset_focus_and_default: * @window: a #GtkWindow