diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/location-geoclue.c | 8 | ||||
-rw-r--r-- | src/redshift-gtk/statusicon.py | 5 | ||||
-rw-r--r-- | src/redshift.c | 120 |
3 files changed, 68 insertions, 65 deletions
diff --git a/src/location-geoclue.c b/src/location-geoclue.c index 5c027c7..07865c5 100644 --- a/src/location-geoclue.c +++ b/src/location-geoclue.c @@ -159,6 +159,10 @@ location_geoclue_set_option(location_geoclue_state_t *state, } state->provider = strdup(provider); + if (state->provider == NULL) { + perror("strdup"); + return -1; + } } else if (strcasecmp(key, "path") == 0) { if (value != NULL && strcasecmp(value, "default") == 0) { path = DEFAULT_PROVIDER_PATH; @@ -167,6 +171,10 @@ location_geoclue_set_option(location_geoclue_state_t *state, } state->provider_path = strdup(path); + if (state->provider_path == NULL) { + perror("strdup"); + return -1; + } } else { fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key); return -1; diff --git a/src/redshift-gtk/statusicon.py b/src/redshift-gtk/statusicon.py index ec0dfe8..2efbc07 100644 --- a/src/redshift-gtk/statusicon.py +++ b/src/redshift-gtk/statusicon.py @@ -28,7 +28,7 @@ import signal, fcntl import re import gettext -from gi.repository import Gtk, GLib +from gi.repository import Gdk, Gtk, GLib try: from gi.repository import AppIndicator3 as appindicator except ImportError: @@ -181,6 +181,9 @@ class RedshiftStatusIcon(object): GLib.io_add_watch(self.process[3], GLib.PRIORITY_DEFAULT, GLib.IO_IN, self.child_data_cb, (False, self.error_buffer)) + # Notify desktop that startup is complete + Gdk.notify_startup_complete() + def start_child_process(self, args): # Start child process with C locale so we can parse the output env = os.environ.copy() diff --git a/src/redshift.c b/src/redshift.c index beecd35..6fc2895 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -262,16 +262,20 @@ static int disable = 0; #endif /* ! HAVE_SIGNAL_H || __WIN32__ */ +/* Transition settings. */ +static float transition_low = TRANSITION_LOW; +static float transition_high = TRANSITION_HIGH; + /* Print which period (night, day or transition) we're currently in. */ static void print_period(double elevation) { - if (elevation < TRANSITION_LOW) { + if (elevation < transition_low) { printf(_("Period: Night\n")); - } else if (elevation < TRANSITION_HIGH) { - float a = (TRANSITION_LOW - elevation) / - (TRANSITION_LOW - TRANSITION_HIGH); + } else if (elevation < transition_high) { + float a = (transition_low - elevation) / + (transition_low - transition_high); printf(_("Period: Transition (%.2f%% day)\n"), a*100); } else { printf(_("Period: Daytime\n")); @@ -283,12 +287,12 @@ static float calculate_interpolated_value(double elevation, float day, float night) { float result; - if (elevation < TRANSITION_LOW) { + if (elevation < transition_low) { result = night; - } else if (elevation < TRANSITION_HIGH) { + } else if (elevation < transition_high) { /* Transition period: interpolate */ - float a = (TRANSITION_LOW - elevation) / - (TRANSITION_LOW - TRANSITION_HIGH); + float a = (transition_low - elevation) / + (transition_low - transition_high); result = (1.0-a)*night + a*day; } else { result = day; @@ -875,6 +879,12 @@ main(int argc, char *argv[]) if (isnan(brightness_night)) { brightness_night = atof(setting->value); } + } else if (strcasecmp(setting->name, + "elevation-high") == 0) { + transition_high = atof(setting->value); + } else if (strcasecmp(setting->name, + "elevation-low") == 0) { + transition_low = atof(setting->value); } else if (strcasecmp(setting->name, "gamma") == 0) { if (isnan(gamma[0])) { r = parse_gamma_string(setting->value, @@ -994,8 +1004,11 @@ main(int argc, char *argv[]) printf(_("Location: %f, %f\n"), lat, lon); printf(_("Temperatures: %dK at day, %dK at night\n"), temp_day, temp_night); + /* TRANSLATORS: Append degree symbols if possible. */ + printf(_("Solar elevations: day above %.1f, night below %.1f\n"), + transition_high, transition_low); } - + /* Latitude */ if (lat < MIN_LAT || lat > MAX_LAT) { /* TRANSLATORS: Append degree symbols if possible. */ @@ -1029,6 +1042,14 @@ main(int argc, char *argv[]) MIN_TEMP, MAX_TEMP); exit(EXIT_FAILURE); } + + /* Solar elevations */ + if (transition_high < transition_low) { + fprintf(stderr, + _("High transition elevation cannot be lower than" + " the low transition elevation.\n")); + exit(EXIT_FAILURE); + } } if (mode == PROGRAM_MODE_MANUAL) { @@ -1182,20 +1203,14 @@ main(int argc, char *argv[]) break; case PROGRAM_MODE_CONTINUAL: { - /* Transition state */ - double short_trans_end = 0; - int short_trans = 0; - int short_trans_done = 0; - /* Make an initial transition from 6500K */ - int short_trans_create = 1; - int short_trans_begin = 1; + int short_trans_delta = -1; int short_trans_len = 10; /* Amount of adjustment to apply. At zero the color temperature will be exactly as calculated, and at one it will be exactly 6500K. */ - double adjustment_alpha = 0.0; + double adjustment_alpha = 1.0; #if defined(HAVE_SIGNAL_H) && !defined(__WIN32__) struct sigaction sigact; @@ -1226,19 +1241,15 @@ main(int argc, char *argv[]) while (1) { /* Check to see if disable signal was caught */ if (disable) { - short_trans_create = 1; short_trans_len = 2; if (!disabled) { /* Transition to disabled state */ - short_trans_begin = 0; - adjustment_alpha = 1.0; - disabled = 1; + short_trans_delta = 1; } else { /* Transition back to enabled */ - short_trans_begin = 1; - adjustment_alpha = 0.0; - disabled = 0; + short_trans_delta = -1; } + disabled = !disabled; disable = 0; if (verbose) { @@ -1252,15 +1263,14 @@ main(int argc, char *argv[]) if (done) { /* On second signal stop the ongoing transition */ - short_trans = 0; + short_trans_delta = 0; + adjustment_alpha = 0.0; } else { if (!disabled) { /* Make a short transition back to 6500K */ - short_trans_create = 1; - short_trans_begin = 0; + short_trans_delta = 1; short_trans_len = 2; - adjustment_alpha = 1.0; } done = 1; @@ -1278,15 +1288,13 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } - /* Set up a new transition */ - if (short_trans_create) { - if (transition) { - short_trans_end = now; - short_trans_end += short_trans_len; - short_trans = 1; - short_trans_create = 0; - } else { - short_trans_done = 1; + /* Skip over transition if transitions are disabled */ + int set_adjustments = 0; + if (!transition) { + if (short_trans_delta) { + adjustment_alpha = short_trans_delta < 0 ? 0.0 : 1.0; + short_trans_delta = 0; + set_adjustments = 1; } } @@ -1302,22 +1310,15 @@ main(int argc, char *argv[]) if (verbose) print_period(elevation); /* Ongoing short transition */ - if (short_trans) { - double start = now; - double end = short_trans_end; - - if (start > end) { - /* Transisiton done */ - short_trans = 0; - short_trans_done = 1; - } - + if (short_trans_delta) { /* Calculate alpha */ - adjustment_alpha = (end - start) / + adjustment_alpha += short_trans_delta * 0.1 / (float)short_trans_len; - if (!short_trans_begin) { - adjustment_alpha = - 1.0 - adjustment_alpha; + + /* Stop transition when done */ + if (adjustment_alpha <= 0.0 || + adjustment_alpha >= 1.0) { + short_trans_delta = 0; } /* Clamp alpha value */ @@ -1325,15 +1326,6 @@ main(int argc, char *argv[]) MAX(0.0, MIN(adjustment_alpha, 1.0)); } - /* Handle end of transition */ - if (short_trans_done) { - if (disabled) { - /* Restore saved gamma ramps */ - method->restore(&state); - } - short_trans_done = 0; - } - /* Interpolate between 6500K and calculated temperature */ temp = adjustment_alpha*6500 + @@ -1343,7 +1335,7 @@ main(int argc, char *argv[]) (1.0-adjustment_alpha)*brightness; /* Quit loop when done */ - if (done && !short_trans) break; + if (done && !short_trans_delta) break; if (verbose) { printf(_("Color temperature: %uK\n"), temp); @@ -1351,7 +1343,7 @@ main(int argc, char *argv[]) } /* Adjust temperature */ - if (!disabled || short_trans) { + if (!disabled || short_trans_delta || set_adjustments) { r = method->set_temperature(&state, temp, brightness, gamma); @@ -1365,10 +1357,10 @@ main(int argc, char *argv[]) /* Sleep for 5 seconds or 0.1 second. */ #ifndef _WIN32 - if (short_trans) usleep(100000); + if (short_trans_delta) usleep(100000); else usleep(5000000); #else /* ! _WIN32 */ - if (short_trans) Sleep(100); + if (short_trans_delta) Sleep(100); else Sleep(5000); #endif /* ! _WIN32 */ } |