diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-04-12 01:04:58 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-04-13 10:40:32 -0400 |
commit | b1038c5d19fb3af858053205608a34480145636e (patch) | |
tree | af7ed2d0db27699a03f14837e9aa4c2170fc2f11 | |
parent | b16b44f1aeb5e37ef69e30bd187110c7a6fa2f4e (diff) | |
download | gtk+-theme-redux.tar.gz |
settings: Add a :theme-change signaltheme-redux
This signal allows applications to intercept and override
what theme gets loaded when the theme settings change.
One possibility is to only load themes from a fixed list
of supported themes. Another is to ignore the user preference
and only load dark themes.
-rw-r--r-- | gtk/gtksettings.c | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c index b1b1a99a9c..5b4aeb0fe3 100644 --- a/gtk/gtksettings.c +++ b/gtk/gtksettings.c @@ -123,6 +123,8 @@ struct _GtkSettings struct _GtkSettingsClass { GObjectClass parent_class; + + char * (* theme_change) (GtkSettings *settings); }; struct _GtkSettingsValuePrivate @@ -138,6 +140,13 @@ struct _GtkSettingsPropertyValue }; enum { + THEME_CHANGE, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; + +enum { PROP_0, PROP_DOUBLE_CLICK_TIME, PROP_DOUBLE_CLICK_DISTANCE, @@ -224,6 +233,7 @@ static void gtk_settings_load_from_key_file (GtkSettings *setting static void settings_update_provider (GdkDisplay *display, GtkCssProvider **old, GtkCssProvider *new); +static char *gtk_settings_theme_change (GtkSettings *settings); /* --- variables --- */ static GQuark quark_gtk_settings = 0; @@ -322,6 +332,8 @@ gtk_settings_class_init (GtkSettingsClass *class) gobject_class->set_property = gtk_settings_set_property; gobject_class->notify = gtk_settings_notify; + class->theme_change = gtk_settings_theme_change; + quark_gtk_settings = g_quark_from_static_string ("gtk-settings"); result = settings_install_property_parser (class, @@ -950,6 +962,33 @@ gtk_settings_class_init (GtkSettingsClass *class) TRUE, GTK_PARAM_READWRITE)); g_assert (result == PROP_OVERLAY_SCROLLING); + + /** + * GtkSettings::theme-change: + * @settings: the #GtkSettings object + * + * The ::theme-change signal is emitted whenever the + * #GtkSettings:gtk-theme-name or #GtkSettings:gtk-user-theme-preference + * settings change. A handler for this signal can inspect the + * values of these properties, and return the name of the theme + * to load. + * + * The default handler will try to find a light or dark variant + * of the theme named by :gtk-theme-name, depending on the value + * of :gtk-user-theme-preference. + * + * Returns: (transfer full): a newly allocated string naming the + * theme to load + */ + signals[THEME_CHANGE] = + g_signal_new (I_("theme-change"), + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (GtkSettingsClass, theme_change), + g_signal_accumulator_first_wins, NULL, + NULL, + G_TYPE_STRING, 0); + } static GtkSettings * @@ -966,6 +1005,7 @@ gtk_settings_provider_iface_init (GtkStyleProviderInterface *iface) static void gtk_settings_finalize (GObject *object) + { GtkSettings *settings = GTK_SETTINGS (object); guint i; @@ -1637,7 +1677,7 @@ settings_update_provider (GdkDisplay *display, */ static char * -get_theme_name (GtkSettings *settings) +gtk_settings_theme_change (GtkSettings *settings) { char *theme_name = NULL; char *theme; @@ -1675,11 +1715,11 @@ get_theme_name (GtkSettings *settings) static void settings_update_theme (GtkSettings *settings) { - gchar *theme_name; - const gchar *theme_dir; - gchar *path; + char *theme_name; + const char *theme_dir; + char *path; - theme_name = get_theme_name (settings); + g_signal_emit (settings, signals[THEME_CHANGE], 0, &theme_name); gtk_css_provider_load_named (settings->theme_provider, theme_name); |