diff options
Diffstat (limited to 'src/randr.c')
-rw-r--r-- | src/randr.c | 93 |
1 files changed, 63 insertions, 30 deletions
diff --git a/src/randr.c b/src/randr.c index 7c05b26..f401190 100644 --- a/src/randr.c +++ b/src/randr.c @@ -36,7 +36,7 @@ int -randr_init(randr_state_t *state, int screen_num) +randr_init(randr_state_t *state, int screen_num, int crtc_num) { xcb_generic_error_t *error; @@ -108,6 +108,7 @@ randr_init(randr_state_t *state, int screen_num) return -1; } + state->crtc_num = crtc_num; state->crtc_count = res_reply->num_crtcs; state->crtcs = malloc(state->crtc_count * sizeof(randr_crtc_state_t)); if (state->crtcs == NULL) { @@ -248,45 +249,77 @@ randr_free(randr_state_t *state) xcb_disconnect(state->conn); } -int -randr_set_temperature(randr_state_t *state, int temp, float gamma[3]) +static int +randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, int temp, + float gamma[3]) { xcb_generic_error_t *error; + + if (crtc_num >= state->crtc_count || crtc_num < 0) { + 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")); + } - /* Set temperature on all CRTCs */ - for (int i = 0; i < state->crtc_count; i++) { - xcb_randr_crtc_t crtc = state->crtcs[i].crtc; - unsigned int ramp_size = state->crtcs[i].ramp_size; + return -1; + } - /* Create new gamma ramps */ - uint16_t *gamma_ramps = malloc(3*ramp_size*sizeof(uint16_t)); - if (gamma_ramps == NULL) { - perror("malloc"); - return -1; - } + xcb_randr_crtc_t crtc = state->crtcs[crtc_num].crtc; + unsigned int ramp_size = state->crtcs[crtc_num].ramp_size; - uint16_t *gamma_r = &gamma_ramps[0*ramp_size]; - uint16_t *gamma_g = &gamma_ramps[1*ramp_size]; - uint16_t *gamma_b = &gamma_ramps[2*ramp_size]; + /* Create new gamma ramps */ + uint16_t *gamma_ramps = malloc(3*ramp_size*sizeof(uint16_t)); + if (gamma_ramps == NULL) { + perror("malloc"); + return -1; + } - colorramp_fill(gamma_r, gamma_g, gamma_b, ramp_size, - temp, gamma); + uint16_t *gamma_r = &gamma_ramps[0*ramp_size]; + uint16_t *gamma_g = &gamma_ramps[1*ramp_size]; + uint16_t *gamma_b = &gamma_ramps[2*ramp_size]; - /* 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); - error = xcb_request_check(state->conn, gamma_set_cookie); + colorramp_fill(gamma_r, gamma_g, gamma_b, ramp_size, + temp, gamma); - if (error) { - fprintf(stderr, _("`%s' returned error %d\n"), - "RANDR Set CRTC Gamma", error->error_code); - free(gamma_ramps); - return -1; - } + /* 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); + 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); free(gamma_ramps); + return -1; + } + + free(gamma_ramps); + + return 0; +} + +int +randr_set_temperature(randr_state_t *state, int temp, float gamma[3]) +{ + 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++) { + 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); } return 0; |