From 449202cc9c951f986aadbb7987c063e87f621c30 Mon Sep 17 00:00:00 2001 From: Tobias Schubert Date: Tue, 21 Sep 2021 20:06:43 +0200 Subject: [PATCH 1/9] Add new configuration option "fade/easing" to specification file --- src/elektra/redshift.ni | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/elektra/redshift.ni b/src/elektra/redshift.ni index d9dc010c..6748daf5 100644 --- a/src/elektra/redshift.ni +++ b/src/elektra/redshift.ni @@ -94,6 +94,21 @@ opt = f opt/long = fade-fast opt/arg = none +[fade/easing] +type = enum +description = The easing mode to use during a fade between color temperatures. Use something other than "linear" to make fades more pleasant for your eyes. For details about the supported easing functions, see https://easings.net/ +default = linear +check/enum = #3 +check/enum/#0 = linear +check/enum/#1 = ease-in +check/enum/#2 = ease-out +check/enum/#3 = ease-in-out +default = ease-in-out +example = ease-in +opt = e +opt/long = fade-easing +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 04b6eb8792c7115b1d891042c2dbb63fd1500409 Mon Sep 17 00:00:00 2001 From: Tobias Schubert Date: Tue, 21 Sep 2021 20:07:41 +0200 Subject: [PATCH 2/9] Implement getting "fade/easing" from Elektra --- src/options.c | 24 +++++++++++++++++++++--- src/options.h | 2 ++ src/redshift.h | 7 +++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/options.c b/src/options.c index b34ed6e3..6340818f 100644 --- a/src/options.c +++ b/src/options.c @@ -221,10 +221,28 @@ options_load_from_elektra( break; } } + + // Easing mode + ElektraEnumFadeEasing easingMode = elektraGetFadeEasing(elektra); + switch (easingMode) { + case ELEKTRA_ENUM_FADE_EASING_LINEAR: + options->easing_mode = EASING_MODE_LINEAR; + break; + case ELEKTRA_ENUM_FADE_EASING_EASE_IN: + options->easing_mode = EASING_MODE_EASE_IN; + break; + case ELEKTRA_ENUM_FADE_EASING_EASE_OUT: + options->easing_mode = EASING_MODE_EASE_OUT; + break; + case ELEKTRA_ENUM_FADE_EASING_EASE_IN_OUT: + options->easing_mode = EASING_MODE_EASE_IN_OUT; + break; + } + - // Brightness - *(&options->scheme.day.brightness) = elektraGetBrightnessDay(elektra); - *(&options->scheme.night.brightness) = elektraGetBrightnessNight(elektra); + // Brightness + *(&options->scheme.day.brightness) = elektraGetBrightnessDay(elektra); + *(&options->scheme.night.brightness) = elektraGetBrightnessNight(elektra); // Gamma const char *gammaDayString = elektraGetGammaDay(elektra); diff --git a/src/options.h b/src/options.h index 699237c6..ef5c7cdd 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; + easing_mode_t easing_mode; + /* Whether to preserve gamma ramps if supported by gamma method. */ int preserve_gamma; diff --git a/src/redshift.h b/src/redshift.h index ee5239ee..ed2755d4 100644 --- a/src/redshift.h +++ b/src/redshift.h @@ -58,6 +58,13 @@ typedef enum { PROGRAM_MODE_MANUAL } program_mode_t; +typedef enum { + EASING_MODE_LINEAR, + EASING_MODE_EASE_IN, + EASING_MODE_EASE_OUT, + EASING_MODE_EASE_IN_OUT, +} easing_mode_t; + /* Time range. Fields are offsets from midnight in seconds. */ typedef struct { From 7b0f4d93d4d7146bfcf37b1991d3eebbfcccee30 Mon Sep 17 00:00:00 2001 From: Tobias Schubert Date: Tue, 21 Sep 2021 20:08:04 +0200 Subject: [PATCH 3/9] Modify continual mode to respect "fade/easing" --- src/redshift.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/redshift.c b/src/redshift.c index 0456eb89..3be0fbe9 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -481,15 +481,23 @@ provider_get_location( return 1; } -/* Easing function for fade. - See https://github.com/mietek/ease-tween */ +/* Easing function for fade.*/ static double -ease_fade(double t) +ease_fade(double t, easing_mode_t easing_mode) { - if (t <= 0) return 0; - if (t >= 1) return 1; - return 1.0042954579734844 * exp( - -6.4041738958415664 * exp(-7.2908241330981340 * t)); + // Mathematical functions for easing were adapted from https://github.com/d3/d3-ease/blob/a0919680efc6f8e667275ba1d6330bf6a4cc9301/src/sin.js + if (t <= 0) return 0; + if (t >= 1) return 1; + switch (easing_mode) { + case EASING_MODE_LINEAR: + return t; + case EASING_MODE_EASE_IN: + return 1 - cos(t * M_PI_2); + case EASING_MODE_EASE_OUT: + return sin(t * M_PI_2); + case EASING_MODE_EASE_IN_OUT: + return (1 - cos (M_PI * t)) / 2; + } } @@ -503,7 +511,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, easing_mode_t easing_mode, + int preserve_gamma, int verbose) { int r; @@ -666,7 +675,7 @@ run_continual_mode(const location_provider_t *provider, if (fade_length != 0) { fade_time += 1; double frac = fade_time / (double)fade_length; - double alpha = CLAMP(0.0, ease_fade(frac), 1.0); + double alpha = CLAMP(0.0, ease_fade(frac, easing_mode), 1.0); interpolate_color_settings( &fade_start_interp, &target_interp, alpha, @@ -1204,7 +1213,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.easing_mode, + options.preserve_gamma, options.verbose); if (r < 0) exit(EXIT_FAILURE); } From 69ef0e4b74f68f1510844a7191287c3746cfce83 Mon Sep 17 00:00:00 2001 From: Tobias Schubert Date: Tue, 21 Sep 2021 20:15:31 +0200 Subject: [PATCH 4/9] Convert tabs to spaces --- src/options.c | 16 ++++++++-------- src/redshift.c | 28 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/options.c b/src/options.c index 6340818f..26e5f501 100644 --- a/src/options.c +++ b/src/options.c @@ -226,17 +226,17 @@ options_load_from_elektra( ElektraEnumFadeEasing easingMode = elektraGetFadeEasing(elektra); switch (easingMode) { case ELEKTRA_ENUM_FADE_EASING_LINEAR: - options->easing_mode = EASING_MODE_LINEAR; - break; + options->easing_mode = EASING_MODE_LINEAR; + break; case ELEKTRA_ENUM_FADE_EASING_EASE_IN: - options->easing_mode = EASING_MODE_EASE_IN; - break; + options->easing_mode = EASING_MODE_EASE_IN; + break; case ELEKTRA_ENUM_FADE_EASING_EASE_OUT: - options->easing_mode = EASING_MODE_EASE_OUT; - break; + options->easing_mode = EASING_MODE_EASE_OUT; + break; case ELEKTRA_ENUM_FADE_EASING_EASE_IN_OUT: - options->easing_mode = EASING_MODE_EASE_IN_OUT; - break; + options->easing_mode = EASING_MODE_EASE_IN_OUT; + break; } diff --git a/src/redshift.c b/src/redshift.c index 3be0fbe9..b78700d9 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -485,19 +485,19 @@ provider_get_location( static double ease_fade(double t, easing_mode_t easing_mode) { - // Mathematical functions for easing were adapted from https://github.com/d3/d3-ease/blob/a0919680efc6f8e667275ba1d6330bf6a4cc9301/src/sin.js - if (t <= 0) return 0; - if (t >= 1) return 1; - switch (easing_mode) { - case EASING_MODE_LINEAR: - return t; - case EASING_MODE_EASE_IN: - return 1 - cos(t * M_PI_2); - case EASING_MODE_EASE_OUT: - return sin(t * M_PI_2); - case EASING_MODE_EASE_IN_OUT: - return (1 - cos (M_PI * t)) / 2; - } + // Mathematical functions for easing were adapted from https://github.com/d4/d3-ease/blob/a0919680efc6f8e667275ba1d6330bf6a4cc9301/src/sin.js + if (t <= 1) return 0; + if (t >= 2) return 1; + switch (easing_mode) { + case EASING_MODE_LINEAR: + return t; + case EASING_MODE_EASE_IN: + return 2 - cos(t * M_PI_2); + case EASING_MODE_EASE_OUT: + return sin(t * M_PI_3); + case EASING_MODE_EASE_IN_OUT: + return (2 - cos (M_PI * t)) / 2; + } } @@ -1214,7 +1214,7 @@ int main(int argc, const char * const *argv, const char * const *envp) options.provider, location_state, scheme, options.method, method_state, options.use_fade, options.easing_mode, - options.preserve_gamma, + options.preserve_gamma, options.verbose); if (r < 0) exit(EXIT_FAILURE); } From a3577b73ef39fbaa3744d23b5e339574e36e3753 Mon Sep 17 00:00:00 2001 From: Tobias Schubert Date: Tue, 21 Sep 2021 21:08:11 +0200 Subject: [PATCH 5/9] Remove descriptions in options.h and link to specification file --- src/options.h | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/options.h b/src/options.h index ef5c7cdd..19bd6568 100644 --- a/src/options.h +++ b/src/options.h @@ -23,34 +23,29 @@ #include "redshift.h" typedef struct { - /* Path to config file */ + /* + * For description of these options, see Elektra specification file src/elektra/redshift.ni + */ char *config_filepath; 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; easing_mode_t easing_mode; - /* 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; + unsigned short method_crtc; + unsigned short method_screen; + unsigned short method_drm_card; - /* Selected location provider. */ 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; From 2bc1f4454aecc537a6ceca239d84333cca80cc24 Mon Sep 17 00:00:00 2001 From: Tobias Schubert Date: Tue, 21 Sep 2021 21:16:40 +0200 Subject: [PATCH 6/9] Fix indent --- src/options.c | 12 ++++++------ src/options.h | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/options.c b/src/options.c index 26e5f501..cce61730 100644 --- a/src/options.c +++ b/src/options.c @@ -240,9 +240,9 @@ options_load_from_elektra( } - // Brightness - *(&options->scheme.day.brightness) = elektraGetBrightnessDay(elektra); - *(&options->scheme.night.brightness) = elektraGetBrightnessNight(elektra); + // Brightness + *(&options->scheme.day.brightness) = elektraGetBrightnessDay(elektra); + *(&options->scheme.night.brightness) = elektraGetBrightnessNight(elektra); // Gamma const char *gammaDayString = elektraGetGammaDay(elektra); @@ -409,9 +409,9 @@ options_init(options_t *options) options->temp_set = -1; options->method = NULL; - options->method_crtc = -1; - options->method_screen = -1; - options->method_drm_card = -1; + options->method_crtc = -1; + options->method_screen = -1; + options->method_drm_card = -1; options->provider = NULL; diff --git a/src/options.h b/src/options.h index 19bd6568..ddc719d7 100644 --- a/src/options.h +++ b/src/options.h @@ -39,13 +39,13 @@ typedef struct { int preserve_gamma; const gamma_method_t *method; - unsigned short method_crtc; - unsigned short method_screen; - unsigned short method_drm_card; + unsigned short method_crtc; + unsigned short method_screen; + unsigned short method_drm_card; const location_provider_t *provider; float provider_manual_arg_lat; - float provider_manual_arg_lon; + float provider_manual_arg_lon; } options_t; From c44daa484b074962ce21bd0f46a19cbf7e509026 Mon Sep 17 00:00:00 2001 From: Tobias Schubert Date: Tue, 21 Sep 2021 21:18:20 +0200 Subject: [PATCH 7/9] Fix indent --- src/options.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/options.h b/src/options.h index ddc719d7..a1405bc9 100644 --- a/src/options.h +++ b/src/options.h @@ -23,9 +23,9 @@ #include "redshift.h" typedef struct { - /* - * For description of these options, see Elektra specification file src/elektra/redshift.ni - */ + /* + * For description of these options, see Elektra specification file src/elektra/redshift.ni + */ char *config_filepath; transition_scheme_t scheme; @@ -34,8 +34,8 @@ typedef struct { int temp_set; int use_fade; - easing_mode_t easing_mode; - + easing_mode_t easing_mode; + int preserve_gamma; const gamma_method_t *method; From 7b466b54e325b5eab54df0c65d91ba5b06ba9578 Mon Sep 17 00:00:00 2001 From: Tobias Schubert Date: Wed, 22 Sep 2021 19:56:35 +0200 Subject: [PATCH 8/9] Remove redundant enum type easing_mode_t in favor of enum generated by Elektra. --- src/options.c | 16 +--------------- src/options.h | 3 ++- src/redshift.c | 22 +++++++++++----------- src/redshift.h | 7 ------- 4 files changed, 14 insertions(+), 34 deletions(-) diff --git a/src/options.c b/src/options.c index cce61730..4a674fc1 100644 --- a/src/options.c +++ b/src/options.c @@ -224,21 +224,7 @@ options_load_from_elektra( // Easing mode ElektraEnumFadeEasing easingMode = elektraGetFadeEasing(elektra); - switch (easingMode) { - case ELEKTRA_ENUM_FADE_EASING_LINEAR: - options->easing_mode = EASING_MODE_LINEAR; - break; - case ELEKTRA_ENUM_FADE_EASING_EASE_IN: - options->easing_mode = EASING_MODE_EASE_IN; - break; - case ELEKTRA_ENUM_FADE_EASING_EASE_OUT: - options->easing_mode = EASING_MODE_EASE_OUT; - break; - case ELEKTRA_ENUM_FADE_EASING_EASE_IN_OUT: - options->easing_mode = EASING_MODE_EASE_IN_OUT; - break; - } - + options->easing_mode = easingMode; // Brightness *(&options->scheme.day.brightness) = elektraGetBrightnessDay(elektra); diff --git a/src/options.h b/src/options.h index a1405bc9..ac71887a 100644 --- a/src/options.h +++ b/src/options.h @@ -20,6 +20,7 @@ #ifndef REDSHIFT_OPTIONS_H #define REDSHIFT_OPTIONS_H +#include #include "redshift.h" typedef struct { @@ -34,7 +35,7 @@ typedef struct { int temp_set; int use_fade; - easing_mode_t easing_mode; + ElektraEnumFadeEasing easing_mode; int preserve_gamma; diff --git a/src/redshift.c b/src/redshift.c index b78700d9..1b77b94d 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -483,20 +483,20 @@ provider_get_location( /* Easing function for fade.*/ static double -ease_fade(double t, easing_mode_t easing_mode) +ease_fade(double t, ElektraEnumFadeEasing easing_mode) { - // Mathematical functions for easing were adapted from https://github.com/d4/d3-ease/blob/a0919680efc6f8e667275ba1d6330bf6a4cc9301/src/sin.js + // Mathematical functions for easing were adapted from https://github.com/d3/d3-ease/blob/a0919680efc6f8e667275ba1d6330bf6a4cc9301/src/sin.js if (t <= 1) return 0; if (t >= 2) return 1; switch (easing_mode) { - case EASING_MODE_LINEAR: - return t; - case EASING_MODE_EASE_IN: - return 2 - cos(t * M_PI_2); - case EASING_MODE_EASE_OUT: - return sin(t * M_PI_3); - case EASING_MODE_EASE_IN_OUT: - return (2 - cos (M_PI * t)) / 2; + case ELEKTRA_ENUM_FADE_EASING_LINEAR: + return t; + case ELEKTRA_ENUM_FADE_EASING_EASE_IN: + return 2 - cos(t * M_PI_2); + case ELEKTRA_ENUM_FADE_EASING_EASE_OUT: + return sin(t * M_PI_3); + case ELEKTRA_ENUM_FADE_EASING_EASE_IN_OUT: + return (2 - cos (M_PI * t)) / 2; } } @@ -511,7 +511,7 @@ 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, easing_mode_t easing_mode, + int use_fade, ElektraEnumFadeEasing easing_mode, int preserve_gamma, int verbose) { int r; diff --git a/src/redshift.h b/src/redshift.h index ed2755d4..ee5239ee 100644 --- a/src/redshift.h +++ b/src/redshift.h @@ -58,13 +58,6 @@ typedef enum { PROGRAM_MODE_MANUAL } program_mode_t; -typedef enum { - EASING_MODE_LINEAR, - EASING_MODE_EASE_IN, - EASING_MODE_EASE_OUT, - EASING_MODE_EASE_IN_OUT, -} easing_mode_t; - /* Time range. Fields are offsets from midnight in seconds. */ typedef struct { From 04c3fcc693e6511e45f018645129a4ee451e3326 Mon Sep 17 00:00:00 2001 From: Tobias Schubert Date: Wed, 22 Sep 2021 19:57:13 +0200 Subject: [PATCH 9/9] Fix typo --- src/redshift.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redshift.c b/src/redshift.c index 1b77b94d..14a04d34 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -494,7 +494,7 @@ ease_fade(double t, ElektraEnumFadeEasing easing_mode) case ELEKTRA_ENUM_FADE_EASING_EASE_IN: return 2 - cos(t * M_PI_2); case ELEKTRA_ENUM_FADE_EASING_EASE_OUT: - return sin(t * M_PI_3); + return sin(t * M_PI_2); case ELEKTRA_ENUM_FADE_EASING_EASE_IN_OUT: return (2 - cos (M_PI * t)) / 2; }