diff --git a/build-aux/flatpak/org.gnome.Calendar.json b/build-aux/flatpak/org.gnome.Calendar.json
index c78da1a8..1bad44b3 100644
--- a/build-aux/flatpak/org.gnome.Calendar.json
+++ b/build-aux/flatpak/org.gnome.Calendar.json
@@ -22,6 +22,7 @@
"--talk-name=org.gnome.evolution.dataserver.Calendar7",
"--talk-name=org.gnome.evolution.dataserver.Sources5",
"--talk-name=org.gnome.evolution.dataserver.Subprocess.Backend.*",
+ "--talk-name=org.gnome.SettingsDaemon.Color",
"--filesystem=home",
"--filesystem=xdg-run/dconf",
"--filesystem=~/.config/dconf:ro",
diff --git a/data/org.gnome.calendar.gschema.xml.in b/data/org.gnome.calendar.gschema.xml.in
index 4310b33a..094c5ae8 100644
--- a/data/org.gnome.calendar.gschema.xml.in
+++ b/data/org.gnome.calendar.gschema.xml.in
@@ -26,5 +26,10 @@
Weather Service Configuration
Whether weather reports are shown, automatic locations are used and a location-name
+
+ true
+ Follow system night light
+ Use GNOME night light setting to activate night-mode.
+
diff --git a/src/gcal-application.c b/src/gcal-application.c
index 4040fcec..59d87102 100644
--- a/src/gcal-application.c
+++ b/src/gcal-application.c
@@ -26,6 +26,7 @@
#include "gcal-debug.h"
#include "gcal-enums.h"
#include "gcal-log.h"
+#include "gcal-night-light-monitor.h"
#include "gcal-shell-search-provider.h"
#include "gcal-weather-service.h"
#include "gcal-window.h"
@@ -53,8 +54,8 @@ struct _GcalApplication
GcalTimeFormat time_format;
GcalWeatherService *weather_service;
-
GcalShellSearchProvider *search_provider;
+ GcalNightLightMonitor *night_light_monitor;
GcalClock *clock;
};
@@ -230,6 +231,7 @@ gcal_application_finalize (GObject *object)
g_clear_object (&self->clock);
g_clear_object (&self->desktop_settings);
g_clear_object (&self->manager);
+ g_clear_object (&self->night_light_monitor);
g_clear_object (&self->provider);
g_clear_object (&self->search_provider);
g_clear_object (&self->weather_service);
@@ -293,6 +295,9 @@ gcal_application_activate (GApplication *application)
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 2);
}
+ if (!self->night_light_monitor)
+ self->night_light_monitor = gcal_night_light_monitor_new (self->manager);
+
if (!self->window)
{
if (!self->initial_date)
diff --git a/src/gcal-night-light-monitor.c b/src/gcal-night-light-monitor.c
new file mode 100644
index 00000000..4198ba08
--- /dev/null
+++ b/src/gcal-night-light-monitor.c
@@ -0,0 +1,206 @@
+/* gcal-night-light-monitor.c
+ *
+ * Copyright 2018 Georges Basile Stavracas Neto
+ *
+ * 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 .
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "gcal-debug.h"
+#include "gcal-night-light-monitor.h"
+
+struct _GcalNightLightMonitor
+{
+ GObject parent;
+
+ GcalManager *manager;
+
+ GDBusProxy *night_light_proxy;
+};
+
+G_DEFINE_TYPE (GcalNightLightMonitor, gcal_night_light_monitor, G_TYPE_OBJECT)
+
+enum
+{
+ PROP_0,
+ PROP_MANAGER,
+ N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+
+/*
+ * Callbacks
+ */
+
+static void
+on_night_light_proxy_properties_changed_cb (GcalNightLightMonitor *self,
+ GVariant *properties,
+ const gchar * const *invalidated,
+ GDBusProxy *proxy)
+{
+ GSettings *settings;
+
+ g_assert (GCAL_IS_NIGHT_LIGHT_MONITOR (self));
+ g_assert (G_IS_DBUS_PROXY (proxy));
+
+ settings = gcal_manager_get_settings (self->manager);
+
+ if (g_settings_get_boolean (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);
+
+ g_object_set (gtk_settings_get_default (),
+ "gtk-application-prefer-dark-theme",
+ active,
+ NULL);
+ }
+}
+
+
+/*
+ * GObject overrides
+ */
+
+static void
+gcal_night_light_monitor_finalize (GObject *object)
+{
+ GcalNightLightMonitor *self = (GcalNightLightMonitor *)object;
+
+ g_clear_object (&self->manager);
+ g_clear_object (&self->night_light_proxy);
+
+ G_OBJECT_CLASS (gcal_night_light_monitor_parent_class)->finalize (object);
+}
+
+static void
+gcal_night_light_monitor_constructed (GObject *object)
+{
+ GcalNightLightMonitor *self = (GcalNightLightMonitor *)object;
+ g_autoptr (GDBusConnection) connection = NULL;
+ g_autoptr (GDBusProxy) proxy = NULL;
+
+ GCAL_ENTRY;
+
+ G_OBJECT_CLASS (gcal_night_light_monitor_parent_class)->constructed (object);
+
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+
+ if (!connection)
+ GCAL_RETURN ();
+
+ proxy = g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
+ NULL,
+ "org.gnome.SettingsDaemon.Color",
+ "/org/gnome/SettingsDaemon/Color",
+ "org.gnome.SettingsDaemon.Color",
+ NULL,
+ NULL);
+
+ if (!proxy)
+ GCAL_RETURN ();
+
+ g_debug ("Created Night Light monitor");
+
+ g_signal_connect_object (proxy,
+ "g-properties-changed",
+ G_CALLBACK (on_night_light_proxy_properties_changed_cb),
+ self,
+ G_CONNECT_SWAPPED);
+
+ self->night_light_proxy = g_steal_pointer (&proxy);
+
+ on_night_light_proxy_properties_changed_cb (self, NULL, NULL, self->night_light_proxy);
+
+ GCAL_EXIT;
+}
+
+static void
+gcal_night_light_monitor_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GcalNightLightMonitor *self = GCAL_NIGHT_LIGHT_MONITOR (object);
+
+ switch (prop_id)
+ {
+ case PROP_MANAGER:
+ g_value_set_object (value, self->manager);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gcal_night_light_monitor_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GcalNightLightMonitor *self = GCAL_NIGHT_LIGHT_MONITOR (object);
+
+ switch (prop_id)
+ {
+ case PROP_MANAGER:
+ g_assert (self->manager == NULL);
+ self->manager = g_value_dup_object (value);
+ g_object_notify_by_pspec (object, pspec);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gcal_night_light_monitor_class_init (GcalNightLightMonitorClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gcal_night_light_monitor_finalize;
+ object_class->constructed = gcal_night_light_monitor_constructed;
+ object_class->get_property = gcal_night_light_monitor_get_property;
+ object_class->set_property = gcal_night_light_monitor_set_property;
+
+ properties[PROP_MANAGER] = g_param_spec_object ("manager",
+ "Manager",
+ "Manager",
+ GCAL_TYPE_MANAGER,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+gcal_night_light_monitor_init (GcalNightLightMonitor *self)
+{
+}
+
+GcalNightLightMonitor*
+gcal_night_light_monitor_new (GcalManager *manager)
+{
+ return g_object_new (GCAL_TYPE_NIGHT_LIGHT_MONITOR,
+ "manager", manager,
+ NULL);
+}
diff --git a/src/gcal-night-light-monitor.h b/src/gcal-night-light-monitor.h
new file mode 100644
index 00000000..3b9d98b3
--- /dev/null
+++ b/src/gcal-night-light-monitor.h
@@ -0,0 +1,34 @@
+/* gcal-night-light-monitor.h
+ *
+ * Copyright 2018 Georges Basile Stavracas Neto
+ *
+ * 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 .
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include "gcal-manager.h"
+#include "gcal-window.h"
+
+G_BEGIN_DECLS
+
+#define GCAL_TYPE_NIGHT_LIGHT_MONITOR (gcal_night_light_monitor_get_type())
+
+G_DECLARE_FINAL_TYPE (GcalNightLightMonitor, gcal_night_light_monitor, GCAL, NIGHT_LIGHT_MONITOR, GObject)
+
+GcalNightLightMonitor* gcal_night_light_monitor_new (GcalManager *manager);
+
+G_END_DECLS
diff --git a/src/meson.build b/src/meson.build
index a02a6b83..724ff425 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -43,6 +43,7 @@ sources = files(
'gcal-log.c',
'gcal-manager.c',
'gcal-multi-choice.c',
+ 'gcal-night-light-monitor.c',
'gcal-quick-add-popover.c',
'gcal-recurrence.c',
'gcal-search-popover.c',