Merge branch 'fix-icontheme-invalidation' into 'master'

Fix icontheme invalidation

See merge request GNOME/gtk!1733
This commit is contained in:
Benjamin Otte 2020-04-23 00:13:26 +00:00
commit 8b1e857a67
29 changed files with 154 additions and 401 deletions

View File

@ -339,7 +339,7 @@ scale[.fine-tune]
<member><literal>-gtk-icontheme(<replaceable>Name</replaceable>)</literal></member>
</simplelist>
The specified icon name is used to look up a themed icon, while taking into
account the values of the -gtk-icon-theme and -gtk-icon-palette properties.
account the values of the -gtk-icon-palette property.
This kind of image is mainly used as value of the -gtk-icon-source property.
</para>
<para>
@ -599,11 +599,6 @@ scale[.fine-tune]
<entry><ulink url="https://www.w3.org/TR/css-backgrounds-3/#typedef-image">Image</ulink>, <literal>builtin</literal> or <literal>none</literal></entry>
<entry>used for builtin icons in buttons and expanders</entry>
</row>
<row>
<entry>-gtk-icon-theme</entry>
<entry>Theme name</entry>
<entry>icon theme to use with -gtk-icontheme()</entry>
</row>
<row>
<entry>-gtk-icon-size</entry>
<entry><ulink url="https://www.w3.org/TR/css3-values/#length-value">Length</ulink></entry>

View File

@ -2312,6 +2312,7 @@ GtkSettingsValue
gtk_settings_get_default
gtk_settings_get_for_display
gtk_settings_reset_property
GtkSystemSetting
<SUBSECTION Standard>
GtkSettingsClass
GTK_IS_SETTINGS
@ -4102,7 +4103,6 @@ gtk_widget_set_css_classes
<SUBSECTION>
gtk_widget_get_style_context
gtk_widget_reset_style
gtk_widget_class_get_css_name
gtk_widget_class_set_css_name

View File

@ -176,10 +176,6 @@ gtk_css_animated_style_set_animated_value (GtkCssAnimatedStyle *animated,
unshare_core (animated);
gtk_css_take_value (&style->core->font_size, value);
break;
case GTK_CSS_PROPERTY_ICON_THEME:
unshare_core (animated);
gtk_css_take_value (&style->core->icon_theme, value);
break;
case GTK_CSS_PROPERTY_ICON_PALETTE:
unshare_core (animated);
gtk_css_take_value (&style->core->icon_palette, value);

View File

@ -1,175 +0,0 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 2011 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gtkcssiconthemevalueprivate.h"
#include "gtkicontheme.h"
#include "gtksettingsprivate.h"
#include "gtkstyleproviderprivate.h"
#include "gtkintl.h"
/*
* The idea behind this value (and the '-gtk-icon-theme' CSS property) is
* to track changes to the icon theme.
*
* We create a new instance of this value whenever the icon theme changes
* (via emitting the changed signal). So as long as the icon theme does
* not change, we will compute the same value. We can then compare values
* by pointer to see if the icon theme changed.
*/
struct _GtkCssValue {
GTK_CSS_VALUE_BASE
GtkIconTheme *icontheme;
guint changed_id;
};
static void
gtk_css_value_icon_theme_disconnect_handler (GtkCssValue *value)
{
if (value->changed_id == 0)
return;
g_object_set_data (G_OBJECT (value->icontheme), "-gtk-css-value", NULL);
g_signal_handler_disconnect (value->icontheme, value->changed_id);
value->changed_id = 0;
}
static void
gtk_css_value_icon_theme_changed_cb (GtkIconTheme *icontheme,
GtkCssValue *value)
{
gtk_css_value_icon_theme_disconnect_handler (value);
}
static void
gtk_css_value_icon_theme_free (GtkCssValue *value)
{
gtk_css_value_icon_theme_disconnect_handler (value);
if (value->icontheme)
g_object_unref (value->icontheme);
g_slice_free (GtkCssValue, value);
}
static GtkCssValue *
gtk_css_value_icon_theme_compute (GtkCssValue *icon_theme,
guint property_id,
GtkStyleProvider *provider,
GtkCssStyle *style,
GtkCssStyle *parent_style)
{
GtkIconTheme *icontheme;
if (icon_theme->icontheme)
icontheme = icon_theme->icontheme;
else
icontheme = gtk_icon_theme_get_for_display (_gtk_settings_get_display (gtk_style_provider_get_settings (provider)));
return gtk_css_icon_theme_value_new (icontheme);
}
static gboolean
gtk_css_value_icon_theme_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
{
return FALSE;
}
static GtkCssValue *
gtk_css_value_icon_theme_transition (GtkCssValue *start,
GtkCssValue *end,
guint property_id,
double progress)
{
return NULL;
}
static void
gtk_css_value_icon_theme_print (const GtkCssValue *icon_theme,
GString *string)
{
g_string_append (string, "initial");
}
static const GtkCssValueClass GTK_CSS_VALUE_ICON_THEME = {
"GtkCssIconThemeValue",
gtk_css_value_icon_theme_free,
gtk_css_value_icon_theme_compute,
gtk_css_value_icon_theme_equal,
gtk_css_value_icon_theme_transition,
NULL,
NULL,
gtk_css_value_icon_theme_print
};
static GtkCssValue default_icon_theme_value = { &GTK_CSS_VALUE_ICON_THEME, 1, FALSE, NULL, 0 };
GtkCssValue *
gtk_css_icon_theme_value_new (GtkIconTheme *icontheme)
{
GtkCssValue *result;
if (icontheme == NULL)
return _gtk_css_value_ref (&default_icon_theme_value);
result = g_object_get_data (G_OBJECT (icontheme), "-gtk-css-value");
if (result)
return _gtk_css_value_ref (result);
result = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_ICON_THEME);
result->icontheme = g_object_ref (icontheme);
g_object_set_data (G_OBJECT (icontheme), I_("-gtk-css-value"), result);
result->changed_id = g_signal_connect (icontheme, "changed", G_CALLBACK (gtk_css_value_icon_theme_changed_cb), result);
return result;
}
GtkCssValue *
gtk_css_icon_theme_value_parse (GtkCssParser *parser)
{
GtkIconTheme *icontheme;
GtkCssValue *result;
char *s;
s = gtk_css_parser_consume_string (parser);
if (s == NULL)
return NULL;
icontheme = gtk_icon_theme_new ();
gtk_icon_theme_set_theme_name (icontheme, s);
result = gtk_css_icon_theme_value_new (icontheme);
g_object_unref (icontheme);
g_free (s);
return result;
}
GtkIconTheme *
gtk_css_icon_theme_value_get_icon_theme (GtkCssValue *value)
{
g_return_val_if_fail (value->class == &GTK_CSS_VALUE_ICON_THEME, NULL);
return value->icontheme;
}

