Skip to content

Commit

Permalink
nightlight: Implement schedule mode 'always'
Browse files Browse the repository at this point in the history
This is more user-friendly than having to tweak the start and stop times.
  • Loading branch information
misch7 committed Jan 19, 2025
1 parent 212eaf8 commit 8371cd2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<enum id="schedule_mode">
<value value="0" nick="auto"/>
<value value="1" nick="manual"/>
<value value="2" nick="always"/>
</enum>
<schema gettext-domain="@GETTEXT_PACKAGE@" id="org.cinnamon.settings-daemon.plugins.color" path="/org/cinnamon/settings-daemon/plugins/color/">
<key name="recalibrate-display-threshold" type="u">
Expand All @@ -27,7 +28,7 @@
<key name="night-light-schedule-mode" enum="schedule_mode">
<default>'auto'</default>
<summary>Set the way start and stop times are determined</summary>
<description>Setting to 'auto' will use the system timezone to determine sunrise and sunset. Using 'manual' mode allows specifying exact start and stop times (night-light-schedule-from and -to).</description>
<description>Setting to 'auto' will use the system timezone to determine sunrise and sunset. Using 'manual' mode allows specifying exact start and stop times (night-light-schedule-from and -to). The 'always' mode keeps the selected color temperature of your display permanently on.</description>
</key>
<key name="night-light-schedule-from" type="d">
<default>20.00</default>
Expand Down
20 changes: 17 additions & 3 deletions plugins/color/csd-night-light.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ enum {

enum {
NIGHT_LIGHT_SCHEDULE_AUTO = 0,
NIGHT_LIGHT_SCHEDULE_MANUAL = 1
NIGHT_LIGHT_SCHEDULE_MANUAL = 1,
NIGHT_LIGHT_SCHEDULE_ALWAYS_ON = 2
};

#define CSD_NIGHT_LIGHT_SCHEDULE_TIMEOUT 5 /* seconds */
Expand Down Expand Up @@ -274,13 +275,26 @@ night_light_recheck (CsdNightLight *self)
return;
}

/* calculate the position of the sun */
if (g_settings_get_enum (self->settings, "night-light-schedule-mode") == NIGHT_LIGHT_SCHEDULE_AUTO) {
/* schedule-mode */
switch (g_settings_get_enum (self->settings, "night-light-schedule-mode")) {
case NIGHT_LIGHT_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",
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;
}
break;
default:
break;
}

/* fall back to manual settings */
Expand Down

0 comments on commit 8371cd2

Please sign in to comment.