[gnome-builder] app: avoid immediate second parse of the theme in some cases



commit 110736a4be5b1b70dc238d299ce4c43a07f22137
Author: Christian Hergert <chergert redhat com>
Date:   Mon Nov 13 00:55:45 2017 -0800

    app: avoid immediate second parse of the theme in some cases
    
    If we startup with dark-mode, we'll have to reparse the theme. But in the
    case of regular mode, we should be able to save a bunch of secondary
    parsing from when this property is set.

 src/libide/application/ide-application.c |   58 +++++++++++++++++++++++++++--
 1 files changed, 54 insertions(+), 4 deletions(-)
---
diff --git a/src/libide/application/ide-application.c b/src/libide/application/ide-application.c
index c8b5e2a..179165e 100644
--- a/src/libide/application/ide-application.c
+++ b/src/libide/application/ide-application.c
@@ -370,6 +370,37 @@ ide_application_language_defaults_cb (GObject      *object,
 }
 
 static void
+gtk_changed_dark_mode (GtkSettings    *settings,
+                       GParamSpec     *pspec,
+                       IdeApplication *self)
+{
+  gboolean value;
+
+  g_object_get (settings,
+                "gtk-application-prefer-dark-theme", &value,
+                NULL);
+  if (value != g_settings_get_boolean (self->settings, "night-mode"))
+    g_settings_set_boolean (self->settings, "night-mode", value);
+}
+
+static void
+settings_changed_dark_mode (GSettings      *settings,
+                            const gchar    *key,
+                            IdeApplication *self)
+{
+  GtkSettings *gtk_settings = gtk_settings_get_default ();
+  gboolean value;
+
+  g_object_get (gtk_settings,
+                "gtk-application-prefer-dark-theme", &value,
+                NULL);
+  if (value != g_settings_get_boolean (settings, "night-mode"))
+    g_object_set (gtk_settings,
+                  "gtk-application-prefer-dark-theme", value,
+                  NULL);
+}
+
+static void
 ide_application_register_settings (IdeApplication *self)
 {
   IDE_ENTRY;
@@ -379,10 +410,29 @@ ide_application_register_settings (IdeApplication *self)
   if (g_getenv ("GTK_THEME") == NULL)
     {
       GtkSettings *gtk_settings = gtk_settings_get_default ();
-
-      g_settings_bind (self->settings, "night-mode",
-                       gtk_settings, "gtk-application-prefer-dark-theme",
-                       G_SETTINGS_BIND_DEFAULT);
+      gboolean night_mode = g_settings_get_boolean (self->settings, "night-mode");
+
+      /*
+       * This tries to avoid using g_settings_bind() because it will always
+       * apply the initial value from settings. We want to avoid that in the
+       * case that night_mode is not set because it doesn't cause an immediate
+       * reloading of the theme.
+       */
+
+      g_signal_connect_object (gtk_settings,
+                               "notify::gtk-application-prefer-dark-theme",
+                               G_CALLBACK (gtk_changed_dark_mode),
+                               self,
+                               0);
+      g_signal_connect_object (self->settings,
+                               "changed::night-mode",
+                               G_CALLBACK (settings_changed_dark_mode),
+                               self,
+                               0);
+      if (night_mode)
+        g_object_set (gtk_settings,
+                      "gtk-application-prefer-dark-theme", TRUE,
+                      NULL);
     }
 
   IDE_EXIT;


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