diff --git a/.gitignore b/.gitignore
index 02888e8b..d698b74c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,4 +10,4 @@ debian/*.install
debian/*.links
debian/.debhelper/
debian/debhelper-build-stamp
-debian/*.debhelper
+debian/*.debhelper
\ No newline at end of file
diff --git a/data/org.cinnamon.settings-daemon.plugins.color.gschema.xml.in.in b/data/org.cinnamon.settings-daemon.plugins.color.gschema.xml.in.in
index 9806d049..180e4f80 100644
--- a/data/org.cinnamon.settings-daemon.plugins.color.gschema.xml.in.in
+++ b/data/org.cinnamon.settings-daemon.plugins.color.gschema.xml.in.in
@@ -4,6 +4,11 @@
+
+
+
+
+
0
@@ -33,17 +38,62 @@
20.00
The start time
- When “night-light-schedule-automatic” is disabled, use this start time in hours from midnight.
+ When “night-light-schedule-mode” is 'manual', use this start time in hours from midnight.
6.00
The end time
- When “night-light-schedule-automatic” is disabled, use this end time in hours from midnight.
+ When “night-light-schedule-mode” is 'manual', use this end time in hours from midnight.
(91,181)
The last detected position
When location services are available this represents the last detected location. The default value is an invalid value to ensure it is always updated at startup.
+
+ false
+ If the night theme switcher is on
+ Changes the theme to “night-theme” when night mode activates (and back).
+
+
+ ''
+ The theme which should be activated at night
+ This theme will be switched on instead of the current theme as soon as the night mode gets activated.
+
+
+ ''
+ The cinnamon-theme which should be activated at night
+ This theme will be switched on instead of the current cinnamon-theme as soon as the night mode gets activated.
+
+
+ ''
+ The icon-theme which should be activated at night
+ This icon-theme will be switched on instead of the current icon-theme as soon as the night mode gets activated.
+
+
+ 'prefer-dark'
+ The xapp color scheme which should be activated at night
+ This scheme will be switched on instead of the current color-scheme as soon as the night mode gets activated.
+
+
+ ''
+ This is set to the last detected day theme
+ When the cinnamon-settings-daemon activates the night theme, this is set to the replaced theme. This theme will get reactivated when the night theme switches off.
+
+
+ ''
+ This is set to the last detected day desktop theme
+ When the cinnamon-settings-daemon activates the night theme, this is set to the replaced cinnamon-theme. This theme will get reactivated when the night theme switches off.
+
+
+ ''
+ This is set to the last detected day icon theme
+ When the cinnamon-settings-daemon activates the night theme, this is set to the replaced icon-theme. This theme will get reactivated when the night theme switches off.
+
+
+ 'default'
+ This is set to the last detected day xapp color-scheme
+ When the cinnamon-settings-daemon activates the night theme, this is set to the replaced theme. This theme will get reactivated when the night theme switches off.
+
diff --git a/plugins/color/ccm-self-test.c b/plugins/color/ccm-self-test.c
index 1b00697b..c0f2f9a4 100644
--- a/plugins/color/ccm-self-test.c
+++ b/plugins/color/ccm-self-test.c
@@ -27,13 +27,13 @@
#include "ccm-edid.h"
#include "csd-color-state.h"
-#include "csd-night-light.h"
-#include "csd-night-light-common.h"
+#include "csd-night-mode.h"
+#include "csd-night-mode-common.h"
GMainLoop *mainloop;
static void
-on_notify (CsdNightLight *nlight,
+on_notify (CsdNightMode *nmode,
GParamSpec *pspec,
gpointer user_data)
{
@@ -50,58 +50,67 @@ quit_mainloop (gpointer user_data)
}
static void
-ccm_test_night_light (void)
+ccm_test_night_mode (void)
{
gboolean ret;
- guint active_cnt = 0;
+ guint active_light_cnt = 0;
+ guint active_theme_cnt = 0;
guint disabled_until_tmw_cnt = 0;
guint sunrise_cnt = 0;
guint sunset_cnt = 0;
guint temperature_cnt = 0;
g_autoptr(GDateTime) datetime_override = NULL;
g_autoptr(GError) error = NULL;
- g_autoptr(CsdNightLight) nlight = NULL;
+ g_autoptr(CsdNightMode) nmode = NULL;
g_autoptr(GSettings) settings = NULL;
- nlight = csd_night_light_new ();
- g_assert (CSD_IS_NIGHT_LIGHT (nlight));
- g_signal_connect (nlight, "notify::active",
- G_CALLBACK (on_notify), &active_cnt);
- g_signal_connect (nlight, "notify::sunset",
+ nmode = csd_night_mode_new ();
+ g_assert (CSD_IS_NIGHT_LIGHT (nmode));
+ g_signal_connect (nmode, "notify::light-active",
+ G_CALLBACK (on_notify), &active_light_cnt);
+ g_signal_connect (nmode, "notify::theme-active",
+ G_CALLBACK (on_notify), &active_theme_cnt);
+ g_signal_connect (nmode, "notify::sunset",
G_CALLBACK (on_notify), &sunset_cnt);
- g_signal_connect (nlight, "notify::sunrise",
+ g_signal_connect (nmode, "notify::sunrise",
G_CALLBACK (on_notify), &sunrise_cnt);
- g_signal_connect (nlight, "notify::temperature",
+ g_signal_connect (nmode, "notify::temperature",
G_CALLBACK (on_notify), &temperature_cnt);
- g_signal_connect (nlight, "notify::disabled-until-tmw",
+ g_signal_connect (nmode, "notify::disabled-until-tmw",
G_CALLBACK (on_notify), &disabled_until_tmw_cnt);
/* hardcode a specific date and time */
datetime_override = g_date_time_new_utc (2017, 2, 8, 20, 0, 0);
- csd_night_light_set_date_time_now (nlight, datetime_override);
+ csd_night_mode_set_date_time_now (nmode, datetime_override);
/* do not smooth the transition */
- csd_night_light_set_smooth_enabled (nlight, FALSE);
+ csd_night_light_set_smooth_enabled (nmode, FALSE);
/* switch off */
settings = g_settings_new ("org.gnome.settings-daemon.plugins.color");
- g_settings_set_boolean (settings, "night-light-schedule-automatic", FALSE);
+ /*
+ to fix: NIGHT_MODE_SCHEDULE_AUTO not defined here?!
+ */
+ // g_settings_set_enum (settings, "night-light-schedule-mode", NIGHT_MODE_SCHEDULE_AUTO);
g_settings_set_boolean (settings, "night-light-enabled", FALSE);
+ g_settings_set_boolean (settings, "night-theme-enabled", FALSE);
g_settings_set_uint (settings, "night-light-temperature", 4000);
/* check default values */
- g_assert (!csd_night_light_get_active (nlight));
- g_assert_cmpint ((gint) csd_night_light_get_sunrise (nlight), ==, -1);
- g_assert_cmpint ((gint) csd_night_light_get_sunset (nlight), ==, -1);
- g_assert_cmpint (csd_night_light_get_temperature (nlight), ==, CSD_COLOR_TEMPERATURE_DEFAULT);
- g_assert (!csd_night_light_get_disabled_until_tmw (nlight));
+ g_assert (!csd_night_light_get_active (nmode));
+ g_assert_cmpint ((gint) csd_night_mode_get_sunrise (nmode), ==, -1);
+ g_assert_cmpint ((gint) csd_night_mode_get_sunset (nmode), ==, -1);
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), ==, CSD_COLOR_TEMPERATURE_DEFAULT);
+ g_assert (!csd_night_mode_get_disabled_until_tmw (nmode));
/* start module, disabled */
- ret = csd_night_light_start (nlight, &error);
+ ret = csd_night_mode_start (nmode, &error);
g_assert_no_error (error);
g_assert (ret);
- g_assert (!csd_night_light_get_active (nlight));
- g_assert_cmpint (active_cnt, ==, 0);
+ g_assert (!csd_night_light_get_active (nmode));
+ g_assert (!csd_night_theme_get_active (nmode));
+ g_assert_cmpint (active_light_cnt, ==, 0);
+ g_assert_cmpint (active_theme_cnt, ==, 0);
g_assert_cmpint (sunset_cnt, ==, 0);
g_assert_cmpint (sunrise_cnt, ==, 0);
g_assert_cmpint (temperature_cnt, ==, 0);
@@ -110,56 +119,73 @@ ccm_test_night_light (void)
/* enable automatic mode */
g_settings_set_value (settings, "night-light-last-coordinates",
g_variant_new ("(dd)", 51.5, -0.1278));
- g_settings_set_boolean (settings, "night-light-schedule-automatic", TRUE);
+ /*
+ to fix: NIGHT_MODE_SCHEDULE_AUTO not defined here?!
+ */
+ //g_settings_set_boolean (settings, "night-light-schedule-mode", NIGHT_MODE_SCHEDULE_AUTO);
g_settings_set_boolean (settings, "night-light-enabled", TRUE);
- g_assert (csd_night_light_get_active (nlight));
- g_assert_cmpint (active_cnt, ==, 1);
+ g_settings_set_boolean (settings, "night-theme-enabled", TRUE);
+ g_assert (csd_night_light_get_active (nmode));
+ g_assert (csd_night_theme_get_active (nmode));
+ g_assert_cmpint (active_light_cnt, ==, 1);
+ g_assert_cmpint (active_theme_cnt, ==, 1);
g_assert_cmpint (sunset_cnt, ==, 1);
g_assert_cmpint (sunrise_cnt, ==, 1);
g_assert_cmpint (temperature_cnt, ==, 1);
g_assert_cmpint (disabled_until_tmw_cnt, ==, 0);
- g_assert_cmpint ((gint) csd_night_light_get_sunrise (nlight), ==, 7);
- g_assert_cmpint ((gint) csd_night_light_get_sunset (nlight), ==, 17);
- g_assert_cmpint (csd_night_light_get_temperature (nlight), ==, 4000);
- g_assert (!csd_night_light_get_disabled_until_tmw (nlight));
+ g_assert_cmpint ((gint) csd_night_mode_get_sunrise (nmode), ==, 7);
+ g_assert_cmpint ((gint) csd_night_mode_get_sunset (nmode), ==, 17);
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), ==, 4000);
+ g_assert (!csd_night_mode_get_disabled_until_tmw (nmode));
/* disable for one day */
- csd_night_light_set_disabled_until_tmw (nlight, TRUE);
- csd_night_light_set_disabled_until_tmw (nlight, TRUE);
- g_assert_cmpint (csd_night_light_get_temperature (nlight), ==, CSD_COLOR_TEMPERATURE_DEFAULT);
- g_assert (csd_night_light_get_active (nlight));
- g_assert (csd_night_light_get_disabled_until_tmw (nlight));
+ csd_night_mode_set_disabled_until_tmw (nmode, TRUE);
+ csd_night_mode_set_disabled_until_tmw (nmode, TRUE);
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), ==, CSD_COLOR_TEMPERATURE_DEFAULT);
+ g_assert (csd_night_light_get_active (nmode));
+ g_assert (csd_night_theme_get_active (nmode));
+ g_assert (csd_night_mode_get_disabled_until_tmw (nmode));
g_assert_cmpint (temperature_cnt, ==, 2);
g_assert_cmpint (disabled_until_tmw_cnt, ==, 1);
/* change our mind */
- csd_night_light_set_disabled_until_tmw (nlight, FALSE);
- g_assert_cmpint (csd_night_light_get_temperature (nlight), ==, 4000);
- g_assert (csd_night_light_get_active (nlight));
- g_assert (!csd_night_light_get_disabled_until_tmw (nlight));
- g_assert_cmpint (active_cnt, ==, 1);
+ csd_night_mode_set_disabled_until_tmw (nmode, FALSE);
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), ==, 4000);
+ g_assert (csd_night_light_get_active (nmode));
+ g_assert (csd_night_theme_get_active (nmode));
+ g_assert (!csd_night_mode_get_disabled_until_tmw (nmode));
+ g_assert_cmpint (active_light_cnt, ==, 1);
+ g_assert_cmpint (active_theme_cnt, ==, 1);
g_assert_cmpint (temperature_cnt, ==, 3);
g_assert_cmpint (disabled_until_tmw_cnt, ==, 2);
/* enabled manual mode (night shift) */
g_settings_set_double (settings, "night-light-schedule-from", 4.0);
g_settings_set_double (settings, "night-light-schedule-to", 16.f);
- g_settings_set_boolean (settings, "night-light-schedule-automatic", FALSE);
- g_assert_cmpint (active_cnt, ==, 2);
+ /*
+ to fix: NIGHT_MODE_SCHEDULE_MANUAL not defined here?!
+ */
+ //g_settings_set_boolean (settings, "night-light-schedule-mode", NIGHT_MODE_SCHEDULE_MANUAL);
+ g_assert_cmpint (active_light_cnt, ==, 2); // why 2?
+ g_assert_cmpint (active_theme_cnt, ==, 2); // why 2? (copy-paste)
g_assert_cmpint (sunset_cnt, ==, 1);
g_assert_cmpint (sunrise_cnt, ==, 1);
g_assert_cmpint (temperature_cnt, ==, 4);
g_assert_cmpint (disabled_until_tmw_cnt, ==, 2);
- g_assert (!csd_night_light_get_active (nlight));
- g_assert_cmpint ((gint) csd_night_light_get_sunrise (nlight), ==, 7);
- g_assert_cmpint ((gint) csd_night_light_get_sunset (nlight), ==, 17);
- g_assert_cmpint (csd_night_light_get_temperature (nlight), ==, CSD_COLOR_TEMPERATURE_DEFAULT);
- g_assert (!csd_night_light_get_disabled_until_tmw (nlight));
+ g_assert (!csd_night_light_get_active (nmode));
+ g_assert (!csd_night_theme_get_active (nmode));
+ g_assert_cmpint ((gint) csd_night_mode_get_sunrise (nmode), ==, 7);
+ g_assert_cmpint ((gint) csd_night_mode_get_sunset (nmode), ==, 17);
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), ==, CSD_COLOR_TEMPERATURE_DEFAULT);
+ g_assert (!csd_night_mode_get_disabled_until_tmw (nmode));
/* disable, with no changes */
g_settings_set_boolean (settings, "night-light-enabled", FALSE);
- g_assert (!csd_night_light_get_active (nlight));
- g_assert_cmpint (active_cnt, ==, 2);
+ g_settings_set_boolean (settings, "night-theme-enabled", FALSE);
+ g_assert (!csd_night_light_get_active (nmode));
+ g_assert (!csd_night_theme_get_active (nmode));
+ g_assert_cmpint (active_light_cnt, ==, 2); // why 2?
+ g_assert_cmpint (active_theme_cnt, ==, 2); // why 2? (copy-paste)
g_assert_cmpint (sunset_cnt, ==, 1);
g_assert_cmpint (sunrise_cnt, ==, 1);
g_assert_cmpint (temperature_cnt, ==, 4);
@@ -167,75 +193,90 @@ ccm_test_night_light (void)
/* Finally, check that cancelling a smooth transition works */
- csd_night_light_set_smooth_enabled (nlight, TRUE);
+ csd_night_light_set_smooth_enabled (nmode, TRUE);
/* Enable night light and automatic scheduling */
- g_settings_set_boolean (settings, "night-light-schedule-automatic", TRUE);
+ /*
+ to fix: NIGHT_MODE_SCHEDULE_AUTO not defined here?!
+ */
+ //g_settings_set_boolean (settings, "night-light-schedule-mode", NIGHT_MODE_SCHEDULE_AUTO);
g_settings_set_boolean (settings, "night-light-enabled", TRUE);
+ g_settings_set_boolean (settings, "night-theme-enabled", TRUE);
/* It should be active again, and a smooth transition is being done,
* so the color temperature is still the default at this point. */
- g_assert (csd_night_light_get_active (nlight));
- g_assert_cmpint (csd_night_light_get_temperature (nlight), ==, CSD_COLOR_TEMPERATURE_DEFAULT);
+ g_assert (csd_night_light_get_active (nmode));
+ g_assert (csd_night_theme_get_active (nmode));
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), ==, CSD_COLOR_TEMPERATURE_DEFAULT);
/* Turn off immediately, before the first timeout event is fired. */
- g_settings_set_boolean (settings, "night-light-schedule-automatic", FALSE);
+ /*
+ to fix: NIGHT_MODE_SCHEDULE_MANUAL not defined here?!
+ */
+ //g_settings_set_boolean (settings, "night-light-schedule-mode", NIGHT_MODE_SCHEDULE_MANUAL);
g_settings_set_boolean (settings, "night-light-enabled", FALSE);
- g_assert (!csd_night_light_get_active (nlight));
+ g_settings_set_boolean (settings, "night-theme-enabled", FALSE);
+ g_assert (!csd_night_light_get_active (nmode));
+ g_assert (!csd_night_theme_get_active (nmode));
/* Now, sleep for a bit (the smooth transition time is 5 seconds) */
g_timeout_add (5000, quit_mainloop, NULL);
g_main_loop_run (mainloop);
/* Ensure that the color temperature is still the default one.*/
- g_assert_cmpint (csd_night_light_get_temperature (nlight), ==, CSD_COLOR_TEMPERATURE_DEFAULT);
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), ==, CSD_COLOR_TEMPERATURE_DEFAULT);
/* Check that disabled until tomorrow resets again correctly. */
g_settings_set_double (settings, "night-light-schedule-from", 17.0);
g_settings_set_double (settings, "night-light-schedule-to", 7.f);
g_settings_set_boolean (settings, "night-light-enabled", TRUE);
- csd_night_light_set_disabled_until_tmw (nlight, TRUE);
+ g_settings_set_boolean (settings, "night-theme-enabled", TRUE);
+ csd_night_mode_set_disabled_until_tmw (nmode, TRUE);
/* Move time past midnight */
g_clear_pointer (&datetime_override, g_date_time_unref);
datetime_override = g_date_time_new_utc (2017, 2, 9, 1, 0, 0);
- csd_night_light_set_date_time_now (nlight, datetime_override);
- g_assert_true (csd_night_light_get_disabled_until_tmw (nlight));
+ csd_night_mode_set_date_time_now (nmode, datetime_override);
+ g_assert_true (csd_night_mode_get_disabled_until_tmw (nmode));
/* Move past sunrise */
g_clear_pointer (&datetime_override, g_date_time_unref);
datetime_override = g_date_time_new_utc (2017, 2, 9, 8, 0, 0);
- csd_night_light_set_date_time_now (nlight, datetime_override);
- g_assert_false (csd_night_light_get_disabled_until_tmw (nlight));
+ csd_night_mode_set_date_time_now (nmode, datetime_override);
+ g_assert_false (csd_night_mode_get_disabled_until_tmw (nmode));
- csd_night_light_set_disabled_until_tmw (nlight, TRUE);
+ csd_night_mode_set_disabled_until_tmw (nmode, TRUE);
/* Move into night more than 24h in the future */
g_clear_pointer (&datetime_override, g_date_time_unref);
datetime_override = g_date_time_new_utc (2017, 2, 10, 20, 0, 0);
- csd_night_light_set_date_time_now (nlight, datetime_override);
- g_assert_false (csd_night_light_get_disabled_until_tmw (nlight));
+ csd_night_mode_set_date_time_now (nmode, datetime_override);
+ g_assert_false (csd_night_mode_get_disabled_until_tmw (nmode));
/* Check that we are always in night mode if from/to are equal. */
- csd_night_light_set_smooth_enabled (nlight, FALSE);
+ csd_night_light_set_smooth_enabled (nmode, FALSE);
g_settings_set_double (settings, "night-light-schedule-from", 6.0);
g_settings_set_double (settings, "night-light-schedule-to", 6.0);
g_settings_set_boolean (settings, "night-light-enabled", TRUE);
+ g_settings_set_boolean (settings, "night-theme-enabled", TRUE);
datetime_override = g_date_time_new_utc (2017, 2, 10, 5, 50, 0);
- csd_night_light_set_date_time_now (nlight, datetime_override);
- g_assert (csd_night_light_get_active (nlight));
- g_assert_cmpint (csd_night_light_get_temperature (nlight), ==, 4000);
+ csd_night_mode_set_date_time_now (nmode, datetime_override);
+ g_assert (csd_night_light_get_active (nmode));
+ g_assert (csd_night_theme_get_active (nmode));
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), ==, 4000);
datetime_override = g_date_time_new_utc (2017, 2, 10, 6, 0, 0);
- csd_night_light_set_date_time_now (nlight, datetime_override);
- g_assert (csd_night_light_get_active (nlight));
- g_assert_cmpint (csd_night_light_get_temperature (nlight), ==, 4000);
+ csd_night_mode_set_date_time_now (nmode, datetime_override);
+ g_assert (csd_night_light_get_active (nmode));
+ g_assert (csd_night_theme_get_active (nmode));
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), ==, 4000);
datetime_override = g_date_time_new_utc (2017, 2, 10, 6, 10, 0);
- csd_night_light_set_date_time_now (nlight, datetime_override);
- g_assert (csd_night_light_get_active (nlight));
- g_assert_cmpint (csd_night_light_get_temperature (nlight), ==, 4000);
+ csd_night_mode_set_date_time_now (nmode, datetime_override);
+ g_assert (csd_night_light_get_active (nmode));
+ g_assert (csd_night_theme_get_active (nmode));
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), ==, 4000);
/* Check that the smearing time is lowered correctly when the times are close. */
@@ -244,31 +285,35 @@ ccm_test_night_light (void)
/* Not enabled 10 minutes before sunset */
datetime_override = g_date_time_new_utc (2017, 2, 10, 5, 50, 0);
- csd_night_light_set_date_time_now (nlight, datetime_override);
- g_assert_false (csd_night_light_get_active (nlight));
- g_assert_cmpint (csd_night_light_get_temperature (nlight), ==, CSD_COLOR_TEMPERATURE_DEFAULT);
+ csd_night_mode_set_date_time_now (nmode, datetime_override);
+ g_assert_false (csd_night_light_get_active (nmode));
+ g_assert_false (csd_night_theme_get_active (nmode));
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), ==, CSD_COLOR_TEMPERATURE_DEFAULT);
/* Not enabled >10 minutes after sunrise */
datetime_override = g_date_time_new_utc (2017, 2, 10, 6, 20, 0);
- csd_night_light_set_date_time_now (nlight, datetime_override);
- g_assert_false (csd_night_light_get_active (nlight));
- g_assert_cmpint (csd_night_light_get_temperature (nlight), ==, CSD_COLOR_TEMPERATURE_DEFAULT);
+ csd_night_mode_set_date_time_now (nmode, datetime_override);
+ g_assert_false (csd_night_light_get_active (nmode));
+ g_assert_false (csd_night_theme_get_active (nmode));
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), ==, CSD_COLOR_TEMPERATURE_DEFAULT);
/* ~50% smeared 3 min before sunrise (sunrise at 6 past) */
datetime_override = g_date_time_new_utc (2017, 2, 10, 6, 3, 0);
- csd_night_light_set_date_time_now (nlight, datetime_override);
- g_assert_true (csd_night_light_get_active (nlight));
- g_assert_cmpint (csd_night_light_get_temperature (nlight), <=, (CSD_COLOR_TEMPERATURE_DEFAULT + 4000) / 2 + 20);
- g_assert_cmpint (csd_night_light_get_temperature (nlight), >=, (CSD_COLOR_TEMPERATURE_DEFAULT + 4000) / 2 - 20);
+ csd_night_mode_set_date_time_now (nmode, datetime_override);
+ g_assert_true (csd_night_light_get_active (nmode));
+ g_assert_true (csd_night_theme_get_active (nmode));
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), <=, (CSD_COLOR_TEMPERATURE_DEFAULT + 4000) / 2 + 20);
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), >=, (CSD_COLOR_TEMPERATURE_DEFAULT + 4000) / 2 - 20);
/* ~50% smeared 3 min before sunset (sunset at 6 past) */
g_settings_set_double (settings, "night-light-schedule-from", 6.1);
g_settings_set_double (settings, "night-light-schedule-to", 6.0);
datetime_override = g_date_time_new_utc (2017, 2, 10, 6, 3, 0);
- csd_night_light_set_date_time_now (nlight, datetime_override);
- g_assert_true (csd_night_light_get_active (nlight));
- g_assert_cmpint (csd_night_light_get_temperature (nlight), <=, (CSD_COLOR_TEMPERATURE_DEFAULT + 4000) / 2 + 20);
- g_assert_cmpint (csd_night_light_get_temperature (nlight), >=, (CSD_COLOR_TEMPERATURE_DEFAULT + 4000) / 2 - 20);
+ csd_night_mode_set_date_time_now (nmode, datetime_override);
+ g_assert_true (csd_night_light_get_active (nmode));
+ g_assert_true (csd_night_theme_get_active (nmode));
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), <=, (CSD_COLOR_TEMPERATURE_DEFAULT + 4000) / 2 + 20);
+ g_assert_cmpint (csd_night_light_get_temperature (nmode), >=, (CSD_COLOR_TEMPERATURE_DEFAULT + 4000) / 2 - 20);
}
static const gboolean
@@ -351,7 +396,7 @@ ccm_test_sunset_sunrise (void)
g_autoptr(GDateTime) dt = g_date_time_new_utc (2007, 2, 1, 0, 0, 0);
/* get for London, today */
- csd_night_light_get_sunrise_sunset (dt, 51.5, -0.1278, &sunrise, &sunset);
+ csd_night_mode_get_sunrise_sunset (dt, 51.5, -0.1278, &sunrise, &sunset);
g_assert_cmpfloat (sunrise, <, sunrise_actual + 0.1);
g_assert_cmpfloat (sunrise, >, sunrise_actual - 0.1);
g_assert_cmpfloat (sunset, <, sunset_actual + 0.1);
@@ -372,7 +417,7 @@ ccm_test_sunset_sunrise_fractional_timezone (void)
dt = g_date_time_new (tz, 2007, 2, 1, 0, 0, 0);
/* get for our made up timezone, today */
- csd_night_light_get_sunrise_sunset (dt, 51.5, -0.1278, &sunrise, &sunset);
+ csd_night_mode_get_sunrise_sunset (dt, 51.5, -0.1278, &sunrise, &sunset);
g_assert_cmpfloat (sunrise, <, sunrise_actual + 0.1);
g_assert_cmpfloat (sunrise, >, sunrise_actual - 0.1);
g_assert_cmpfloat (sunset, <, sunset_actual + 0.1);
@@ -387,26 +432,26 @@ ccm_test_frac_day (void)
gdouble fd_actual = 12.99;
/* test for 12:59:59 */
- fd = csd_night_light_frac_day_from_dt (dt);
+ fd = csd_night_mode_frac_day_from_dt (dt);
g_assert_cmpfloat (fd, >, fd_actual - 0.01);
g_assert_cmpfloat (fd, <, fd_actual + 0.01);
/* test same day */
- g_assert_true (csd_night_light_frac_day_is_between (12, 6, 20));
- g_assert_false (csd_night_light_frac_day_is_between (5, 6, 20));
- g_assert_true (csd_night_light_frac_day_is_between (12, 0, 24));
- g_assert_true (csd_night_light_frac_day_is_between (12, -1, 25));
+ g_assert_true (csd_night_mode_frac_day_is_between (12, 6, 20));
+ g_assert_false (csd_night_mode_frac_day_is_between (5, 6, 20));
+ g_assert_true (csd_night_mode_frac_day_is_between (12, 0, 24));
+ g_assert_true (csd_night_mode_frac_day_is_between (12, -1, 25));
/* test rollover to next day */
- g_assert_true (csd_night_light_frac_day_is_between (23, 20, 6));
- g_assert_false (csd_night_light_frac_day_is_between (12, 20, 6));
+ g_assert_true (csd_night_mode_frac_day_is_between (23, 20, 6));
+ g_assert_false (csd_night_mode_frac_day_is_between (12, 20, 6));
/* test rollover to the previous day */
- g_assert_true (csd_night_light_frac_day_is_between (5, 16, 8));
+ g_assert_true (csd_night_mode_frac_day_is_between (5, 16, 8));
/* test equality */
- g_assert_true (csd_night_light_frac_day_is_between (12, 0.5, 24.5));
- g_assert_true (csd_night_light_frac_day_is_between (0.5, 0.5, 0.5));
+ g_assert_true (csd_night_mode_frac_day_is_between (12, 0.5, 24.5));
+ g_assert_true (csd_night_mode_frac_day_is_between (0.5, 0.5, 0.5));
}
int
@@ -422,7 +467,7 @@ main (int argc, char **argv)
g_test_add_func ("/color/sunset-sunrise", ccm_test_sunset_sunrise);
g_test_add_func ("/color/sunset-sunrise/fractional-timezone", ccm_test_sunset_sunrise_fractional_timezone);
g_test_add_func ("/color/fractional-day", ccm_test_frac_day);
- g_test_add_func ("/color/night-light", ccm_test_night_light);
+ g_test_add_func ("/color/night-mode", ccm_test_night_mode);
return g_test_run ();
}
diff --git a/plugins/color/csd-color-manager.c b/plugins/color/csd-color-manager.c
index 936a5cca..b5752cf5 100644
--- a/plugins/color/csd-color-manager.c
+++ b/plugins/color/csd-color-manager.c
@@ -29,7 +29,7 @@
#include "csd-color-manager.h"
#include "csd-color-profiles.h"
#include "csd-color-state.h"
-#include "csd-night-light.h"
+#include "csd-night-mode.h"
#define CSD_DBUS_NAME "org.cinnamon.SettingsDaemon"
#define CSD_DBUS_PATH "/org/cinnamon/SettingsDaemon"
@@ -45,7 +45,11 @@ static const gchar introspection_xml[] =
" "
" "
" "
+" "
+" "
+" "
" "
+" "
" "
" "
" "
@@ -66,9 +70,10 @@ struct _CsdColorManager
CsdColorCalibrate *calibrate;
CsdColorProfiles *profiles;
CsdColorState *state;
- CsdNightLight *nlight;
+ CsdNightMode *nmode;
- guint nlight_forced_timeout_id;
+ guint nlight_forced_timeout_id;
+ guint ntheme_forced_timeout_id;
};
enum {
@@ -163,52 +168,62 @@ emit_property_changed (CsdColorManager *manager,
}
static void
-on_active_notify (CsdNightLight *nlight,
- GParamSpec *pspec,
- gpointer user_data)
+on_active_nlight_notify (CsdNightMode *nmode,
+ GParamSpec *pspec,
+ gpointer user_data)
{
CsdColorManager *manager = CSD_COLOR_MANAGER (user_data);
emit_property_changed (manager, "NightLightActive",
- g_variant_new_boolean (csd_night_light_get_active (manager->nlight)));
+ g_variant_new_boolean (csd_night_light_get_active (manager->nmode)));
}
static void
-on_sunset_notify (CsdNightLight *nlight,
+on_active_ntheme_notify (CsdNightMode *nmode,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ CsdColorManager *manager = CSD_COLOR_MANAGER (user_data);
+ emit_property_changed (manager, "NightThemeActive",
+ g_variant_new_boolean (csd_night_theme_get_active (manager->nmode)));
+}
+
+static void
+on_sunset_notify (CsdNightMode *nmode,
GParamSpec *pspec,
gpointer user_data)
{
CsdColorManager *manager = CSD_COLOR_MANAGER (user_data);
emit_property_changed (manager, "Sunset",
- g_variant_new_double (csd_night_light_get_sunset (manager->nlight)));
+ g_variant_new_double (csd_night_mode_get_sunset (manager->nmode)));
}
static void
-on_sunrise_notify (CsdNightLight *nlight,
+on_sunrise_notify (CsdNightMode *nmode,
GParamSpec *pspec,
gpointer user_data)
{
CsdColorManager *manager = CSD_COLOR_MANAGER (user_data);
emit_property_changed (manager, "Sunrise",
- g_variant_new_double (csd_night_light_get_sunrise (manager->nlight)));
+ g_variant_new_double (csd_night_mode_get_sunrise (manager->nmode)));
}
static void
-on_disabled_until_tmw_notify (CsdNightLight *nlight,
+on_disabled_until_tmw_notify (CsdNightMode *nmode,
GParamSpec *pspec,
gpointer user_data)
{
CsdColorManager *manager = CSD_COLOR_MANAGER (user_data);
emit_property_changed (manager, "DisabledUntilTomorrow",
- g_variant_new_boolean (csd_night_light_get_disabled_until_tmw (manager->nlight)));
+ g_variant_new_boolean (csd_night_mode_get_disabled_until_tmw (manager->nmode)));
}
static void
-on_temperature_notify (CsdNightLight *nlight,
+on_temperature_notify (CsdNightMode *nmode,
GParamSpec *pspec,
gpointer user_data)
{
CsdColorManager *manager = CSD_COLOR_MANAGER (user_data);
- gdouble temperature = csd_night_light_get_temperature (manager->nlight);
+ gdouble temperature = csd_night_light_get_temperature (manager->nmode);
csd_color_state_set_temperature (manager->state, temperature);
emit_property_changed (manager, "Temperature",
g_variant_new_double (temperature));
@@ -222,17 +237,19 @@ csd_color_manager_init (CsdColorManager *manager)
manager->profiles = csd_color_profiles_new ();
manager->state = csd_color_state_new ();
- /* night light features */
- manager->nlight = csd_night_light_new ();
- g_signal_connect (manager->nlight, "notify::active",
- G_CALLBACK (on_active_notify), manager);
- g_signal_connect (manager->nlight, "notify::sunset",
+ /* night light (and theme) features */
+ manager->nmode = csd_night_mode_new ();
+ g_signal_connect (manager->nmode, "notify::light-active",
+ G_CALLBACK (on_active_nlight_notify), manager);
+ g_signal_connect (manager->nmode, "notify::theme-active",
+ G_CALLBACK (on_active_ntheme_notify), manager);
+ g_signal_connect (manager->nmode, "notify::sunset",
G_CALLBACK (on_sunset_notify), manager);
- g_signal_connect (manager->nlight, "notify::sunrise",
+ g_signal_connect (manager->nmode, "notify::sunrise",
G_CALLBACK (on_sunrise_notify), manager);
- g_signal_connect (manager->nlight, "notify::temperature",
+ g_signal_connect (manager->nmode, "notify::temperature",
G_CALLBACK (on_temperature_notify), manager);
- g_signal_connect (manager->nlight, "notify::disabled-until-tmw",
+ g_signal_connect (manager->nmode, "notify::disabled-until-tmw",
G_CALLBACK (on_disabled_until_tmw_notify), manager);
}
@@ -261,13 +278,17 @@ csd_color_manager_finalize (GObject *object)
manager->name_id = 0;
}
- if (manager->nlight_forced_timeout_id)
+ if (manager->nlight_forced_timeout_id) {
g_source_remove (manager->nlight_forced_timeout_id);
+ }
+ if (manager->ntheme_forced_timeout_id) {
+ g_source_remove (manager->ntheme_forced_timeout_id);
+ }
g_clear_object (&manager->calibrate);
g_clear_object (&manager->profiles);
g_clear_object (&manager->state);
- g_clear_object (&manager->nlight);
+ g_clear_object (&manager->nmode);
G_OBJECT_CLASS (csd_color_manager_parent_class)->finalize (object);
}
@@ -278,7 +299,18 @@ nlight_forced_timeout_cb (gpointer user_data)
CsdColorManager *manager = CSD_COLOR_MANAGER (user_data);
manager->nlight_forced_timeout_id = 0;
- csd_night_light_set_forced (manager->nlight, FALSE);
+ csd_night_light_set_forced (manager->nmode, FALSE);
+
+ return G_SOURCE_REMOVE;
+}
+
+static gboolean
+ntheme_forced_timeout_cb (gpointer user_data)
+{
+ CsdColorManager *manager = CSD_COLOR_MANAGER (user_data);
+
+ manager->ntheme_forced_timeout_id = 0;
+ csd_night_theme_set_forced (manager->nmode, FALSE);
return G_SOURCE_REMOVE;
}
@@ -298,10 +330,10 @@ handle_method_call (GDBusConnection *connection,
if (g_strcmp0 (method_name, "NightLightPreview") == 0) {
guint32 duration = 0;
- if (!manager->nlight) {
+ if (!manager->nmode) {
g_dbus_method_invocation_return_error_literal (invocation,
G_IO_ERROR, G_IO_ERROR_NOT_INITIALIZED,
- "Night-light is currently unavailable");
+ "Night-mode is currently unavailable");
return;
}
@@ -320,9 +352,39 @@ handle_method_call (GDBusConnection *connection,
g_source_remove (manager->nlight_forced_timeout_id);
manager->nlight_forced_timeout_id = g_timeout_add_seconds (duration, nlight_forced_timeout_cb, manager);
- csd_night_light_set_forced (manager->nlight, TRUE);
+ csd_night_light_set_forced (manager->nmode, TRUE);
g_dbus_method_invocation_return_value (invocation, NULL);
+
+ } else if (g_strcmp0 (method_name, "NightThemePreview") == 0) {
+ guint duration = 0;
+
+ if (!manager->nmode) {
+ g_dbus_method_invocation_return_error_literal (invocation,
+ G_IO_ERROR, G_IO_ERROR_NOT_INITIALIZED,
+ "Night-mode is currently unavailable");
+
+ return;
+ }
+
+ g_variant_get (parameters, "(u)", &duration);
+
+ if (duration == 0 || duration > 120) {
+ g_dbus_method_invocation_return_error_literal (invocation,
+ G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
+ "Duration is out of the range (0-120].");
+
+ return;
+ }
+
+ if (manager->ntheme_forced_timeout_id)
+ g_source_remove (manager->ntheme_forced_timeout_id);
+ manager->ntheme_forced_timeout_id = g_timeout_add_seconds (duration, ntheme_forced_timeout_cb, manager);
+
+ csd_night_theme_set_forced (manager->nmode, TRUE);
+
+ g_dbus_method_invocation_return_value (invocation, NULL);
+
} else {
g_assert_not_reached ();
}
@@ -345,7 +407,10 @@ handle_get_property (GDBusConnection *connection,
}
if (g_strcmp0 (property_name, "NightLightActive") == 0)
- return g_variant_new_boolean (csd_night_light_get_active (manager->nlight));
+ return g_variant_new_boolean (csd_night_light_get_active (manager->nmode));
+
+ if (g_strcmp0 (property_name, "NightThemeActive") == 0)
+ return g_variant_new_boolean (csd_night_theme_get_active (manager->nmode));
if (g_strcmp0 (property_name, "Temperature") == 0) {
guint temperature;
@@ -354,13 +419,13 @@ handle_get_property (GDBusConnection *connection,
}
if (g_strcmp0 (property_name, "DisabledUntilTomorrow") == 0)
- return g_variant_new_boolean (csd_night_light_get_disabled_until_tmw (manager->nlight));
+ return g_variant_new_boolean (csd_night_mode_get_disabled_until_tmw (manager->nmode));
if (g_strcmp0 (property_name, "Sunrise") == 0)
- return g_variant_new_double (csd_night_light_get_sunrise (manager->nlight));
+ return g_variant_new_double (csd_night_mode_get_sunrise (manager->nmode));
if (g_strcmp0 (property_name, "Sunset") == 0)
- return g_variant_new_double (csd_night_light_get_sunset (manager->nlight));
+ return g_variant_new_double (csd_night_mode_get_sunset (manager->nmode));
g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,
"Failed to get property: %s", property_name);
@@ -408,7 +473,7 @@ handle_set_property (GDBusConnection *connection,
}
if (g_strcmp0 (property_name, "DisabledUntilTomorrow") == 0) {
- csd_night_light_set_disabled_until_tmw (manager->nlight,
+ csd_night_mode_set_disabled_until_tmw (manager->nmode,
g_variant_get_boolean (value));
return TRUE;
}
@@ -466,9 +531,9 @@ on_bus_gotten (GObject *source_object,
manager,
NULL);
- /* setup night light module */
- if (!csd_night_light_start (manager->nlight, &error)) {
- g_warning ("Could not start night light module: %s", error->message);
+ /* setup night mode module */
+ if (!csd_night_mode_start (manager->nmode, &error)) {
+ g_warning ("Could not start night mode module: %s", error->message);
g_error_free (error);
}
}
diff --git a/plugins/color/csd-night-light.h b/plugins/color/csd-night-light.h
deleted file mode 100644
index 0786d1aa..00000000
--- a/plugins/color/csd-night-light.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2017 Richard Hughes
- *
- * Licensed under the GNU General Public License Version 2
- *
- * 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 2 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, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef __CSD_NIGHT_LIGHT_H__
-#define __CSD_NIGHT_LIGHT_H__
-
-#include
-
-G_BEGIN_DECLS
-
-#define CSD_TYPE_NIGHT_LIGHT (csd_night_light_get_type ())
-G_DECLARE_FINAL_TYPE (CsdNightLight, csd_night_light, CSD, NIGHT_LIGHT, GObject)
-
-CsdNightLight *csd_night_light_new (void);
-gboolean csd_night_light_start (CsdNightLight *self,
- GError **error);
-
-gboolean csd_night_light_get_active (CsdNightLight *self);
-gdouble csd_night_light_get_sunrise (CsdNightLight *self);
-gdouble csd_night_light_get_sunset (CsdNightLight *self);
-gdouble csd_night_light_get_temperature (CsdNightLight *self);
-
-gboolean csd_night_light_get_disabled_until_tmw (CsdNightLight *self);
-void csd_night_light_set_disabled_until_tmw (CsdNightLight *self,
- gboolean value);
-
-gboolean csd_night_light_get_forced (CsdNightLight *self);
-void csd_night_light_set_forced (CsdNightLight *self,
- gboolean value);
-
-void csd_night_light_set_date_time_now (CsdNightLight *self,
- GDateTime *datetime);
-void csd_night_light_set_smooth_enabled (CsdNightLight *self,
- gboolean smooth_enabled);
-
-G_END_DECLS
-
-#endif
diff --git a/plugins/color/csd-night-light-common.c b/plugins/color/csd-night-mode-common.c
similarity index 92%
rename from plugins/color/csd-night-light-common.c
rename to plugins/color/csd-night-mode-common.c
index 6710e5c0..af8051ac 100644
--- a/plugins/color/csd-night-light-common.c
+++ b/plugins/color/csd-night-mode-common.c
@@ -22,7 +22,7 @@
#include
#include
-#include "csd-night-light-common.h"
+#include "csd-night-mode-common.h"
static gdouble
deg2rad (gdouble degrees)
@@ -47,9 +47,9 @@ rad2deg (gdouble radians)
* a sunrise at all.
*/
gboolean
-csd_night_light_get_sunrise_sunset (GDateTime *dt,
- gdouble pos_lat, gdouble pos_long,
- gdouble *sunrise, gdouble *sunset)
+csd_night_mode_get_sunrise_sunset (GDateTime *dt,
+ gdouble pos_lat, gdouble pos_long,
+ gdouble *sunrise, gdouble *sunset)
{
g_autoptr(GDateTime) dt_zero = g_date_time_new_utc (1900, 1, 1, 0, 0, 0);
GTimeSpan ts = g_date_time_difference (dt, dt_zero);
@@ -107,7 +107,7 @@ csd_night_light_get_sunrise_sunset (GDateTime *dt,
}
gdouble
-csd_night_light_frac_day_from_dt (GDateTime *dt)
+csd_night_mode_frac_day_from_dt (GDateTime *dt)
{
return g_date_time_get_hour (dt) +
(gdouble) g_date_time_get_minute (dt) / 60.f +
@@ -115,16 +115,16 @@ csd_night_light_frac_day_from_dt (GDateTime *dt)
}
gchar *
-csd_night_light_time_string_from_frac (gdouble fraction)
+csd_night_mode_time_string_from_frac (gdouble fraction)
{
g_autoptr(GDateTime) dt = g_date_time_new_local (2000, 1, 1, (int) trunc (fraction), (int) ((fraction - trunc(fraction)) * 60.0f), 0);
return g_date_time_format (dt, "%H:%M");
}
gboolean
-csd_night_light_frac_day_is_between (gdouble value,
- gdouble start,
- gdouble end)
+csd_night_mode_frac_day_is_between (gdouble value,
+ gdouble start,
+ gdouble end)
{
/* wrap end to the next day if it is before start,
* considering equal values as a full 24h period
diff --git a/plugins/color/csd-night-light-common.h b/plugins/color/csd-night-mode-common.h
similarity index 78%
rename from plugins/color/csd-night-light-common.h
rename to plugins/color/csd-night-mode-common.h
index f095e8d9..b1d916cc 100644
--- a/plugins/color/csd-night-light-common.h
+++ b/plugins/color/csd-night-mode-common.h
@@ -17,24 +17,24 @@
*
*/
-#ifndef __CSD_NIGHT_LIGHT_COMMON_H
-#define __CSD_NIGHT_LIGHT_COMMON_H
+#ifndef __CSD_NIGHT_MODE_COMMON_H
+#define __CSD_NIGHT_MODE_COMMON_H
#include
G_BEGIN_DECLS
-gboolean csd_night_light_get_sunrise_sunset (GDateTime *dt,
+gboolean csd_night_mode_get_sunrise_sunset (GDateTime *dt,
gdouble pos_lat,
gdouble pos_long,
gdouble *sunrise,
gdouble *sunset);
-gdouble csd_night_light_frac_day_from_dt (GDateTime *dt);
-gchar * csd_night_light_time_string_from_frac (gdouble fraction);
-gboolean csd_night_light_frac_day_is_between (gdouble value,
+gdouble csd_night_mode_frac_day_from_dt (GDateTime *dt);
+gchar * csd_night_mode_time_string_from_frac (gdouble fraction);
+gboolean csd_night_mode_frac_day_is_between (gdouble value,
gdouble start,
gdouble end);
G_END_DECLS
-#endif /* __CSD_NIGHT_LIGHT_COMMON_H */
+#endif /* __CSD_NIGHT_MODE_COMMON_H */
diff --git a/plugins/color/csd-night-light.c b/plugins/color/csd-night-mode.c
similarity index 50%
rename from plugins/color/csd-night-light.c
rename to plugins/color/csd-night-mode.c
index 249fdbd8..a2edd56b 100644
--- a/plugins/color/csd-night-light.c
+++ b/plugins/color/csd-night-mode.c
@@ -25,14 +25,20 @@
#include "csd-color-state.h"
-#include "csd-night-light.h"
-#include "csd-night-light-common.h"
+#include "csd-night-mode.h"
+#include "csd-night-mode-common.h"
#include "tz-coords.h"
-struct _CsdNightLight {
+struct _CsdNightMode {
GObject parent;
GSettings *settings;
- gboolean forced;
+ GSettings *theme_settings;
+ GSettings *x_theme_settings;
+ GSettings *cinnamon_theme_settings;
+ gboolean cached_light_active_unset;
+ gboolean cached_theme_active_unset;
+ gboolean light_forced;
+ gboolean theme_forced;
gboolean disabled_until_tmw;
GDateTime *disabled_until_tmw_dt;
GSource *source;
@@ -40,7 +46,8 @@ struct _CsdNightLight {
gdouble cached_sunrise;
gdouble cached_sunset;
gdouble cached_temperature;
- gboolean cached_active;
+ gboolean cached_light_active;
+ gboolean cached_theme_active;
gboolean smooth_enabled;
GTimer *smooth_timer;
guint smooth_id;
@@ -51,37 +58,41 @@ struct _CsdNightLight {
enum {
PROP_0,
- PROP_ACTIVE,
+ PROP_LIGHT_ACTIVE,
+ PROP_THEME_ACTIVE,
PROP_SUNRISE,
PROP_SUNSET,
PROP_TEMPERATURE,
PROP_DISABLED_UNTIL_TMW,
- PROP_FORCED,
+ PROP_LIGHT_FORCED,
+ PROP_THEME_FORCED,
PROP_LAST
};
enum {
- NIGHT_LIGHT_SCHEDULE_AUTO = 0,
- NIGHT_LIGHT_SCHEDULE_MANUAL = 1,
- NIGHT_LIGHT_SCHEDULE_ALWAYS_ON = 2
+ NIGHT_MODE_SCHEDULE_AUTO = 0,
+ NIGHT_MODE_SCHEDULE_MANUAL = 1,
+ NIGHT_MODE_SCHEDULE_ALWAYS_ON = 2
};
-#define CSD_NIGHT_LIGHT_SCHEDULE_TIMEOUT 5 /* seconds */
-#define CSD_NIGHT_LIGHT_POLL_TIMEOUT 60 /* seconds */
+#define CSD_NIGHT_MODE_SCHEDULE_TIMEOUT 5 /* seconds */
+#define CSD_NIGHT_MODE_POLL_TIMEOUT 60 /* seconds */
#define CSD_NIGHT_LIGHT_POLL_SMEAR 1 /* hours */
#define CSD_NIGHT_LIGHT_SMOOTH_SMEAR 5.f /* seconds */
#define CSD_FRAC_DAY_MAX_DELTA (1.f/60.f) /* 1 minute */
#define CSD_TEMPERATURE_MAX_DELTA (10.f) /* Kelvin */
-static void poll_timeout_destroy (CsdNightLight *self);
-static void poll_timeout_create (CsdNightLight *self);
-static void night_light_recheck (CsdNightLight *self);
+static void poll_timeout_destroy (CsdNightMode *self);
+static void poll_timeout_create (CsdNightMode *self);
+static void night_mode_recheck (CsdNightMode *self);
+static void night_light_recheck (CsdNightMode *self);
+static void night_theme_recheck (CsdNightMode *self);
-G_DEFINE_TYPE (CsdNightLight, csd_night_light, G_TYPE_OBJECT);
+G_DEFINE_TYPE (CsdNightMode, csd_night_mode, G_TYPE_OBJECT);
static GDateTime *
-csd_night_light_get_date_time_now (CsdNightLight *self)
+csd_night_mode_get_date_time_now (CsdNightMode *self)
{
if (self->datetime_override != NULL)
return g_date_time_ref (self->datetime_override);
@@ -89,17 +100,17 @@ csd_night_light_get_date_time_now (CsdNightLight *self)
}
void
-csd_night_light_set_date_time_now (CsdNightLight *self, GDateTime *datetime)
+csd_night_mode_set_date_time_now (CsdNightMode *self, GDateTime *datetime)
{
if (self->datetime_override != NULL)
g_date_time_unref (self->datetime_override);
self->datetime_override = g_date_time_ref (datetime);
- night_light_recheck (self);
+ night_mode_recheck (self);
}
static void
-poll_smooth_destroy (CsdNightLight *self)
+poll_smooth_destroy (CsdNightMode *self)
{
if (self->smooth_id != 0) {
g_source_remove (self->smooth_id);
@@ -110,8 +121,8 @@ poll_smooth_destroy (CsdNightLight *self)
}
void
-csd_night_light_set_smooth_enabled (CsdNightLight *self,
- gboolean smooth_enabled)
+csd_night_mode_set_smooth_enabled (CsdNightMode *self,
+ gboolean smooth_enabled)
{
/* ensure the timeout is stopped if called at runtime */
if (!smooth_enabled)
@@ -128,7 +139,7 @@ linear_interpolate (gdouble val1, gdouble val2, gdouble factor)
}
static gboolean
-update_cached_sunrise_sunset (CsdNightLight *self)
+update_cached_sunrise_sunset (CsdNightMode *self)
{
gboolean ret = FALSE;
gdouble latitude;
@@ -136,7 +147,7 @@ update_cached_sunrise_sunset (CsdNightLight *self)
gdouble sunrise;
gdouble sunset;
g_autoptr(GVariant) tmp = NULL;
- g_autoptr(GDateTime) dt_now = csd_night_light_get_date_time_now (self);
+ g_autoptr(GDateTime) dt_now = csd_night_mode_get_date_time_now (self);
/* calculate the sunrise/sunset for the location */
tmp = g_settings_get_value (self->settings, "night-light-last-coordinates");
@@ -145,8 +156,8 @@ update_cached_sunrise_sunset (CsdNightLight *self)
return FALSE;
if (longitude > 180.f || longitude < -180.f)
return FALSE;
- if (!csd_night_light_get_sunrise_sunset (dt_now, latitude, longitude,
- &sunrise, &sunset)) {
+ if (!csd_night_mode_get_sunrise_sunset (dt_now, latitude, longitude,
+ &sunrise, &sunset)) {
g_warning ("failed to get sunset/sunrise for %.3f,%.3f",
latitude, longitude);
return FALSE;
@@ -156,14 +167,14 @@ update_cached_sunrise_sunset (CsdNightLight *self)
if (ABS (self->cached_sunrise - sunrise) > CSD_FRAC_DAY_MAX_DELTA) {
self->cached_sunrise = sunrise;
g_object_notify (G_OBJECT (self), "sunrise");
- g_autofree gchar *formatted = csd_night_light_time_string_from_frac (sunrise);
+ g_autofree gchar *formatted = csd_night_mode_time_string_from_frac (sunrise);
g_debug ("Sunrise updated: %.3f (%s)", sunrise, formatted);
ret = TRUE;
}
if (ABS (self->cached_sunset - sunset) > CSD_FRAC_DAY_MAX_DELTA) {
self->cached_sunset = sunset;
g_object_notify (G_OBJECT (self), "sunset");
- g_autofree gchar *formatted = csd_night_light_time_string_from_frac (sunset);
+ g_autofree gchar *formatted = csd_night_mode_time_string_from_frac (sunset);
g_debug ("Sunset updated: %.3f (%s)", sunset, formatted);
ret = TRUE;
}
@@ -171,7 +182,7 @@ update_cached_sunrise_sunset (CsdNightLight *self)
}
static void
-csd_night_light_set_temperature_internal (CsdNightLight *self, gdouble temperature)
+csd_night_light_set_temperature_internal (CsdNightMode *self, gdouble temperature)
{
if (ABS (self->cached_temperature - temperature) <= CSD_TEMPERATURE_MAX_DELTA)
return;
@@ -182,7 +193,7 @@ csd_night_light_set_temperature_internal (CsdNightLight *self, gdouble temperatu
static gboolean
csd_night_light_smooth_cb (gpointer user_data)
{
- CsdNightLight *self = CSD_NIGHT_LIGHT (user_data);
+ CsdNightMode *self = CSD_NIGHT_MODE (user_data);
gdouble tmp;
gdouble frac;
@@ -205,7 +216,7 @@ csd_night_light_smooth_cb (gpointer user_data)
}
static void
-poll_smooth_create (CsdNightLight *self, gdouble temperature)
+poll_smooth_create (CsdNightMode *self, gdouble temperature)
{
g_assert (self->smooth_id == 0);
self->smooth_target_temperature = temperature;
@@ -214,7 +225,7 @@ poll_smooth_create (CsdNightLight *self, gdouble temperature)
}
static void
-csd_night_light_set_temperature (CsdNightLight *self, gdouble temperature)
+csd_night_light_set_temperature (CsdNightMode *self, gdouble temperature)
{
/* immediate */
if (!self->smooth_enabled) {
@@ -236,21 +247,248 @@ csd_night_light_set_temperature (CsdNightLight *self, gdouble temperature)
}
static void
-csd_night_light_set_active (CsdNightLight *self, gboolean active)
+night_theme_switch_on (CsdNightMode *self)
+{
+ gboolean is_active;
+ /* get backups */
+ gchar *backup_day_theme = g_settings_get_string (self->settings, "backup-day-theme");
+ gchar *backup_day_icon_theme = g_settings_get_string (self->settings, "backup-day-icon-theme");
+ gchar *backup_day_cinnamon_theme = g_settings_get_string (self->settings, "backup-day-cinnamon-theme");
+ /* check if there are backups */
+ is_active = (
+ (backup_day_theme != NULL &&
+ g_strcmp0 (backup_day_theme, "") != 0) ||
+ (backup_day_icon_theme != NULL &&
+ g_strcmp0 (backup_day_icon_theme, "") != 0) ||
+ (backup_day_cinnamon_theme != NULL &&
+ g_strcmp0 (backup_day_cinnamon_theme, "") != 0)
+ );
+ /* free memory */
+ g_free (backup_day_theme);
+ g_free (backup_day_icon_theme);
+ g_free (backup_day_cinnamon_theme);
+
+ if (is_active) {
+ g_debug ("night theme already active => not switching on");
+ return;
+ }
+ g_debug ("switching on night theme...");
+ /* copy values to the backups */
+ g_settings_set_string (self->settings, "backup-day-theme", g_settings_get_string (self->theme_settings, "gtk-theme"));
+ g_settings_set_string (self->settings, "backup-day-cinnamon-theme", g_settings_get_string (self->cinnamon_theme_settings, "name"));
+ g_settings_set_string (self->settings, "backup-day-icon-theme", g_settings_get_string (self->theme_settings, "icon-theme"));
+ g_settings_set_enum (self->settings, "backup-day-color-scheme", g_settings_get_enum (self->x_theme_settings, "color-scheme"));
+ /* activate the night themes */
+ g_settings_set_string (self->theme_settings, "gtk-theme", g_settings_get_string (self->settings, "night-theme"));
+ g_settings_set_string (self->theme_settings, "icon-theme", g_settings_get_string (self->settings, "night-icon-theme"));
+ g_settings_set_string (self->cinnamon_theme_settings, "name", g_settings_get_string (self->settings, "night-cinnamon-theme"));
+ g_settings_set_enum (self->x_theme_settings, "color-scheme", g_settings_get_enum (self->settings, "night-color-scheme"));
+}
+
+static void
+night_theme_switch_off (CsdNightMode *self)
+{
+ gboolean is_active;
+ /* get backups */
+ gchar *backup_day_theme = g_settings_get_string (self->settings, "backup-day-theme");
+ gchar *backup_day_icon_theme = g_settings_get_string (self->settings, "backup-day-icon-theme");
+ gchar *backup_day_cinnamon_theme = g_settings_get_string (self->settings, "backup-day-cinnamon-theme");
+ /* check if there are no backups */
+ is_active = (
+ (backup_day_theme != NULL &&
+ g_strcmp0 (backup_day_theme, "") != 0) ||
+ (backup_day_icon_theme != NULL &&
+ g_strcmp0 (backup_day_icon_theme, "") != 0) ||
+ (backup_day_cinnamon_theme != NULL &&
+ g_strcmp0 (backup_day_cinnamon_theme, "") != 0)
+ );
+
+ if (!is_active) {
+ g_debug ("night theme already inactive => not switching off");
+ g_free (backup_day_theme);
+ g_free (backup_day_icon_theme);
+ g_free (backup_day_cinnamon_theme);
+ return;
+ }
+ g_debug ("switching off night theme...");
+ /* save the current night theme */
+ g_settings_set_string (self->settings, "night-theme", g_settings_get_string (self->theme_settings, "gtk-theme"));
+ g_settings_set_string (self->settings, "night-icon-theme", g_settings_get_string (self->theme_settings, "icon-theme"));
+ g_settings_set_string (self->settings, "night-cinnamon-theme", g_settings_get_string (self->cinnamon_theme_settings, "name"));
+ g_settings_set_enum (self->settings, "night-color-scheme", g_settings_get_enum (self->x_theme_settings, "color-scheme"));
+ /* restore the backups */
+ g_settings_set_string (self->theme_settings, "gtk-theme", backup_day_theme);
+ g_settings_set_string (self->theme_settings, "icon-theme", backup_day_icon_theme);
+ g_settings_set_string (self->cinnamon_theme_settings, "name", backup_day_cinnamon_theme);
+ g_settings_set_enum (self->x_theme_settings, "color-scheme", g_settings_get_enum (self->settings, "backup-day-color-scheme"));
+ /* clear the backups */
+ g_settings_set_string (self->settings, "backup-day-theme", "");
+ g_settings_set_string (self->settings, "backup-day-icon-theme", "");
+ g_settings_set_string (self->settings, "backup-day-cinnamon-theme", "");
+ /* free memory */
+ g_free (backup_day_theme);
+ g_free (backup_day_icon_theme);
+ g_free (backup_day_cinnamon_theme);
+}
+
+static void
+csd_night_light_set_active (CsdNightMode *self, gboolean active)
{
- if (self->cached_active == active)
+ if (self->cached_light_active == active && !self->cached_light_active_unset) {
return;
- self->cached_active = active;
+ } else if (self->cached_light_active_unset) {
+ self->cached_light_active_unset = FALSE;
+ }
+ self->cached_light_active = active;
/* ensure set to unity temperature */
if (!active)
csd_night_light_set_temperature (self, CSD_COLOR_TEMPERATURE_DEFAULT);
- g_object_notify (G_OBJECT (self), "active");
+ g_object_notify (G_OBJECT (self), "light-active");
}
static void
-night_light_recheck (CsdNightLight *self)
+csd_night_theme_set_active (CsdNightMode *self, gboolean active)
+{
+ if (self->cached_theme_active == active && !self->cached_theme_active_unset) {
+ return;
+ } else if (self->cached_theme_active_unset) {
+ self->cached_theme_active_unset = FALSE;
+ }
+ self->cached_theme_active = active;
+
+ /* switch off theme if not active & switch on else */
+ if (!active)
+ night_theme_switch_off (self);
+ else
+ night_theme_switch_on (self);
+
+ g_object_notify (G_OBJECT (self), "theme-active");
+}
+
+static void
+night_mode_recheck (CsdNightMode *self)
+{
+ if (self->light_forced && self->theme_forced) {
+ night_light_recheck (self);
+ night_theme_recheck (self);
+ return;
+ }
+
+ /* calculate the position of the sun */
+ update_cached_sunrise_sunset (self);
+
+ gdouble frac_day;
+ g_autoptr(GDateTime) dt_now = csd_night_mode_get_date_time_now (self);
+ frac_day = csd_night_mode_frac_day_from_dt (dt_now);
+
+ /* check if it's still not tomorrow */
+ if (self->disabled_until_tmw) {
+ GTimeSpan time_span;
+ gboolean reset = FALSE;
+
+ time_span = g_date_time_difference (dt_now, self->disabled_until_tmw_dt);
+
+ /* Reset if disabled until tomorrow is more than 24h ago. */
+ if (time_span > (GTimeSpan) 24 * 60 * 60 * 1000000) {
+ g_debug ("night mode disabled-until-tomorrow is older than 24h, resetting disabled-until-tomorrow");
+ reset = TRUE;
+ } else if (time_span > 0) {
+ /* Or if a sunrise lies between the time it was disabled and now. */
+ gdouble frac_disabled;
+ frac_disabled = csd_night_mode_frac_day_from_dt (self->disabled_until_tmw_dt);
+ if (frac_disabled != frac_day &&
+ csd_night_mode_frac_day_is_between (self->cached_sunrise,
+ frac_disabled,
+ frac_day)) {
+ g_debug ("night mode sun rise happened, resetting disabled-until-tomorrow");
+ reset = TRUE;
+ }
+ }
+
+ if (reset) {
+ self->disabled_until_tmw = FALSE;
+ g_clear_pointer(&self->disabled_until_tmw_dt, g_date_time_unref);
+ g_object_notify (G_OBJECT (self), "disabled-until-tmw");
+ } else {
+ g_debug ("night mode disabled-until-tomorrow is true");
+ }
+ }
+
+ night_light_recheck (self);
+ night_theme_recheck (self);
+}
+
+static void
+night_theme_recheck (CsdNightMode *self)
+{
+ gdouble frac_day;
+ gdouble schedule_from = -1.f;
+ gdouble schedule_to = -1.f;
+ g_autoptr(GDateTime) dt_now = csd_night_mode_get_date_time_now (self);
+
+ /* If forced (e.g. for preview), just switch on and return */
+ if (self->theme_forced) {
+ night_theme_switch_on (self);
+ g_debug ("night theme forced on");
+ return;
+ }
+
+ if (!g_settings_get_boolean (self->settings, "night-theme-enabled")) {
+ /* settings say NO */
+ csd_night_theme_set_active (self, FALSE);
+ g_debug ("night theme disabled");
+ return;
+ }
+
+ switch (g_settings_get_enum (self->settings, "night-light-schedule-mode")) {
+ case NIGHT_MODE_SCHEDULE_ALWAYS_ON:
+ /* turn on and return */
+ g_debug ("night mode always on - theme on");
+ csd_night_theme_set_active (self, TRUE);
+ return;
+ case NIGHT_MODE_SCHEDULE_AUTO:
+ /* was updated in night_mode_recheck(self) */
+ schedule_to = self->cached_sunrise;
+ schedule_from = self->cached_sunset;
+ break;
+ default:
+ break;
+ }
+
+ /* fall back to manual settings (if nothing was calculated) */
+ if (schedule_to <= 0.f || schedule_from <= 0.f) {
+ schedule_from = g_settings_get_double (self->settings,
+ "night-light-schedule-from");
+ schedule_to = g_settings_get_double (self->settings,
+ "night-light-schedule-to");
+ }
+
+ /* get the current hour of a day as a fraction */
+ frac_day = csd_night_mode_frac_day_from_dt (dt_now);
+
+ /* disabled until tomorrow - updated in night_mode_recheck(self) */
+ if (self->disabled_until_tmw) {
+ csd_night_theme_set_active(self, FALSE);
+ return;
+ }
+
+ /* theme is activated from schedule_from to schedule_to - easy */
+ if (!csd_night_mode_frac_day_is_between (frac_day,
+ schedule_from,
+ schedule_to)) {
+ g_debug ("not time for night theme");
+ csd_night_theme_set_active (self, FALSE);
+ return;
+ }
+
+ csd_night_theme_set_active(self, TRUE);
+ g_debug ("night theme is active!");
+}
+
+static void
+night_light_recheck (CsdNightMode *self)
{
gdouble frac_day;
gdouble schedule_from = -1.f;
@@ -258,13 +496,14 @@ night_light_recheck (CsdNightLight *self)
gdouble smear = CSD_NIGHT_LIGHT_POLL_SMEAR; /* hours */
guint temperature;
guint temp_smeared;
- g_autoptr(GDateTime) dt_now = csd_night_light_get_date_time_now (self);
+ g_autoptr(GDateTime) dt_now = csd_night_mode_get_date_time_now (self);
- /* Forced mode, just set the temperature to night light.
+ /* Forced mode, just set the temperature to night.
* Proper rechecking will happen once forced mode is disabled again */
- if (self->forced) {
+ if (self->light_forced) {
temperature = g_settings_get_uint (self->settings, "night-light-temperature");
csd_night_light_set_temperature (self, temperature);
+ g_debug ("night light forced on");
return;
}
@@ -277,27 +516,24 @@ night_light_recheck (CsdNightLight *self)
/* schedule-mode */
switch (g_settings_get_enum (self->settings, "night-light-schedule-mode")) {
- case NIGHT_LIGHT_SCHEDULE_ALWAYS_ON:
+ case NIGHT_MODE_SCHEDULE_ALWAYS_ON:
/* just set the temperature to night light */
temperature = g_settings_get_uint (self->settings, "night-light-temperature");
- g_debug ("night light mode always on, using temperature of %uK",
+ g_debug ("night light always on, using temperature of %uK",
temperature);
csd_night_light_set_active (self, TRUE);
csd_night_light_set_temperature (self, temperature);
return;
- case NIGHT_LIGHT_SCHEDULE_AUTO:
- /* calculate the position of the sun */
- update_cached_sunrise_sunset (self);
- if (self->cached_sunrise > 0.f && self->cached_sunset > 0.f) {
- schedule_to = self->cached_sunrise;
- schedule_from = self->cached_sunset;
- }
+ case NIGHT_MODE_SCHEDULE_AUTO:
+ /* sun was updated in night_mode_recheck(self) */
+ schedule_to = self->cached_sunrise;
+ schedule_from = self->cached_sunset;
break;
default:
break;
}
- /* fall back to manual settings */
+ /* fall back to manual settings in case of no calculation */
if (schedule_to <= 0.f || schedule_from <= 0.f) {
schedule_from = g_settings_get_double (self->settings,
"night-light-schedule-from");
@@ -306,44 +542,14 @@ night_light_recheck (CsdNightLight *self)
}
/* get the current hour of a day as a fraction */
- frac_day = csd_night_light_frac_day_from_dt (dt_now);
+ frac_day = csd_night_mode_frac_day_from_dt (dt_now);
g_debug ("fractional day = %.3f, limits = %.3f->%.3f",
frac_day, schedule_from, schedule_to);
- /* disabled until tomorrow */
+ /* disabled until tomorrow - is updated in night_mode_recheck(self) */
if (self->disabled_until_tmw) {
- GTimeSpan time_span;
- gboolean reset = FALSE;
-
- time_span = g_date_time_difference (dt_now, self->disabled_until_tmw_dt);
-
- /* Reset if disabled until tomorrow is more than 24h ago. */
- if (time_span > (GTimeSpan) 24 * 60 * 60 * 1000000) {
- g_debug ("night light disabled until tomorrow is older than 24h, resetting disabled until tomorrow");
- reset = TRUE;
- } else if (time_span > 0) {
- /* Or if a sunrise lies between the time it was disabled and now. */
- gdouble frac_disabled;
- frac_disabled = csd_night_light_frac_day_from_dt (self->disabled_until_tmw_dt);
- if (frac_disabled != frac_day &&
- csd_night_light_frac_day_is_between (schedule_to,
- frac_disabled,
- frac_day)) {
- g_debug ("night light sun rise happened, resetting disabled until tomorrow");
- reset = TRUE;
- }
- }
-
- if (reset) {
- self->disabled_until_tmw = FALSE;
- g_clear_pointer(&self->disabled_until_tmw_dt, g_date_time_unref);
- g_object_notify (G_OBJECT (self), "disabled-until-tmw");
- } else {
- g_debug ("night light still day-disabled, resetting");
- csd_night_light_set_temperature (self,
- CSD_COLOR_TEMPERATURE_DEFAULT);
- return;
- }
+ csd_night_light_set_active(self, FALSE);
+ return;
}
/* lower smearing period to be smaller than the time between start/stop */
@@ -351,10 +557,10 @@ night_light_recheck (CsdNightLight *self)
MIN ( ABS (schedule_to - schedule_from),
24 - ABS (schedule_to - schedule_from)));
- if (!csd_night_light_frac_day_is_between (frac_day,
- schedule_from - smear,
- schedule_to)) {
- g_debug ("not time for night-light");
+ if (!csd_night_mode_frac_day_is_between (frac_day,
+ schedule_from - smear,
+ schedule_to)) {
+ g_debug ("not time for night light");
csd_night_light_set_active (self, FALSE);
return;
}
@@ -373,15 +579,15 @@ night_light_recheck (CsdNightLight *self)
if (smear < 0.01) {
/* Don't try to smear for extremely short or zero periods */
temp_smeared = temperature;
- } else if (csd_night_light_frac_day_is_between (frac_day,
- schedule_from - smear,
- schedule_from)) {
+ } else if (csd_night_mode_frac_day_is_between (frac_day,
+ schedule_from - smear,
+ schedule_from)) {
gdouble factor = 1.f - ((frac_day - (schedule_from - smear)) / smear);
temp_smeared = linear_interpolate (CSD_COLOR_TEMPERATURE_DEFAULT,
temperature, factor);
- } else if (csd_night_light_frac_day_is_between (frac_day,
- schedule_to - smear,
- schedule_to)) {
+ } else if (csd_night_mode_frac_day_is_between (frac_day,
+ schedule_to - smear,
+ schedule_to)) {
gdouble factor = (frac_day - (schedule_to - smear)) / smear;
temp_smeared = linear_interpolate (CSD_COLOR_TEMPERATURE_DEFAULT,
temperature, factor);
@@ -396,12 +602,12 @@ night_light_recheck (CsdNightLight *self)
/* called when the time may have changed */
static gboolean
-night_light_recheck_cb (gpointer user_data)
+night_mode_recheck_cb (gpointer user_data)
{
- CsdNightLight *self = CSD_NIGHT_LIGHT (user_data);
+ CsdNightMode *self = CSD_NIGHT_MODE (user_data);
/* recheck parameters, then reschedule a new timeout */
- night_light_recheck (self);
+ night_mode_recheck (self);
poll_timeout_destroy (self);
poll_timeout_create (self);
@@ -410,7 +616,7 @@ night_light_recheck_cb (gpointer user_data)
}
static void
-poll_timeout_create (CsdNightLight *self)
+poll_timeout_create (CsdNightMode *self)
{
g_autoptr(GDateTime) dt_now = NULL;
g_autoptr(GDateTime) dt_expiry = NULL;
@@ -418,19 +624,19 @@ poll_timeout_create (CsdNightLight *self)
if (self->source != NULL)
return;
- dt_now = csd_night_light_get_date_time_now (self);
- dt_expiry = g_date_time_add_seconds (dt_now, CSD_NIGHT_LIGHT_POLL_TIMEOUT);
+ dt_now = csd_night_mode_get_date_time_now (self);
+ dt_expiry = g_date_time_add_seconds (dt_now, CSD_NIGHT_MODE_POLL_TIMEOUT);
self->source = _gnome_datetime_source_new (dt_now,
dt_expiry,
TRUE);
g_source_set_callback (self->source,
- night_light_recheck_cb,
+ night_mode_recheck_cb,
self, NULL);
g_source_attach (self->source, NULL);
}
static void
-poll_timeout_destroy (CsdNightLight *self)
+poll_timeout_destroy (CsdNightMode *self)
{
if (self->source == NULL)
@@ -444,13 +650,13 @@ poll_timeout_destroy (CsdNightLight *self)
static void
settings_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
{
- CsdNightLight *self = CSD_NIGHT_LIGHT (user_data);
+ CsdNightMode *self = CSD_NIGHT_MODE (user_data);
g_debug ("settings changed");
- night_light_recheck (self);
+ night_mode_recheck (self);
}
static void
-update_location_from_timezone (CsdNightLight *self)
+update_location_from_timezone (CsdNightMode *self)
{
GTimeZone *tz = g_time_zone_new_local ();
const gchar *id = g_time_zone_get_identifier (tz);
@@ -473,9 +679,9 @@ update_location_from_timezone (CsdNightLight *self)
}
void
-csd_night_light_set_disabled_until_tmw (CsdNightLight *self, gboolean value)
+csd_night_mode_set_disabled_until_tmw (CsdNightMode *self, gboolean value)
{
- g_autoptr(GDateTime) dt = csd_night_light_get_date_time_now (self);
+ g_autoptr(GDateTime) dt = csd_night_mode_get_date_time_now (self);
if (self->disabled_until_tmw == value)
return;
@@ -484,67 +690,102 @@ csd_night_light_set_disabled_until_tmw (CsdNightLight *self, gboolean value)
g_clear_pointer (&self->disabled_until_tmw_dt, g_date_time_unref);
if (self->disabled_until_tmw)
self->disabled_until_tmw_dt = g_steal_pointer (&dt);
- night_light_recheck (self);
+ night_mode_recheck (self);
g_object_notify (G_OBJECT (self), "disabled-until-tmw");
}
gboolean
-csd_night_light_get_disabled_until_tmw (CsdNightLight *self)
+csd_night_mode_get_disabled_until_tmw (CsdNightMode *self)
{
return self->disabled_until_tmw;
}
void
-csd_night_light_set_forced (CsdNightLight *self, gboolean value)
+csd_night_light_set_forced (CsdNightMode *self, gboolean value)
{
- if (self->forced == value)
+ if (self->light_forced == value)
return;
- self->forced = value;
- g_object_notify (G_OBJECT (self), "forced");
+ self->light_forced = value;
+ g_object_notify (G_OBJECT (self), "light-forced");
/* A simple recheck might not reset the temperature if
* night light is currently disabled. */
- if (!self->forced && !self->cached_active)
+ if (!self->light_forced && !self->cached_light_active) {
csd_night_light_set_temperature (self, CSD_COLOR_TEMPERATURE_DEFAULT);
+ g_debug ("night light exited forced mode");
+ return;
+ }
night_light_recheck (self);
}
+void
+csd_night_theme_set_forced (CsdNightMode *self, gboolean value)
+{
+ if (self->theme_forced == value)
+ return;
+
+ self->theme_forced = value;
+ g_object_notify (G_OBJECT (self), "theme-forced");
+
+ /* A simple recheck might not switch off if
+ * night theme is currently disabled. */
+ if (!self->theme_forced && !self->cached_theme_active) {
+ night_theme_switch_off (self);
+ g_debug ("night theme exited forced mode");
+ return;
+ }
+
+ night_theme_recheck (self);
+}
+
+gboolean
+csd_night_light_get_forced (CsdNightMode *self)
+{
+ return self->light_forced;
+}
+
+gboolean
+csd_night_theme_get_forced (CsdNightMode *self)
+{
+ return self->theme_forced;
+}
+
gboolean
-csd_night_light_get_forced (CsdNightLight *self)
+csd_night_light_get_active (CsdNightMode *self)
{
- return self->forced;
+ return self->cached_light_active;
}
gboolean
-csd_night_light_get_active (CsdNightLight *self)
+csd_night_theme_get_active (CsdNightMode *self)
{
- return self->cached_active;
+ return self->cached_theme_active;
}
gdouble
-csd_night_light_get_sunrise (CsdNightLight *self)
+csd_night_mode_get_sunrise (CsdNightMode *self)
{
return self->cached_sunrise;
}
gdouble
-csd_night_light_get_sunset (CsdNightLight *self)
+csd_night_mode_get_sunset (CsdNightMode *self)
{
return self->cached_sunset;
}
gdouble
-csd_night_light_get_temperature (CsdNightLight *self)
+csd_night_light_get_temperature (CsdNightMode *self)
{
return self->cached_temperature;
}
gboolean
-csd_night_light_start (CsdNightLight *self, GError **error)
+csd_night_mode_start (CsdNightMode *self, GError **error)
{
- night_light_recheck (self);
+ night_mode_recheck (self);
poll_timeout_create (self);
/* care about changes */
@@ -557,14 +798,17 @@ csd_night_light_start (CsdNightLight *self, GError **error)
}
static void
-csd_night_light_finalize (GObject *object)
+csd_night_mode_finalize (GObject *object)
{
- CsdNightLight *self = CSD_NIGHT_LIGHT (object);
+ CsdNightMode *self = CSD_NIGHT_MODE (object);
poll_timeout_destroy (self);
poll_smooth_destroy (self);
g_clear_object (&self->settings);
+ g_clear_object (&self->theme_settings);
+ g_clear_object (&self->cinnamon_theme_settings);
+ g_clear_object (&self->x_theme_settings);
g_clear_pointer (&self->datetime_override, g_date_time_unref);
g_clear_pointer (&self->disabled_until_tmw_dt, g_date_time_unref);
@@ -573,16 +817,16 @@ csd_night_light_finalize (GObject *object)
self->validate_id = 0;
}
- G_OBJECT_CLASS (csd_night_light_parent_class)->finalize (object);
+ G_OBJECT_CLASS (csd_night_mode_parent_class)->finalize (object);
}
static void
-csd_night_light_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+csd_night_mode_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- CsdNightLight *self = CSD_NIGHT_LIGHT (object);
+ CsdNightMode *self = CSD_NIGHT_MODE (object);
switch (prop_id) {
case PROP_SUNRISE:
@@ -595,64 +839,81 @@ csd_night_light_set_property (GObject *object,
self->cached_temperature = g_value_get_double (value);
break;
case PROP_DISABLED_UNTIL_TMW:
- csd_night_light_set_disabled_until_tmw (self, g_value_get_boolean (value));
+ csd_night_mode_set_disabled_until_tmw (self, g_value_get_boolean (value));
break;
- case PROP_FORCED:
+ case PROP_LIGHT_FORCED:
csd_night_light_set_forced (self, g_value_get_boolean (value));
break;
+ case PROP_THEME_FORCED:
+ csd_night_theme_set_forced (self, g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
-csd_night_light_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+csd_night_mode_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- CsdNightLight *self = CSD_NIGHT_LIGHT (object);
+ CsdNightMode *self = CSD_NIGHT_MODE (object);
switch (prop_id) {
- case PROP_ACTIVE:
- g_value_set_boolean (value, self->cached_active);
+ case PROP_LIGHT_ACTIVE:
+ g_value_set_boolean (value, self->cached_light_active);
+ break;
+ case PROP_THEME_ACTIVE:
+ g_value_set_boolean (value, self->cached_theme_active);
break;
case PROP_SUNRISE:
g_value_set_double (value, self->cached_sunrise);
break;
case PROP_SUNSET:
- g_value_set_double (value, self->cached_sunrise);
+ g_value_set_double (value, self->cached_sunset);
break;
case PROP_TEMPERATURE:
- g_value_set_double (value, self->cached_sunrise);
+ g_value_set_double (value, self->cached_temperature);
break;
case PROP_DISABLED_UNTIL_TMW:
- g_value_set_boolean (value, csd_night_light_get_disabled_until_tmw (self));
+ g_value_set_boolean (value, csd_night_mode_get_disabled_until_tmw (self));
break;
- case PROP_FORCED:
+ case PROP_LIGHT_FORCED:
g_value_set_boolean (value, csd_night_light_get_forced (self));
break;
+ case PROP_THEME_FORCED:
+ g_value_set_boolean (value, csd_night_theme_get_forced (self));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
-csd_night_light_class_init (CsdNightLightClass *klass)
+csd_night_mode_class_init (CsdNightModeClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = csd_night_light_finalize;
+ object_class->finalize = csd_night_mode_finalize;
- object_class->set_property = csd_night_light_set_property;
- object_class->get_property = csd_night_light_get_property;
+ object_class->set_property = csd_night_mode_set_property;
+ object_class->get_property = csd_night_mode_get_property;
g_object_class_install_property (object_class,
- PROP_ACTIVE,
- g_param_spec_boolean ("active",
- "Active",
+ PROP_LIGHT_ACTIVE,
+ g_param_spec_boolean ("light-active",
+ "Light active",
"If night light functionality is active right now",
FALSE,
G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_THEME_ACTIVE,
+ g_param_spec_boolean ("theme-active",
+ "Theme active",
+ "If night theme is active right now",
+ FALSE,
+ G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_SUNRISE,
@@ -688,32 +949,45 @@ csd_night_light_class_init (CsdNightLightClass *klass)
PROP_DISABLED_UNTIL_TMW,
g_param_spec_boolean ("disabled-until-tmw",
"Disabled until tomorrow",
- "If the night light is disabled until the next day",
+ "If the night mode is disabled until the next day",
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
- PROP_FORCED,
- g_param_spec_boolean ("forced",
- "Forced",
+ PROP_LIGHT_FORCED,
+ g_param_spec_boolean ("light-forced",
+ "Light forced",
"Whether night light should be forced on, useful for previewing",
FALSE,
G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_THEME_FORCED,
+ g_param_spec_boolean ("theme-forced",
+ "Theme forced",
+ "Whether night theme should be forced on, useful for previewing",
+ FALSE,
+ G_PARAM_READWRITE));
}
static void
-csd_night_light_init (CsdNightLight *self)
+csd_night_mode_init (CsdNightMode *self)
{
self->smooth_enabled = TRUE;
+ self->cached_light_active_unset = TRUE;
+ self->cached_theme_active_unset = TRUE;
self->cached_sunrise = -1.f;
self->cached_sunset = -1.f;
self->cached_temperature = CSD_COLOR_TEMPERATURE_DEFAULT;
self->settings = g_settings_new ("org.cinnamon.settings-daemon.plugins.color");
+ self->theme_settings = g_settings_new ("org.cinnamon.desktop.interface");
+ self->x_theme_settings = g_settings_new ("org.x.apps.portal");
+ self->cinnamon_theme_settings = g_settings_new ("org.cinnamon.theme");
}
-CsdNightLight *
-csd_night_light_new (void)
+CsdNightMode *
+csd_night_mode_new (void)
{
- return g_object_new (CSD_TYPE_NIGHT_LIGHT, NULL);
+ return g_object_new (CSD_TYPE_NIGHT_MODE, NULL);
}
diff --git a/plugins/color/csd-night-mode.h b/plugins/color/csd-night-mode.h
new file mode 100644
index 00000000..49e0ab83
--- /dev/null
+++ b/plugins/color/csd-night-mode.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2017 Richard Hughes
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __CSD_NIGHT_MODE_H__
+#define __CSD_NIGHT_MODE_H__
+
+#include "csd-night-mode-common.h"
+#include
+
+G_BEGIN_DECLS
+
+#define CSD_TYPE_NIGHT_MODE (csd_night_mode_get_type ())
+G_DECLARE_FINAL_TYPE (CsdNightMode, csd_night_mode, CSD, NIGHT_MODE, GObject)
+
+CsdNightMode *csd_night_mode_new (void);
+gboolean csd_night_mode_start (CsdNightMode *self,
+ GError **error);
+
+gboolean csd_night_light_get_active (CsdNightMode *self);
+gboolean csd_night_theme_get_active (CsdNightMode *self);
+gdouble csd_night_mode_get_sunrise (CsdNightMode *self);
+gdouble csd_night_mode_get_sunset (CsdNightMode *self);
+gdouble csd_night_light_get_temperature (CsdNightMode *self);
+
+gboolean csd_night_mode_get_disabled_until_tmw (CsdNightMode *self);
+void csd_night_mode_set_disabled_until_tmw (CsdNightMode *self,
+ gboolean value);
+
+gboolean csd_night_light_get_forced (CsdNightMode *self);
+void csd_night_light_set_forced (CsdNightMode *self,
+ gboolean value);
+gboolean csd_night_theme_get_forced (CsdNightMode *self);
+void csd_night_theme_set_forced (CsdNightMode *self,
+ gboolean value);
+
+void csd_night_mode_set_date_time_now (CsdNightMode *self,
+ GDateTime *datetime);
+void csd_night_light_set_smooth_enabled (CsdNightMode *self,
+ gboolean smooth_enabled);
+
+G_END_DECLS
+
+#endif
diff --git a/plugins/color/meson.build b/plugins/color/meson.build
index e421e526..619436f2 100644
--- a/plugins/color/meson.build
+++ b/plugins/color/meson.build
@@ -26,8 +26,8 @@ sources = files(
'csd-color-manager.c',
'csd-color-profiles.c',
'csd-color-state.c',
- 'csd-night-light.c',
- 'csd-night-light-common.c',
+ 'csd-night-mode-common.c',
+ 'csd-night-mode.c',
'main.c'
)
@@ -73,8 +73,8 @@ sources = files(
'ccm-edid.c',
'ccm-self-test.c',
'gnome-datetime-source.c',
- 'csd-night-light.c',
- 'csd-night-light-common.c'
+ 'csd-night-mode.c',
+ 'csd-night-mode-common.c'
)
# test_unit = 'ccm-self-test'