From 4a9fe11d6f912a086901fb1be6f75bf12e06875b Mon Sep 17 00:00:00 2001 From: Tobias Schubert Date: Mon, 20 Sep 2021 16:30:33 +0200 Subject: [PATCH 1/6] Add new configuration option "fade duration" to specification file --- src/elektra/redshift.ni | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/elektra/redshift.ni b/src/elektra/redshift.ni index d9dc010c..da943651 100644 --- a/src/elektra/redshift.ni +++ b/src/elektra/redshift.ni @@ -94,6 +94,14 @@ opt = f opt/long = fade-fast opt/arg = none +[fade/duration] +type = unsigned_long +description = Set fade duration (for fading between color temperatures) in full seconds. +default = 4 +example = 5 +opt/long = fade-duration +opt/arg = required + [brightness/day] type = float description = The screen brightness during daytime. If both day and night brightness are set, these will overrule the value of brightness. From ed4b787c42f329a8a9921181d09bfbe0f4b96a58 Mon Sep 17 00:00:00 2001 From: Tobias Schubert Date: Mon, 20 Sep 2021 16:31:09 +0200 Subject: [PATCH 2/6] Implement getting "fade duration" from Elektra --- src/options.c | 3 +++ src/options.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/options.c b/src/options.c index b34ed6e3..bcc08ffe 100644 --- a/src/options.c +++ b/src/options.c @@ -322,6 +322,8 @@ options_load_from_elektra( // Fade options->use_fade = !elektraGetFadeFast(elektra); + + options->fade_duration = elektraGetFadeDuration(elektra); // Temperature options->scheme.day.temperature = elektraGetTempDay(elektra); @@ -398,6 +400,7 @@ options_init(options_t *options) options->provider = NULL; options->use_fade = -1; + options->fade_duration = -1; options->preserve_gamma = 1; options->mode = PROGRAM_MODE_CONTINUAL; options->verbose = 0; diff --git a/src/options.h b/src/options.h index 699237c6..b785f165 100644 --- a/src/options.h +++ b/src/options.h @@ -34,6 +34,8 @@ typedef struct { int temp_set; /* Whether to fade between large skips in color temperature. */ int use_fade; + /* The length of the fade duration in seconds */ + long fade_duration; /* Whether to preserve gamma ramps if supported by gamma method. */ int preserve_gamma; From edecb912194f65d88afa1b509502b3aa57969af1 Mon Sep 17 00:00:00 2001 From: Tobias Schubert Date: Mon, 20 Sep 2021 16:31:52 +0200 Subject: [PATCH 3/6] Modify continual mode to respect "fade_duration" --- src/redshift.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/redshift.c b/src/redshift.c index 0456eb89..ce93954a 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -503,7 +503,8 @@ run_continual_mode(const location_provider_t *provider, const transition_scheme_t *scheme, const gamma_method_t *method, gamma_state_t *method_state, - int use_fade, int preserve_gamma, int verbose) + int use_fade, long fade_duration, + int preserve_gamma, int verbose) { int r; @@ -656,8 +657,9 @@ run_continual_mode(const location_provider_t *provider, color_setting_diff_is_major( &target_interp, &prev_target_interp))) { - fade_length = FADE_LENGTH; - fade_time = 0; + // Scale fade_length according to desired fade_duration. + fade_length = (FADE_LENGTH * (fade_duration * 1000)) / (FADE_LENGTH * SLEEP_DURATION_SHORT); + fade_time = 0; fade_start_interp = interp; } } @@ -1204,7 +1206,8 @@ int main(int argc, const char * const *argv, const char * const *envp) r = run_continual_mode( options.provider, location_state, scheme, options.method, method_state, - options.use_fade, options.preserve_gamma, + options.use_fade, options.fade_duration, + options.preserve_gamma, options.verbose); if (r < 0) exit(EXIT_FAILURE); } From ab7dfd15645d574da0508a4e7127ddb311156143 Mon Sep 17 00:00:00 2001 From: Tobias Schubert Date: Tue, 21 Sep 2021 10:35:12 +0200 Subject: [PATCH 4/6] Make description of configuration option "fade/duration" easier to understand --- src/elektra/redshift.ni | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elektra/redshift.ni b/src/elektra/redshift.ni index da943651..acb0b531 100644 --- a/src/elektra/redshift.ni +++ b/src/elektra/redshift.ni @@ -96,7 +96,7 @@ opt/arg = none [fade/duration] type = unsigned_long -description = Set fade duration (for fading between color temperatures) in full seconds. +description = Set length of the fade duration in full seconds for fading between color temperatures. default = 4 example = 5 opt/long = fade-duration From 005ddb0cf8b84c19dfa912635332f1b8519f3ad5 Mon Sep 17 00:00:00 2001 From: Tobias Schubert Date: Tue, 21 Sep 2021 10:37:27 +0200 Subject: [PATCH 5/6] Normalize indent to tabs --- src/options.c | 200 +++++++++++++++++++++++++------------------------- src/options.h | 8 +- 2 files changed, 104 insertions(+), 104 deletions(-) diff --git a/src/options.c b/src/options.c index bcc08ffe..d9adcd4f 100644 --- a/src/options.c +++ b/src/options.c @@ -93,8 +93,8 @@ static void print_method_list(const gamma_method_t *gamma_methods) { if (gamma_methods[0].name == NULL) { - printf("This build of redshift contains no adjustment methods that work on your system!"); - return; + printf("This build of redshift contains no adjustment methods that work on your system!"); + return; } fputs(_("Available adjustment methods in this build of redshift:\n"), stdout); @@ -112,8 +112,8 @@ static void print_provider_list(const location_provider_t location_providers[]) { if (location_providers[0].name == NULL) { - printf("This build of redshift contains no adjustment methods that work on your system!"); - return; + printf("This build of redshift contains no adjustment methods that work on your system!"); + return; } fputs(_("Available location providers in this build of redshift:\n"), stdout); @@ -171,10 +171,10 @@ find_location_provider( */ int options_load_from_elektra( - options_t *options, - Elektra *elektra, - const gamma_method_t *gamma_methods, - const location_provider_t *location_providers) { + options_t *options, + Elektra *elektra, + const gamma_method_t *gamma_methods, + const location_provider_t *location_providers) { /** * Before using Elektra, there were two sources for configuration: CLI options and config file. * From redshift's point of view there is only one source now, namely Elektra. @@ -189,8 +189,8 @@ options_load_from_elektra( // Version if (elektraGetVersion(elektra)) { - printf("%s\n", PACKAGE_STRING); - return -1; + printf("%s\n", PACKAGE_STRING); + return -1; } // Verbose @@ -199,27 +199,27 @@ options_load_from_elektra( // Programm mode ElektraEnumMode mode = elektraGetMode(elektra); switch (mode) { - case ELEKTRA_ENUM_MODE_CONTINUAL: { - options->mode = PROGRAM_MODE_CONTINUAL; - break; - } - case ELEKTRA_ENUM_MODE_ONESHOT: { - options->mode = PROGRAM_MODE_ONE_SHOT; - break; - } - case ELEKTRA_ENUM_MODE_PRINT: { - options->mode = PROGRAM_MODE_PRINT; - break; - } - case ELEKTRA_ENUM_MODE_RESET: { - options->mode = PROGRAM_MODE_RESET; - break; - } - case ELEKTRA_ENUM_MODE_ONESHOTMANUAL: { - options->temp_set = elektraGetTempOneshotmanual(elektra); - options->mode = PROGRAM_MODE_MANUAL; - break; - } + case ELEKTRA_ENUM_MODE_CONTINUAL: { + options->mode = PROGRAM_MODE_CONTINUAL; + break; + } + case ELEKTRA_ENUM_MODE_ONESHOT: { + options->mode = PROGRAM_MODE_ONE_SHOT; + break; + } + case ELEKTRA_ENUM_MODE_PRINT: { + options->mode = PROGRAM_MODE_PRINT; + break; + } + case ELEKTRA_ENUM_MODE_RESET: { + options->mode = PROGRAM_MODE_RESET; + break; + } + case ELEKTRA_ENUM_MODE_ONESHOTMANUAL: { + options->temp_set = elektraGetTempOneshotmanual(elektra); + options->mode = PROGRAM_MODE_MANUAL; + break; + } } // Brightness @@ -234,52 +234,52 @@ options_load_from_elektra( // Location and adjustment help if (elektraGetAdjustmentMethodHelp(elektra)) { - for (int i = 0; gamma_methods[i].name != NULL; i++) { - const gamma_method_t *m = &gamma_methods[i]; - printf(_("Help section for method `%s':\n"), m->name); - printf(_("=============================\n")); - m->print_help(stdout); - printf(_("=============================\n\n")); - } - return -1; + for (int i = 0; gamma_methods[i].name != NULL; i++) { + const gamma_method_t *m = &gamma_methods[i]; + printf(_("Help section for method `%s':\n"), m->name); + printf(_("=============================\n")); + m->print_help(stdout); + printf(_("=============================\n\n")); + } + return -1; } if (elektraGetProviderLocationHelp(elektra)) { - for (int i = 0; location_providers[i].name != NULL; i++) { - const location_provider_t *p = &location_providers[i]; - printf(_("Help section for provider `%s':\n"), p->name); - printf(_("=============================\n")); - p->print_help(stdout); - printf(_("=============================\n\n")); - } - return -1; + for (int i = 0; location_providers[i].name != NULL; i++) { + const location_provider_t *p = &location_providers[i]; + printf(_("Help section for provider `%s':\n"), p->name); + printf(_("=============================\n")); + p->print_help(stdout); + printf(_("=============================\n\n")); + } + return -1; } // Location provider ElektraEnumProviderLocation locationProvider = elektraGetProviderLocation(elektra); if (locationProvider == ELEKTRA_ENUM_PROVIDER_LOCATION_LIST) { - // In list mode, print list of supported location providers. - print_provider_list(location_providers); - return -1; + // In list mode, print list of supported location providers. + print_provider_list(location_providers); + return -1; } else if (locationProvider == ELEKTRA_ENUM_PROVIDER_LOCATION_AUTO) { - // In auto mode, a supported provider will be chosen in redshift.c:main(...) - options->provider = NULL; + // In auto mode, a supported provider will be chosen in redshift.c:main(...) + options->provider = NULL; } else { - // Otherwise, try to find the provider by name. - const char *locationProviderName = elektraEnumProviderLocationToConstString( - elektraGetProviderLocation(elektra) - ); - const location_provider_t *provider = find_location_provider(location_providers, locationProviderName); - if(provider == NULL) { - // User picked a locationProvider provider which is not supported in this build. - fprintf(stderr, _("The chosen location provider \"%s\" is not supported in this build of redshift.\n"), locationProviderName); - return -1; - } - else { - options->provider = provider; - } + // Otherwise, try to find the provider by name. + const char *locationProviderName = elektraEnumProviderLocationToConstString( + elektraGetProviderLocation(elektra) + ); + const location_provider_t *provider = find_location_provider(location_providers, locationProviderName); + if(provider == NULL) { + // User picked a locationProvider provider which is not supported in this build. + fprintf(stderr, _("The chosen location provider \"%s\" is not supported in this build of redshift.\n"), locationProviderName); + return -1; + } + else { + options->provider = provider; + } } // Set lat and lon. Will only be used if the manual provider is chosen const float lat = elektraGetProviderLocationManualLat(elektra); @@ -290,26 +290,26 @@ options_load_from_elektra( // Adjustment method ElektraEnumAdjustmentMethod adjustmentMethod = elektraGetAdjustmentMethod(elektra); if (adjustmentMethod == ELEKTRA_ENUM_ADJUSTMENT_METHOD_LIST) { - // In list mode, print list of supported adjustment methods. - print_method_list(gamma_methods); - return -1; + // In list mode, print list of supported adjustment methods. + print_method_list(gamma_methods); + return -1; } else if (adjustmentMethod == ELEKTRA_ENUM_ADJUSTMENT_METHOD_AUTO) { - // In auto mode, a supported method will be chosen in redshift.c:main(...) - options->method = NULL; + // In auto mode, a supported method will be chosen in redshift.c:main(...) + options->method = NULL; } else { - // Otherwise, try to find the method by name. - const char * adjustmentMethodName = elektraEnumAdjustmentMethodToConstString( - elektraGetAdjustmentMethod(elektra) - ); - const gamma_method_t *method = find_gamma_method(gamma_methods, adjustmentMethodName); - if (method == NULL) { - // User picked a method which is not supported in this build. - fprintf(stderr, _("The chosen adjustment method \"%s\" is not supported in this build of redshift.\n"), adjustmentMethodName); - return -1; - } - else { - options->method = method; - } + // Otherwise, try to find the method by name. + const char * adjustmentMethodName = elektraEnumAdjustmentMethodToConstString( + elektraGetAdjustmentMethod(elektra) + ); + const gamma_method_t *method = find_gamma_method(gamma_methods, adjustmentMethodName); + if (method == NULL) { + // User picked a method which is not supported in this build. + fprintf(stderr, _("The chosen adjustment method \"%s\" is not supported in this build of redshift.\n"), adjustmentMethodName); + return -1; + } + else { + options->method = method; + } } options->method_crtc = elektraGetAdjustmentCrtc(elektra); @@ -341,23 +341,23 @@ options_load_from_elektra( options->scheme.use_time = elektraGetProvider(elektra) == ELEKTRA_ENUM_PROVIDER_TIME; if(options->scheme.use_time) { - const char* dawnStartString = elektraGetProviderTimeDawnStart(elektra); - const char* dawnEndString = elektraGetProviderTimeDawnEnd(elektra); - const char* duskStartString = elektraGetProviderTimeDuskStart(elektra); - const char* duskEndString = elektraGetProviderTimeDuskEnd(elektra); - options->scheme.dawn.start = parse_transition_time(dawnStartString, NULL); - options->scheme.dawn.end = parse_transition_time(dawnEndString, NULL); - options->scheme.dusk.start = parse_transition_time(duskStartString, NULL); - options->scheme.dusk.end = parse_transition_time(duskEndString, NULL); - - // Validation from redshift.c:main(...) - if (options->scheme.dawn.start > options->scheme.dawn.end || - options->scheme.dawn.end > options->scheme.dusk.start || - options->scheme.dusk.start > options->scheme.dusk.end) { - fputs(_("Invalid dawn/dusk time configuration!\n"), - stderr); - return -1; - } + const char* dawnStartString = elektraGetProviderTimeDawnStart(elektra); + const char* dawnEndString = elektraGetProviderTimeDawnEnd(elektra); + const char* duskStartString = elektraGetProviderTimeDuskStart(elektra); + const char* duskEndString = elektraGetProviderTimeDuskEnd(elektra); + options->scheme.dawn.start = parse_transition_time(dawnStartString, NULL); + options->scheme.dawn.end = parse_transition_time(dawnEndString, NULL); + options->scheme.dusk.start = parse_transition_time(duskStartString, NULL); + options->scheme.dusk.end = parse_transition_time(duskEndString, NULL); + + // Validation from redshift.c:main(...) + if (options->scheme.dawn.start > options->scheme.dawn.end || + options->scheme.dawn.end > options->scheme.dusk.start || + options->scheme.dusk.start > options->scheme.dusk.end) { + fputs(_("Invalid dawn/dusk time configuration!\n"), + stderr); + return -1; + } } // END Block diff --git a/src/options.h b/src/options.h index b785f165..fb474c77 100644 --- a/src/options.h +++ b/src/options.h @@ -56,10 +56,10 @@ typedef struct { int options_load_from_elektra( - options_t *options, - Elektra *elektra, - const gamma_method_t *gamma_methods, - const location_provider_t *location_providers); + options_t *options, + Elektra *elektra, + const gamma_method_t *gamma_methods, + const location_provider_t *location_providers); void options_init(options_t *options); #endif /* ! REDSHIFT_OPTIONS_H */ From 082b872bcdcb46f9e5677377b1fa04e6beb72e67 Mon Sep 17 00:00:00 2001 From: Tobias Schubert Date: Tue, 21 Sep 2021 10:45:58 +0200 Subject: [PATCH 6/6] Remove descriptions in options.h and link to specification file --- src/options.h | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/options.h b/src/options.h index fb474c77..8baf1adc 100644 --- a/src/options.h +++ b/src/options.h @@ -26,31 +26,26 @@ typedef struct { /* Path to config file */ char *config_filepath; + /* + * For description of these options, see Elektra specification file src/elektra/redshift.ni + */ transition_scheme_t scheme; program_mode_t mode; int verbose; - /* Temperature to set in manual mode. */ int temp_set; - /* Whether to fade between large skips in color temperature. */ int use_fade; - /* The length of the fade duration in seconds */ long fade_duration; - /* Whether to preserve gamma ramps if supported by gamma method. */ int preserve_gamma; - - /* Selected gamma method. */ + const gamma_method_t *method; - /* Options for adjustment methods */ - unsigned short method_crtc; - unsigned short method_screen; - unsigned short method_drm_card; - - /* Selected location provider. */ + unsigned short method_crtc; + unsigned short method_screen; + unsigned short method_drm_card; + const location_provider_t *provider; - /* Lat, lon for location provider. */ float provider_manual_arg_lat; - float provider_manual_arg_lon; + float provider_manual_arg_lon; } options_t;