From f95038cb0393991e0bc6cc42560c008abf1dd318 Mon Sep 17 00:00:00 2001 From: Marco Fontani Date: Thu, 16 May 2019 13:36:28 +0200 Subject: [PATCH] fix disable resetting color+temp continuously To reproduce without this patch: 1. run `./src/redshift -v` in a terminal 2. in another terminal, `pkill -USR1 redshift` ... which ought to disable its processing altogether, once completed ... but doesn't :( 3. while it's disabled, manually set the brightness: `xrandr --output HDMI2 --brightness 0.5` 4. after a few seconds (default is 5secs between iterations), the brightness (and temp) jumps up again despite redshift being disabled With this patch, instead - the resetting of colour and temperature is done only once after the program's been disabled, and subsequent changes of brightness or temperature etc. via a separate `xrandr` while the program is disabled have the desired effect (i.e. they stick instead of being reset by a "disabled" redshift program). Once the program is re-enabled again (i.e. via another `pkill -USR1 redshift`), the program is again allowed to make changes to brightness and temperature, as it ought to be able to. --- src/redshift.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/redshift.c b/src/redshift.c index e0221d5e..a68a1c3e 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -662,6 +662,7 @@ run_continual_mode(const location_provider_t *provider, int prev_disabled = 1; int disabled = 0; int location_available = 1; + int should_reset = 0; while (1) { /* Check to see if disable signal was caught */ if (disable && !done) { @@ -685,6 +686,7 @@ run_continual_mode(const location_provider_t *provider, if (verbose && disabled != prev_disabled) { printf(_("Status: %s\n"), disabled ? _("Disabled") : _("Enabled")); + should_reset = 1; } prev_disabled = disabled; @@ -724,7 +726,9 @@ run_continual_mode(const location_provider_t *provider, if (disabled) { period = PERIOD_NONE; - color_setting_reset(&target_interp); + if (should_reset) { + color_setting_reset(&target_interp); + } } if (done) { @@ -797,18 +801,23 @@ run_continual_mode(const location_provider_t *provider, } /* Adjust temperature */ - r = method->set_temperature( - method_state, &interp, preserve_gamma); - if (r < 0) { - fputs(_("Temperature adjustment failed.\n"), - stderr); - return -1; + if (!disabled || should_reset) { + r = method->set_temperature( + method_state, &interp, preserve_gamma); + if (r < 0) { + fputs(_("Temperature adjustment failed.\n"), + stderr); + return -1; + } } /* Save period and target color setting as previous */ prev_period = period; prev_target_interp = target_interp; + /* All resets have been done now */ + should_reset = 0; + /* Sleep length depends on whether a fade is ongoing. */ int delay = SLEEP_DURATION; if (fade_length != 0) {