[gnome-shell/wip/exalm/dark: 1/2] Use the new high-contrast gsettings key




commit 2a974446397a76e8a129ebb38a19a54b03f5090e
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Dec 12 23:27:58 2021 +0500

    Use the new high-contrast gsettings key

 js/ui/main.js                 |  7 ++---
 js/ui/status/accessibility.js | 33 ++++++++------------
 src/st/st-settings.c          | 71 +++++++++++++++++++++++++------------------
 3 files changed, 56 insertions(+), 55 deletions(-)
---
diff --git a/js/ui/main.js b/js/ui/main.js
index ab97c6cc37..31bdfed44e 100644
--- a/js/ui/main.js
+++ b/js/ui/main.js
@@ -154,7 +154,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();
@@ -385,9 +385,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)
diff --git a/js/ui/status/accessibility.js b/js/ui/status/accessibility.js
index a0513f68c8..fddc0caeb4 100644
--- a/js/ui/status/accessibility.js
+++ b/js/ui/status/accessibility.js
@@ -27,6 +27,9 @@ const KEY_GTK_THEME                 = 'gtk-theme';
 const KEY_ICON_THEME                = 'icon-theme';
 const KEY_TEXT_SCALING_FACTOR       = 'text-scaling-factor';
 
+const A11Y_INTERFACE_SCHEMA         = 'org.gnome.desktop.a11y.interface';
+const KEY_HIGH_CONTRAST             = 'high-contrast';
+
 const HIGH_CONTRAST_THEME           = 'HighContrast';
 
 var ATIndicator = GObject.registerClass(
@@ -127,45 +130,33 @@ class ATIndicator extends PanelMenu.Button {
 
     _buildHCItem() {
         let interfaceSettings = new Gio.Settings({ schema_id: DESKTOP_INTERFACE_SCHEMA });
-        let gtkTheme = interfaceSettings.get_string(KEY_GTK_THEME);
-        let iconTheme = interfaceSettings.get_string(KEY_ICON_THEME);
-        let hasHC = gtkTheme == HIGH_CONTRAST_THEME;
+        let a11ySettings = new Gio.Settings({ schema_id: A11Y_INTERFACE_SCHEMA });
+        let hc = a11ySettings.get_boolean(KEY_HIGH_CONTRAST);
         let highContrast = this._buildItemExtended(
             _("High Contrast"),
-            hasHC,
+            hc,
+            a11ySettings.is_writable(KEY_HIGH_CONTRAST) &&
             interfaceSettings.is_writable(KEY_GTK_THEME) &&
             interfaceSettings.is_writable(KEY_ICON_THEME),
             enabled => {
                 if (enabled) {
+                    a11ySettings.set_boolean(KEY_HIGH_CONTRAST, enabled);
                     interfaceSettings.set_string(KEY_ICON_THEME, HIGH_CONTRAST_THEME);
                     interfaceSettings.set_string(KEY_GTK_THEME, HIGH_CONTRAST_THEME);
-                } else if (!hasHC) {
-                    interfaceSettings.set_string(KEY_ICON_THEME, iconTheme);
-                    interfaceSettings.set_string(KEY_GTK_THEME, gtkTheme);
                 } else {
+                    a11ySettings.reset(KEY_HIGH_CONTRAST);
                     interfaceSettings.reset(KEY_ICON_THEME);
                     interfaceSettings.reset(KEY_GTK_THEME);
                 }
             });
 
-        interfaceSettings.connect('changed::%s'.format(KEY_GTK_THEME), () => {
-            let value = interfaceSettings.get_string(KEY_GTK_THEME);
-            if (value == HIGH_CONTRAST_THEME) {
-                highContrast.setToggleState(true);
-            } else {
-                highContrast.setToggleState(false);
-                gtkTheme = value;
-            }
+        a11ySettings.connect('changed::%s'.format(KEY_HIGH_CONTRAST), () => {
+            hc = a11ySettings.get_boolean(KEY_HIGH_CONTRAST);
+            highContrast.setToggleState(hc);
 
             this._queueSyncMenuVisibility();
         });
 
-        interfaceSettings.connect('changed::%s'.format(KEY_ICON_THEME), () => {
-            let value = interfaceSettings.get_string(KEY_ICON_THEME);
-            if (value != HIGH_CONTRAST_THEME)
-                iconTheme = value;
-        });
-
         return highContrast;
     }
 
diff --git a/src/st/st-settings.c b/src/st/st-settings.c
index f4ca4a5a68..4a198758bf 100644
--- a/src/st/st-settings.c
+++ b/src/st/st-settings.c
@@ -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,15 +254,15 @@ 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",
-                                               "",
-                                               ST_PARAM_READABLE);
+  props[PROP_HIGH_CONTRAST] = g_param_spec_boolean ("high-contrast",
+                                                    "High contrast",
+                                                    "High contrast",
+                                                    FALSE,
+                                                    ST_PARAM_READABLE);
 
   /**
    * StSettings:gtk-icon-theme:
@@ -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,9 +354,9 @@ on_mouse_settings_changed (GSettings   *g_settings,
 }
 
 static void
-on_a11y_settings_changed (GSettings   *g_settings,
-                          const gchar *key,
-                          StSettings  *settings)
+on_a11y_applications_settings_changed (GSettings   *g_settings,
+                                       const gchar *key,
+                                       StSettings  *settings)
 {
   if (g_str_equal (key, KEY_MAGNIFIER_ACTIVE))
     {
@@ -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);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]