aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexandros Frantzis <alf82@freemail.gr>2010-04-24 11:48:46 +0300
committerAlexandros Frantzis <alf82@freemail.gr>2010-04-24 11:48:46 +0300
commit9f6901aed383a7babd369381ff1572d64db1f846 (patch)
tree79520ee0aabe218e7932c0d6fb05c8567d1f8326 /src
parentUpdate ChangeLog, NEWS and README for release. (diff)
downloadredshift-ng-9f6901aed383a7babd369381ff1572d64db1f846.tar.gz
redshift-ng-9f6901aed383a7babd369381ff1572d64db1f846.tar.bz2
redshift-ng-9f6901aed383a7babd369381ff1572d64db1f846.tar.xz
Add support for changing the temperature of a specific CRTC (randr only).
Diffstat (limited to 'src')
-rw-r--r--src/randr.c82
-rw-r--r--src/randr.h3
-rw-r--r--src/redshift.c9
3 files changed, 61 insertions, 33 deletions
diff --git a/src/randr.c b/src/randr.c
index 7c05b26..369ac34 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,46 +249,67 @@ 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 (Valid CRTCs are [0-%d])\n"),
+ state->crtc_num, state->crtc_count - 1);
+ return -1;
+ }
- /* 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;
+ xcb_randr_crtc_t crtc = state->crtcs[crtc_num].crtc;
+ unsigned int ramp_size = state->crtcs[crtc_num].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;
- }
+ /* Create new gamma ramps */
+ uint16_t *gamma_ramps = malloc(3*ramp_size*sizeof(uint16_t));
+ if (gamma_ramps == NULL) {
+ perror("malloc");
+ return -1;
+ }
- 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];
+ 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];
- colorramp_fill(gamma_r, gamma_g, gamma_b, ramp_size,
- temp, gamma);
+ colorramp_fill(gamma_r, gamma_g, gamma_b, ramp_size,
+ 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);
- error = xcb_request_check(state->conn, gamma_set_cookie);
+ /* 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"),
+ 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 -1;
}
+ free(gamma_ramps);
+
+ return 0;
+}
+
+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 */
+ 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;
+ }
+ }
+ else
+ return randr_set_temperature_for_crtc(state, state->crtc_num, temp,
+ gamma);
+
return 0;
}
diff --git a/src/randr.h b/src/randr.h
index 94d653f..6e11274 100644
--- a/src/randr.h
+++ b/src/randr.h
@@ -34,12 +34,13 @@ typedef struct {
typedef struct {
xcb_connection_t *conn;
xcb_screen_t *screen;
+ int crtc_num;
unsigned int crtc_count;
randr_crtc_state_t *crtcs;
} randr_state_t;
-int randr_init(randr_state_t *state, int screen_num);
+int randr_init(randr_state_t *state, int screen_num, int crtc_num);
void randr_free(randr_state_t *state);
void randr_restore(randr_state_t *state);
int randr_set_temperature(randr_state_t *state, int temp, float gamma[3]);
diff --git a/src/redshift.c b/src/redshift.c
index 9c3f404..c553abb 100644
--- a/src/redshift.c
+++ b/src/redshift.c
@@ -221,6 +221,7 @@ print_help(const char *program_name)
" 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"
" -t DAY:NIGHT\tColor temperature to set at daytime/night\n"),
stdout);
fputs("\n", stdout);
@@ -253,6 +254,7 @@ main(int argc, char *argv[])
float gamma[3] = { DEFAULT_GAMMA, DEFAULT_GAMMA, DEFAULT_GAMMA };
int use_randr = -1;
int screen_num = -1;
+ int crtc_num = -1;
int transition = 1;
int one_shot = 0;
int verbose = 0;
@@ -260,7 +262,7 @@ main(int argc, char *argv[])
/* Parse arguments. */
int opt;
- while ((opt = getopt(argc, argv, "g:hl:m:ors:t:v")) != -1) {
+ while ((opt = getopt(argc, argv, "g:hl:m:ors:c:t:v")) != -1) {
switch (opt) {
case 'g':
s = strchr(optarg, ':');
@@ -342,6 +344,9 @@ 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) {
@@ -432,7 +437,7 @@ main(int argc, char *argv[])
#ifdef ENABLE_RANDR
if (use_randr < 0 || use_randr == 1) {
/* Initialize RANDR state */
- r = randr_init(&state.randr, screen_num);
+ r = randr_init(&state.randr, screen_num, crtc_num);
if (r < 0) {
fputs(_("Initialization of RANDR failed.\n"), stderr);
if (use_randr < 0) {