Allow selection of X screen to apply adjustments to.
This commit is contained in:
@@ -42,6 +42,7 @@ have reasonable defaults.
|
||||
vidmode). Default is randr. In some cases one of the
|
||||
methods will not work. In that case you may be able to
|
||||
use the other method.
|
||||
-s SCREEN X screen to apply adjustments to.
|
||||
-t DAY:NIGHT Color temperature to set at daytime/night.
|
||||
-v Verbose output.
|
||||
|
||||
|
||||
+22
-4
@@ -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);
|
||||
|
||||
/* Get first screen */
|
||||
if (screen_num < 0) screen_num = preferred_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 =
|
||||
|
||||
+1
-1
@@ -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 */
|
||||
|
||||
+14
-7
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -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);
|
||||
|
||||
+1
-1
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user