[gnome-builder] night-light: add switch to follow night-light setting
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] night-light: add switch to follow night-light setting
- Date: Thu, 16 Nov 2017 04:01:17 +0000 (UTC)
commit 28df37133ab54092e013be8aa1b2eef90ec449c7
Author: Christian Hergert <chergert redhat com>
Date: Wed Nov 15 20:00:11 2017 -0800
night-light: add switch to follow night-light setting
This watches the DBus service for changes to the night-light setting. When
activated, Builder will switch to night mode automatically.
Like night-light, this setting is disabled by default.
data/gsettings/org.gnome.builder.gschema.xml | 5 ++
src/libide/application/ide-application-color.c | 75 ++++++++++++++++++++++
src/libide/application/ide-application-private.h | 3 +
src/libide/application/ide-application.c | 2 +
src/libide/application/meson.build | 1 +
src/libide/preferences/ide-preferences-builtin.c | 5 +-
6 files changed, 89 insertions(+), 2 deletions(-)
---
diff --git a/data/gsettings/org.gnome.builder.gschema.xml b/data/gsettings/org.gnome.builder.gschema.xml
index 52b5ca7..d061924 100644
--- a/data/gsettings/org.gnome.builder.gschema.xml
+++ b/data/gsettings/org.gnome.builder.gschema.xml
@@ -20,6 +20,11 @@
<summary>Night Mode</summary>
<description>Prefer dark application chrome.</description>
</key>
+ <key name="follow-night-light" type="b">
+ <default>false</default>
+ <summary>Follow system night light</summary>
+ <description>Use GNOME night light setting to activate night-mode.</description>
+ </key>
<key name="projects-directory" type="s">
<default>"Projects"</default>
<summary>Projects directory</summary>
diff --git a/src/libide/application/ide-application-color.c b/src/libide/application/ide-application-color.c
new file mode 100644
index 0000000..8ab9614
--- /dev/null
+++ b/src/libide/application/ide-application-color.c
@@ -0,0 +1,75 @@
+/* ide-application-color.c
+ *
+ * Copyright (C) 2017 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "ide-application-color"
+
+#include "application/ide-application.h"
+#include "application/ide-application-private.h"
+
+static void
+ide_application_color_properties_changed (IdeApplication *self,
+ GVariant *properties,
+ const gchar * const *invalidated,
+ GDBusProxy *proxy)
+{
+ g_assert (IDE_IS_APPLICATION (self));
+ g_assert (G_IS_DBUS_PROXY (proxy));
+
+ if (g_settings_get_boolean (self->settings, "follow-night-light"))
+ {
+ g_autoptr(GVariant) activev = NULL;
+ gboolean active;
+
+ activev = g_dbus_proxy_get_cached_property (proxy, "NightLightActive");
+ active = g_variant_get_boolean (activev);
+
+ if (active != g_settings_get_boolean (self->settings, "night-mode"))
+ g_settings_set_boolean (self->settings, "night-mode", active);
+ }
+}
+
+void
+_ide_application_init_color (IdeApplication *self)
+{
+ g_autoptr(GDBusConnection) conn = NULL;
+ g_autoptr(GDBusProxy) proxy = NULL;
+
+ g_return_if_fail (IDE_IS_APPLICATION (self));
+
+ if (NULL == (conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL)))
+ return;
+
+ if (NULL == (proxy = g_dbus_proxy_new_sync (conn,
+ G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
+ NULL,
+ "org.gnome.SettingsDaemon.Color",
+ "/org/gnome/SettingsDaemon/Color",
+ "org.gnome.SettingsDaemon.Color",
+ NULL, NULL)))
+ return;
+
+ g_signal_connect_object (proxy,
+ "g-properties-changed",
+ G_CALLBACK (ide_application_color_properties_changed),
+ self,
+ G_CONNECT_SWAPPED);
+
+ self->color_proxy = g_steal_pointer (&proxy);
+
+ ide_application_color_properties_changed (self, NULL, NULL, self->color_proxy);
+}
diff --git a/src/libide/application/ide-application-private.h
b/src/libide/application/ide-application-private.h
index 07f69b2..c2e619b 100644
--- a/src/libide/application/ide-application-private.h
+++ b/src/libide/application/ide-application-private.h
@@ -63,6 +63,8 @@ struct _IdeApplication
GPtrArray *reapers;
GSettings *settings;
+
+ GDBusProxy *color_proxy;
};
void ide_application_discover_plugins (IdeApplication *self) G_GNUC_INTERNAL;
@@ -83,6 +85,7 @@ void ide_application_open_async (IdeApplication *self
gboolean ide_application_open_finish (IdeApplication *self,
GAsyncResult *reuslt,
GError **error);
+void _ide_application_init_color (IdeApplication *self);
void _ide_application_init_shortcuts (IdeApplication *self);
void _ide_application_set_mode (IdeApplication *self,
IdeApplicationMode mode);
diff --git a/src/libide/application/ide-application.c b/src/libide/application/ide-application.c
index 5842a87..830ebf2 100644
--- a/src/libide/application/ide-application.c
+++ b/src/libide/application/ide-application.c
@@ -417,6 +417,7 @@ ide_application_startup (GApplication *application)
ide_application_register_keybindings (self);
ide_application_actions_init (self);
_ide_application_init_shortcuts (self);
+ _ide_application_init_color (self);
modeline_parser_init ();
}
@@ -520,6 +521,7 @@ ide_application_finalize (GObject *object)
g_clear_object (&self->keybindings);
g_clear_object (&self->recent_projects);
g_clear_object (&self->settings);
+ g_clear_object (&self->color_proxy);
G_OBJECT_CLASS (ide_application_parent_class)->finalize (object);
}
diff --git a/src/libide/application/meson.build b/src/libide/application/meson.build
index 4632564..5a55d08 100644
--- a/src/libide/application/meson.build
+++ b/src/libide/application/meson.build
@@ -15,6 +15,7 @@ application_sources = [
application_private_sources = [
'ide-application-actions.c',
'ide-application-actions.h',
+ 'ide-application-color.c',
'ide-application-command-line.c',
'ide-application-plugins.c',
'ide-application-private.h',
diff --git a/src/libide/preferences/ide-preferences-builtin.c
b/src/libide/preferences/ide-preferences-builtin.c
index 105b49c..4083ad6 100644
--- a/src/libide/preferences/ide-preferences-builtin.c
+++ b/src/libide/preferences/ide-preferences-builtin.c
@@ -98,8 +98,9 @@ ide_preferences_builtin_register_appearance (DzlPreferences *preferences)
dzl_preferences_add_page (preferences, "appearance", _("Appearance"), 0);
dzl_preferences_add_list_group (preferences, "appearance", "basic", _("Themes"), GTK_SELECTION_NONE, 0);
- dark_mode = dzl_preferences_add_switch (preferences, "appearance", "basic", "org.gnome.builder",
"night-mode", NULL, NULL, _("Dark Theme"), _("Whether Builder should use a dark theme"), _("dark theme"), 0);
- dzl_preferences_add_switch (preferences, "appearance", "basic", "org.gnome.builder.editor",
"show-grid-lines", NULL, NULL, _("Grid Pattern"), _("Display a grid pattern underneath source code"), NULL,
0);
+ dark_mode = dzl_preferences_add_switch (preferences, "appearance", "basic", "org.gnome.builder",
"night-mode", NULL, NULL, _("Dark Mode"), _("Whether Builder should use a dark theme"), _("dark theme"), 0);
+ dzl_preferences_add_switch (preferences, "appearance", "basic", "org.gnome.builder", "follow-night-light",
NULL, NULL, _("Night Light"), _("Automatically enable dark mode at night"), _("follow night light"), 5);
+ dzl_preferences_add_switch (preferences, "appearance", "basic", "org.gnome.builder.editor",
"show-grid-lines", NULL, NULL, _("Grid Pattern"), _("Display a grid pattern underneath source code"), NULL,
10);
dzl_preferences_add_list_group (preferences, "appearance", "font", _("Font"), GTK_SELECTION_NONE, 10);
dzl_preferences_add_font_button (preferences, "appearance", "font", "org.gnome.builder.editor",
"font-name", _("Editor"), C_("Keywords", "editor font monospace"), 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]