From 4c727b4680dc5abfe6ffff55f2bde117077ce183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Fri, 3 Jun 2022 17:19:59 +0200 Subject: [PATCH] st/settings: Expose system color scheme This is the same interface setting that backs AdwStyleManager. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5545 Part-of: --- src/st/meson.build | 2 +- src/st/st-settings.c | 27 +++++++++++++++++++++++++++ src/st/st-settings.h | 7 +++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/st/meson.build b/src/st/meson.build index 456860d56..d77e43ba8 100644 --- a/src/st/meson.build +++ b/src/st/meson.build @@ -183,7 +183,7 @@ st_cflags = [ libst = shared_library('st-' + mutter_api_version, sources: st_gir_sources + st_nogir_sources + croco_sources, c_args: st_cflags, - dependencies: [clutter_dep, mutter_dep, libxml_dep, gdk_pixbuf_dep, m_dep], + dependencies: [clutter_dep, mutter_dep, libxml_dep, gdk_pixbuf_dep, m_dep, schemas_dep], build_rpath: mutter_typelibdir, install_rpath: mutter_typelibdir, install_dir: pkglibdir, diff --git a/src/st/st-settings.c b/src/st/st-settings.c index 04bf68f40..790ec6445 100644 --- a/src/st/st-settings.c +++ b/src/st/st-settings.c @@ -26,11 +26,13 @@ #include "st-private.h" #include "st-settings.h" +#include "st-enum-types.h" #define KEY_ENABLE_ANIMATIONS "enable-animations" #define KEY_PRIMARY_PASTE "gtk-enable-primary-paste" #define KEY_DRAG_THRESHOLD "drag-threshold" #define KEY_FONT_NAME "font-name" +#define KEY_COLOR_SCHEME "color-scheme" #define KEY_HIGH_CONTRAST "high-contrast" #define KEY_GTK_ICON_THEME "icon-theme" #define KEY_MAGNIFIER_ACTIVE "screen-magnifier-enabled" @@ -42,6 +44,7 @@ enum { PROP_PRIMARY_PASTE, PROP_DRAG_THRESHOLD, PROP_FONT_NAME, + PROP_COLOR_SCHEME, PROP_HIGH_CONTRAST, PROP_GTK_ICON_THEME, PROP_MAGNIFIER_ACTIVE, @@ -71,6 +74,7 @@ struct _StSettings gboolean disable_show_password; gint drag_threshold; double slow_down_factor; + StSystemColorScheme color_scheme; }; G_DEFINE_TYPE (StSettings, st_settings, G_TYPE_OBJECT) @@ -185,6 +189,9 @@ st_settings_get_property (GObject *object, case PROP_GTK_ICON_THEME: g_value_set_string (value, settings->gtk_icon_theme); break; + case PROP_COLOR_SCHEME: + g_value_set_enum (value, settings->color_scheme); + break; case PROP_MAGNIFIER_ACTIVE: g_value_set_boolean (value, settings->magnifier_active); break; @@ -275,6 +282,18 @@ st_settings_class_init (StSettingsClass *klass) "", ST_PARAM_READABLE); + /** + * StSettings:color-scheme: + * + * The preferred color-scheme + */ + props[PROP_COLOR_SCHEME] = g_param_spec_enum ("color-scheme", + "Color scheme", + "Color scheme", + ST_TYPE_SYSTEM_COLOR_SCHEME, + ST_SYSTEM_COLOR_SCHEME_DEFAULT, + ST_PARAM_READABLE); + /** * StSettings:magnifier-active: * @@ -339,6 +358,12 @@ on_interface_settings_changed (GSettings *g_settings, g_object_notify_by_pspec (G_OBJECT (settings), props[PROP_GTK_ICON_THEME]); } + else if (g_str_equal (key, KEY_COLOR_SCHEME)) + { + settings->color_scheme = g_settings_get_enum (g_settings, key); + g_object_notify_by_pspec (G_OBJECT (settings), + props[PROP_COLOR_SCHEME]); + } } static void @@ -422,6 +447,8 @@ st_settings_init (StSettings *settings) KEY_FONT_NAME); settings->gtk_icon_theme = g_settings_get_string (settings->interface_settings, KEY_GTK_ICON_THEME); + settings->color_scheme = g_settings_get_enum (settings->interface_settings, + KEY_COLOR_SCHEME); settings->drag_threshold = g_settings_get_int (settings->mouse_settings, KEY_DRAG_THRESHOLD); settings->magnifier_active = g_settings_get_boolean (settings->a11y_applications_settings, diff --git a/src/st/st-settings.h b/src/st/st-settings.h index 8b2549469..f12c4b5da 100644 --- a/src/st/st-settings.h +++ b/src/st/st-settings.h @@ -25,9 +25,16 @@ #define __ST_SETTINGS_H__ #include +#include G_BEGIN_DECLS +typedef enum { + ST_SYSTEM_COLOR_SCHEME_DEFAULT = G_DESKTOP_COLOR_SCHEME_DEFAULT, + ST_SYSTEM_COLOR_SCHEME_PREFER_DARK = G_DESKTOP_COLOR_SCHEME_PREFER_DARK, + ST_SYSTEM_COLOR_SCHEME_PREFER_LIGHT = G_DESKTOP_COLOR_SCHEME_PREFER_LIGHT, +} StSystemColorScheme; + #define ST_TYPE_SETTINGS (st_settings_get_type ()) G_DECLARE_FINAL_TYPE (StSettings, st_settings, ST, SETTINGS, GObject)