Merge lp:~afrantzis/redshift/specific-crtc-temperature into lp:~jonls/redshift/trunk

Proposed by Alexandros Frantzis
Status: Merged
Merged at revision: 71
Proposed branch: lp:~afrantzis/redshift/specific-crtc-temperature
Merge into: lp:~jonls/redshift/trunk
Diff against target: 192 lines (+69/-41)
3 files modified
src/randr.c (+60/-38)
src/randr.h (+2/-1)
src/redshift.c (+7/-2)
To merge this branch: bzr merge lp:~afrantzis/redshift/specific-crtc-temperature
Reviewer Review Type Date Requested Status
Jon Lund Steffensen Pending
Review via email: mp+24058@code.launchpad.net

Description of the change

Add support for changing the temperature of a specific CRTC (randr only).

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/randr.c'
2--- src/randr.c 2010-02-01 23:51:50 +0000
3+++ src/randr.c 2010-04-24 08:54:18 +0000
4@@ -36,7 +36,7 @@
5
6
7 int
8-randr_init(randr_state_t *state, int screen_num)
9+randr_init(randr_state_t *state, int screen_num, int crtc_num)
10 {
11 xcb_generic_error_t *error;
12
13@@ -108,6 +108,7 @@
14 return -1;
15 }
16
17+ state->crtc_num = crtc_num;
18 state->crtc_count = res_reply->num_crtcs;
19 state->crtcs = malloc(state->crtc_count * sizeof(randr_crtc_state_t));
20 if (state->crtcs == NULL) {
21@@ -248,46 +249,67 @@
22 xcb_disconnect(state->conn);
23 }
24
25+static int
26+randr_set_temperature_for_crtc(randr_state_t *state, int crtc_num, int temp,
27+ float gamma[3])
28+{
29+ xcb_generic_error_t *error;
30+
31+ if (crtc_num >= state->crtc_count || crtc_num < 0) {
32+ fprintf(stderr, _("CRTC %d does not exist (Valid CRTCs are [0-%d])\n"),
33+ state->crtc_num, state->crtc_count - 1);
34+ return -1;
35+ }
36+
37+ xcb_randr_crtc_t crtc = state->crtcs[crtc_num].crtc;
38+ unsigned int ramp_size = state->crtcs[crtc_num].ramp_size;
39+
40+ /* Create new gamma ramps */
41+ uint16_t *gamma_ramps = malloc(3*ramp_size*sizeof(uint16_t));
42+ if (gamma_ramps == NULL) {
43+ perror("malloc");
44+ return -1;
45+ }
46+
47+ uint16_t *gamma_r = &gamma_ramps[0*ramp_size];
48+ uint16_t *gamma_g = &gamma_ramps[1*ramp_size];
49+ uint16_t *gamma_b = &gamma_ramps[2*ramp_size];
50+
51+ colorramp_fill(gamma_r, gamma_g, gamma_b, ramp_size,
52+ temp, gamma);
53+
54+ /* Set new gamma ramps */
55+ xcb_void_cookie_t gamma_set_cookie =
56+ xcb_randr_set_crtc_gamma_checked(state->conn, crtc,
57+ ramp_size, gamma_r,
58+ gamma_g, gamma_b);
59+ error = xcb_request_check(state->conn, gamma_set_cookie);
60+
61+ if (error) {
62+ fprintf(stderr, _("`%s' returned error %d\n"),
63+ "RANDR Set CRTC Gamma", error->error_code);
64+ free(gamma_ramps);
65+ return -1;
66+ }
67+
68+ free(gamma_ramps);
69+
70+ return 0;
71+}
72+
73 int
74 randr_set_temperature(randr_state_t *state, int temp, float gamma[3])
75 {
76- xcb_generic_error_t *error;
77-
78- /* Set temperature on all CRTCs */
79- for (int i = 0; i < state->crtc_count; i++) {
80- xcb_randr_crtc_t crtc = state->crtcs[i].crtc;
81- unsigned int ramp_size = state->crtcs[i].ramp_size;
82-
83- /* Create new gamma ramps */
84- uint16_t *gamma_ramps = malloc(3*ramp_size*sizeof(uint16_t));
85- if (gamma_ramps == NULL) {
86- perror("malloc");
87- return -1;
88- }
89-
90- uint16_t *gamma_r = &gamma_ramps[0*ramp_size];
91- uint16_t *gamma_g = &gamma_ramps[1*ramp_size];
92- uint16_t *gamma_b = &gamma_ramps[2*ramp_size];
93-
94- colorramp_fill(gamma_r, gamma_g, gamma_b, ramp_size,
95- temp, gamma);
96-
97- /* Set new gamma ramps */
98- xcb_void_cookie_t gamma_set_cookie =
99- xcb_randr_set_crtc_gamma_checked(state->conn, crtc,
100- ramp_size, gamma_r,
101- gamma_g, gamma_b);
102- error = xcb_request_check(state->conn, gamma_set_cookie);
103-
104- if (error) {
105- fprintf(stderr, _("`%s' returned error %d\n"),
106- "RANDR Set CRTC Gamma", error->error_code);
107- free(gamma_ramps);
108- return -1;
109- }
110-
111- free(gamma_ramps);
112+ /* If no CRTC number has been specified, set temperature on all CRTCs */
113+ if (state->crtc_num < 0) {
114+ for (int i = 0; i < state->crtc_count; i++) {
115+ if (randr_set_temperature_for_crtc(state, i, temp, gamma))
116+ return -1;
117+ }
118 }
119-
120+ else
121+ return randr_set_temperature_for_crtc(state, state->crtc_num, temp,
122+ gamma);
123+
124 return 0;
125 }
126
127=== modified file 'src/randr.h'
128--- src/randr.h 2010-02-01 23:51:50 +0000
129+++ src/randr.h 2010-04-24 08:54:18 +0000
130@@ -34,12 +34,13 @@
131 typedef struct {
132 xcb_connection_t *conn;
133 xcb_screen_t *screen;
134+ int crtc_num;
135 unsigned int crtc_count;
136 randr_crtc_state_t *crtcs;
137 } randr_state_t;
138
139
140-int randr_init(randr_state_t *state, int screen_num);
141+int randr_init(randr_state_t *state, int screen_num, int crtc_num);
142 void randr_free(randr_state_t *state);
143 void randr_restore(randr_state_t *state);
144 int randr_set_temperature(randr_state_t *state, int temp, float gamma[3]);
145
146=== modified file 'src/redshift.c'
147--- src/redshift.c 2010-02-10 21:52:11 +0000
148+++ src/redshift.c 2010-04-24 08:54:18 +0000
149@@ -221,6 +221,7 @@
150 " color temperature)\n"
151 " -r\t\tDisable initial temperature transition\n"
152 " -s SCREEN\tX screen to apply adjustments to\n"
153+ " -c CRTC\tCRTC to apply adjustments to (randr only)\n"
154 " -t DAY:NIGHT\tColor temperature to set at daytime/night\n"),
155 stdout);
156 fputs("\n", stdout);
157@@ -253,6 +254,7 @@
158 float gamma[3] = { DEFAULT_GAMMA, DEFAULT_GAMMA, DEFAULT_GAMMA };
159 int use_randr = -1;
160 int screen_num = -1;
161+ int crtc_num = -1;
162 int transition = 1;
163 int one_shot = 0;
164 int verbose = 0;
165@@ -260,7 +262,7 @@
166
167 /* Parse arguments. */
168 int opt;
169- while ((opt = getopt(argc, argv, "g:hl:m:ors:t:v")) != -1) {
170+ while ((opt = getopt(argc, argv, "g:hl:m:ors:c:t:v")) != -1) {
171 switch (opt) {
172 case 'g':
173 s = strchr(optarg, ':');
174@@ -342,6 +344,9 @@
175 case 's':
176 screen_num = atoi(optarg);
177 break;
178+ case 'c':
179+ crtc_num = atoi(optarg);
180+ break;
181 case 't':
182 s = strchr(optarg, ':');
183 if (s == NULL) {
184@@ -432,7 +437,7 @@
185 #ifdef ENABLE_RANDR
186 if (use_randr < 0 || use_randr == 1) {
187 /* Initialize RANDR state */
188- r = randr_init(&state.randr, screen_num);
189+ r = randr_init(&state.randr, screen_num, crtc_num);
190 if (r < 0) {
191 fputs(_("Initialization of RANDR failed.\n"), stderr);
192 if (use_randr < 0) {

Subscribers

People subscribed via source and target branches