aboutsummaryrefslogtreecommitdiffstats
path: root/src/redshift.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/redshift.c')
-rw-r--r--src/redshift.c111
1 files changed, 77 insertions, 34 deletions
diff --git a/src/redshift.c b/src/redshift.c
index 5042bd6..2273d7c 100644
--- a/src/redshift.c
+++ b/src/redshift.c
@@ -76,6 +76,10 @@
# include "location-gnome-clock.h"
#endif
+#ifdef ENABLE_GEOCLUE
+# include "location-geoclue.h"
+#endif
+
/* Union of state data for gamma adjustment methods */
typedef union {
@@ -139,11 +143,28 @@ typedef union {
#ifdef ENABLE_GNOME_CLOCK
location_gnome_clock_state_t gnome_clock;
#endif
+#ifdef ENABLE_GEOCLUE
+ location_geoclue_state_t geoclue;
+#endif
} location_state_t;
/* Location provider method structs */
static const location_provider_t location_providers[] = {
+#ifdef ENABLE_GEOCLUE
+ {
+ "geoclue",
+ (location_provider_init_func *)location_geoclue_init,
+ (location_provider_start_func *)location_geoclue_start,
+ (location_provider_free_func *)location_geoclue_free,
+ (location_provider_print_help_func *)
+ location_geoclue_print_help,
+ (location_provider_set_option_func *)
+ location_geoclue_set_option,
+ (location_provider_get_location_func *)
+ location_geoclue_get_location
+ },
+#endif
#ifdef ENABLE_GNOME_CLOCK
{
"gnome-clock",
@@ -180,12 +201,15 @@ static const location_provider_t location_providers[] = {
#define MAX_LON 180.0
#define MIN_TEMP 1000
#define MAX_TEMP 10000
+#define MIN_BRIGHTNESS 0.1
+#define MAX_BRIGHTNESS 1.0
#define MIN_GAMMA 0.1
#define MAX_GAMMA 10.0
/* Default values for parameters. */
#define DEFAULT_DAY_TEMP 5500
#define DEFAULT_NIGHT_TEMP 3700
+#define DEFAULT_BRIGHTNESS 1.0
#define DEFAULT_GAMMA 1.0
/* The color temperature when no adjustment is applied. */
@@ -535,6 +559,8 @@ parse_gamma_string(const char *str, float gamma[])
gamma[1] = atof(g_s); /* Blue */
gamma[2] = atof(s); /* Green */
}
+
+ return 0;
}
static const gamma_method_t *
@@ -567,19 +593,6 @@ find_location_provider(const char *name)
return provider;
}
-/* Check Color Temperature */
-void
-check_temp(int temp)
-{
- /* Color temperature at daytime */
- if (temp < MIN_TEMP || temp > MAX_TEMP) {
- fprintf(stderr,
- _("Temperature must be between %uK and %uK.\n"),
- MIN_TEMP, MAX_TEMP);
- exit(EXIT_FAILURE);
- }
-}
-
int
main(int argc, char *argv[])
@@ -603,6 +616,7 @@ main(int argc, char *argv[])
int temp_day = -1;
int temp_night = -1;
float gamma[3] = { NAN, NAN, NAN };
+ float brightness = NAN;
const gamma_method_t *method = NULL;
char *method_args = NULL;
@@ -617,8 +631,11 @@ main(int argc, char *argv[])
/* Parse command line arguments. */
int opt;
- while ((opt = getopt(argc, argv, "c:g:hl:m:oO:rt:vx")) != -1) {
+ while ((opt = getopt(argc, argv, "b:c:g:hl:m:oO:rt:vx")) != -1) {
switch (opt) {
+ case 'b':
+ brightness = atof(optarg);
+ break;
case 'c':
if (config_filepath != NULL) free(config_filepath);
config_filepath = strdup(optarg);
@@ -717,19 +734,7 @@ main(int argc, char *argv[])
break;
case 'O':
mode = PROGRAM_MODE_MANUAL;
-
- /* Remove K and k from argument just in case. */
- char* s = optarg; //arg string
- char* p; // position
- char* k = "Kk";
- for (int i = 0; i < strlen(k); i++)
- {
- if (p = strchr(s, k[i]))
- memmove(p, p+1, strlen(p));
- }
-
- temp_set = atoi(s);
- check_temp(temp_set);
+ temp_set = atoi(optarg);
break;
case 'r':
transition = 0;
@@ -790,6 +795,11 @@ main(int argc, char *argv[])
if (transition < 0) {
transition = !!atoi(setting->value);
}
+ } else if (strcasecmp(setting->name,
+ "brightness") == 0) {
+ if (isnan(brightness)) {
+ brightness = atof(setting->value);
+ }
} else if (strcasecmp(setting->name, "gamma") == 0) {
if (isnan(gamma[0])) {
r = parse_gamma_string(setting->value,
@@ -842,6 +852,7 @@ main(int argc, char *argv[])
the config file nor on the command line. */
if (temp_day < 0) temp_day = DEFAULT_DAY_TEMP;
if (temp_night < 0) temp_night = DEFAULT_NIGHT_TEMP;
+ if (isnan(brightness)) brightness = DEFAULT_BRIGHTNESS;
if (isnan(gamma[0])) gamma[0] = gamma[1] = gamma[2] = DEFAULT_GAMMA;
if (transition < 0) transition = 1;
@@ -853,7 +864,7 @@ main(int argc, char *argv[])
location_state_t location_state;
/* Location is not needed for reset mode
- or for manual temperature setting */
+ or for manual temperature setting. */
if (mode != PROGRAM_MODE_RESET && mode != PROGRAM_MODE_MANUAL) {
if (provider != NULL) {
/* Use provider specified on command line. */
@@ -923,12 +934,43 @@ main(int argc, char *argv[])
}
/* Color temperature at daytime */
- check_temp(temp_day);
+ if (temp_day < MIN_TEMP || temp_day >= MAX_TEMP) {
+ fprintf(stderr,
+ _("Temperature must be between %uK and %uK.\n"),
+ MIN_TEMP, MAX_TEMP);
+ exit(EXIT_FAILURE);
+ }
/* Color temperature at night */
- check_temp(temp_night);
+ if (temp_night < MIN_TEMP || temp_night >= MAX_TEMP) {
+ fprintf(stderr,
+ _("Temperature must be between %uK and %uK.\n"),
+ MIN_TEMP, MAX_TEMP);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (mode == PROGRAM_MODE_MANUAL) {
+ /* Check color temperature to be set */
+ if (temp_set < MIN_TEMP || temp_set >= MAX_TEMP) {
+ fprintf(stderr,
+ _("Temperature must be between %uK and %uK.\n"),
+ MIN_TEMP, MAX_TEMP);
+ exit(EXIT_FAILURE);
+ }
}
+ /* Brightness */
+ if (brightness < MIN_BRIGHTNESS || brightness > MAX_BRIGHTNESS) {
+ fprintf(stderr,
+ _("Brightness value must be between %.1f and %.1f.\n"),
+ MIN_BRIGHTNESS, MAX_BRIGHTNESS);
+ exit(EXIT_FAILURE);
+ }
+
+ if (verbose) {
+ printf(_("Brightness: %.2f\n"), brightness);
+ }
/* Gamma */
if (gamma[0] < MIN_GAMMA || gamma[0] > MAX_GAMMA ||
@@ -1003,7 +1045,7 @@ main(int argc, char *argv[])
if (verbose) printf(_("Color temperature: %uK\n"), temp);
/* Adjust temperature */
- r = method->set_temperature(&state, temp, gamma);
+ r = method->set_temperature(&state, temp, brightness, gamma);
if (r < 0) {
fputs(_("Temperature adjustment failed.\n"), stderr);
method->free(&state);
@@ -1016,7 +1058,7 @@ main(int argc, char *argv[])
if (verbose) printf(_("Color temperature: %uK\n"), temp_set);
/* Adjust temperature */
- r = method->set_temperature(&state, temp_set, gamma);
+ r = method->set_temperature(&state, temp_set, brightness, gamma);
if (r < 0) {
fputs(_("Temperature adjustment failed.\n"), stderr);
method->free(&state);
@@ -1028,7 +1070,7 @@ main(int argc, char *argv[])
case PROGRAM_MODE_RESET:
{
/* Reset screen */
- r = method->set_temperature(&state, NEUTRAL_TEMP, gamma);
+ r = method->set_temperature(&state, NEUTRAL_TEMP, 1.0, gamma);
if (r < 0) {
fputs(_("Temperature adjustment failed.\n"), stderr);
method->free(&state);
@@ -1192,7 +1234,8 @@ main(int argc, char *argv[])
/* Adjust temperature */
if (!disabled || short_trans) {
r = method->set_temperature(&state,
- temp, gamma);
+ temp, brightness,
+ gamma);
if (r < 0) {
fputs(_("Temperature adjustment"
" failed.\n"), stderr);