diff options
author | Jon Lund Steffensen <jonlst@gmail.com> | 2009-12-23 18:25:56 +0100 |
---|---|---|
committer | Jon Lund Steffensen <jonlst@gmail.com> | 2009-12-23 18:25:56 +0100 |
commit | cfeb79731abcc6e9a6cc0379473b86faebb6c88d (patch) | |
tree | 2082bdef3a1e9b5eece1ad6afdd82f581fa5d0b2 /src/redshift.c | |
parent | Move source and headers to src dir. (diff) | |
download | redshift-ng-cfeb79731abcc6e9a6cc0379473b86faebb6c88d.tar.gz redshift-ng-cfeb79731abcc6e9a6cc0379473b86faebb6c88d.tar.bz2 redshift-ng-cfeb79731abcc6e9a6cc0379473b86faebb6c88d.tar.xz |
Add setting gamma ramps with the VidMode extension.
Allow selection of gamma setting method with program parameter (-m).
Fallback to VidMode if RANDR doesn't work.
Diffstat (limited to 'src/redshift.c')
-rw-r--r-- | src/redshift.c | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/src/redshift.c b/src/redshift.c index 70bc4fa..653df5a 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -27,6 +27,7 @@ #include "solar.h" #include "randr.h" +#include "vidmode.h" /* Bounds for parameters. */ @@ -60,6 +61,7 @@ " -g R:G:B\tAdditional gamma correction to apply\n" \ " -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" \ " -t DAY:NIGHT\tColor temperature to set at daytime/night\n" \ " -v\t\tVerbose output\n" @@ -70,13 +72,7 @@ int main(int argc, char *argv[]) { - /* Check extensions needed for color temperature adjustment. */ - int r = randr_check_extension(); - if (r < 0) { - fprintf(stderr, "Unable to set color temperature:" - " Needed extension is missing.\n"); - exit(EXIT_FAILURE); - } + int r; /* Init locale for degree symbol. */ char *loc = setlocale(LC_CTYPE, ""); @@ -91,11 +87,12 @@ main(int argc, char *argv[]) int temp_day = DEFAULT_DAY_TEMP; int temp_night = DEFAULT_NIGHT_TEMP; float gamma[3] = { DEFAULT_GAMMA, DEFAULT_GAMMA, DEFAULT_GAMMA }; + int use_randr = 1; int verbose = 0; char *s; int opt; - while ((opt = getopt(argc, argv, "g:hl:t:v")) != -1) { + while ((opt = getopt(argc, argv, "g:hl:m:t:v")) != -1) { switch (opt) { case 'g': s = strchr(optarg, ':'); @@ -133,6 +130,16 @@ main(int argc, char *argv[]) lat = atof(optarg); lon = atof(s); break; + case 'm': + if (strcmp(optarg, "randr") == 0) { + use_randr = 1; + } else if (strcmp(optarg, "vidmode") == 0) { + use_randr = 0; + } else { + fprintf(stderr, "Unknown method `%s'.\n", optarg); + exit(EXIT_FAILURE); + } + break; case 't': s = strchr(optarg, ':'); if (s == NULL) { @@ -236,10 +243,35 @@ main(int argc, char *argv[]) } /* Set color temperature */ - r = randr_set_temperature(temp, gamma); - if (r < 0) { - fprintf(stderr, "Unable to set color temperature.\n"); - exit(EXIT_FAILURE); + if (use_randr) { + /* Check RANDR extension. */ + int r = randr_check_extension(); + if (r < 0) { + use_randr = 0; + } else { + r = randr_set_temperature(temp, gamma); + if (r < 0) { + fprintf(stderr, "Unable to set color temperature with RANDR," + " trying VidMode...\n"); + use_randr = 0; + } + } + } + + if (!use_randr) { + /* Check VidMode extension */ + r = vidmode_check_extension(); + if (r < 0) { + fprintf(stderr, "Missing needed extension to set gamma ramp" + "(RANDR or VidMode).\n"); + exit(EXIT_FAILURE); + } + + r = vidmode_set_temperature(temp, gamma); + if (r < 0) { + fprintf(stderr, "Unable to set color temperature with VidMode.\n"); + exit(EXIT_FAILURE); + } } return EXIT_SUCCESS; |