diff options
author | Mattias Andrée <m@maandree.se> | 2025-03-21 16:50:15 +0100 |
---|---|---|
committer | Mattias Andrée <m@maandree.se> | 2025-03-21 16:50:15 +0100 |
commit | 96a6575e23b5baebcdd38269b80f47cc02a2627e (patch) | |
tree | 0561580306c882e0e7a4f76c542130bb7ee44537 /src/config.c | |
parent | Refactor (diff) | |
download | redshift-ng-96a6575e23b5baebcdd38269b80f47cc02a2627e.tar.gz redshift-ng-96a6575e23b5baebcdd38269b80f47cc02a2627e.tar.bz2 redshift-ng-96a6575e23b5baebcdd38269b80f47cc02a2627e.tar.xz |
Refactor
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/src/config.c b/src/config.c index 1613770..5762a9c 100644 --- a/src/config.c +++ b/src/config.c @@ -1,4 +1,5 @@ -/* redshift-ng - Automatically adjust display colour temperature according the Sun +/*- + * redshift-ng - Automatically adjust display colour temperature according the Sun * * Copyright (c) 2009-2018 Jon Lund Steffensen <jonlst@gmail.com> * Copyright (c) 2014-2016, 2025 Mattias Andrée <m@maandree.se> @@ -21,13 +22,15 @@ /* TODO missing translation */ USAGE("[-b day:night] [-c file] [-g r:g:b] [-l latitude:longitude | -l provider[:options]]" - " [-m method[:options]] [-o | -O temperature | -t day:night | -x] [-pPrv] | -hV"); + " [-m method[:options]] [-o | -O temperature | -t day:night | -x] [-pPrv] | -h | -V"); struct colour_setting day_settings; struct colour_setting night_settings; union scheme scheme = {.type = SOLAR_SCHEME}; enum program_mode mode = PROGRAM_MODE_CONTINUAL; +int preserve_gamma; +int use_fade; int verbose = 0; @@ -266,7 +269,7 @@ set_temperature(char *str, struct setting_lu *day, struct setting_lu *night, con } errno = 0; - for (i = 0, j = 0; i < ELEMSOF(settings); i++, j += settings[i] ? 1 : 0) { + for (i = 0, j = 0; i < ELEMSOF(settings); j += settings[i++] ? 1 : 0) { if (!settings[i] || !strs[j] || settings[i]->source > source) continue; if (settings[i]->source & SETTING_CONFIGFILE) { @@ -311,7 +314,7 @@ set_brightness(char *str, struct setting_f *day, struct setting_f *night, const } errno = 0; - for (i = 0, j = 0; i < ELEMSOF(settings); i++, j += settings[i] ? 1 : 0) { + for (i = 0, j = 0; i < ELEMSOF(settings); j += settings[i++] ? 1 : 0) { if (!settings[i] || !strs[j] || settings[i]->source > source) continue; if (settings[i]->source & SETTING_CONFIGFILE) { @@ -356,7 +359,7 @@ set_gamma(char *str, struct setting_f3 *day, struct setting_f3 *night, const cha } errno = 0; - for (i = 0, j = 0; i < ELEMSOF(settings); i++, j += settings[i] ? 3 : 0) { + for (i = 0, j = 0; i < ELEMSOF(settings); j += settings[i++] ? 3 : 0) { if (!settings[i] || !strs[j] || settings[i]->source > source) continue; if (settings[i]->source & SETTING_CONFIGFILE) { @@ -445,7 +448,7 @@ set_transition_time(char *str, struct setting_time *start, struct setting_time * if (!get_strings(str, ELEMSOF(strs), strs, '-')) return 0; - for (i = 0; i < ELEMSOF(settings); i++) { + for (i = 0; i < (int)ELEMSOF(settings); i++) { if (!strs[i] || settings[i]->source > source) continue; if (settings[i]->source & SETTING_CONFIGFILE) { @@ -703,9 +706,8 @@ load_from_cmdline(struct settings *settings, int argc, char *argv[]) break; case 'V': - printf("%s\n", PACKAGE_STRING); + printf("%s\n", VERSION_STRING); exit(0); - break; case 'x': mode = PROGRAM_MODE_RESET; @@ -815,6 +817,10 @@ load_settings(struct settings *settings, int argc, char *argv[]) int i, j, n; time_t duration; + /* Clear unused bit so they do not interfere with comparsion */ + memset(&day_settings, 0, sizeof(day_settings)); + memset(&night_settings, 0, sizeof(night_settings)); + /* Load settings; some validation takes place */ load_defaults(settings); load_from_cmdline(settings, argc, argv); @@ -824,8 +830,8 @@ load_settings(struct settings *settings, int argc, char *argv[]) load_from_config_ini(settings, setting->name, setting->value); /* Further validate settings */ - n = !settings->dawn.start.source + !settings->dawn.end.source; - n += !settings->dusk.start.source + !settings->dusk.end.source; + n = !!settings->dawn.start.source + !!settings->dawn.end.source; + n += !!settings->dusk.start.source + !!settings->dusk.end.source; if (n) { scheme.type = CLOCK_SCHEME; if (n != 4) @@ -852,22 +858,6 @@ load_settings(struct settings *settings, int argc, char *argv[]) if (settings->elevation_high.value < settings->elevation_low.value) eprintf(_("High transition elevation cannot be lower than the low transition elevation.")); - /* If the effects are the same throughout the day, do not use a transition scheme */ -#if defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wfloat-equal" -#endif - if (settings->day.temperature.value == settings->night.temperature.value && - settings->day.brightness.value == settings->night.brightness.value && - settings->day.gamma.value[0] == settings->night.gamma.value[0] && - settings->day.gamma.value[1] == settings->night.gamma.value[1] && - settings->day.gamma.value[2] == settings->night.gamma.value[2]) { - scheme.type = STATIC_SCHEME; - } -#if defined(__GNUC__) -# pragma GCC diagnostic pop -#endif - /* If reseting effects, use neutral colour settings (static scheme) and do not preserve gamma */ if (mode == PROGRAM_MODE_RESET) { scheme.type = STATIC_SCHEME; @@ -878,6 +868,8 @@ load_settings(struct settings *settings, int argc, char *argv[]) } /* Publish loaded settings */ + preserve_gamma = settings->preserve_gamma.value; + use_fade = settings->use_fade.value; day_settings.temperature = settings->day.temperature.value; day_settings.brightness = settings->day.brightness.value; day_settings.gamma[0] = settings->day.gamma.value[0]; @@ -888,7 +880,10 @@ load_settings(struct settings *settings, int argc, char *argv[]) night_settings.gamma[0] = settings->night.gamma.value[0]; night_settings.gamma[1] = settings->night.gamma.value[1]; night_settings.gamma[2] = settings->night.gamma.value[2]; - if (scheme.type == SOLAR_SCHEME) { + if (!memcmp(&day_settings, &night_settings, sizeof(day_settings))) { + /* If the effects are the same throughout the day, do not use a transition scheme */ + scheme.type = STATIC_SCHEME; + } else if (scheme.type == SOLAR_SCHEME) { scheme.elevation.high = settings->elevation_high.value; scheme.elevation.low = settings->elevation_low.value; scheme.elevation.range = scheme.elevation.high - scheme.elevation.low; |