[gnome-settings-daemon/benzea/night-light-570] night-light: Move disable-until-tomorrow check to after active check




commit 8b5086a53d9e8dd8dd8a9d0414f81bd97734dd8f
Author: Benjamin Berg <bberg redhat com>
Date:   Mon Nov 23 13:33:09 2020 +0100

    night-light: Move disable-until-tomorrow check to after active check
    
    When DUT is active (i.e. night light is effectively off), we should
    still report the correct active state depending on whether we have
    detected night-time or not.
    
    So do all the ramp/colour temperature calculation and just check for DUT
    afterwards.
    
    Closes: #570

 plugins/color/gsd-night-light.c | 75 +++++++++++++++++++++--------------------
 1 file changed, 38 insertions(+), 37 deletions(-)
---
diff --git a/plugins/color/gsd-night-light.c b/plugins/color/gsd-night-light.c
index 635f1608..33feadee 100644
--- a/plugins/color/gsd-night-light.c
+++ b/plugins/color/gsd-night-light.c
@@ -294,42 +294,6 @@ night_light_recheck (GsdNightLight *self)
         g_debug ("fractional day = %.3f, limits = %.3f->%.3f",
                  frac_day, schedule_from, schedule_to);
 
-        /* disabled until 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 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 = gsd_night_light_frac_day_from_dt (self->disabled_until_tmw_dt);
-                        if (frac_disabled != frac_day &&
-                            gsd_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");
-                        gsd_night_light_set_temperature (self,
-                                                         GSD_COLOR_TEMPERATURE_DEFAULT);
-                        return;
-                }
-        }
-
         /* lower smearing period to be smaller than the time between start/stop */
         smear = MIN (smear,
                      MIN (     ABS (schedule_to - schedule_from),
@@ -372,9 +336,46 @@ night_light_recheck (GsdNightLight *self)
         } else {
                 temp_smeared = temperature;
         }
+        gsd_night_light_set_active (self, TRUE);
+
+        /* disabled until 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 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 = gsd_night_light_frac_day_from_dt (self->disabled_until_tmw_dt);
+                        if (frac_disabled != frac_day &&
+                            gsd_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");
+                        gsd_night_light_set_temperature (self,
+                                                         GSD_COLOR_TEMPERATURE_DEFAULT);
+                        return;
+                }
+        }
+
         g_debug ("night light mode on, using temperature of %uK (aiming for %uK)",
                  temp_smeared, temperature);
-        gsd_night_light_set_active (self, TRUE);
         gsd_night_light_set_temperature (self, temp_smeared);
 }
 


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