Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/elektra/redshift.ni
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ options_load_from_elektra(
if(options->mode == ELEKTRA_ENUM_MODE_ONESHOTMANUAL) {
options->temp_set = elektraGetTempOneshotmanual(elektra);
}

// Easing mode
ElektraEnumFadeEasing easingMode = elektraGetFadeEasing(elektra);
options->easing_mode = easingMode;

// Brightness
*(&options->scheme.day.brightness) = elektraGetBrightnessDay(elektra);
Expand Down Expand Up @@ -371,9 +375,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;

Expand Down
22 changes: 10 additions & 12 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,34 @@
#ifndef REDSHIFT_OPTIONS_H
#define REDSHIFT_OPTIONS_H

#include <elektra/redshift-conf.h>
#include "redshift.h"
#include "elektra/redshift-conf.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;
ElektraEnumMode mode;
int verbose;

/* Temperature to set in manual mode. */
int temp_set;
/* Whether to fade between large skips in color temperature. */
int use_fade;
/* Whether to preserve gamma ramps if supported by gamma method. */
ElektraEnumFadeEasing easing_mode;

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;


Expand Down
30 changes: 20 additions & 10 deletions src/redshift.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ElektraEnumFadeEasing 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 <= 1) return 0;
if (t >= 2) return 1;
switch (easing_mode) {
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_2);
case ELEKTRA_ENUM_FADE_EASING_EASE_IN_OUT:
return (2 - cos (M_PI * t)) / 2;
}
}


Expand All @@ -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, ElektraEnumFadeEasing easing_mode,
int preserve_gamma, int verbose)
{
int r;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1172,7 +1181,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);
}
Expand Down