forked from AuroraMiddleware/gtk
settings: Cache style properties
This way we don't need to compute them every lookup. (That's not the real reason though - the real reason is that I want to add new APIs that require the caching because they return consts).
This commit is contained in:
parent
524938aa53
commit
45161fbb55
@ -110,6 +110,7 @@ struct _GtkSettingsPrivate
|
|||||||
GdkScreen *screen;
|
GdkScreen *screen;
|
||||||
GtkCssProvider *theme_provider;
|
GtkCssProvider *theme_provider;
|
||||||
GtkCssProvider *key_theme_provider;
|
GtkCssProvider *key_theme_provider;
|
||||||
|
GtkStyleProperties *style;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
@ -1348,19 +1349,19 @@ gtk_settings_class_init (GtkSettingsClass *class)
|
|||||||
g_type_class_add_private (class, sizeof (GtkSettingsPrivate));
|
g_type_class_add_private (class, sizeof (GtkSettingsPrivate));
|
||||||
}
|
}
|
||||||
|
|
||||||
static GtkStyleProperties *
|
static void
|
||||||
gtk_settings_get_style (GtkStyleProvider *provider,
|
settings_ensure_style (GtkSettings *settings)
|
||||||
GtkWidgetPath *path)
|
|
||||||
{
|
{
|
||||||
|
GtkSettingsPrivate *priv = settings->priv;
|
||||||
PangoFontDescription *font_desc;
|
PangoFontDescription *font_desc;
|
||||||
gchar *font_name, *color_scheme;
|
gchar *font_name, *color_scheme;
|
||||||
GtkSettings *settings;
|
|
||||||
GtkStyleProperties *props;
|
|
||||||
gchar **colors;
|
gchar **colors;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
settings = GTK_SETTINGS (provider);
|
if (priv->style)
|
||||||
props = gtk_style_properties_new ();
|
return;
|
||||||
|
|
||||||
|
priv->style = gtk_style_properties_new ();
|
||||||
|
|
||||||
g_object_get (settings,
|
g_object_get (settings,
|
||||||
"gtk-font-name", &font_name,
|
"gtk-font-name", &font_name,
|
||||||
@ -1396,7 +1397,7 @@ gtk_settings_get_style (GtkStyleProvider *provider,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
color = gtk_symbolic_color_new_literal (&col);
|
color = gtk_symbolic_color_new_literal (&col);
|
||||||
gtk_style_properties_map_color (props, name, color);
|
gtk_style_properties_map_color (priv->style, name, color);
|
||||||
gtk_symbolic_color_unref (color);
|
gtk_symbolic_color_unref (color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1420,7 +1421,7 @@ gtk_settings_get_style (GtkStyleProvider *provider,
|
|||||||
pango_font_description_unset_fields (font_desc,
|
pango_font_description_unset_fields (font_desc,
|
||||||
PANGO_FONT_MASK_STYLE);
|
PANGO_FONT_MASK_STYLE);
|
||||||
|
|
||||||
gtk_style_properties_set (props, 0,
|
gtk_style_properties_set (priv->style, 0,
|
||||||
"font", font_desc,
|
"font", font_desc,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
@ -1428,8 +1429,19 @@ gtk_settings_get_style (GtkStyleProvider *provider,
|
|||||||
g_strfreev (colors);
|
g_strfreev (colors);
|
||||||
g_free (color_scheme);
|
g_free (color_scheme);
|
||||||
g_free (font_name);
|
g_free (font_name);
|
||||||
|
}
|
||||||
|
|
||||||
return props;
|
static GtkStyleProperties *
|
||||||
|
gtk_settings_get_style (GtkStyleProvider *provider,
|
||||||
|
GtkWidgetPath *path)
|
||||||
|
{
|
||||||
|
GtkSettings *settings;
|
||||||
|
|
||||||
|
settings = GTK_SETTINGS (provider);
|
||||||
|
|
||||||
|
settings_ensure_style (settings);
|
||||||
|
|
||||||
|
return g_object_ref (settings->priv->style);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1459,6 +1471,9 @@ gtk_settings_finalize (GObject *object)
|
|||||||
if (priv->key_theme_provider)
|
if (priv->key_theme_provider)
|
||||||
g_object_unref (priv->key_theme_provider);
|
g_object_unref (priv->key_theme_provider);
|
||||||
|
|
||||||
|
if (priv->style)
|
||||||
|
g_object_unref (priv->style);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
|
G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1668,6 +1683,18 @@ gtk_settings_get_property (GObject *object,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
settings_invalidate_style (GtkSettings *settings)
|
||||||
|
{
|
||||||
|
GtkSettingsPrivate *priv = settings->priv;
|
||||||
|
|
||||||
|
if (priv->style)
|
||||||
|
{
|
||||||
|
g_object_unref (priv->style);
|
||||||
|
priv->style = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_settings_notify (GObject *object,
|
gtk_settings_notify (GObject *object,
|
||||||
GParamSpec *pspec)
|
GParamSpec *pspec)
|
||||||
@ -1690,9 +1717,11 @@ gtk_settings_notify (GObject *object,
|
|||||||
break;
|
break;
|
||||||
case PROP_COLOR_SCHEME:
|
case PROP_COLOR_SCHEME:
|
||||||
settings_update_color_scheme (settings);
|
settings_update_color_scheme (settings);
|
||||||
|
settings_invalidate_style (settings);
|
||||||
gtk_style_context_reset_widgets (priv->screen);
|
gtk_style_context_reset_widgets (priv->screen);
|
||||||
break;
|
break;
|
||||||
case PROP_FONT_NAME:
|
case PROP_FONT_NAME:
|
||||||
|
settings_invalidate_style (settings);
|
||||||
gtk_style_context_reset_widgets (priv->screen);
|
gtk_style_context_reset_widgets (priv->screen);
|
||||||
break;
|
break;
|
||||||
case PROP_KEY_THEME_NAME:
|
case PROP_KEY_THEME_NAME:
|
||||||
|
Loading…
Reference in New Issue
Block a user