aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-03-22 23:44:26 +0100
committerMattias Andrée <m@maandree.se>2025-03-22 23:44:26 +0100
commit4f051baf4514d2a0879490d23b865e76f7562f79 (patch)
treee89a3419d92c12637b6610562efb705ac1e60fe1
parentFix documentation (diff)
downloadredshift-ng-4f051baf4514d2a0879490d23b865e76f7562f79.tar.gz
redshift-ng-4f051baf4514d2a0879490d23b865e76f7562f79.tar.bz2
redshift-ng-4f051baf4514d2a0879490d23b865e76f7562f79.tar.xz
Add -e, -E, and +E
Signed-off-by: Mattias Andrée <m@maandree.se>
-rw-r--r--README28
-rw-r--r--TODO2
-rw-r--r--redshift.136
-rw-r--r--src/common.h21
-rw-r--r--src/config.c69
-rw-r--r--src/redshift.c1
6 files changed, 144 insertions, 13 deletions
diff --git a/README b/README
index 32d4153..dc57501 100644
--- a/README
+++ b/README
@@ -8,7 +8,8 @@ NAME
redshift - Automatically adjust display colour temperature according the Sun
SYNOPSIS
- redshift [-b brightness] [-c config-file] [-D | +D] [-g gamma]
+ redshift [-b brightness] [-c config-file] [-D | +D]
+ [-E | +E | -e elevations] [-g gamma]
[-l latitude:longitude | -l provider[:options]]
[-m method[:options]] [-P | +P] [-r | +r] [-dv]
[-O temperature | -o | -p | -t temperature | -x] | -h | -V
@@ -65,6 +66,31 @@ OPTIONS
Ignored in one-shot mode.
+ -E
+ Use wall-clock based schedule.
+
+ +E
+ Use solar elevation based schedule.
+
+ -e elevations
+ Synonym for "-e elevations:elevations".
+
+ -e elevation-high:elevation-low
+ Sets the lowest solar elevation during daytime to elevation-high
+ and the higest solar elevation during nighttime to elevation-low.
+ (Default: 3.0:-6.0, may change between versions.)
+
+ The value should be formatted as real, decimal values measured
+ in degrees. Each value shall be formatted as one complete value,
+ without unit suffix, and not split into degrees, minutes, and
+ seconds. Positive values are above the horizon and negative
+ values are below the horizon.
+
+ elevation-high or elevation-low may be omitted, to keep
+ unmodified, however at least one must be specified.
+
+ Implies +E.
+
-d
Keep the process alive and remove the colour effects
when killed.
diff --git a/TODO b/TODO
index 24c1d6e..905ec53 100644
--- a/TODO
+++ b/TODO
@@ -140,7 +140,7 @@ https://github.com/jonls/redshift/issues/892 Show dusk/dawn times when hovering
https://github.com/jonls/redshift/issues/750 Supporting multiple time periods
https://github.com/jonls/redshift/issues/703 allow to set brightness as default tray action
-Add -H for hook file/directory
+Add -H for hook file/directory, support /var/empty on all platforms (should always disable hooks even if that directory isn't actually empty)
po/sv.po: gammaförfining[ar] -> gammatabell[er]; lost -> förlorat {wrong gender} -> försvunnen; CRTC -> CRTC[:er]
po/de.po: lost -> verloren -> verschwunden
po/sv.po: felaktig -> ogiltig (?)
diff --git a/redshift.1 b/redshift.1
index 1a6f5cd..16b6f4c 100644
--- a/redshift.1
+++ b/redshift.1
@@ -8,7 +8,8 @@ redshift \- Automatically adjust display colour temperature according the Sun
.IR brightness ]
[-c
.IR config-file ]
-[-D | +D]
+[-D | +D] [-E | +E | -e
+.IR elevations ]
[-g
.IR gamma ]
[-l
@@ -89,6 +90,39 @@ Start in disabled state.
Ignored in one-shot mode.
.TP
+.B -E
+Use wall-clock based schedule.
+.TP
+.B +E
+Use solar elevation based schedule.
+.TP
+.BI -e\fR\ elevations
+Synonym for
+.B -e
+.IB elevations : elevations\fR.
+.TP
+.BI -e\fR\ elevation-high : elevation-low
+Sets the lowest solar elevation during daytime to
+.I elevation-high
+and the higest solar elevation during nighttime to
+.IR elevation-low .
+
+The value should be formatted as real, decimal
+values measured in degrees. Each value shall be
+formatted as one complete value, without unit
+suffix, and not split into degrees, minutes, and
+seconds. Positive values are above the horizon
+and negative values are below the horizon.
+
+.I elevation-high
+or
+.I elevation-low
+may be omitted, to keep unmodified, however at least
+one must be specified.
+
+Implies
+.BR +E .
+.TP
.B -d
Keep the process alive and remove the colour effects
when killed.
diff --git a/src/common.h b/src/common.h
index 2345d5b..b7cf872 100644
--- a/src/common.h
+++ b/src/common.h
@@ -404,6 +404,11 @@ enum scheme_type {
STATIC_SCHEME
};
+/**
+ * Scheme has not been specified
+ */
+#define UNSPECIFIED_SCHEME STATIC_SCHEME
+
/**
* The sources where an setting was been loaded from
@@ -785,6 +790,12 @@ struct settings {
const char *config_file;
/**
+ * Scheme type to use as according the the command line
+ * options, `UNSPECIFIED_SCHEME` if not unspecified
+ */
+ enum scheme_type scheme_type;
+
+ /**
* Whether the program should, if ran in one-shot mode,
* pause after applying the effect and reset them when
* killed
@@ -833,17 +844,21 @@ struct settings {
* The lowest solar elevation, in degrees, at daytime,
* when using solar scheme
*
- * This represents the "elevation-high" setting
+ * This represents the "elevation-high" setting and the
+ * left value of the -e option
*/
- struct setting_f elevation_high; /* TODO no cmdline option */
+ struct setting_f elevation_high;
/**
* The highest solar elevation, in degrees, at nighttime,
* when using solar scheme
*
* This represents the "elevation-low" setting
+ *
+ * This represents the "elevation-low" setting and the
+ * right value of the -e option
*/
- struct setting_f elevation_low; /* TODO no cmdline option */
+ struct setting_f elevation_low;
/**
* The wall-clock time that marks the end of nighttime,
diff --git a/src/config.c b/src/config.c
index 751b882..de7207d 100644
--- a/src/config.c
+++ b/src/config.c
@@ -27,11 +27,10 @@ static void
usage(void)
{
fprintf(stderr, _("usage: %s %s\n"), argv0,
- _("[-b brightness] [-c config-file] [-D | +D] [-g gamma] "
- "[-l latitude:longitude | -l provider[:options]] "
- "[-m method[:options]] [-P | +P] [-r | +r] [-dv]"
- "[-O temperature | -o | -p | -t temperature | -x] "
- "| -h | -V"));
+ _("[-b brightness] [-c config-file] [-D | +D] [-E | +E | -e elevations] "
+ "[-g gamma] [-l latitude:longitude | -l provider[:options]] "
+ "[-m method[:options]] [-P | +P] [-r | +r] [-dv] "
+ "[-O temperature | -o | -p | -t temperature | -x] | -h | -V"));
exit(1);
}
@@ -435,6 +434,43 @@ set_gamma(char *str, struct setting_f3 *day, struct setting_f3 *night, const cha
/**
+ * Parse and set solar elevation settings
+ *
+ * The fucntion assumes that the setting source is the command line
+ *
+ * @param str The gamma specification to parse
+ * @param day The currently specified lowest solar elevation for
+ * daytime, will be updated; `NULL` if it shall not be set
+ * @param night The currently specified highest solar elevation for
+ * nighttime, will be updated; `NULL` if it shall not be set
+ */
+static void
+set_elevations(char *str, struct setting_f *day, struct setting_f *night)
+{
+ struct setting_f *settings[] = {day, night};
+ const enum setting_source source = SETTING_CMDLINE;
+ char *strs[2], *end;
+ size_t i, j;
+
+ if (!get_strings(str, !!day + !!night, strs, ':')) {
+ invalid:
+ weprintf(_("Malformed solar elevation argument."));
+ eprintf(_("Try `-h' for more information."));
+ }
+
+ errno = 0;
+ for (i = 0, j = 0; i < ELEMSOF(settings); j += settings[i++] ? 1 : 0) {
+ if (!settings[i] || !strs[j] || settings[i]->source > source)
+ continue;
+ settings[i]->source |= source;
+ settings[i]->value = strtod(strs[j], &end);
+ if (errno || *end)
+ goto invalid;
+ }
+}
+
+
+/**
* Parse a time string on either of the formats "HH:MM" and "HH:MM:SS"
*
* Times up to, but excluding, 48:00 are supported.
@@ -607,7 +643,7 @@ load_defaults(struct settings *settings)
memset(settings, 0, sizeof(*settings)); /* set each `.source` to `SETTING_DEFAULT` and booleans to 0 */
settings->config_file = NULL;
- settings->until_death = 0;
+ settings->scheme_type = UNSPECIFIED_SCHEME;
settings->day.temperature.value = DEFAULT_DAY_TEMPERATURE;
settings->day.brightness.value = DEFAULT_DAY_BRIGHTNESS;
@@ -667,6 +703,15 @@ load_from_cmdline(struct settings *settings, int argc, char *argv[])
settings->until_death = 1;
break;
+ case 'E':
+ settings->scheme_type = CLOCK_SCHEME;
+ break;
+
+ case 'e':
+ set_elevations(ARG(), &settings->elevation_high, &settings->elevation_low);
+ settings->scheme_type = SOLAR_SCHEME;
+ break;
+
case 'g':
set_gamma(ARG(), &settings->day.gamma, &settings->night.gamma, NULL);
break;
@@ -789,6 +834,10 @@ load_from_cmdline(struct settings *settings, int argc, char *argv[])
settings->disabled.value = 1;
break;
+ case 'E':
+ settings->scheme_type = SOLAR_SCHEME;
+ break;
+
case 'P':
settings->preserve_gamma.source |= SETTING_CMDLINE;
settings->preserve_gamma.value = 1;
@@ -921,9 +970,15 @@ load_settings(struct settings *settings, int argc, char *argv[])
for (setting = section->settings; setting; setting = setting->next)
load_from_config_ini(settings, setting->name, setting->value);
- /* Further validate settings */
+ /* Further validate settings and select scheme */
n = !!settings->dawn_start.source + !!settings->dawn_end.source;
n += !!settings->dusk_start.source + !!settings->dusk_end.source;
+ if (settings->scheme_type == SOLAR_SCHEME) {
+ n = 0;
+ } else if (settings->scheme_type == CLOCK_SCHEME) {
+ if (!n)
+ eprintf(_("`-E' option used with a time-configuration configured."));
+ }
if (n) {
scheme.type = CLOCK_SCHEME;
if (n != 4)
diff --git a/src/redshift.c b/src/redshift.c
index 6e9b627..bcd9db9 100644
--- a/src/redshift.c
+++ b/src/redshift.c
@@ -169,6 +169,7 @@ get_colour_settings(struct colour_setting *colour_out, enum period *period_out,
printf(_("Solar elevation: %f\n"), elevation);
}
*day_level_out = (elevation - scheme.elevation.low) / scheme.elevation.range;
+ /* TODO ensure scheme.elevation.range==0 is supported */
} else {
/* Static scheme, no dayness-level or peroid; day_settings == nigh_settings, use either */