From fe454591389697d99337e5c00155db9f33da29e7 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 1/3] st/settings: Expose system color scheme This is the same interface setting that backs AdwStyleManager. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5545 --- src/st/meson.build | 2 +- src/st/st-settings.c | 28 ++++++++++++++++++++++++++++ src/st/st-settings.h | 7 +++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/st/meson.build b/src/st/meson.build index 717aa05887..e389f8a2d9 100644 --- a/src/st/meson.build +++ b/src/st/meson.build @@ -180,7 +180,7 @@ st_cflags = [ libst = shared_library('st-1.0', sources: st_gir_sources + st_nogir_sources + croco_sources, c_args: st_cflags, - dependencies: [clutter_dep, gtk_dep, mutter_dep, libxml_dep, m_dep], + dependencies: [clutter_dep, gtk_dep, mutter_dep, libxml_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 839171b8a0..6c0b3b393d 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,13 @@ 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_warning ("%d", settings->color_scheme); + g_object_notify_by_pspec (G_OBJECT (settings), + props[PROP_COLOR_SCHEME]); + } } static void @@ -422,6 +448,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 8b25494699..f12c4b5da0 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) -- GitLab From 09f8f5e0de374ac12bb4bd52012af3e8ce7929c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Fri, 3 Jun 2022 16:15:38 +0200 Subject: [PATCH 2/3] theme: Include both dark and light variant in resource This will allow us to switch between the variants according to the color-scheme setting. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5545 --- data/gnome-shell-theme.gresource.xml | 3 ++- data/theme/{gnome-shell.scss => gnome-shell-dark.scss} | 0 data/theme/gnome-shell-light.scss | 6 ++++++ data/theme/meson.build | 6 ++++-- js/ui/sessionMode.js | 2 +- meson/generate-stylesheets.py | 3 ++- 6 files changed, 15 insertions(+), 5 deletions(-) rename data/theme/{gnome-shell.scss => gnome-shell-dark.scss} (100%) create mode 100644 data/theme/gnome-shell-light.scss diff --git a/data/gnome-shell-theme.gresource.xml b/data/gnome-shell-theme.gresource.xml index 24b3be8dbb..8a4948e41b 100644 --- a/data/gnome-shell-theme.gresource.xml +++ b/data/gnome-shell-theme.gresource.xml @@ -9,7 +9,8 @@ checkbox-off-focused.svg checkbox-off-light.svg checkbox-off.svg - gnome-shell.css + gnome-shell-dark.css + gnome-shell-light.css gnome-shell-high-contrast.css gnome-shell-start.svg pad-osd.css diff --git a/data/theme/gnome-shell.scss b/data/theme/gnome-shell-dark.scss similarity index 100% rename from data/theme/gnome-shell.scss rename to data/theme/gnome-shell-dark.scss diff --git a/data/theme/gnome-shell-light.scss b/data/theme/gnome-shell-light.scss new file mode 100644 index 0000000000..ae6fce7ddd --- /dev/null +++ b/data/theme/gnome-shell-light.scss @@ -0,0 +1,6 @@ +$variant: 'light'; + +@import "gnome-shell-sass/_colors"; //use gtk colors +@import "gnome-shell-sass/_drawing"; +@import "gnome-shell-sass/_common"; +@import "gnome-shell-sass/_widgets"; diff --git a/data/theme/meson.build b/data/theme/meson.build index 26471b6792..b9d283f372 100644 --- a/data/theme/meson.build +++ b/data/theme/meson.build @@ -1,6 +1,7 @@ theme_sources = files([ 'gnome-shell-high-contrast.scss', - 'gnome-shell.scss', + 'gnome-shell-dark.scss', + 'gnome-shell-light.scss', 'gnome-shell-sass/_colors.scss', 'gnome-shell-sass/_common.scss', 'gnome-shell-sass/_drawing.scss', @@ -44,7 +45,8 @@ theme_sources = files([ stylesheets = [ 'gnome-shell-high-contrast.css', - 'gnome-shell.css' + 'gnome-shell-dark.css', + 'gnome-shell-light.css', ] foreach stylesheet: stylesheets diff --git a/js/ui/sessionMode.js b/js/ui/sessionMode.js index b8b627370d..c047c94056 100644 --- a/js/ui/sessionMode.js +++ b/js/ui/sessionMode.js @@ -22,7 +22,7 @@ if (Config.HAVE_NETWORKMANAGER) const _modes = { 'restrictive': { parentMode: null, - stylesheetName: 'gnome-shell.css', + stylesheetName: 'gnome-shell-dark.css', themeResourceName: 'gnome-shell-theme.gresource', hasOverview: false, showCalendarEvents: false, diff --git a/meson/generate-stylesheets.py b/meson/generate-stylesheets.py index bd6b641b8e..10e65b7569 100644 --- a/meson/generate-stylesheets.py +++ b/meson/generate-stylesheets.py @@ -6,7 +6,8 @@ import subprocess stylesheets = [ 'data/theme/gnome-shell-high-contrast.css', - 'data/theme/gnome-shell.css' + 'data/theme/gnome-shell-dark.css', + 'data/theme/gnome-shell-light.css' ] sourceroot = os.environ.get('MESON_SOURCE_ROOT') -- GitLab From 882f4d932ac67a653fc979407a29fb473424120f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Fri, 3 Jun 2022 17:21:08 +0200 Subject: [PATCH 3/3] main: Consider color-scheme setting for default stylesheet Our own preference - equivalent to AdwStyleManager's color-scheme property - is expressed via a new session mode property. The default mode uses 'prefer-dark', gnome-classic is expected to use 'force-light'. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5545 --- js/ui/main.js | 25 ++++++++++++++++++++++++- js/ui/sessionMode.js | 3 ++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/js/ui/main.js b/js/ui/main.js index d1a2076f66..e7d567da81 100644 --- a/js/ui/main.js +++ b/js/ui/main.js @@ -159,6 +159,7 @@ function start() { sessionMode.connect('updated', _sessionUpdated); St.Settings.get().connect('notify::high-contrast', _loadDefaultStylesheet); + St.Settings.get().connect('notify::color-scheme', _loadDefaultStylesheet); // Initialize ParentalControlsManager before the UI ParentalControlsManager.getDefault(); @@ -388,6 +389,25 @@ function _getStylesheet(name) { return null; } +/** @returns {string} */ +function _getStyleVariant() { + const { colorScheme } = St.Settings.get(); + switch (sessionMode.colorScheme) { + case 'force-dark': + return 'dark'; + case 'force-light': + return 'light'; + case 'prefer-dark': + return colorScheme === St.SystemColorScheme.PREFER_LIGHT + ? 'light' : 'dark'; + case 'prefer-light': + return colorScheme === St.SystemColorScheme.PREFER_DARK + ? 'dark' : 'light'; + default: + return ''; + } +} + function _getDefaultStylesheet() { let stylesheet = null; let name = sessionMode.stylesheetName; @@ -396,8 +416,11 @@ function _getDefaultStylesheet() { if (St.Settings.get().high_contrast) stylesheet = _getStylesheet(name.replace('.css', '-high-contrast.css')); + if (stylesheet === null) + stylesheet = _getStylesheet(name.replace('.css', `-${_getStyleVariant()}.css`)); + if (stylesheet == null) - stylesheet = _getStylesheet(sessionMode.stylesheetName); + stylesheet = _getStylesheet(name); return stylesheet; } diff --git a/js/ui/sessionMode.js b/js/ui/sessionMode.js index c047c94056..4c20bf5811 100644 --- a/js/ui/sessionMode.js +++ b/js/ui/sessionMode.js @@ -22,7 +22,8 @@ if (Config.HAVE_NETWORKMANAGER) const _modes = { 'restrictive': { parentMode: null, - stylesheetName: 'gnome-shell-dark.css', + stylesheetName: 'gnome-shell.css', + colorScheme: 'prefer-dark', themeResourceName: 'gnome-shell-theme.gresource', hasOverview: false, showCalendarEvents: false, -- GitLab