aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/randr.c39
-rw-r--r--src/redshift.c19
2 files changed, 38 insertions, 20 deletions
diff --git a/src/randr.c b/src/randr.c
index 369ac34..f401190 100644
--- a/src/randr.c
+++ b/src/randr.c
@@ -251,13 +251,20 @@ randr_free(randr_state_t *state)
static int
randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, int temp,
- float gamma[3])
+ float gamma[3])
{
xcb_generic_error_t *error;
if (crtc_num >= state->crtc_count || crtc_num < 0) {
- fprintf(stderr, _("CRTC %d does not exist (Valid CRTCs are [0-%d])\n"),
- state->crtc_num, state->crtc_count - 1);
+ fprintf(stderr, _("CRTC %d does not exist. "),
+ state->crtc_num);
+ if (state->crtc_count > 1) {
+ fprintf(stderr, _("Valid CRTCs are [0-%d].\n"),
+ state->crtc_count-1);
+ } else {
+ fprintf(stderr, _("Only CRTC 0 exists.\n"));
+ }
+
return -1;
}
@@ -276,18 +283,18 @@ 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, gamma);
/* Set new gamma ramps */
xcb_void_cookie_t gamma_set_cookie =
xcb_randr_set_crtc_gamma_checked(state->conn, crtc,
- ramp_size, gamma_r,
- gamma_g, gamma_b);
+ ramp_size, gamma_r,
+ gamma_g, gamma_b);
error = xcb_request_check(state->conn, gamma_set_cookie);
if (error) {
fprintf(stderr, _("`%s' returned error %d\n"),
- "RANDR Set CRTC Gamma", error->error_code);
+ "RANDR Set CRTC Gamma", error->error_code);
free(gamma_ramps);
return -1;
}
@@ -300,16 +307,20 @@ 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])
{
- /* If no CRTC number has been specified, set temperature on all CRTCs */
+ int r;
+
+ /* If no CRTC number has been specified,
+ set temperature on all CRTCs. */
if (state->crtc_num < 0) {
for (int i = 0; i < state->crtc_count; i++) {
- if (randr_set_temperature_for_crtc(state, i, temp, gamma))
- return -1;
+ r = randr_set_temperature_for_crtc(state, i,
+ temp, gamma);
+ if (r < 0) return -1;
}
+ } else {
+ return randr_set_temperature_for_crtc(state, state->crtc_num,
+ temp, gamma);
}
- else
- return randr_set_temperature_for_crtc(state, state->crtc_num, temp,
- gamma);
-
+
return 0;
}
diff --git a/src/redshift.c b/src/redshift.c
index c553abb..abb0bfd 100644
--- a/src/redshift.c
+++ b/src/redshift.c
@@ -216,12 +216,12 @@ print_help(const char *program_name)
fputs(_(" -g R:G:B\tAdditional gamma correction to apply\n"
" -l LAT:LON\tYour current location\n"
" -m METHOD\tMethod to use to set color temperature"
- " (randr or vidmode)\n"
+ " (RANDR or VidMode)\n"
" -o\t\tOne shot mode (do not continously adjust"
" color temperature)\n"
" -r\t\tDisable initial temperature transition\n"
" -s SCREEN\tX screen to apply adjustments to\n"
- " -c CRTC\tCRTC to apply adjustments to (randr only)\n"
+ " -c CRTC\tCRTC to apply adjustments to (RANDR only)\n"
" -t DAY:NIGHT\tColor temperature to set at daytime/night\n"),
stdout);
fputs("\n", stdout);
@@ -262,8 +262,11 @@ main(int argc, char *argv[])
/* Parse arguments. */
int opt;
- while ((opt = getopt(argc, argv, "g:hl:m:ors:c:t:v")) != -1) {
+ while ((opt = getopt(argc, argv, "c:g:hl:m:ors:t:v")) != -1) {
switch (opt) {
+ case 'c':
+ crtc_num = atoi(optarg);
+ break;
case 'g':
s = strchr(optarg, ':');
if (s == NULL) {
@@ -344,9 +347,6 @@ main(int argc, char *argv[])
case 's':
screen_num = atoi(optarg);
break;
- case 'c':
- crtc_num = atoi(optarg);
- break;
case 't':
s = strchr(optarg, ':');
if (s == NULL) {
@@ -431,6 +431,13 @@ main(int argc, char *argv[])
gamma[0], gamma[1], gamma[2]);
}
+ /* CRTC can only be selected for RANDR */
+ if (crtc_num > -1 && !use_randr) {
+ fprintf(stderr, _("CRTC can only be selected"
+ " with the RANDR method.\n"));
+ exit(EXIT_FAILURE);
+ }
+
/* Initialize gamma adjustment method. If use_randr is negative
try all methods until one that works is found. */
gamma_state_t state;