aboutsummaryrefslogtreecommitdiffstats
path: root/src/redshift.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-03-22 20:42:34 +0100
committerMattias Andrée <m@maandree.se>2025-03-22 20:42:34 +0100
commitebd0bdbbf8fbcfc2742a3b62909fe7f761a30890 (patch)
tree48506648560650c2a527c8b7a09e36fb2e76a078 /src/redshift.c
parentUnlist redshift/issues/807: expected behaviour (diff)
downloadredshift-ng-ebd0bdbbf8fbcfc2742a3b62909fe7f761a30890.tar.gz
redshift-ng-ebd0bdbbf8fbcfc2742a3b62909fe7f761a30890.tar.bz2
redshift-ng-ebd0bdbbf8fbcfc2742a3b62909fe7f761a30890.tar.xz
Misc stuff
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'src/redshift.c')
-rw-r--r--src/redshift.c64
1 files changed, 60 insertions, 4 deletions
diff --git a/src/redshift.c b/src/redshift.c
index ddab891..6e9b627 100644
--- a/src/redshift.c
+++ b/src/redshift.c
@@ -281,7 +281,9 @@ run_continual_mode(void)
{
enum period period, prev_period = PERIOD_NONE;
double day_level = FNAN, prev_day_level = FNAN;
- int disabled = 0, prev_disabled = !disabled;
+ int disabled = disable, prev_disabled = !disable;
+ int prev_use_fade = !use_fade;
+ int prev_preserve_gamma = !preserve_gamma;
int done = 0;
struct colour_setting colour;
struct colour_setting target_colour, prev_target_colour;
@@ -292,8 +294,15 @@ run_continual_mode(void)
double fade_progress, eased_fade_progress;
#ifndef WINDOWS
int location_fd;
+ sigset_t sigusr2_mask, old_mask;
+ enum signals commands;
+
+ sigemptyset(&sigusr2_mask);
+ sigaddset(&sigusr2_mask, SIGUSR2);
#endif
+ disable = 0;
+
prev_target_colour = COLOUR_SETTING_NEUTRAL;
colour = COLOUR_SETTING_NEUTRAL;
@@ -310,9 +319,49 @@ run_continual_mode(void)
break; /* On second signal stop the ongoing fade */
done = 1;
}
- if (verbose && disabled != prev_disabled)
- printf(_("Status: %s\n"), disabled ? _("Disabled") : _("Enabled"));
+#ifndef WINDOWS
+ while (signals) {
+ if (sigprocmask(SIG_BLOCK, &sigusr2_mask, &old_mask))
+ eprintf("sigprocmask:");
+ commands = signals;
+ signals = 0;
+
+ if (commands & SIGNAL_ORDER_BARRIER) sigdelset(&old_mask, SIGUSR2);
+ if (commands & SIGNAL_DISABLE) disabled = 1;
+ if (commands & SIGNAL_ENABLE) disabled = 0;
+ if (commands & SIGNAL_RELOAD) {} /* TODO */
+ if (commands & SIGNAL_USE_FADE_OFF) use_fade = 0;
+ if (commands & SIGNAL_USE_FADE_ON) use_fade = 1;
+ if (commands & SIGNAL_PRESERVE_GAMMA_OFF) preserve_gamma = 0;
+ if (commands & SIGNAL_PRESERVE_GAMMA_ON) preserve_gamma = 1;
+ if (commands & SIGNAL_EXIT_WITHOUT_RESET) {} /* TODO */
+ if (commands & SIGNAL_VERBOSE_ON) verbose |= 2;
+ if (commands & SIGNAL_VERBOSE_OFF) verbose &= ~2;
+
+ if (commands & SIGNAL_IGNORE_SIGPIPE)
+ if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
+ weprintf("signal SIGPIPE SIG_IGN:");
+
+ if (sigprocmask(SIG_SETMASK, &old_mask, NULL))
+ eprintf("sigprocmask:");
+
+# if defined(__linux__)
+ if (commands & SIGNAL_REEXEC) { /* TODO */
+ }
+# endif
+ }
+#endif
+ if (verbose) {
+ if (disabled != prev_disabled)
+ printf(_("Status: %s\n"), disabled ? _("Disabled") : _("Enabled"));
+ if (use_fade != prev_use_fade)
+ printf(_("Fade: %s\n"), use_fade ? _("Disabled") : _("Enabled"));
+ if (preserve_gamma != prev_preserve_gamma)
+ printf(_("Preserve gamma: %s\n"), use_fade ? _("Disabled") : _("Enabled"));
+ }
prev_disabled = disabled;
+ prev_use_fade = use_fade;
+ prev_preserve_gamma = preserve_gamma;
/* Get dayness level and corresponding colour settings */
if (disabled) {
@@ -462,8 +511,14 @@ main(int argc, char *argv[])
eprintf(_("Temperature adjustment failed."));
if (mode == PROGRAM_MODE_UNTIL_DEATH || method->autoreset) {
weprintf(_("Press ctrl-c to stop..."));
- while (!exiting)
+ while (!exiting) {
pause();
+ if (signals & SIGNAL_EXIT_WITHOUT_RESET) {
+ /* TODO disable reset if if using coopgamma */
+ goto out;
+ }
+ }
+ /* TODO reset if not using coopgamma */
}
break;
@@ -477,6 +532,7 @@ main(int argc, char *argv[])
#endif
}
+out:
if (provider_state)
provider->free(provider_state);
if (method_state)