aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am10
-rw-r--r--src/colorramp.c8
-rw-r--r--src/colorramp.h2
-rw-r--r--src/config-ini.c6
-rw-r--r--src/gamma-randr.c12
-rw-r--r--src/gamma-randr.h3
-rw-r--r--src/gamma-vidmode.c5
-rw-r--r--src/gamma-vidmode.h3
-rw-r--r--src/gamma-w32gdi.c53
-rw-r--r--src/gamma-w32gdi.h4
-rw-r--r--src/location-geoclue.c186
-rw-r--r--src/location-geoclue.h44
-rw-r--r--src/redshift.c111
-rw-r--r--src/redshift.h1
14 files changed, 383 insertions, 65 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 3680f4a..6c4a613 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,7 +20,8 @@ EXTRA_redshift_SOURCES = \
gamma-randr.c gamma-randr.h \
gamma-vidmode.c gamma-vidmode.h \
gamma-w32gdi.c gamma-w32gdi.h \
- location-gnome-clock.c location-gnome-clock.h
+ location-gnome-clock.c location-gnome-clock.h \
+ location-geoclue.c location-geoclue.h
AM_CFLAGS =
redshift_LDADD = @LIBINTL@
@@ -54,3 +55,10 @@ redshift_LDADD += \
$(GLIB_LIBS) $(GLIB_CFLAGS) \
$(GCONF_LIBS) $(GCONF_CFLAGS)
endif
+
+if ENABLE_GEOCLUE
+redshift_SOURCES += location-geoclue.c location-geoclue.h
+AM_CFLAGS += $(GEOCLUE_CFLAGS) $(GEOCLUE_LIBS)
+redshift_LDADD += \
+ $(GEOCLUE_LIBS) $(GEOCLUE_CFLAGS)
+endif
diff --git a/src/colorramp.c b/src/colorramp.c
index 7241a8d..ed399f8 100644
--- a/src/colorramp.c
+++ b/src/colorramp.c
@@ -128,7 +128,7 @@ interpolate_color(float a, const float *c1, const float *c2, float *c)
void
colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b,
- int size, int temp, float gamma[3])
+ int size, int temp, float brightness, float gamma[3])
{
/* Approximate white point */
float white_point[3];
@@ -139,10 +139,10 @@ colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b,
for (int i = 0; i < size; i++) {
gamma_r[i] = pow((float)i/size, 1.0/gamma[0]) *
- UINT16_MAX * white_point[0];
+ UINT16_MAX * brightness * white_point[0];
gamma_g[i] = pow((float)i/size, 1.0/gamma[1]) *
- UINT16_MAX * white_point[1];
+ UINT16_MAX * brightness * white_point[1];
gamma_b[i] = pow((float)i/size, 1.0/gamma[2]) *
- UINT16_MAX * white_point[2];
+ UINT16_MAX * brightness * white_point[2];
}
}
diff --git a/src/colorramp.h b/src/colorramp.h
index 88aa984..326969e 100644
--- a/src/colorramp.h
+++ b/src/colorramp.h
@@ -23,6 +23,6 @@
#include <stdint.h>
void colorramp_fill(uint16_t *gamma_r, uint16_t *gamma_g, uint16_t *gamma_b,
- int size, int temp, float gamma[3]);
+ int size, int temp, float brightness, float gamma[3]);
#endif /* ! _REDSHIFT_COLORRAMP_H */
diff --git a/src/config-ini.c b/src/config-ini.c
index 5231ba5..eae19c7 100644
--- a/src/config-ini.c
+++ b/src/config-ini.c
@@ -49,6 +49,12 @@ open_config_file(const char *filepath)
env[0] != '\0') {
snprintf(cp, sizeof(cp), "%s/redshift.conf", env);
filepath = cp;
+#ifdef _WIN32
+ } else if ((env = getenv("userprofile")) != NULL && env[0] != '\0') {
+ snprintf(cp, sizeof(cp),
+ "%s/.config/redshift.conf", env);
+ filepath = cp;
+#endif
} else if ((env = getenv("HOME")) != NULL && env[0] != '\0') {
snprintf(cp, sizeof(cp),
"%s/.config/redshift.conf", env);
diff --git a/src/gamma-randr.c b/src/gamma-randr.c
index be8bdd9..8781e92 100644
--- a/src/gamma-randr.c
+++ b/src/gamma-randr.c
@@ -301,7 +301,7 @@ randr_set_option(randr_state_t *state, const char *key, const char *value)
static int
randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, int temp,
- float gamma[3])
+ float brightness, float gamma[3])
{
xcb_generic_error_t *error;
@@ -333,7 +333,7 @@ randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, int temp,
uint16_t *gamma_b = &gamma_ramps[2*ramp_size];
colorramp_fill(gamma_r, gamma_g, gamma_b, ramp_size,
- temp, gamma);
+ temp, brightness, gamma);
/* Set new gamma ramps */
xcb_void_cookie_t gamma_set_cookie =
@@ -355,7 +355,8 @@ randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, int temp,
}
int
-randr_set_temperature(randr_state_t *state, int temp, float gamma[3])
+randr_set_temperature(randr_state_t *state, int temp, float brightness,
+ float gamma[3])
{
int r;
@@ -364,12 +365,13 @@ randr_set_temperature(randr_state_t *state, int temp, float gamma[3])
if (state->crtc_num < 0) {
for (int i = 0; i < state->crtc_count; i++) {
r = randr_set_temperature_for_crtc(state, i,
- temp, gamma);
+ temp, brightness,
+ gamma);
if (r < 0) return -1;
}
} else {
return randr_set_temperature_for_crtc(state, state->crtc_num,
- temp, gamma);
+ temp, brightness, gamma);
}
return 0;
diff --git a/src/gamma-randr.h b/src/gamma-randr.h
index 4ccad8f..11818fa 100644
--- a/src/gamma-randr.h
+++ b/src/gamma-randr.h
@@ -54,7 +54,8 @@ void randr_print_help(FILE *f);
int randr_set_option(randr_state_t *state, const char *key, const char *value);
void randr_restore(randr_state_t *state);
-int randr_set_temperature(randr_state_t *state, int temp, float gamma[3]);
+int randr_set_temperature(randr_state_t *state, int temp, float brightness,
+ float gamma[3]);
#endif /* ! _REDSHIFT_GAMMA_RANDR_H */
diff --git a/src/gamma-vidmode.c b/src/gamma-vidmode.c
index 7b891d8..a083658 100644
--- a/src/gamma-vidmode.c
+++ b/src/gamma-vidmode.c
@@ -169,7 +169,8 @@ vidmode_restore(vidmode_state_t *state)
}
int
-vidmode_set_temperature(vidmode_state_t *state, int temp, float gamma[3])
+vidmode_set_temperature(vidmode_state_t *state, int temp, float brightness,
+ float gamma[3])
{
int r;
@@ -185,7 +186,7 @@ vidmode_set_temperature(vidmode_state_t *state, int temp, float gamma[3])
uint16_t *gamma_b = &gamma_ramps[2*state->ramp_size];
colorramp_fill(gamma_r, gamma_g, gamma_b, state->ramp_size,
- temp, gamma);
+ temp, brightness, gamma);
/* Set new gamma ramps */
r = XF86VidModeSetGammaRamp(state->display, state->screen_num,
diff --git a/src/gamma-vidmode.h b/src/gamma-vidmode.h
index 18a4a88..735ba1f 100644
--- a/src/gamma-vidmode.h
+++ b/src/gamma-vidmode.h
@@ -42,7 +42,8 @@ int vidmode_set_option(vidmode_state_t *state, const char *key,
const char *value);
void vidmode_restore(vidmode_state_t *state);
-int vidmode_set_temperature(vidmode_state_t *state, int temp, float gamma[3]);
+int vidmode_set_temperature(vidmode_state_t *state, int temp, float brightness,
+ float gamma[3]);
#endif /* ! _REDSHIFT_GAMMA_VIDMODE_H */
diff --git a/src/gamma-w32gdi.c b/src/gamma-w32gdi.c
index aa2474d..d23bf72 100644
--- a/src/gamma-w32gdi.c
+++ b/src/gamma-w32gdi.c
@@ -43,7 +43,6 @@ int
w32gdi_init(w32gdi_state_t *state)
{
state->saved_ramps = NULL;
- state->hDC = NULL;
return 0;
}
@@ -54,14 +53,14 @@ w32gdi_start(w32gdi_state_t *state)
BOOL r;
/* Open device context */
- state->hDC = GetDC(NULL);
- if (state->hDC == NULL) {
+ HDC hDC = GetDC(NULL);
+ if (hDC == NULL) {
fputs(_("Unable to open device context.\n"), stderr);
return -1;
}
/* Check support for gamma ramps */
- int cmcap = GetDeviceCaps(state->hDC, COLORMGMTCAPS);
+ int cmcap = GetDeviceCaps(hDC, COLORMGMTCAPS);
if (cmcap != CM_GAMMA_RAMP) {
fputs(_("Display device does not support gamma ramps.\n"),
stderr);
@@ -72,18 +71,21 @@ w32gdi_start(w32gdi_state_t *state)
state->saved_ramps = malloc(3*GAMMA_RAMP_SIZE*sizeof(WORD));
if (state->saved_ramps == NULL) {
perror("malloc");
- ReleaseDC(NULL, state->hDC);
+ ReleaseDC(NULL, hDC);
return -1;
}
/* Save current gamma ramps so we can restore them at program exit */
- r = GetDeviceGammaRamp(state->hDC, state->saved_ramps);
+ r = GetDeviceGammaRamp(hDC, state->saved_ramps);
if (!r) {
fputs(_("Unable to save current gamma ramp.\n"), stderr);
- ReleaseDC(NULL, state->hDC);
+ ReleaseDC(NULL, hDC);
return -1;
}
+ /* Release device context */
+ ReleaseDC(NULL, hDC);
+
return 0;
}
@@ -92,9 +94,6 @@ w32gdi_free(w32gdi_state_t *state)
{
/* Free saved ramps */
free(state->saved_ramps);
-
- /* Release device context */
- if (state->hDC != NULL) ReleaseDC(NULL, state->hDC);
}
@@ -114,20 +113,39 @@ w32gdi_set_option(w32gdi_state_t *state, const char *key, const char *value)
void
w32gdi_restore(w32gdi_state_t *state)
{
+ /* Open device context */
+ HDC hDC = GetDC(NULL);
+ if (hDC == NULL) {
+ fputs(_("Unable to open device context.\n"), stderr);
+ return;
+ }
+
/* Restore gamma ramps */
- BOOL r = SetDeviceGammaRamp(state->hDC, state->saved_ramps);
+ BOOL r = SetDeviceGammaRamp(hDC, state->saved_ramps);
if (!r) fputs(_("Unable to restore gamma ramps.\n"), stderr);
+
+ /* Release device context */
+ ReleaseDC(NULL, hDC);
}
int
-w32gdi_set_temperature(w32gdi_state_t *state, int temp, float gamma[3])
+w32gdi_set_temperature(w32gdi_state_t *state, int temp, float brightness,
+ float gamma[3])
{
BOOL r;
+ /* Open device context */
+ HDC hDC = GetDC(NULL);
+ if (hDC == NULL) {
+ fputs(_("Unable to open device context.\n"), stderr);
+ return -1;
+ }
+
/* Create new gamma ramps */
WORD *gamma_ramps = malloc(3*GAMMA_RAMP_SIZE*sizeof(WORD));
if (gamma_ramps == NULL) {
perror("malloc");
+ ReleaseDC(NULL, hDC);
return -1;
}
@@ -136,17 +154,24 @@ w32gdi_set_temperature(w32gdi_state_t *state, int temp, float gamma[3])
WORD *gamma_b = &gamma_ramps[2*GAMMA_RAMP_SIZE];
colorramp_fill(gamma_r, gamma_g, gamma_b, GAMMA_RAMP_SIZE,
- temp, gamma);
+ temp, brightness, gamma);
/* Set new gamma ramps */
- r = SetDeviceGammaRamp(state->hDC, gamma_ramps);
+ r = SetDeviceGammaRamp(hDC, gamma_ramps);
if (!r) {
+ /* TODO it happens that SetDeviceGammaRamp returns FALSE on
+ occasions where the adjustment seems to be successful.
+ Does this only happen with multiple monitors connected? */
fputs(_("Unable to set gamma ramps.\n"), stderr);
free(gamma_ramps);
+ ReleaseDC(NULL, hDC);
return -1;
}
free(gamma_ramps);
+ /* Release device context */
+ ReleaseDC(NULL, hDC);
+
return 0;
}
diff --git a/src/gamma-w32gdi.h b/src/gamma-w32gdi.h
index 6cb9799..57a604f 100644
--- a/src/gamma-w32gdi.h
+++ b/src/gamma-w32gdi.h
@@ -25,7 +25,6 @@
typedef struct {
- HDC hDC;
WORD *saved_ramps;
} w32gdi_state_t;
@@ -39,7 +38,8 @@ int w32gdi_set_option(w32gdi_state_t *state, const char *key,
const char *value);
void w32gdi_restore(w32gdi_state_t *state);
-int w32gdi_set_temperature(w32gdi_state_t *state, int temp, float gamma[3]);
+int w32gdi_set_temperature(w32gdi_state_t *state, int temp, float brightness,
+ float gamma[3]);
#endif /* ! _REDSHIFT_GAMMA_W32GDI_H */
diff --git a/src/location-geoclue.c b/src/location-geoclue.c
new file mode 100644
index 0000000..6946dd8
--- /dev/null
+++ b/src/location-geoclue.c
@@ -0,0 +1,186 @@
+/* location-geoclue.c -- Geoclue location provider source
+ This file is part of Redshift.
+
+ Redshift is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Redshift is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Redshift. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright (c) 2010 Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com>
+*/
+
+#include <stdio.h>
+#include <string.h>
+
+#include <geoclue/geoclue-master.h>
+#include <geoclue/geoclue-position.h>
+
+#include "location-geoclue.h"
+
+#ifdef ENABLE_NLS
+# include <libintl.h>
+# define _(s) gettext(s)
+#else
+# define _(s) s
+#endif
+
+#define DEFAULT_PROVIDER "org.freedesktop.Geoclue.Providers.UbuntuGeoIP"
+#define DEFAULT_PROVIDER_PATH "/org/freedesktop/Geoclue/Providers/UbuntuGeoIP"
+
+int
+location_geoclue_init(location_geoclue_state_t *state)
+{
+ g_type_init();
+
+ state->position = NULL;
+ state->provider = NULL;
+ state->provider_path = NULL;
+
+ return 0;
+}
+
+int
+location_geoclue_start(location_geoclue_state_t *state)
+{
+ GeoclueMaster *master = NULL;
+ GeoclueMasterClient *client = NULL;
+ GError *error = NULL;
+ gchar *name = NULL;
+
+ if (!(state->provider && state->provider_path)) {
+ master = geoclue_master_get_default();
+ client = geoclue_master_create_client(master, NULL, NULL);
+
+ if (!geoclue_master_client_set_requirements(client,
+ GEOCLUE_ACCURACY_LEVEL_REGION,
+ 0, FALSE,
+ GEOCLUE_RESOURCE_NETWORK,
+ &error)) {
+ g_printerr(_("Can't set requirements for master: %s"),
+ error->message);
+ g_error_free(error);
+ g_object_unref(client);
+
+ return -1;
+ }
+
+ state->position = geoclue_master_client_create_position(client, NULL);
+ } else {
+ state->position = geoclue_position_new(state->provider,
+ state->provider_path);
+ }
+
+ if (geoclue_provider_get_provider_info(GEOCLUE_PROVIDER(state->position),
+ &name, NULL, NULL)) {
+ fprintf(stdout, _("Started Geoclue provider `%s'.\n"), name);
+ g_free(name);
+ } else {
+ fputs(_("Could not find a usable Geoclue provider.\n"), stderr);
+ fputs(_("Try setting name and path to specify which to use.\n"), stderr);
+ return -1;
+ }
+
+ return 0;
+}
+
+void
+location_geoclue_free(location_geoclue_state_t *state)
+{
+ if (state->position != NULL) g_object_unref(state->position);
+}
+
+void
+location_geoclue_print_help(FILE *f)
+{
+ fputs(_("Use the location as discovered by a Geoclue provider.\n"), f);
+ fputs("\n", f);
+
+ /* TRANSLATORS: Geoclue help output
+ left column must not be translated */
+ fputs(_(" name=N\tName of Geoclue provider (or `default')\n"
+ " path=N\tPath of Geoclue provider (or `default')\n"), f);
+ fputs("\n", f);
+}
+
+int
+location_geoclue_set_option(location_geoclue_state_t *state,
+ const char *key, const char *value)
+{
+ const char *provider = NULL;
+ const char *path = NULL;
+
+ /* Parse string value */
+ if (key != NULL && strcasecmp(key, "name") == 0) {
+ if (value != NULL && strcasecmp(value, "default") == 0) {
+ provider = DEFAULT_PROVIDER;
+ } else if (value != NULL) {
+ provider = value;
+ } else {
+ fputs(_("Must specify a provider `name' (or use `default').\n"), stderr);
+ return -1;
+ }
+
+ /* TODO I don't think we own the string here, should be copied. */
+ state->provider = provider;
+ } else if (key != NULL && strcasecmp(key, "path") == 0) {
+ if (value != NULL && strcasecmp(value, "default") == 0) {
+ path = DEFAULT_PROVIDER_PATH;
+ } else if (value != NULL) {
+ path = value;
+ } else {
+ fputs(_("Must specify a provider `path' (or use `default').\n"), stderr);
+ return -1;
+ }
+
+ /* TODO I don't think we own the string here, should be copied. */
+ state->provider_path = path;
+ } else if (key == NULL) {
+ return -1;
+ } else {
+ fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key);
+ return -1;
+ }
+
+ return 0;
+}
+
+int
+location_geoclue_get_location(location_geoclue_state_t *state,
+ float *lat, float *lon)
+{
+ GeocluePositionFields fields;
+ GError *error = NULL;
+ double latitude = 0, longitude = 0;
+
+ fields = geoclue_position_get_position(state->position, NULL,
+ &latitude, &longitude, NULL,
+ NULL, &error);
+ if (error) {
+ g_printerr(_("Could not get location: %s.\n"), error->message);
+ g_error_free(error);
+ return -1;
+ }
+
+ if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE &&
+ fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) {
+ fprintf(stdout, _("According to the geoclue provider"
+ " we're at: %.2f, %.2f\n"),
+ latitude, longitude);
+ } else {
+ g_warning(_("Provider does not have a valid location available."));
+ return -1;
+ }
+
+ *lat = latitude;
+ *lon = longitude;
+
+ return 0;
+}
diff --git a/src/location-geoclue.h b/src/location-geoclue.h
new file mode 100644
index 0000000..40ab22c
--- /dev/null
+++ b/src/location-geoclue.h
@@ -0,0 +1,44 @@
+/* location-geoclue.h -- Geoclue location provider header
+ This file is part of Redshift.
+
+ Redshift is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Redshift is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Redshift. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright (c) 2010 Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com>
+*/
+
+#ifndef _REDSHIFT_LOCATION_GEOCLUE_H
+#define _REDSHIFT_LOCATION_GEOCLUE_H
+
+#include <stdio.h>
+#include <geoclue/geoclue-position.h>
+
+typedef struct {
+ GeocluePosition *position; /* main geoclue object */
+ const char *provider; /* name of a geoclue provider */
+ const char *provider_path; /* path of the geoclue provider */
+} location_geoclue_state_t;
+
+int location_geoclue_init(location_geoclue_state_t *state);
+int location_geoclue_start(location_geoclue_state_t *state);
+void location_geoclue_free(location_geoclue_state_t *state);
+
+void location_geoclue_print_help(FILE *f);
+int location_geoclue_set_option(location_geoclue_state_t *state,
+ const char *key, const char *value);
+
+int location_geoclue_get_location(location_geoclue_state_t *state,
+ float *lat, float *lon);
+
+
+#endif /* ! _REDSHIFT_LOCATION_GEOCLUE_H */
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);
diff --git a/src/redshift.h b/src/redshift.h
index 8f488f6..c3d1239 100644
--- a/src/redshift.h
+++ b/src/redshift.h
@@ -33,6 +33,7 @@ typedef int gamma_method_set_option_func(void *state, const char *key,
const char *value);
typedef void gamma_method_restore_func(void *state);
typedef int gamma_method_set_temperature_func(void *state, int temp,
+ float brightness,
float gamma[3]);
typedef struct {