[ghex/ghex-42] config: Add GNOME 42+ compatibility for dark mode
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ghex/ghex-42] config: Add GNOME 42+ compatibility for dark mode
- Date: Sun, 12 Jun 2022 23:33:56 +0000 (UTC)
commit 9db17f3cb07362633f7b3997200e9a5e8f142c5b
Author: Logan Rathbone <poprocks gmail com>
Date: Sun Jun 12 18:22:35 2022 -0400
config: Add GNOME 42+ compatibility for dark mode
src/configuration.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 47 insertions(+), 5 deletions(-)
---
diff --git a/src/configuration.c b/src/configuration.c
index 9ecccba..ec52834 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -78,12 +78,54 @@ dark_mode_changed_cb (GSettings *settings,
void
get_sys_default_is_dark (void)
{
+ /* NOTE: for GTK 4.0 backwards compatibility, we manually define these
+ * here. If we wish to add an additional dependency on
+ * gsettings-desktop-schemas >= 42, this can be eliminated.
+ */
+ enum {
+ SYSTEM_DEFAULT,
+ SYSTEM_PREFER_DARK,
+ SYSTEM_PREFER_LIGHT,
+ } color_scheme;
+ GSettings *set;
GtkSettings *gtk_settings;
-
- gtk_settings = gtk_settings_get_default ();
- g_object_get (gtk_settings,
- "gtk-application-prefer-dark-theme", &sys_default_is_dark,
- NULL);
+ GSettingsSchemaSource *source;
+ GSettingsSchema *schema;
+ char *schema_id = NULL;
+
+ source = g_settings_schema_source_get_default ();
+ schema = g_settings_schema_source_lookup (source, "org.freedesktop.appearance", TRUE);
+
+ if (schema && g_settings_schema_has_key (schema, "color-scheme"))
+ {
+ schema_id = "org.freedesktop.appearance";
+ g_settings_schema_unref (schema);
+ }
+ else
+ {
+ schema = g_settings_schema_source_lookup (source, "org.gnome.desktop.interface", TRUE);
+ if (schema && g_settings_schema_has_key (schema, "color-scheme"))
+ {
+ schema_id = "org.gnome.desktop.interface";
+ g_settings_schema_unref (schema);
+ }
+ }
+
+ if (schema_id)
+ {
+ set = g_settings_new (schema_id);
+ color_scheme = g_settings_get_enum (set, "color-scheme");
+ if (color_scheme == SYSTEM_PREFER_DARK)
+ sys_default_is_dark = TRUE;
+ g_object_unref (set);
+ }
+ else
+ {
+ gtk_settings = gtk_settings_get_default ();
+ g_object_get (gtk_settings,
+ "gtk-application-prefer-dark-theme", &sys_default_is_dark,
+ NULL);
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]