aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJon Lund Steffensen <jonlst@gmail.com>2009-12-25 13:22:08 +0100
committerJon Lund Steffensen <jonlst@gmail.com>2009-12-25 13:22:08 +0100
commit03b5c7f88b3bf6ae7147ac3c5b14a6293b7b0987 (patch)
treea317a884fba6395209f31a80cde5dd8bad8ab06f /src
parentIncrement version to 0.2 (diff)
downloadredshift-ng-03b5c7f88b3bf6ae7147ac3c5b14a6293b7b0987.tar.gz
redshift-ng-03b5c7f88b3bf6ae7147ac3c5b14a6293b7b0987.tar.bz2
redshift-ng-03b5c7f88b3bf6ae7147ac3c5b14a6293b7b0987.tar.xz
RANDR: Adjust color temperature fro all CRTCs.
Diffstat (limited to 'src')
-rw-r--r--src/randr.c82
1 files changed, 48 insertions, 34 deletions
diff --git a/src/randr.c b/src/randr.c
index a209bc8..54f0fc1 100644
--- a/src/randr.c
+++ b/src/randr.c
@@ -63,39 +63,12 @@ randr_check_extension()
return 0;
}
-int
-randr_set_temperature(int temp, float gamma[3])
+static int
+randr_crtc_set_temperature(xcb_connection_t *conn, xcb_randr_crtc_t crtc,
+ int temp, float gamma[3])
{
xcb_generic_error_t *error;
- /* Open X server connection */
- xcb_connection_t *conn = xcb_connect(NULL, NULL);
-
- /* Get first screen */
- const xcb_setup_t *setup = xcb_get_setup(conn);
- xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup);
- xcb_screen_t *screen = iter.data;
-
- /* Get list of CRTCs for the screen */
- xcb_randr_get_screen_resources_current_cookie_t res_cookie =
- xcb_randr_get_screen_resources_current(conn, screen->root);
- xcb_randr_get_screen_resources_current_reply_t *res_reply =
- xcb_randr_get_screen_resources_current_reply(conn, res_cookie,
- &error);
-
- if (error) {
- fprintf(stderr, "RANDR Get Screen Resources Current,"
- " error: %d\n", error->error_code);
- xcb_disconnect(conn);
- return -1;
- }
-
- xcb_randr_crtc_t *crtcs =
- xcb_randr_get_screen_resources_current_crtcs(res_reply);
- xcb_randr_crtc_t crtc = crtcs[0];
-
- free(res_reply);
-
/* Request size of gamma ramps */
xcb_randr_get_crtc_gamma_size_cookie_t gamma_size_cookie =
xcb_randr_get_crtc_gamma_size(conn, crtc);
@@ -106,7 +79,6 @@ randr_set_temperature(int temp, float gamma[3])
if (error) {
fprintf(stderr, "RANDR Get CRTC Gamma Size, error: %d\n",
error->error_code);
- xcb_disconnect(conn);
return -1;
}
@@ -115,9 +87,8 @@ randr_set_temperature(int temp, float gamma[3])
free(gamma_size_reply);
if (gamma_ramp_size == 0) {
- fprintf(stderr, "Error: Gamma ramp size too small: %i\n",
+ fprintf(stderr, "Gamma ramp size too small: %i\n",
gamma_ramp_size);
- xcb_disconnect(conn);
return -1;
}
@@ -142,12 +113,55 @@ randr_set_temperature(int temp, float gamma[3])
fprintf(stderr, "RANDR Set CRTC Gamma, error: %d\n",
error->error_code);
free(gamma_ramps);
- xcb_disconnect(conn);
return -1;
}
free(gamma_ramps);
+ return 0;
+}
+
+int
+randr_set_temperature(int temp, float gamma[3])
+{
+ xcb_generic_error_t *error;
+
+ /* Open X server connection */
+ xcb_connection_t *conn = xcb_connect(NULL, NULL);
+
+ /* Get first screen */
+ const xcb_setup_t *setup = xcb_get_setup(conn);
+ xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup);
+ xcb_screen_t *screen = iter.data;
+
+ /* Get list of CRTCs for the screen */
+ xcb_randr_get_screen_resources_current_cookie_t res_cookie =
+ xcb_randr_get_screen_resources_current(conn, screen->root);
+ xcb_randr_get_screen_resources_current_reply_t *res_reply =
+ xcb_randr_get_screen_resources_current_reply(conn, res_cookie,
+ &error);
+
+ if (error) {
+ fprintf(stderr, "RANDR Get Screen Resources Current,"
+ " error: %d\n", error->error_code);
+ xcb_disconnect(conn);
+ return -1;
+ }
+
+ xcb_randr_crtc_t *crtcs =
+ xcb_randr_get_screen_resources_current_crtcs(res_reply);
+
+ for (int i = 0; i < res_reply->num_crtcs; i++) {
+ int r = randr_crtc_set_temperature(conn, crtcs[i],
+ temp, gamma);
+ if (r < 0) {
+ fprintf(stderr, "WARNING: Unable to adjust"
+ " CRTC %i.\n", i);
+ }
+ }
+
+ free(res_reply);
+
/* Close connection */
xcb_disconnect(conn);