From b9740163280c872f2af1c43e271b1469a6fc8b0a Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Sun, 17 Sep 2023 00:33:31 +0200 Subject: data/org.ArcticaProject.arctica-greeter.gschema.xml: Switch from HighContrastInverse to HighContrast as default GTK+ theme. --- data/org.ArcticaProject.arctica-greeter.gschema.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/org.ArcticaProject.arctica-greeter.gschema.xml b/data/org.ArcticaProject.arctica-greeter.gschema.xml index b8085af..018cebb 100644 --- a/data/org.ArcticaProject.arctica-greeter.gschema.xml +++ b/data/org.ArcticaProject.arctica-greeter.gschema.xml @@ -90,7 +90,7 @@ GTK+ theme to use - 'HighContrastInverse' + 'HighContrast' GTK+ theme to use in high contrast mode -- cgit v1.2.3 From c57a53ea271175876ab86ad4ca7549d5d8e371c2 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Sun, 17 Sep 2023 00:35:32 +0200 Subject: src/settings.vala: Introduce 'high-contrast-icon-theme-name' gsetting and toggle icon theme if a11y indicator's high contrast switch gets toggled. --- data/org.ArcticaProject.arctica-greeter.gschema.xml | 4 ++++ src/settings.vala | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/data/org.ArcticaProject.arctica-greeter.gschema.xml b/data/org.ArcticaProject.arctica-greeter.gschema.xml index 018cebb..dad830a 100644 --- a/data/org.ArcticaProject.arctica-greeter.gschema.xml +++ b/data/org.ArcticaProject.arctica-greeter.gschema.xml @@ -97,6 +97,10 @@ 'Numix' Icon theme to use + + 'HighContrast' + Icon theme to use in high contrast mode + 'default' Cursor theme to use diff --git a/src/settings.vala b/src/settings.vala index 7e8306d..67154e9 100644 --- a/src/settings.vala +++ b/src/settings.vala @@ -38,6 +38,7 @@ public class AGSettings : Object public const string KEY_THEME_NAME = "theme-name"; public const string KEY_HIGH_CONTRAST_THEME_NAME = "high-contrast-theme-name"; public const string KEY_ICON_THEME_NAME = "icon-theme-name"; + public const string KEY_HIGH_CONTRAST_ICON_THEME_NAME = "high-contrast-icon-theme-name"; public const string KEY_CURSOR_THEME_NAME = "cursor-theme-name"; public const string KEY_CURSOR_THEME_SIZE = "cursor-theme-size"; public const string KEY_FONT_NAME = "font-name"; @@ -164,17 +165,17 @@ public class AGSettings : Object var settings = Gtk.Settings.get_default (); if (value) { - /* debug ("Switching GTK Theme to high contrast theme \"%s\"", AGSettings.get_string (AGSettings.KEY_HIGH_CONTRAST_THEME_NAME)); - */ + debug ("Switching icon theme to high contrast theme \"%s\"", AGSettings.get_string (AGSettings.KEY_HIGH_CONTRAST_ICON_THEME_NAME)); settings.set ("gtk-theme-name", AGSettings.get_string (AGSettings.KEY_HIGH_CONTRAST_THEME_NAME)); + settings.set ("gtk-icon-theme-name", AGSettings.get_string (AGSettings.KEY_HIGH_CONTRAST_ICON_THEME_NAME)); } else { - /* debug ("Switching GTK Theme to default theme \"%s\"", this.default_theme_name_); - */ + debug ("Switching icon theme to default icon theme \"%s\"", AGSettings.get_string (AGSettings.KEY_ICON_THEME_NAME)); settings.set ("gtk-theme-name", this.default_theme_name_); + settings.set ("gtk-icon-theme-name", AGSettings.get_string (AGSettings.KEY_ICON_THEME_NAME)); } } } -- cgit v1.2.3 From f2f92d4da533b047174fa9d8a90303003a6c2d51 Mon Sep 17 00:00:00 2001 From: Mihai Moldovan Date: Tue, 19 Sep 2023 15:36:13 +0200 Subject: src/settings.vala: remove default_theme_name_ private variable. This functionality doesn't make sense, for two reasons: - If we query the gtk-theme-name property before setting anything else, we will certainly get the default theme name. But that is hardcoded in GTK and not exactly secret. It can't be configured directly, only by changing specific macros in GTK's source code and recompiling it. The chances of someone doing that are... very small. Thus, we can also just hardcode "Adwaita" in AG. - If we query the gtk-theme-name property after setting it to a different value... we will fetch the value we just set. That's totally useless. My initial idea was that GTK is doing some input sanitization on the provided theme name and handles an invalid name by falling back to its built-in default and setting the gtk-theme-name property to this built-in default as well. This, however, is not true. Setting an invalid theme name will just mean that GTK will fail loading the new theme and stay on whatever theme it was before, copying the new value to the gtk-theme-name property regardless. Unfortunately, querying the property is not something we could use for error handling, which makes it completely useless. It's better to just get rid of this. --- src/settings.vala | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/settings.vala b/src/settings.vala index 67154e9..5c7c10f 100644 --- a/src/settings.vala +++ b/src/settings.vala @@ -141,10 +141,19 @@ public class AGSettings : Object } construct { - Gtk.Settings.get_default ().get ("gtk-theme-name", out this.default_theme_name_); /* - debug ("Fetched default theme name in construct: %s", this.default_theme_name_); - */ + * This function is currently empty, but we'll keep it around, + * including this comment, because it's important to know what to do + * with it if it's needed. + * + * Since AGSettings is a SingleInstance class, this function will only + * be called once, as long as we make sure to create an instance early + * in the program cycle and keep a reference to it for the rest of its + * execution. + * + * In case you need to execute code once, whenever the first AGSettings + * instance is created, do it here. + */ } public bool high_contrast { @@ -172,9 +181,9 @@ public class AGSettings : Object } else { - debug ("Switching GTK Theme to default theme \"%s\"", this.default_theme_name_); + debug ("Switching GTK Theme to default theme \"%s\"", AGSettings.get_string (AGSettings.KEY_THEME_NAME)); debug ("Switching icon theme to default icon theme \"%s\"", AGSettings.get_string (AGSettings.KEY_ICON_THEME_NAME)); - settings.set ("gtk-theme-name", this.default_theme_name_); + settings.set ("gtk-theme-name", AGSettings.get_string (AGSettings.KEY_THEME_NAME)); settings.set ("gtk-icon-theme-name", AGSettings.get_string (AGSettings.KEY_ICON_THEME_NAME)); } } @@ -199,5 +208,4 @@ public class AGSettings : Object private const string SCHEMA = "org.ArcticaProject.arctica-greeter"; private bool high_contrast_ = AGSettings.get_boolean (AGSettings.KEY_HIGH_CONTRAST); private bool big_font_ = AGSettings.get_boolean (AGSettings.KEY_BIG_FONT); - private string default_theme_name_; } -- cgit v1.2.3 From 0f287c93d586f16a7d37829da7c54c0f7e48709d Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Mon, 18 Sep 2023 10:38:25 +0200 Subject: src/arctica-greeter.vala: Check for high-contrast mode when initializing gtk-theme-name and gtk-icon-theme-name. --- src/arctica-greeter.vala | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/arctica-greeter.vala b/src/arctica-greeter.vala index 245c1dc..d0f9902 100644 --- a/src/arctica-greeter.vala +++ b/src/arctica-greeter.vala @@ -1071,12 +1071,37 @@ public class ArcticaGreeter : Object /* Set GTK+ settings */ debug ("Setting GTK+ settings"); var settings = Gtk.Settings.get_default (); - var value = AGSettings.get_string (AGSettings.KEY_THEME_NAME); + + /* + * Keep a reference to an AGSettings instance for the whole program + * run, so that the SingleInstance property is working the way we'd + * like it to work. + * + * We want to do this before creating the actual greeter, since the + * latter is using AGSettings quite extensively. + * + * This might throw a Vala warning: "local variable `agsettings' + * declared but never used" if we don't use the variable, but this can + * safely be ignored. + */ + var agsettings = new AGSettings (); + string value = ""; + if (agsettings.high_contrast) + { + value = AGSettings.get_string (AGSettings.KEY_HIGH_CONTRAST_THEME_NAME); + } else { + value = AGSettings.get_string (AGSettings.KEY_THEME_NAME); + } if (value != ""){ debug ("Setting GTK theme: %s", value); settings.set ("gtk-theme-name", value, null); } - value = AGSettings.get_string (AGSettings.KEY_ICON_THEME_NAME); + if (agsettings.high_contrast) + { + value = AGSettings.get_string (AGSettings.KEY_HIGH_CONTRAST_ICON_THEME_NAME); + } else { + value = AGSettings.get_string (AGSettings.KEY_ICON_THEME_NAME); + } if (value != ""){ debug ("Setting icon theme: %s", value); settings.set ("gtk-icon-theme-name", value, null); @@ -1107,19 +1132,6 @@ public class ArcticaGreeter : Object if (value != "") settings.set ("gtk-xft-rgba", value, null); - /* - * Keep a reference to an AGSettings instance for the whole program - * run, so that the SingleInstance property is working the way we'd - * like it to work. - * - * We want to do this before creating the actual greeter, since the - * latter is using AGSettings quite extensively. - * - * This will throw a Vala warning: "local variable `agsettings' declared - * but never used". Which can be ignored. - */ - var agsettings = new AGSettings (); - debug ("Creating Arctica Greeter"); var greeter = new ArcticaGreeter (do_test_mode, do_test_highcontrast, do_test_bigfont); greeter.go(); -- cgit v1.2.3 From 273045dc19e23c31f7cf412e56c4acd325c8ef92 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Mon, 18 Sep 2023 12:52:50 +0200 Subject: src/settings.vala: refactor (icon) theme setting in a cleaner way. --- src/settings.vala | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/settings.vala b/src/settings.vala index 5c7c10f..656b52a 100644 --- a/src/settings.vala +++ b/src/settings.vala @@ -172,20 +172,31 @@ public class AGSettings : Object greeter.switch_contrast (value); var settings = Gtk.Settings.get_default (); + var theme_name = ""; + var icon_theme_name = ""; + if (value) { - debug ("Switching GTK Theme to high contrast theme \"%s\"", AGSettings.get_string (AGSettings.KEY_HIGH_CONTRAST_THEME_NAME)); - debug ("Switching icon theme to high contrast theme \"%s\"", AGSettings.get_string (AGSettings.KEY_HIGH_CONTRAST_ICON_THEME_NAME)); - settings.set ("gtk-theme-name", AGSettings.get_string (AGSettings.KEY_HIGH_CONTRAST_THEME_NAME)); - settings.set ("gtk-icon-theme-name", AGSettings.get_string (AGSettings.KEY_HIGH_CONTRAST_ICON_THEME_NAME)); + + /* FIXME: We need to check for wrong theme names here and handle such flaws gracefully */ + + theme_name = AGSettings.get_string (AGSettings.KEY_HIGH_CONTRAST_THEME_NAME); + icon_theme_name = AGSettings.get_string (AGSettings.KEY_HIGH_CONTRAST_ICON_THEME_NAME); + debug ("Switching GTK Theme to high contrast theme \"%s\"", theme_name); + debug ("Switching icon theme to high contrast theme \"%s\"", icon_theme_name); } else { - debug ("Switching GTK Theme to default theme \"%s\"", AGSettings.get_string (AGSettings.KEY_THEME_NAME)); - debug ("Switching icon theme to default icon theme \"%s\"", AGSettings.get_string (AGSettings.KEY_ICON_THEME_NAME)); - settings.set ("gtk-theme-name", AGSettings.get_string (AGSettings.KEY_THEME_NAME)); - settings.set ("gtk-icon-theme-name", AGSettings.get_string (AGSettings.KEY_ICON_THEME_NAME)); + + /* FIXME: We need to check for wrong theme names here and handle such flaws gracefully */ + + theme_name = AGSettings.get_string (AGSettings.KEY_THEME_NAME); + icon_theme_name = AGSettings.get_string (AGSettings.KEY_ICON_THEME_NAME); + debug ("Switching GTK Theme to default theme \"%s\"", theme_name); + debug ("Switching icon theme to default icon theme \"%s\"", icon_theme_name); } + settings.set ("gtk-theme-name", theme_name); + settings.set ("gtk-icon-theme-name", icon_theme_name); } } -- cgit v1.2.3