[xdg-desktop-portal-gnome/wip/exalm/dark] settings: Provide org.freedesktop.appearance.color-scheme key




commit 5895fd06ce8841117962940fc525bfa61e496636
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sun Sep 19 22:06:49 2021 +0500

    settings: Provide org.freedesktop.appearance.color-scheme key

 src/settings.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
---
diff --git a/src/settings.c b/src/settings.c
index 8e1bb28..f7d7a3d 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <glib/gi18n.h>
 #include <gio/gio.h>
+#include <gdesktop-enums.h>
 
 #include "settings.h"
 #include "utils.h"
@@ -89,6 +90,15 @@ namespace_matches (const char         *namespace,
   return FALSE;
 }
 
+static GVariant *
+get_color_scheme (void)
+{
+  SettingsBundle *bundle = g_hash_table_lookup (settings, "org.gnome.desktop.interface");
+  GDesktopColorScheme color_scheme = g_settings_get_enum (bundle->settings, "color-scheme");
+
+  return g_variant_new_uint32 (color_scheme);
+}
+
 static gboolean
 settings_handle_read_all (XdpImplSettings       *object,
                           GDBusMethodInvocation *invocation,
@@ -136,6 +146,16 @@ settings_handle_read_all (XdpImplSettings       *object,
       g_variant_builder_add (builder, "{s@a{sv}}", "org.gnome.fontconfig", g_variant_dict_end (&dict));
     }
 
+  if (namespace_matches ("org.freedesktop.appearance", arg_namespaces))
+    {
+      GVariantDict dict;
+
+      g_variant_dict_init (&dict, NULL);
+      g_variant_dict_insert_value (&dict, "color-scheme", get_color_scheme ());
+
+      g_variant_builder_add (builder, "{s@a{sv}}", "org.freedesktop.appearance", g_variant_dict_end (&dict));
+    }
+
   g_variant_builder_close (builder);
 
   g_dbus_method_invocation_return_value (invocation, g_variant_builder_end (builder));
@@ -161,6 +181,13 @@ settings_handle_read (XdpImplSettings       *object,
           return TRUE;
         }
     }
+  else if (strcmp (arg_namespace, "org.freedesktop.appearance") == 0 &&
+           strcmp (arg_key, "color-scheme") == 0)
+    {
+      g_dbus_method_invocation_return_value (invocation,
+                                             g_variant_new ("(v)", get_color_scheme ()));
+      return TRUE;
+    }
   else if (strcmp (arg_namespace, "org.gnome.desktop.interface") == 0 &&
            strcmp (arg_key, "enable-animations") == 0)
     {
@@ -225,6 +252,12 @@ on_settings_changed (GSettings             *settings,
     xdp_impl_settings_emit_setting_changed (user_data->self,
                                             user_data->namespace, key,
                                             g_variant_new ("v", new_value));
+
+  if (strcmp (user_data->namespace, "org.gnome.desktop.interface") == 0 &&
+      strcmp (key, "color-scheme") == 0)
+    xdp_impl_settings_emit_setting_changed (user_data->self,
+                                            "org.freedesktop.appearance", key,
+                                            g_variant_new ("v", get_color_scheme ()));
 }
 
 static void


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