[gtk: 1/2] gdk/wayland: Support new `high-contrast` key




commit 49589e1da180a0070124ca69234673e18ce1f635
Author: Florian Müllner <fmuellner gnome org>
Date:   Mon Dec 20 19:10:35 2021 +0100

    gdk/wayland: Support new `high-contrast` key
    
    We now have a boolean setting that determines whether the high-contrast
    theme should be used. Support it by automatically setting the existing
    `gtk-theme-name` and `gtk-icon-theme-name` properties when enabled.
    
    With that, it is no longer necessary to change the regular theme settings
    for high-contrast, so toggling between high-contrast and a non-default
    theme finally works reliably.

 gdk/wayland/gdkdisplay-wayland.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
---
diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c
index a277954832..1b6f728f06 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -1662,6 +1662,7 @@ static TranslationEntry translations[] = {
   { FALSE, "org.gnome.desktop.wm.preferences", "action-middle-click-titlebar", "gtk-titlebar-middle-click", 
G_TYPE_STRING, { .s = "none" } },
   { FALSE, "org.gnome.desktop.wm.preferences", "action-right-click-titlebar", "gtk-titlebar-right-click", 
G_TYPE_STRING, { .s = "menu" } },
   { FALSE, "org.gnome.desktop.a11y", "always-show-text-caret", "gtk-keynav-use-caret", G_TYPE_BOOLEAN, { .b 
= FALSE } },
+  { FALSE, "org.gnome.desktop.a11y.interface", "high-contrast", "high-contast", G_TYPE_NONE, { .b = FALSE } 
},
   /* Note, this setting doesn't exist, the portal and gsd fake it */
   { FALSE, "org.gnome.fontconfig", "serial", "gtk-fontconfig-timestamp", G_TYPE_NONE, { .i = 0 } },
 };
@@ -1711,6 +1712,13 @@ find_translation_entry_by_setting (const char *setting)
   return NULL;
 }
 
+static void
+high_contrast_changed (GdkDisplay *display)
+{
+  gdk_display_setting_changed (display, "gtk-theme-name");
+  gdk_display_setting_changed (display, "gtk-icon-theme-name");
+}
+
 static void
 settings_changed (GSettings  *settings,
                   const char *key,
@@ -1724,6 +1732,8 @@ settings_changed (GSettings  *settings,
     {
       if (entry->type != G_TYPE_NONE)
         gdk_display_setting_changed (display, entry->setting);
+      else if (strcmp (key, "high-contrast") == 0)
+        high_contrast_changed (display);
       else
         update_xft_settings (display);
     }
@@ -2090,6 +2100,32 @@ set_decoration_layout_from_entry (GdkDisplay       *display,
     }
 }
 
+static void
+set_theme_from_entry (GdkDisplay       *display,
+                      TranslationEntry *entry,
+                      GValue           *value)
+{
+  GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
+  GSettings *settings = NULL;
+  GSettingsSchema *schema = NULL;
+  gboolean hc = FALSE;
+
+  settings = (GSettings *)g_hash_table_lookup (display_wayland->settings, 
"org.gnome.desktop.a11y.interface");
+
+  if (settings)
+    g_object_get (settings, "settings-schema", &schema, NULL);
+
+  if (schema && g_settings_schema_has_key (schema, "high-contrast"))
+    hc = g_settings_get_boolean (settings, "high-contrast");
+
+  g_clear_pointer (&schema, g_settings_schema_unref);
+
+  if (hc)
+    g_value_set_static_string (value, "HighContrast");
+  else
+    set_value_from_entry (display, entry, value);
+}
+
 static gboolean
 set_capability_setting (GdkDisplay                *display,
                         GValue                    *value,
@@ -2121,6 +2157,9 @@ gdk_wayland_display_get_setting (GdkDisplay *display,
     {
       if (strcmp (name, "gtk-decoration-layout") == 0)
         set_decoration_layout_from_entry (display, entry, value);
+      else if (strcmp (name, "gtk-theme-name") == 0 ||
+               strcmp (name, "gtk-icon-theme-name") == 0)
+        set_theme_from_entry (display, entry, value);
       else
         set_value_from_entry (display, entry, value);
       return TRUE;


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