sct

set color temperature
git clone anongit@rnpnr.xyz:sct.git
Log | Files | Refs | Feed | README | LICENSE

Commit: a00a2f8a6042365427048c4465e91ae08081ae72
Parent: 0dadad0055bb9753a1a93e13c9903b82c2cf0f41
Author: Fabian Foerg
Date:   Wed,  1 Jun 2022 08:02:28 -0400

Add CLI options for screen and CRTC selection (#28)

- Add options for screen and CRTC selection.
- Address https://github.com/faf0/sct/issues/25 .
Diffstat:
MCHANGELOG | 5++++-
MREADME.md | 11+++++++----
Mxsct.1 | 24+++++++++++-------------
Mxsct.c | 65+++++++++++++++++++++++++++++++++++++++++++++++------------------
4 files changed, 69 insertions(+), 36 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,6 +1,9 @@ PROJECT: https://github.com/faf0/sct -1.7: zikzik on May 30 2022 +1.8: faf0 on 01 Jun 2022 +* Options --screen and --crtc added to select a specific screen and CRTC to use + +1.7: zikzik on 30 May 2022 * Options to specify the screen index and CRTC index to change the color temperature of a specific screen and CTRC combination only diff --git a/README.md b/README.md @@ -33,15 +33,18 @@ Execute xsct using the following command: ./xsct 3700 ~~~ -The first parameter (`3700` above) denotes the color temperature. +The first parameter (`3700` above) represents the color temperature. If `xsct` is called with parameter 0, the color temperature is set to `6500`. If `xsct` is called without parameters, the current display temperature is estimated. -If `xsct` is called with a temperature parameter as well as a screen index -followed by a CRTC index, the color temperature of the specified screen and -CRTC combination is changed only. +The following options, which can be specified before the optional temperature parameter, are supported: +- `-h`, `--help`: display the help page +- `-v`, `--verbose`: display debugging information +- `-d <delta>`, `--delta <delta>`: shift temperature by the temperature value +- `-s <screen>`, `--screen <screen>` `N`: use the screen specified by given zero-based index +- `-c <crtc>`, `--crtc <crtc>` `N`: use the CRTC specified by given zero-based index Test xsct using the following command: ~~~sh diff --git a/xsct.1 b/xsct.1 @@ -1,12 +1,10 @@ -.TH xsct 1 "Aug 2020" "1.6" "User Manual" +.TH xsct 1 "Jun 2022" "1.8" "User Manual" .SH NAME xsct \- X11 set screen color temperature .SH SYNOPSIS .B xsct [options] .I [temperature] -.I [screen_index] -.I [crtc_index] .SH DESCRIPTION .B xsct @@ -14,30 +12,30 @@ sets the screen's color temperature. .SH OPTIONS .TP -.B -d, --delta -Shift temperature by given value -.TP .B -h, --help Display usage information and exit .TP .B -v, --verbose Display debugging information .TP +.B -d, --delta +Shift temperature by temperature value +.TP +.B -s, --screen N +Zero-based index of screen to use. +.TP +.B -c, --crtc N +Zero-based index of CRTC to use. +.TP .I [temperature] Black body temperature .br If the value is 0, xsct sets the color temperature to the default of 6500 .br If no arguments are passed, xsct estimates the current display temperature -.TP -.I [screen_index] -Screen to change temperature of. -.TP -.I [crtc_index] -CRTC (output) of specified screen to change temperature of. .SH AUTHOR -xsct was written by Ted Unangst <tedu@openbsd.org> +xsct is based on sct by Ted Unangst <tedu@openbsd.org> .SH SEE ALSO redshift(1), xtemp(1) diff --git a/xsct.c b/xsct.c @@ -16,14 +16,16 @@ static void usage(char * pname) { - printf("Xsct (1.6)\n" - "Usage: %s [options] [temperature] [screen_index] [crtc_index]\n" + printf("Xsct (1.8)\n" + "Usage: %s [options] [temperature]\n" "\tIf the argument is 0, xsct resets the display to the default temperature (6500K)\n" "\tIf no arguments are passed, xsct estimates the current display temperature\n" "Options:\n" + "\t-h, --help \t xsct will display this usage information\n" "\t-v, --verbose \t xsct will display debugging information\n" - "\t-d, --delta \t xsct will shift temperature by given value\n" - "\t-h, --help \t xsct will display this usage information\n", pname); + "\t-d, --delta\t xsct will shift temperature by the temperature value\n" + "\t-s, --screen N\t xsct will only select screen specified by given zero-based index\n" + "\t-c, --crtc N\t xsct will only select CRTC specified by given zero-based index\n", pname); } #define TEMPERATURE_NORM 6500 @@ -64,8 +66,8 @@ static int get_sct_for_screen(Display *dpy, int screen, int icrtc, int fdebug) double gammar = 0.0, gammag = 0.0, gammab = 0.0, gammam = 1.0, gammad = 0.0; n = res->ncrtc; - int icrtc_is_specified = icrtc >= 0 && icrtc < n; - for (c = icrtc_is_specified ? icrtc : 0; c < (icrtc_is_specified ? icrtc + 1 : n); c++) + int icrtc_specified = icrtc >= 0 && icrtc < n; + for (c = icrtc_specified ? icrtc : 0; c < (icrtc_specified ? icrtc + 1 : n); c++) { RRCrtc crtcxid; int size; @@ -143,8 +145,8 @@ static void sct_for_screen(Display *dpy, int screen, int icrtc, int temp, int fd } if (fdebug > 0) fprintf(stderr, "DEBUG: Gamma: %f, %f, %f\n", gammar, gammag, gammab); n = res->ncrtc; - int icrtc_is_specified = icrtc >= 0 && icrtc < n; - for (c = icrtc_is_specified ? icrtc : 0; c < (icrtc_is_specified ? icrtc + 1 : n); c++) + int icrtc_specified = icrtc >= 0 && icrtc < n; + for (c = icrtc_specified ? icrtc : 0; c < (icrtc_specified ? icrtc + 1 : n); c++) { int size, i; RRCrtc crtcxid; @@ -179,7 +181,7 @@ int main(int argc, char **argv) if (!dpy) { perror("XOpenDisplay(NULL) failed"); - fprintf(stderr, "Make sure DISPLAY is set correctly.\n"); + fprintf(stderr, "ERROR! Ensure DISPLAY is set correctly!\n"); return EXIT_FAILURE; } screens = XScreenCount(dpy); @@ -190,31 +192,58 @@ int main(int argc, char **argv) crtc_specified = -1; for (i = 1; i < argc; i++) { - if ((strcmp(argv[i],"-v") == 0) || (strcmp(argv[i],"--verbose") == 0)) fdebug = 1; + if ((strcmp(argv[i],"-h") == 0) || (strcmp(argv[i],"--help") == 0)) fhelp = 1; + else if ((strcmp(argv[i],"-v") == 0) || (strcmp(argv[i],"--verbose") == 0)) fdebug = 1; else if ((strcmp(argv[i],"-d") == 0) || (strcmp(argv[i],"--delta") == 0)) fdelta = 1; - else if ((strcmp(argv[i],"-h") == 0) || (strcmp(argv[i],"--help") == 0)) fhelp = 1; + else if ((strcmp(argv[i],"-s") == 0) || (strcmp(argv[i],"--screen") == 0)) + { + i++; + if (i < argc) + { + screen_specified = atoi(argv[i]); + } else { + fprintf(stderr, "ERROR! Required value for screen not specified!\n"); + fhelp = 1; + } + } + else if ((strcmp(argv[i],"-c") == 0) || (strcmp(argv[i],"--crtc") == 0)) + { + i++; + if (i < argc) + { + crtc_specified = atoi(argv[i]); + } else { + fprintf(stderr, "ERROR! Required value for crtc not specified!\n"); + fhelp = 1; + } + } else if (temp == -1) temp = atoi(argv[i]); - else if (screen_specified == -1) screen_specified = atoi(argv[i]); - else crtc_specified = atoi(argv[i]); + else + { + fprintf(stderr, "ERROR! Unknown parameter: %s\n!", argv[i]); + fhelp = 1; + } } - if (fhelp > 0) + if (fhelp > 0) { usage(argv[0]); } - else if (screen_specified >= screens) { - fprintf(stderr, "ERROR! Invalid screen index: %d\n", screen_specified); + else if (screen_specified >= screens) + { + fprintf(stderr, "ERROR! Invalid screen index: %d!\n", screen_specified); } else { - if (screen_specified >= 0) { + if (screen_specified >= 0) + { screen_first = screen_specified; screen_last = screen_specified; } if ((temp < 0) && (fdelta == 0)) { // No arguments, so print estimated temperature for each screen - for (screen = 0; screen < screens; screen++) + for (screen = screen_first; screen <= screen_last; screen++) { temp = get_sct_for_screen(dpy, screen, crtc_specified, fdebug); printf("Screen %d: temperature ~ %d\n", screen, temp);