[gtk/wip/otte/css: 301/307] css: Get the GtkSettings from the root
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/css: 301/307] css: Get the GtkSettings from the root
- Date: Tue, 18 Feb 2020 20:05:12 +0000 (UTC)
commit cdbc80ed6abb50422823f5c8100fb1e0f9fd6f22
Author: Benjamin Otte <otte redhat com>
Date: Sun Feb 9 22:21:04 2020 +0100
css: Get the GtkSettings from the root
... instead of providing it via the style provider.
As a side effect, GtkSettings no longer needs to implement
GtkStyleProvider.
gtk/gtkcssiconthemevalue.c | 11 +++++++--
gtk/gtkcssinitialvalue.c | 12 +++++++---
gtk/gtkcssstaticstyle.c | 19 +++++----------
gtk/gtksettings.c | 54 +++++++++++++++++++++----------------------
gtk/gtkstylecascade.c | 25 --------------------
gtk/gtkstyleprovider.c | 15 ------------
gtk/gtkstyleproviderprivate.h | 2 --
7 files changed, 50 insertions(+), 88 deletions(-)
---
diff --git a/gtk/gtkcssiconthemevalue.c b/gtk/gtkcssiconthemevalue.c
index 55f90f18b3..092f7403da 100644
--- a/gtk/gtkcssiconthemevalue.c
+++ b/gtk/gtkcssiconthemevalue.c
@@ -20,9 +20,10 @@
#include "gtkcssiconthemevalueprivate.h"
#include "gtkicontheme.h"
+#include "gtkintl.h"
#include "gtksettingsprivate.h"
#include "gtkstyleproviderprivate.h"
-#include "gtkintl.h"
+#include "gtkwidget.h"
/*
* The idea behind this value (and the '-gtk-icon-theme' CSS property) is
@@ -79,11 +80,17 @@ gtk_css_value_icon_theme_compute (GtkCssValue *icon_theme,
GtkCssStyle *parent_style)
{
GtkIconTheme *icontheme;
+ GdkDisplay *display;
+
+ if (root)
+ display = gtk_widget_get_display (root);
+ else
+ display = gdk_display_get_default ();
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)));
+ icontheme = gtk_icon_theme_get_for_display (display);
return gtk_css_icon_theme_value_new (icontheme);
}
diff --git a/gtk/gtkcssinitialvalue.c b/gtk/gtkcssinitialvalue.c
index 912fc4f721..dc6aeed402 100644
--- a/gtk/gtkcssinitialvalue.c
+++ b/gtk/gtkcssinitialvalue.c
@@ -24,7 +24,7 @@
#include "gtkcssstringvalueprivate.h"
#include "gtkcssstylepropertyprivate.h"
#include "gtksettingsprivate.h"
-#include "gtkstyleproviderprivate.h"
+#include "gtkwidget.h"
struct _GtkCssValue {
GTK_CSS_VALUE_BASE
@@ -50,7 +50,10 @@ gtk_css_value_initial_compute (GtkCssValue *value,
switch (property_id)
{
case GTK_CSS_PROPERTY_DPI:
- settings = gtk_style_provider_get_settings (provider);
+ if (root)
+ settings = gtk_widget_get_settings (root);
+ else
+ settings = gtk_settings_get_for_display (gdk_display_get_default ());
if (settings)
{
int dpi_int;
@@ -63,7 +66,10 @@ gtk_css_value_initial_compute (GtkCssValue *value,
break;
case GTK_CSS_PROPERTY_FONT_FAMILY:
- settings = gtk_style_provider_get_settings (provider);
+ if (root)
+ settings = gtk_widget_get_settings (root);
+ else
+ settings = gtk_settings_get_for_display (gdk_display_get_default ());
if (settings && gtk_settings_get_font_family (settings) != NULL)
return _gtk_css_string_value_new (gtk_settings_get_font_family (settings));
break;
diff --git a/gtk/gtkcssstaticstyle.c b/gtk/gtkcssstaticstyle.c
index 80923d9620..86b3324bf2 100644
--- a/gtk/gtkcssstaticstyle.c
+++ b/gtk/gtkcssstaticstyle.c
@@ -682,17 +682,11 @@ gtk_css_static_style_set_value (GtkCssStaticStyle *sstyle,
}
}
-static GtkCssStyle *default_style;
-
-static void
-clear_default_style (gpointer data)
-{
- g_set_object (&default_style, NULL);
-}
-
GtkCssStyle *
gtk_css_static_style_get_default (void)
{
+ static GtkCssStyle *default_style = NULL;
+
/* FIXME: This really depends on the screen, but we don't have
* a screen at hand when we call this function, and in practice,
* the default style is always replaced by something else
@@ -701,15 +695,14 @@ gtk_css_static_style_get_default (void)
if (default_style == NULL)
{
GtkCountingBloomFilter filter = GTK_COUNTING_BLOOM_FILTER_INIT;
- GtkSettings *settings;
+ GtkCssProvider *provider;
- settings = gtk_settings_get_default ();
- default_style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER (settings),
+ provider = gtk_css_provider_new ();
+ default_style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER (provider),
&filter,
NULL,
0);
- g_object_set_data_full (G_OBJECT (settings), I_("gtk-default-style"),
- default_style, clear_default_style);
+ g_object_unref (provider);
}
return default_style;
diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c
index 4995fb6cf0..b92773a209 100644
--- a/gtk/gtksettings.c
+++ b/gtk/gtksettings.c
@@ -26,10 +26,10 @@
#include "gtkprivate.h"
#include "gtkscrolledwindow.h"
#include "gtkstylecontext.h"
-#include "gtkstyleproviderprivate.h"
#include "gtktypebuiltins.h"
#include "gtkversion.h"
-#include "gtkwidget.h"
+#include "gtkwidgetprivate.h"
+#include "gtkwindow.h"
#include "gdk/gdk-private.h"
@@ -196,8 +196,6 @@ enum {
};
/* --- prototypes --- */
-static void gtk_settings_provider_iface_init (GtkStyleProviderInterface *iface);
-
static void gtk_settings_finalize (GObject *object);
static void gtk_settings_get_property (GObject *object,
guint property_id,
@@ -238,10 +236,7 @@ static guint class_n_properties = 0;
static GPtrArray *display_settings;
-G_DEFINE_TYPE_EXTENDED (GtkSettings, gtk_settings, G_TYPE_OBJECT, 0,
- G_ADD_PRIVATE (GtkSettings)
- G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
- gtk_settings_provider_iface_init));
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSettings, gtk_settings, G_TYPE_OBJECT);
/* --- functions --- */
static void
@@ -967,18 +962,6 @@ gtk_settings_class_init (GtkSettingsClass *class)
g_assert (result == PROP_OVERLAY_SCROLLING);
}
-static GtkSettings *
-gtk_settings_style_provider_get_settings (GtkStyleProvider *provider)
-{
- return GTK_SETTINGS (provider);
-}
-
-static void
-gtk_settings_provider_iface_init (GtkStyleProviderInterface *iface)
-{
- iface->get_settings = gtk_settings_style_provider_get_settings;
-}
-
static void
gtk_settings_finalize (GObject *object)
{
@@ -1065,10 +1048,6 @@ settings_init_style (GtkSettings *settings)
GTK_STYLE_PROVIDER (css_provider),
GTK_STYLE_PROVIDER_PRIORITY_USER);
- _gtk_style_cascade_add_provider (cascade,
- GTK_STYLE_PROVIDER (settings),
- GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
-
_gtk_style_cascade_add_provider (cascade,
GTK_STYLE_PROVIDER (priv->theme_provider),
GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
@@ -1192,10 +1171,29 @@ gtk_settings_set_property (GObject *object,
priv->property_values[property_id - 1].source = GTK_SETTINGS_SOURCE_APPLICATION;
}
+/* This function exists to avoid roots needing to connect to
+ * GtkSettings::notify to track CSS changes
+ */
static void
-settings_invalidate_style (GtkSettings *settings)
+settings_invalidate_style (GtkSettings *settings,
+ GtkCssChange change)
{
- gtk_style_provider_changed (GTK_STYLE_PROVIDER (settings));
+ GList *list, *toplevels;
+ GdkDisplay *display;
+
+ display = _gtk_settings_get_display (settings);
+ 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_css_node_invalidate (gtk_widget_get_css_node (list->data), change);
+
+ g_object_unref (list->data);
+ }
+
+ g_list_free (toplevels);
}
static void
@@ -1255,8 +1253,7 @@ gtk_settings_notify (GObject *object,
break;
case PROP_FONT_NAME:
settings_update_font_values (settings);
- settings_invalidate_style (settings);
- gtk_style_context_reset_widgets (priv->display);
+ settings_invalidate_style (settings, GTK_CSS_CHANGE_ROOT);
break;
case PROP_THEME_NAME:
case PROP_APPLICATION_PREFER_DARK_THEME:
@@ -1267,6 +1264,7 @@ gtk_settings_notify (GObject *object,
* widgets with gtk_widget_style_set(), and also causes more
* recomputation than necessary.
*/
+ settings_invalidate_style (settings, GTK_CSS_CHANGE_ROOT);
gtk_style_context_reset_widgets (priv->display);
break;
case PROP_XFT_ANTIALIAS:
diff --git a/gtk/gtkstylecascade.c b/gtk/gtkstylecascade.c
index 1871b7073e..f3f57bd7f7 100644
--- a/gtk/gtkstylecascade.c
+++ b/gtk/gtkstylecascade.c
@@ -96,30 +96,6 @@ gtk_style_cascade_iter_clear (GtkStyleCascadeIter *iter)
g_free (iter->cascade_index);
}
-static GtkSettings *
-gtk_style_cascade_get_settings (GtkStyleProvider *provider)
-{
- GtkStyleCascade *cascade = GTK_STYLE_CASCADE (provider);
- GtkStyleCascadeIter iter;
- GtkSettings *settings;
- GtkStyleProvider *item;
-
- for (item = gtk_style_cascade_iter_init (cascade, &iter);
- item;
- item = gtk_style_cascade_iter_next (cascade, &iter))
- {
- settings = gtk_style_provider_get_settings (item);
- if (settings)
- {
- gtk_style_cascade_iter_clear (&iter);
- return settings;
- }
- }
-
- gtk_style_cascade_iter_clear (&iter);
- return NULL;
-}
-
static GtkCssValue *
gtk_style_cascade_get_color (GtkStyleProvider *provider,
const char *name)
@@ -206,7 +182,6 @@ static void
gtk_style_cascade_provider_iface_init (GtkStyleProviderInterface *iface)
{
iface->get_color = gtk_style_cascade_get_color;
- iface->get_settings = gtk_style_cascade_get_settings;
iface->get_scale = gtk_style_cascade_get_scale;
iface->get_keyframes = gtk_style_cascade_get_keyframes;
iface->lookup = gtk_style_cascade_lookup;
diff --git a/gtk/gtkstyleprovider.c b/gtk/gtkstyleprovider.c
index 4bcd241054..6b6c6d2752 100644
--- a/gtk/gtkstyleprovider.c
+++ b/gtk/gtkstyleprovider.c
@@ -123,21 +123,6 @@ gtk_style_provider_changed (GtkStyleProvider *provider)
g_signal_emit (provider, signals[CHANGED], 0);
}
-GtkSettings *
-gtk_style_provider_get_settings (GtkStyleProvider *provider)
-{
- GtkStyleProviderInterface *iface;
-
- gtk_internal_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
-
- iface = GTK_STYLE_PROVIDER_GET_INTERFACE (provider);
-
- if (!iface->get_settings)
- return NULL;
-
- return iface->get_settings (provider);
-}
-
int
gtk_style_provider_get_scale (GtkStyleProvider *provider)
{
diff --git a/gtk/gtkstyleproviderprivate.h b/gtk/gtkstyleproviderprivate.h
index 5ee16e3d00..a665ef81c2 100644
--- a/gtk/gtkstyleproviderprivate.h
+++ b/gtk/gtkstyleproviderprivate.h
@@ -38,7 +38,6 @@ struct _GtkStyleProviderInterface
GtkCssValue * (* get_color) (GtkStyleProvider *provider,
const char *name);
- GtkSettings * (* get_settings) (GtkStyleProvider *provider);
GtkCssKeyframes * (* get_keyframes) (GtkStyleProvider *provider,
const char *name);
int (* get_scale) (GtkStyleProvider *provider);
@@ -54,7 +53,6 @@ struct _GtkStyleProviderInterface
void (* changed) (GtkStyleProvider *provider);
};
-GtkSettings * gtk_style_provider_get_settings (GtkStyleProvider *provider);
GtkCssValue * gtk_style_provider_get_color (GtkStyleProvider *provider,
const char *name);
GtkCssKeyframes * gtk_style_provider_get_keyframes (GtkStyleProvider *provider,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]