diff options
author | Jon Lund Steffensen <jonlst@gmail.com> | 2009-12-25 16:30:56 +0100 |
---|---|---|
committer | Jon Lund Steffensen <jonlst@gmail.com> | 2009-12-25 16:30:56 +0100 |
commit | f7548343c842ba1b825e1da07336f39781ce2bbe (patch) | |
tree | 9fccf22229bd255613943788bf8825ae8f63e631 /src | |
parent | RANDR: Adjust color temperature fro all CRTCs. (diff) | |
download | redshift-ng-f7548343c842ba1b825e1da07336f39781ce2bbe.tar.gz redshift-ng-f7548343c842ba1b825e1da07336f39781ce2bbe.tar.bz2 redshift-ng-f7548343c842ba1b825e1da07336f39781ce2bbe.tar.xz |
Allow selection of X screen to apply adjustments to.
Diffstat (limited to 'src')
-rw-r--r-- | src/randr.c | 26 | ||||
-rw-r--r-- | src/randr.h | 2 | ||||
-rw-r--r-- | src/redshift.c | 21 | ||||
-rw-r--r-- | src/vidmode.c | 11 | ||||
-rw-r--r-- | src/vidmode.h | 2 |
5 files changed, 45 insertions, 17 deletions
diff --git a/src/randr.c b/src/randr.c index 54f0fc1..99ac9ec 100644 --- a/src/randr.c +++ b/src/randr.c @@ -122,17 +122,35 @@ randr_crtc_set_temperature(xcb_connection_t *conn, xcb_randr_crtc_t crtc, } int -randr_set_temperature(int temp, float gamma[3]) +randr_set_temperature(int screen_num, int temp, float gamma[3]) { xcb_generic_error_t *error; /* Open X server connection */ - xcb_connection_t *conn = xcb_connect(NULL, NULL); + int preferred_screen; + xcb_connection_t *conn = xcb_connect(NULL, &preferred_screen); + + if (screen_num < 0) screen_num = preferred_screen; - /* Get first screen */ + /* Get 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; + xcb_screen_t *screen = NULL; + + for (int i = 0; iter.rem > 0; i++) { + if (i == screen_num) { + screen = iter.data; + break; + } + xcb_screen_next(&iter); + } + + if (screen == NULL) { + fprintf(stderr, "Screen %i could not be found.\n", + screen_num); + xcb_disconnect(conn); + return -1; + } /* Get list of CRTCs for the screen */ xcb_randr_get_screen_resources_current_cookie_t res_cookie = diff --git a/src/randr.h b/src/randr.h index 7efa94c..d03f766 100644 --- a/src/randr.h +++ b/src/randr.h @@ -21,6 +21,6 @@ #define _REDSHIFT_RANDR_H int randr_check_extension(); -int randr_set_temperature(int temp, float gamma[3]); +int randr_set_temperature(int screen_num, int temp, float gamma[3]); #endif /* ! _REDSHIFT_RANDR_H */ diff --git a/src/redshift.c b/src/redshift.c index 653df5a..6ac815d 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -62,6 +62,7 @@ " -h\t\tDisplay this help message\n" \ " -l LAT:LON\tYour current location\n" \ " -m METHOD\tMethod to use to set color temperature (randr or vidmode)\n" \ + " -s SCREEN\tX screen to apply adjustments to\n" \ " -t DAY:NIGHT\tColor temperature to set at daytime/night\n" \ " -v\t\tVerbose output\n" @@ -88,11 +89,12 @@ main(int argc, char *argv[]) int temp_night = DEFAULT_NIGHT_TEMP; float gamma[3] = { DEFAULT_GAMMA, DEFAULT_GAMMA, DEFAULT_GAMMA }; int use_randr = 1; + int screen_num = -1; int verbose = 0; char *s; int opt; - while ((opt = getopt(argc, argv, "g:hl:m:t:v")) != -1) { + while ((opt = getopt(argc, argv, "g:hl:m:s:t:v")) != -1) { switch (opt) { case 'g': s = strchr(optarg, ':'); @@ -140,6 +142,9 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } break; + case 's': + screen_num = atoi(optarg); + break; case 't': s = strchr(optarg, ':'); if (s == NULL) { @@ -249,9 +254,10 @@ main(int argc, char *argv[]) if (r < 0) { use_randr = 0; } else { - r = randr_set_temperature(temp, gamma); + r = randr_set_temperature(screen_num, temp, gamma); if (r < 0) { - fprintf(stderr, "Unable to set color temperature with RANDR," + fprintf(stderr, "Unable to set color" + " temperature with RANDR," " trying VidMode...\n"); use_randr = 0; } @@ -262,14 +268,15 @@ main(int argc, char *argv[]) /* Check VidMode extension */ r = vidmode_check_extension(); if (r < 0) { - fprintf(stderr, "Missing needed extension to set gamma ramp" - "(RANDR or VidMode).\n"); + fprintf(stderr, "Missing needed extension" + " to set gamma ramp (RANDR or VidMode).\n"); exit(EXIT_FAILURE); } - r = vidmode_set_temperature(temp, gamma); + r = vidmode_set_temperature(screen_num, temp, gamma); if (r < 0) { - fprintf(stderr, "Unable to set color temperature with VidMode.\n"); + fprintf(stderr, "Unable to set color temperature" + " with VidMode.\n"); exit(EXIT_FAILURE); } } diff --git a/src/vidmode.c b/src/vidmode.c index 7cc0d02..5c2a8c1 100644 --- a/src/vidmode.c +++ b/src/vidmode.c @@ -56,7 +56,7 @@ vidmode_check_extension() } int -vidmode_set_temperature(int temp, float gamma[3]) +vidmode_set_temperature(int screen_num, int temp, float gamma[3]) { int r; @@ -67,9 +67,11 @@ vidmode_set_temperature(int temp, float gamma[3]) return -1; } - /* Request size of gamma ramps for screen 0 */ + if (screen_num < 0) screen_num = DefaultScreen(dpy); + + /* Request size of gamma ramps */ int gamma_ramp_size; - r = XF86VidModeGetGammaRampSize(dpy, 0, &gamma_ramp_size); + r = XF86VidModeGetGammaRampSize(dpy, screen_num, &gamma_ramp_size); if (!r) { fprintf(stderr, "XF86VidModeGetGammaRampSize failed.\n"); XCloseDisplay(dpy); @@ -95,7 +97,8 @@ vidmode_set_temperature(int temp, float gamma[3]) temp, gamma); /* Set new gamma ramps */ - r = XF86VidModeSetGammaRamp(dpy, 0, gamma_ramp_size, gamma_r, gamma_g, gamma_b); + r = XF86VidModeSetGammaRamp(dpy, screen_num, gamma_ramp_size, + gamma_r, gamma_g, gamma_b); if (!r) { fprintf(stderr, "XF86VidModeSetGammaRamp failed.\n"); XCloseDisplay(dpy); diff --git a/src/vidmode.h b/src/vidmode.h index 893fcc8..cf5516c 100644 --- a/src/vidmode.h +++ b/src/vidmode.h @@ -21,6 +21,6 @@ #define _REDSHIFT_VIDMODE_H int vidmode_check_extension(); -int vidmode_set_temperature(int temp, float gamma[3]); +int vidmode_set_temperature(int screen_num, int temp, float gamma[3]); #endif /* ! _REDSHIFT_VIDMODE_H */ |