[gnome-builder] app: disable theme tracking when global dark-mode is enabled



commit a37cf9bf777a3dcc7cecdc351cdf8e7cf3b702a3
Author: Christian Hergert <chergert redhat com>
Date:   Sun Jun 5 15:06:27 2016 -0700

    app: disable theme tracking when global dark-mode is enabled
    
    When users select the global dark-mode setting from gnome-tweak-tool, we
    were inadvertently overriding that setting at startup based on our own
    dark-mode setting in org.gnome.builder.
    
    When we detect global dark-mode, we also need to disable the preference
    to toggle the setting since we can no longer keep things consistent.

 libide/ide-application-private.h             |   19 +++++++++-------
 libide/ide-application.c                     |   30 +++++++++++++++++++++++--
 libide/preferences/ide-preferences-builtin.c |    3 +-
 3 files changed, 40 insertions(+), 12 deletions(-)
---
diff --git a/libide/ide-application-private.h b/libide/ide-application-private.h
index 0d6aeaa..fec7cfa 100644
--- a/libide/ide-application-private.h
+++ b/libide/ide-application-private.h
@@ -63,16 +63,19 @@ struct _IdeApplication
   GList               *test_funcs;
 
   GHashTable          *plugin_settings;
+
+  guint                disable_theme_tracking : 1;
 };
 
-void     ide_application_discover_plugins   (IdeApplication   *self) G_GNUC_INTERNAL;
-void     ide_application_load_plugins       (IdeApplication   *self) G_GNUC_INTERNAL;
-void     ide_application_load_addins        (IdeApplication   *self) G_GNUC_INTERNAL;
-void     ide_application_init_plugin_menus  (IdeApplication   *self) G_GNUC_INTERNAL;
-gboolean ide_application_local_command_line (GApplication     *application,
-                                             gchar          ***arguments,
-                                             gint             *exit_status) G_GNUC_INTERNAL;
-void     ide_application_run_tests          (IdeApplication   *self);
+void     ide_application_discover_plugins           (IdeApplication   *self) G_GNUC_INTERNAL;
+void     ide_application_load_plugins               (IdeApplication   *self) G_GNUC_INTERNAL;
+void     ide_application_load_addins                (IdeApplication   *self) G_GNUC_INTERNAL;
+void     ide_application_init_plugin_menus          (IdeApplication   *self) G_GNUC_INTERNAL;
+gboolean ide_application_local_command_line         (GApplication     *application,
+                                                     gchar          ***arguments,
+                                                     gint             *exit_status) G_GNUC_INTERNAL;
+void     ide_application_run_tests                  (IdeApplication   *self);
+gboolean ide_application_get_disable_theme_tracking (IdeApplication   *self) G_GNUC_INTERNAL;
 
 G_END_DECLS
 
diff --git a/libide/ide-application.c b/libide/ide-application.c
index f3d6188..cb5c233 100644
--- a/libide/ide-application.c
+++ b/libide/ide-application.c
@@ -96,6 +96,7 @@ ide_application_register_theme_overrides (IdeApplication *self)
   g_autoptr(GSettings) settings = NULL;
   GtkSettings *gtk_settings;
   GdkScreen *screen;
+  gboolean wants_dark_theme = FALSE;
 
   IDE_ENTRY;
 
@@ -106,9 +107,24 @@ ide_application_register_theme_overrides (IdeApplication *self)
   screen = gdk_screen_get_default ();
   gtk_settings = gtk_settings_get_for_screen (screen);
   settings = g_settings_new ("org.gnome.builder");
-  g_settings_bind (settings, "night-mode",
-                   gtk_settings, "gtk-application-prefer-dark-theme",
-                   G_SETTINGS_BIND_DEFAULT);
+
+  /*
+   * Some users override the "default to dark theme" in gnome-tweak-tool,
+   * which means if they haven't selected the dark theme, we will
+   * inadvertantly set the application to light-mode. If we detect this,
+   * we will avoid tracking the dark status.
+   */
+  g_object_get (gtk_settings,
+                "gtk-application-prefer-dark-theme", &wants_dark_theme,
+                NULL);
+
+  if (wants_dark_theme || g_getenv ("GTK_THEME") != NULL)
+    self->disable_theme_tracking = TRUE;
+
+  if (!self->disable_theme_tracking)
+    g_settings_bind (settings, "night-mode",
+                     gtk_settings, "gtk-application-prefer-dark-theme",
+                     G_SETTINGS_BIND_DEFAULT);
 
   IDE_EXIT;
 }
@@ -728,3 +744,11 @@ ide_application_open_project (IdeApplication *self,
   else
     return FALSE;
 }
+
+gboolean
+ide_application_get_disable_theme_tracking (IdeApplication *self)
+{
+  g_return_val_if_fail (IDE_IS_APPLICATION (self), FALSE);
+
+  return self->disable_theme_tracking;
+}
diff --git a/libide/preferences/ide-preferences-builtin.c b/libide/preferences/ide-preferences-builtin.c
index 373bf3e..14cdf4f 100644
--- a/libide/preferences/ide-preferences-builtin.c
+++ b/libide/preferences/ide-preferences-builtin.c
@@ -20,6 +20,7 @@
 #include <gtksourceview/gtksource.h>
 #include <libpeas/peas.h>
 
+#include "ide-application-private.h"
 #include "ide-macros.h"
 #include "ide-preferences-builtin.h"
 #include "ide-preferences-entry.h"
@@ -106,7 +107,7 @@ ide_preferences_builtin_register_appearance (IdePreferences *preferences)
   /* XXX: This belongs in terminal addin */
   ide_preferences_add_font_button (preferences, "appearance", "font", "org.gnome.builder.terminal", 
"font-name", _("Terminal"), C_("Keywords", "terminal font monospace"), 0);
 
-  if (g_getenv ("GTK_THEME") != NULL)
+  if (ide_application_get_disable_theme_tracking (IDE_APPLICATION_DEFAULT))
     {
       bin = ide_preferences_get_widget (preferences, dark_mode);
       gtk_widget_set_sensitive (bin, FALSE);


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