[gtk/theme-redux] settings: Add a :theme-change signal
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/theme-redux] settings: Add a :theme-change signal
- Date: Sun, 12 Apr 2020 05:07:02 +0000 (UTC)
commit 5d94b1a5a97983a1f1384beec63bbca4c83447f2
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Apr 12 01:04:58 2020 -0400
settings: Add a :theme-change signal
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.
gtk/gtksettings.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-----
1 file 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
@@ -137,6 +139,13 @@ struct _GtkSettingsPropertyValue
GtkSettingsSource source;
};
+enum {
+ THEME_CHANGE,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
enum {
PROP_0,
PROP_DOUBLE_CLICK_TIME,
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]