st/settings: Use the new high-contrast gsettings key

We now have a dedicated "high-contrast" setting that we can
use instead of a "magic" theme name.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2069>
This commit is contained in:
Alexander Mikhaylenko 2021-12-19 21:29:51 +05:00 committed by Marge Bot
parent ed7fe756ef
commit f67418c682
2 changed files with 44 additions and 34 deletions

View File

@ -156,7 +156,7 @@ function start() {
sessionMode = new SessionMode.SessionMode();
sessionMode.connect('updated', _sessionUpdated);
St.Settings.get().connect('notify::gtk-theme', _loadDefaultStylesheet);
St.Settings.get().connect('notify::high-contrast', _loadDefaultStylesheet);
// Initialize ParentalControlsManager before the UI
ParentalControlsManager.getDefault();
@ -389,9 +389,8 @@ function _getDefaultStylesheet() {
let stylesheet = null;
let name = sessionMode.stylesheetName;
// Look for a high-contrast variant first when using GTK+'s HighContrast
// theme
if (St.Settings.get().gtk_theme == 'HighContrast')
// Look for a high-contrast variant first
if (St.Settings.get().high_contrast)
stylesheet = _getStylesheet(name.replace('.css', '-high-contrast.css'));
if (stylesheet == null)

View File

@ -31,7 +31,7 @@
#define KEY_PRIMARY_PASTE "gtk-enable-primary-paste"
#define KEY_DRAG_THRESHOLD "drag-threshold"
#define KEY_FONT_NAME "font-name"
#define KEY_GTK_THEME "gtk-theme"
#define KEY_HIGH_CONTRAST "high-contrast"
#define KEY_GTK_ICON_THEME "icon-theme"
#define KEY_MAGNIFIER_ACTIVE "screen-magnifier-enabled"
#define KEY_DISABLE_SHOW_PASSWORD "disable-show-password"
@ -42,7 +42,7 @@ enum {
PROP_PRIMARY_PASTE,
PROP_DRAG_THRESHOLD,
PROP_FONT_NAME,
PROP_GTK_THEME,
PROP_HIGH_CONTRAST,
PROP_GTK_ICON_THEME,
PROP_MAGNIFIER_ACTIVE,
PROP_SLOW_DOWN_FACTOR,
@ -57,11 +57,12 @@ struct _StSettings
GObject parent_object;
GSettings *interface_settings;
GSettings *mouse_settings;
GSettings *a11y_settings;
GSettings *a11y_applications_settings;
GSettings *a11y_interface_settings;
GSettings *lockdown_settings;
gchar *font_name;
gchar *gtk_theme;
gboolean high_contrast;
gchar *gtk_icon_theme;
int inhibit_animations_count;
gboolean enable_animations;
@ -129,10 +130,10 @@ st_settings_finalize (GObject *object)
g_object_unref (settings->interface_settings);
g_object_unref (settings->mouse_settings);
g_object_unref (settings->a11y_settings);
g_object_unref (settings->a11y_applications_settings);
g_object_unref (settings->a11y_interface_settings);
g_object_unref (settings->lockdown_settings);
g_free (settings->font_name);
g_free (settings->gtk_theme);
g_free (settings->gtk_icon_theme);
G_OBJECT_CLASS (st_settings_parent_class)->finalize (object);
@ -178,8 +179,8 @@ st_settings_get_property (GObject *object,
case PROP_FONT_NAME:
g_value_set_string (value, settings->font_name);
break;
case PROP_GTK_THEME:
g_value_set_string (value, settings->gtk_theme);
case PROP_HIGH_CONTRAST:
g_value_set_boolean (value, settings->high_contrast);
break;
case PROP_GTK_ICON_THEME:
g_value_set_string (value, settings->gtk_icon_theme);
@ -253,14 +254,14 @@ st_settings_class_init (StSettingsClass *klass)
ST_PARAM_READABLE);
/**
* StSettings:gtk-theme:
* StSettings:high-contrast:
*
* The current GTK theme.
* Whether the accessibility high contrast mode is enabled.
*/
props[PROP_GTK_THEME] = g_param_spec_string ("gtk-theme",
"GTK Theme",
"GTK Theme",
"",
props[PROP_HIGH_CONTRAST] = g_param_spec_boolean ("high-contrast",
"High contrast",
"High contrast",
FALSE,
ST_PARAM_READABLE);
/**
@ -331,12 +332,6 @@ on_interface_settings_changed (GSettings *g_settings,
settings->font_name = g_settings_get_string (g_settings, key);
g_object_notify_by_pspec (G_OBJECT (settings), props[PROP_FONT_NAME]);
}
else if (g_str_equal (key, KEY_GTK_THEME))
{
g_free (settings->gtk_theme);
settings->gtk_theme = g_settings_get_string (g_settings, key);
g_object_notify_by_pspec (G_OBJECT (settings), props[PROP_GTK_THEME]);
}
else if (g_str_equal (key, KEY_GTK_ICON_THEME))
{
g_free (settings->gtk_icon_theme);
@ -359,7 +354,7 @@ on_mouse_settings_changed (GSettings *g_settings,
}
static void
on_a11y_settings_changed (GSettings *g_settings,
on_a11y_applications_settings_changed (GSettings *g_settings,
const gchar *key,
StSettings *settings)
{
@ -370,6 +365,18 @@ on_a11y_settings_changed (GSettings *g_settings,
}
}
static void
on_a11y_interface_settings_changed (GSettings *g_settings,
const gchar *key,
StSettings *settings)
{
if (g_str_equal (key, KEY_HIGH_CONTRAST))
{
settings->high_contrast = g_settings_get_boolean (g_settings, key);
g_object_notify_by_pspec (G_OBJECT (settings), props[PROP_HIGH_CONTRAST]);
}
}
static void
on_lockdown_settings_changed (GSettings *g_settings,
const gchar *key,
@ -393,9 +400,13 @@ st_settings_init (StSettings *settings)
g_signal_connect (settings->interface_settings, "changed",
G_CALLBACK (on_mouse_settings_changed), settings);
settings->a11y_settings = g_settings_new ("org.gnome.desktop.a11y.applications");
g_signal_connect (settings->a11y_settings, "changed",
G_CALLBACK (on_a11y_settings_changed), settings);
settings->a11y_applications_settings = g_settings_new ("org.gnome.desktop.a11y.applications");
g_signal_connect (settings->a11y_applications_settings, "changed",
G_CALLBACK (on_a11y_applications_settings_changed), settings);
settings->a11y_interface_settings = g_settings_new ("org.gnome.desktop.a11y.interface");
g_signal_connect (settings->a11y_interface_settings, "changed",
G_CALLBACK (on_a11y_interface_settings_changed), settings);
settings->lockdown_settings = g_settings_new ("org.gnome.desktop.lockdown");
g_signal_connect (settings->lockdown_settings, "changed",
@ -407,14 +418,14 @@ st_settings_init (StSettings *settings)
KEY_PRIMARY_PASTE);
settings->font_name = g_settings_get_string (settings->interface_settings,
KEY_FONT_NAME);
settings->gtk_theme = g_settings_get_string (settings->interface_settings,
KEY_GTK_THEME);
settings->gtk_icon_theme = g_settings_get_string (settings->interface_settings,
KEY_GTK_ICON_THEME);
settings->drag_threshold = g_settings_get_int (settings->mouse_settings,
KEY_DRAG_THRESHOLD);
settings->magnifier_active = g_settings_get_boolean (settings->a11y_settings,
settings->magnifier_active = g_settings_get_boolean (settings->a11y_applications_settings,
KEY_MAGNIFIER_ACTIVE);
settings->high_contrast = g_settings_get_boolean (settings->a11y_interface_settings,
KEY_HIGH_CONTRAST);
settings->slow_down_factor = 1.;
settings->disable_show_password = g_settings_get_boolean (settings->lockdown_settings, KEY_DISABLE_SHOW_PASSWORD);
}