View File

@ -1,38 +0,0 @@
/*
* Copyright © 2012 Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Alexander Larsson <alexl@gnome.org>
*/
#ifndef __GTK_CSS_ICON_THEME_VALUE_PRIVATE_H__
#define __GTK_CSS_ICON_THEME_VALUE_PRIVATE_H__
#include "gtkicontheme.h"
#include "gtkcssparserprivate.h"
#include "gtkcssvalueprivate.h"
G_BEGIN_DECLS
GtkCssValue * gtk_css_icon_theme_value_new (GtkIconTheme *icontheme);
GtkCssValue * gtk_css_icon_theme_value_parse (GtkCssParser *parser);
GtkIconTheme * gtk_css_icon_theme_value_get_icon_theme (GtkCssValue *value);
G_END_DECLS
#endif /* __GTK_CSS_ICON_THEME_VALUE_PRIVATE_H__ */

View File

@ -23,7 +23,6 @@
#include <math.h>
#include "gtkcssiconthemevalueprivate.h"
#include "gtksettingsprivate.h"
#include "gtksnapshot.h"
#include "gtkstyleproviderprivate.h"
@ -146,10 +145,15 @@ gtk_css_image_icon_theme_compute (GtkCssImage *image,
{
GtkCssImageIconTheme *icon_theme = GTK_CSS_IMAGE_ICON_THEME (image);
GtkCssImageIconTheme *copy;
GtkSettings *settings;
GdkDisplay *display;
copy = g_object_new (GTK_TYPE_CSS_IMAGE_ICON_THEME, NULL);
copy->name = g_strdup (icon_theme->name);
copy->icon_theme = gtk_css_icon_theme_value_get_icon_theme (style->core->icon_theme);
settings = gtk_style_provider_get_settings (provider);
display = _gtk_settings_get_display (settings);
copy->icon_theme = gtk_icon_theme_get_for_display (display);
copy->serial = gtk_icon_theme_get_serial (copy->icon_theme);
copy->scale = gtk_style_provider_get_scale (provider);
gtk_icon_theme_lookup_symbolic_colors (style, &copy->color, &copy->success, &copy->warning, &copy->error);
@ -163,7 +167,9 @@ gtk_css_image_icon_theme_equal (GtkCssImage *image1,
GtkCssImageIconTheme *icon_theme1 = (GtkCssImageIconTheme *) image1;
GtkCssImageIconTheme *icon_theme2 = (GtkCssImageIconTheme *) image2;
return g_str_equal (icon_theme1->name, icon_theme2->name);
return icon_theme1->serial == icon_theme2->serial &&
icon_theme1->icon_theme == icon_theme2->icon_theme &&
g_str_equal (icon_theme1->name, icon_theme2->name);
}
static void

View File

@ -44,7 +44,8 @@ struct _GtkCssImageIconTheme
GdkRGBA success;
GdkRGBA warning;
GdkRGBA error;
gint scale;
int serial;
int scale;
char *name;
int cached_size;

View File

@ -19,7 +19,6 @@
#include "gtkcsspalettevalueprivate.h"
#include "gtkcssiconthemevalueprivate.h"
#include "gtkcsscolorvalueprivate.h"
#include "gtkcsscolorvalueprivate.h"
#include "gtkprivate.h"

View File

@ -50,7 +50,6 @@ static const int core_props[] = {
GTK_CSS_PROPERTY_COLOR,
GTK_CSS_PROPERTY_DPI,
GTK_CSS_PROPERTY_FONT_SIZE,
GTK_CSS_PROPERTY_ICON_THEME,
GTK_CSS_PROPERTY_ICON_PALETTE
};
@ -396,9 +395,6 @@ gtk_css_static_style_set_value (GtkCssStaticStyle *sstyle,
case GTK_CSS_PROPERTY_FONT_SIZE:
gtk_css_take_value (&style->core->font_size, value);
break;
case GTK_CSS_PROPERTY_ICON_THEME:
gtk_css_take_value (&style->core->icon_theme, value);
break;
case GTK_CSS_PROPERTY_ICON_PALETTE:
gtk_css_take_value (&style->core->icon_palette, value);
break;

View File

@ -103,8 +103,6 @@ gtk_css_style_get_value (GtkCssStyle *style,
return style->core->dpi;
case GTK_CSS_PROPERTY_FONT_SIZE:
return style->core->font_size;
case GTK_CSS_PROPERTY_ICON_THEME:
return style->core->icon_theme;
case GTK_CSS_PROPERTY_ICON_PALETTE:
return style->core->icon_palette;
case GTK_CSS_PROPERTY_BACKGROUND_COLOR:

View File

@ -83,7 +83,6 @@ struct _GtkCssCoreValues {
GtkCssValue *color;
GtkCssValue *dpi;
GtkCssValue *font_size;
GtkCssValue *icon_theme;
GtkCssValue *icon_palette;
};

View File

@ -43,7 +43,6 @@
#include "gtkcsseasevalueprivate.h"
#include "gtkcssfiltervalueprivate.h"
#include "gtkcssfontfeaturesvalueprivate.h"
#include "gtkcssiconthemevalueprivate.h"
#include "gtkcssimageprivate.h"
#include "gtkcssimagevalueprivate.h"
#include "gtkcssinitialvalueprivate.h"
@ -794,13 +793,6 @@ background_position_parse (GtkCssStyleProperty *property,
return _gtk_css_array_value_parse (parser, _gtk_css_position_value_parse);
}
static GtkCssValue *
icon_theme_value_parse (GtkCssStyleProperty *property,
GtkCssParser *parser)
{
return gtk_css_icon_theme_value_parse (parser);
}
/*** REGISTRATION ***/
G_STATIC_ASSERT (GTK_CSS_PROPERTY_COLOR == 0);
@ -831,12 +823,6 @@ _gtk_css_style_property_init_properties (void)
GTK_CSS_AFFECTS_SIZE | GTK_CSS_AFFECTS_TEXT_SIZE,
font_size_parse,
_gtk_css_font_size_value_new (GTK_CSS_FONT_SIZE_MEDIUM));
gtk_css_style_property_register ("-gtk-icon-theme",
GTK_CSS_PROPERTY_ICON_THEME,
GTK_STYLE_PROPERTY_INHERIT,
GTK_CSS_AFFECTS_ICON_TEXTURE,
icon_theme_value_parse,
gtk_css_icon_theme_value_new (NULL));
gtk_css_style_property_register ("-gtk-icon-palette",
GTK_CSS_PROPERTY_ICON_PALETTE,
GTK_STYLE_PROPERTY_ANIMATED | GTK_STYLE_PROPERTY_INHERIT,

View File

@ -188,7 +188,6 @@ enum { /*< skip >*/
GTK_CSS_PROPERTY_COLOR,
GTK_CSS_PROPERTY_DPI,
GTK_CSS_PROPERTY_FONT_SIZE,
GTK_CSS_PROPERTY_ICON_THEME,
GTK_CSS_PROPERTY_ICON_PALETTE,
GTK_CSS_PROPERTY_BACKGROUND_COLOR,
GTK_CSS_PROPERTY_FONT_FAMILY,

View File

@ -1088,4 +1088,33 @@ typedef enum {
GTK_CONSTRAINT_VFL_PARSER_ERROR_INVALID_RELATION
} GtkConstraintVflParserError;
/**
* GtkSystemSetting:
* @GTK_SYSTEM_SETTING_DPI: the #GtkSettings:gtk-xft-dpi setting has changed
* @GTK_SYSTEM_SETTING_FONT_NAME: The #GtkSettings:gtk-font-name setting has changed
* @GTK_SYSTEM_SETTING_FONT_CONFIG: The font configuration has changed in a way that
* requires text to be redrawn. This can be any of the
* #GtkSettings:gtk-xft-antialias, #GtkSettings:gtk-xft-hinting,
* #GtkSettings:gtk-xft-hintstyle, #GtkSettings:gtk-xft-rgba or
* #GtkSettings:gtk-fontconfig-timestamp settings
* @GTK_SYSTEM_SETTING_DISPLAY: The display has changed
* @GTK_SYSTEM_SETTING_ICON_THEME: The icon theme has changed in a way that requires
* icons to be looked up again
*
* Values that can be passed to the GtkWidgetClass.system_setting_changed
* vfunc to indicate that a system setting has changed and widgets may
* need to drop caches, or react otherwise.
*
* Most of the values correspond to #GtkSettings properties.
*
* More values may be added over time.
*/
typedef enum {
GTK_SYSTEM_SETTING_DPI,
GTK_SYSTEM_SETTING_FONT_NAME,
GTK_SYSTEM_SETTING_FONT_CONFIG,
GTK_SYSTEM_SETTING_DISPLAY,
GTK_SYSTEM_SETTING_ICON_THEME
} GtkSystemSetting;
#endif /* __GTK_ENUMS_H__ */

View File

@ -36,7 +36,6 @@
#include "gtkcellrenderertext.h"
#include "gtkcellrendererpixbuf.h"
#include "gtkcombobox.h"
#include "gtkcssiconthemevalueprivate.h"
#include "gtkdroptarget.h"
#include "gtkicontheme.h"
#include "gtkimage.h"
@ -273,8 +272,6 @@ static void gtk_file_chooser_button_root (GtkWidget *widget);
static void gtk_file_chooser_button_map (GtkWidget *widget);
static gboolean gtk_file_chooser_button_mnemonic_activate (GtkWidget *widget,
gboolean group_cycling);
static void gtk_file_chooser_button_css_changed (GtkWidget *widget,
GtkCssStyleChange *change);
static void gtk_file_chooser_button_state_flags_changed (GtkWidget *widget,
GtkStateFlags previous_state);
@ -468,7 +465,6 @@ gtk_file_chooser_button_class_init (GtkFileChooserButtonClass * class)
widget_class->show = gtk_file_chooser_button_show;
widget_class->hide = gtk_file_chooser_button_hide;
widget_class->map = gtk_file_chooser_button_map;
widget_class->css_changed = gtk_file_chooser_button_css_changed;
widget_class->root = gtk_file_chooser_button_root;
widget_class->mnemonic_activate = gtk_file_chooser_button_mnemonic_activate;
widget_class->state_flags_changed = gtk_file_chooser_button_state_flags_changed;
@ -1347,18 +1343,6 @@ change_icon_theme (GtkFileChooserButton *button)
NULL);
}
static void
gtk_file_chooser_button_css_changed (GtkWidget *widget,
GtkCssStyleChange *change)
{
GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->css_changed (widget, change);
/* We need to update the icon surface, but only in case
* the icon theme really changed. */
if (!change || gtk_css_style_change_changes_property (change, GTK_CSS_PROPERTY_ICON_THEME))
change_icon_theme (GTK_FILE_CHOOSER_BUTTON (widget));
}
static void
gtk_file_chooser_button_root (GtkWidget *widget)
{

View File

@ -27,7 +27,6 @@
#include <glib/gi18n-lib.h>
#include "gtkfilechooser.h"
#include "gtkcssiconthemevalueprivate.h"
#include "gtkintl.h"
#include "gtkprivate.h"
#include "gtkstylecontextprivate.h"

View File

@ -24,7 +24,6 @@
#include <math.h>
#include "gtkcssenumvalueprivate.h"
#include "gtkcssiconthemevalueprivate.h"
#include "gtkcssnodeprivate.h"
#include "gtkcssnumbervalueprivate.h"
#include "gtkcssstyleprivate.h"
@ -96,7 +95,7 @@ ensure_paintable_for_gicon (GtkIconHelper *self,
GtkIconPaintable *icon;
GtkIconLookupFlags flags;
icon_theme = gtk_css_icon_theme_value_get_icon_theme (style->core->icon_theme);
icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (self->owner));
flags = get_icon_lookup_flags (self, style);
if (preload)
flags |= GTK_ICON_LOOKUP_PRELOAD;

View File

@ -47,8 +47,10 @@
#include "gtkmain.h"
#include "gtksettingsprivate.h"
#include "gtkstylecontextprivate.h"
#include "gtkstyleproviderprivate.h"
#include "gtkprivate.h"
#include "gtksnapshot.h"
#include "gtkwidgetprivate.h"
#include "gdkpixbufutilsprivate.h"
#include "gdk/gdktextureprivate.h"
#include "gdk/gdkprofilerprivate.h"
@ -331,6 +333,8 @@ struct _GtkIconTheme
GList *dir_mtimes;
gulong theme_changed_idle;
int serial;
};
struct _GtkIconThemeClass
@ -549,9 +553,16 @@ gtk_icon_theme_ref_aquire (GtkIconThemeRef *ref)
static void
gtk_icon_theme_ref_release (GtkIconThemeRef *ref)
{
if (ref->theme)
g_object_unref (ref->theme);
GtkIconTheme *theme;
/* Get a pointer to the theme, becuse when we unlock it could become NULLed by dispose, this pointer still owns a ref */
theme = ref->theme;
g_mutex_unlock (&ref->lock);
/* Then unref outside the lock, because otherwis if this is the last ref the dispose handler would deadlock trying to NULL ref->theme */
if (theme)
g_object_unref (theme);
}
static void
@ -1308,7 +1319,9 @@ theme_changed_idle__mainthread_unlocked (gpointer user_data)
if (display)
{
gtk_style_context_reset_widgets (self->display);
GtkSettings *settings = gtk_settings_get_for_display (self->display);
gtk_style_provider_changed (GTK_STYLE_PROVIDER (settings));
gtk_system_setting_changed (display, GTK_SYSTEM_SETTING_ICON_THEME);
g_object_unref (display);
}
@ -1344,7 +1357,6 @@ do_theme_change (GtkIconTheme *self)
blow_themes (self);
queue_theme_changed (self);
}
static void
@ -1360,6 +1372,13 @@ blow_themes (GtkIconTheme *self)
self->unthemed_icons = NULL;
self->dir_mtimes = NULL;
self->themes_valid = FALSE;
self->serial++;
}
int
gtk_icon_theme_get_serial (GtkIconTheme *self)
{
return self->serial;
}
static void

View File

@ -41,4 +41,6 @@ void gtk_icon_paintable_snapshot_with_colors (GtkIconPaintable *icon,
const GdkRGBA *warning_color,
const GdkRGBA *error_color);
int gtk_icon_theme_get_serial (GtkIconTheme *self);
#endif /* __GTK_ICON_THEME_PRIVATE_H__ */

View File

@ -110,6 +110,8 @@ static void gtk_image_measure (GtkWidget *widget,
static void gtk_image_css_changed (GtkWidget *widget,
GtkCssStyleChange *change);
static void gtk_image_system_setting_changed (GtkWidget *widget,
GtkSystemSetting seting);
static void gtk_image_finalize (GObject *object);
static void gtk_image_set_property (GObject *object,
@ -157,6 +159,7 @@ gtk_image_class_init (GtkImageClass *class)
widget_class->measure = gtk_image_measure;
widget_class->unrealize = gtk_image_unrealize;
widget_class->css_changed = gtk_image_css_changed;
widget_class->system_setting_changed = gtk_image_system_setting_changed;
widget_class->grab_focus = gtk_widget_grab_focus_none;
widget_class->focus = gtk_widget_focus_none;
@ -1264,6 +1267,18 @@ gtk_image_css_changed (GtkWidget *widget,
image->baseline_align = 0.0;
}
static void
gtk_image_system_setting_changed (GtkWidget *widget,
GtkSystemSetting setting)
{
GtkImage *image = GTK_IMAGE (widget);
if (setting == GTK_SYSTEM_SETTING_ICON_THEME)
gtk_icon_helper_invalidate (image->icon_helper);
GTK_WIDGET_CLASS (gtk_image_parent_class)->system_setting_changed (widget, setting);
}
/**
* gtk_image_set_pixel_size:
* @image: a #GtkImage

View File

@ -30,7 +30,6 @@
#include "gtkmountoperationprivate.h"
#include "gtkbox.h"
#include "gtkcssiconthemevalueprivate.h"
#include "gtkdbusgenerated.h"
#include "gtkentry.h"
#include "gtkbox.h"
@ -1206,9 +1205,7 @@ add_pid_to_process_list_store (GtkMountOperation *mount_operation,
GtkIconTheme *theme;
GtkIconPaintable *icon;
theme = gtk_css_icon_theme_value_get_icon_theme
(_gtk_style_context_peek_property (gtk_widget_get_style_context (GTK_WIDGET (mount_operation->priv->dialog)),
GTK_CSS_PROPERTY_ICON_THEME));
theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (mount_operation->priv->dialog)));
icon = gtk_icon_theme_lookup_icon (theme,
"application-x-executable",
NULL,

View File

@ -29,7 +29,7 @@
#include "gtkstyleproviderprivate.h"
#include "gtktypebuiltins.h"
#include "gtkversion.h"
#include "gtkwidget.h"
#include "gtkwidgetprivate.h"
#include "gdk/gdk-private.h"
@ -1246,32 +1246,28 @@ gtk_settings_notify (GObject *object,
case PROP_FONT_NAME:
settings_update_font_values (settings);
settings_invalidate_style (settings);
gtk_style_context_reset_widgets (settings->display);
gtk_system_setting_changed (settings->display, GTK_SYSTEM_SETTING_FONT_NAME);
break;
case PROP_THEME_NAME:
case PROP_APPLICATION_PREFER_DARK_THEME:
settings_update_theme (settings);
break;
case PROP_XFT_DPI:
/* This is a hack because with gtk_rc_reset_styles() doesn't get
* widgets with gtk_widget_style_set(), and also causes more
* recomputation than necessary.
*/
gtk_style_context_reset_widgets (settings->display);
gtk_system_setting_changed (settings->display, GTK_SYSTEM_SETTING_DPI);
break;
case PROP_XFT_ANTIALIAS:
case PROP_XFT_HINTING:
case PROP_XFT_HINTSTYLE:
case PROP_XFT_RGBA:
settings_update_font_options (settings);
gtk_style_context_reset_widgets (settings->display);
gtk_system_setting_changed (settings->display, GTK_SYSTEM_SETTING_FONT_CONFIG);
break;
case PROP_FONTCONFIG_TIMESTAMP:
if (settings_update_fontconfig (settings))
gtk_style_context_reset_widgets (settings->display);
gtk_system_setting_changed (settings->display, GTK_SYSTEM_SETTING_FONT_CONFIG);
break;
case PROP_ENABLE_ANIMATIONS:
gtk_style_context_reset_widgets (settings->display);
settings_invalidate_style (settings);
break;
case PROP_CURSOR_THEME_NAME:
case PROP_CURSOR_THEME_SIZE:

View File

@ -415,36 +415,6 @@ gtk_style_context_remove_provider (GtkStyleContext *context,
_gtk_style_cascade_remove_provider (priv->cascade, provider);
}
/**
* gtk_style_context_reset_widgets:
* @display: a #GdkDisplay
*
* This function recomputes the styles for all widgets under a particular
* #GdkDisplay. This is useful when some global parameter has changed that
* affects the appearance of all widgets, because when a widget gets a new
* style, it will both redraw and recompute any cached information about
* its appearance. As an example, it is used when the color scheme changes
* in the related #GtkSettings object.
**/
void
gtk_style_context_reset_widgets (GdkDisplay *display)
{
GList *list, *toplevels;
toplevels = gtk_window_list_toplevels ();
g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
for (list = toplevels; list; list = list->next)
{
if (gtk_widget_get_display (list->data) == display)
gtk_widget_reset_style (list->data);
g_object_unref (list->data);
}
g_list_free (toplevels);
}
/**
* gtk_style_context_add_provider_for_display:
* @display: a #GdkDisplay

View File

@ -57,9 +57,6 @@ void _gtk_style_context_get_cursor_color (GtkStyleContext
AtkAttributeSet *_gtk_style_context_get_attributes (AtkAttributeSet *attributes,
GtkStyleContext *context);
GDK_AVAILABLE_IN_ALL
void gtk_style_context_reset_widgets (GdkDisplay *display);
G_END_DECLS
#endif /* __GTK_STYLE_CONTEXT_PRIVATE_H__ */

View File

@ -592,6 +592,8 @@ static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
GtkTooltip *tooltip);
static void gtk_widget_real_css_changed (GtkWidget *widget,
GtkCssStyleChange *change);
static void gtk_widget_real_system_setting_changed (GtkWidget *widget,
GtkSystemSetting setting);
static void gtk_widget_real_set_focus_child (GtkWidget *widget,
GtkWidget *child);
@ -911,6 +913,7 @@ gtk_widget_class_init (GtkWidgetClass *klass)
klass->keynav_failed = gtk_widget_real_keynav_failed;
klass->query_tooltip = gtk_widget_real_query_tooltip;
klass->css_changed = gtk_widget_real_css_changed;
klass->system_setting_changed = gtk_widget_real_system_setting_changed;
/* Accessibility support */
klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
@ -4865,6 +4868,29 @@ gtk_widget_real_css_changed (GtkWidget *widget,
}
}
static void
gtk_widget_real_system_setting_changed (GtkWidget *widget,
GtkSystemSetting setting)
{
GtkWidget *child;
if (setting == GTK_SYSTEM_SETTING_DPI ||
setting == GTK_SYSTEM_SETTING_FONT_NAME ||
setting == GTK_SYSTEM_SETTING_FONT_CONFIG)
{
gtk_widget_update_pango_context (widget);
if (gtk_widget_peek_pango_context (widget))
gtk_widget_queue_resize (widget);
}
for (child = _gtk_widget_get_first_child (widget);
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
gtk_widget_system_setting_changed (child, setting);
}
}
static gboolean
direction_is_forward (GtkDirectionType direction)
{
@ -6001,38 +6027,6 @@ gtk_widget_real_direction_changed (GtkWidget *widget,
gtk_widget_queue_resize (widget);
}
static void
reset_style_recurse (GtkWidget *widget, gpointer user_data)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
gtk_css_node_invalidate (priv->cssnode, GTK_CSS_CHANGE_ANY);
gtk_widget_forall (widget, reset_style_recurse, user_data);
}
/**
* gtk_widget_reset_style:
* @widget: a #GtkWidget
*
* Updates the style context of @widget and all descendants
* by updating its widget path. #GtkContainers may want
* to use this on a child when reordering it in a way that a different
* style might apply to it.
*/
void
gtk_widget_reset_style (GtkWidget *widget)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
g_return_if_fail (GTK_IS_WIDGET (widget));
reset_style_recurse (widget, NULL);
g_list_foreach (priv->attached_windows,
(GFunc) reset_style_recurse, NULL);
}
#ifdef G_ENABLE_CONSISTENCY_CHECKS
/* Verify invariants, see docs/widget_system.txt for notes on much of
@ -9188,8 +9182,6 @@ gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
for (l = style_data->classes; l; l = l->next)
gtk_widget_add_css_class (GTK_WIDGET (buildable), (const char *)l->data);
gtk_widget_reset_style (GTK_WIDGET (buildable));
g_slist_free_full (style_data->classes, g_free);
g_slice_free (StyleParserData, style_data);
}
@ -10555,24 +10547,6 @@ _gtk_widget_get_sizegroups (GtkWidget *widget)
return NULL;
}
void
_gtk_widget_add_attached_window (GtkWidget *widget,
GtkWindow *window)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
priv->attached_windows = g_list_prepend (priv->attached_windows, window);
}
void
_gtk_widget_remove_attached_window (GtkWidget *widget,
GtkWindow *window)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
priv->attached_windows = g_list_remove (priv->attached_windows, window);
}
/**
* gtk_widget_class_set_css_name:
* @widget_class: class to set the name on
@ -10627,6 +10601,32 @@ gtk_widget_css_changed (GtkWidget *widget,
GTK_WIDGET_GET_CLASS (widget)->css_changed (widget, change);
}
void
gtk_widget_system_setting_changed (GtkWidget *widget,
GtkSystemSetting setting)
{
GTK_WIDGET_GET_CLASS (widget)->system_setting_changed (widget, setting);
}
void
gtk_system_setting_changed (GdkDisplay *display,
GtkSystemSetting setting)
{
GList *list, *toplevels;
toplevels = gtk_window_list_toplevels ();
g_list_foreach (toplevels, (GFunc) g_object_ref, NULL);
for (list = toplevels; list; list = list->next)
{
if (gtk_widget_get_display (list->data) == display)
gtk_widget_system_setting_changed (list->data, setting);
g_object_unref (list->data);
}
g_list_free (toplevels);
}
GtkCssNode *
gtk_widget_get_css_node (GtkWidget *widget)
{

View File

@ -201,6 +201,7 @@ struct _GtkWidget
* should then discard their caches that depend on CSS and queue resizes or
* redraws accordingly. The default implementation will take care of this for
* all the default CSS properties, so implementations must chain up.
* @system_setting_changed: Emitted when a system setting was changed. Must chain up.
* @snapshot: Vfunc for gtk_widget_snapshot().
* @contains: Vfunc for gtk_widget_contains().
*/
@ -277,6 +278,9 @@ struct _GtkWidgetClass
void (* css_changed) (GtkWidget *widget,
GtkCssStyleChange *change);
void (* system_setting_changed) (GtkWidget *widget,
GtkSystemSetting settings);
void (* snapshot) (GtkWidget *widget,
GtkSnapshot *snapshot);
@ -676,8 +680,6 @@ void gtk_widget_add_controller (GtkWidget *widget,
GDK_AVAILABLE_IN_ALL
void gtk_widget_remove_controller (GtkWidget *widget,
GtkEventController *controller);
GDK_AVAILABLE_IN_ALL
void gtk_widget_reset_style (GtkWidget *widget);
GDK_AVAILABLE_IN_ALL
PangoContext *gtk_widget_create_pango_context (GtkWidget *widget);

View File

@ -144,12 +144,6 @@ struct _GtkWidgetPrivate
*/
GtkRoot *root;
/* The list of attached windows to this widget.
* We keep a list in order to call reset_style to all of them,
* recursively.
*/
GList *attached_windows;
/* The style for the widget. The style contains the
* colors the widget should be drawn in for each state
* along with graphics contexts used to draw with and
@ -243,11 +237,6 @@ void _gtk_widget_remove_sizegroup (GtkWidget *widget,
gpointer group);
GSList *_gtk_widget_get_sizegroups (GtkWidget *widget);
void _gtk_widget_add_attached_window (GtkWidget *widget,
GtkWindow *window);
void _gtk_widget_remove_attached_window (GtkWidget *widget,
GtkWindow *window);
AtkObject * _gtk_widget_peek_accessible (GtkWidget *widget);
void _gtk_widget_set_has_default (GtkWidget *widget,
@ -282,6 +271,10 @@ gboolean _gtk_widget_captured_event (GtkWidget *widget,
void gtk_widget_css_changed (GtkWidget *widget,
GtkCssStyleChange *change);
void gtk_widget_system_setting_changed (GtkWidget *widget,
GtkSystemSetting setting);
void gtk_system_setting_changed (GdkDisplay *display,
GtkSystemSetting setting);
void _gtk_widget_update_parent_muxer (GtkWidget *widget);
GtkActionMuxer * _gtk_widget_get_action_muxer (GtkWidget *widget,

View File

@ -34,7 +34,6 @@
#include "gtkbutton.h"
#include "gtkcheckbutton.h"
#include "gtkcsscornervalueprivate.h"
#include "gtkcssiconthemevalueprivate.h"
#include "gtkcsscolorvalueprivate.h"
#include "gtkcssshadowvalueprivate.h"
#include "gtkcssstylepropertyprivate.h"
@ -2551,11 +2550,7 @@ remove_attach_widget (GtkWindow *window)
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
if (priv->attach_widget)
{
_gtk_widget_remove_attached_window (priv->attach_widget, window);
priv->attach_widget = NULL;
}
priv->attach_widget = NULL;
}
static void
@ -3363,17 +3358,13 @@ icon_list_from_theme (GtkWindow *window,
{
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
GList *list;
GtkStyleContext *context;
GtkCssValue *value;
GtkIconTheme *icon_theme;
GtkIconPaintable *info;
GdkTexture *texture;
gint *sizes;
gint i;
context = gtk_widget_get_style_context (GTK_WIDGET (window));
value = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_THEME);
icon_theme = gtk_css_icon_theme_value_get_icon_theme (value);
icon_theme = gtk_icon_theme_get_for_display (priv->display);
sizes = gtk_icon_theme_get_icon_sizes (icon_theme, name);
@ -5736,9 +5727,6 @@ gtk_window_css_changed (GtkWidget *widget,
update_opaque_region (window, &window_border, &allocation);
}
if (change == NULL || gtk_css_style_change_changes_property (change, GTK_CSS_PROPERTY_ICON_THEME))
update_themed_icon (window);
}
/**
@ -7118,6 +7106,8 @@ gtk_window_set_display (GtkWindow *window,
gtk_widget_map (widget);
check_scale_changed (window);
gtk_widget_system_setting_changed (GTK_WIDGET (window), GTK_SYSTEM_SETTING_DISPLAY);
}
static void

View File

@ -55,7 +55,6 @@ gtk_private_sources = files([
'gtkcssfiltervalue.c',
'gtkcssfontfeaturesvalue.c',
'gtkcssfontvariationsvalue.c',
'gtkcssiconthemevalue.c',
'gtkcssimage.c',
'gtkcssimagecrossfade.c',
'gtkcssimagefallback.c',