sct

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

Commit: 6ee56eab6a783b69f82092e46163badaf1a61b78
Parent: d8bf308e6462d02b4ea24e359cf409bc422b8a19
Author: zvezdochiot
Date:   Thu,  8 Aug 2019 18:29:53 +0300

1.5: Option --verbose for debug

Diffstat:
MCHANGELOG | 3+++
Msct.c | 54++++++++++++++++++++++++++++++++----------------------
Mxsct.1 | 31++++++++++++++++---------------
3 files changed, 51 insertions(+), 37 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,5 +1,8 @@ PROJECT: https://github.com/faf0/sct +1.5: zvezdochiot on 08 Aug 2019 +* Option --verbose for debug + 1.5: zvezdochiot on 07 Aug 2019 * Approximation of the `redshift` table (no limits) diff --git a/sct.c b/sct.c @@ -31,13 +31,15 @@ #include <string.h> #include <math.h> -static void usage() +static void usage(char * pname) { - printf("Usage: xsct [temperature]\n" - "Temperatures must be in a range from 1000-10000\n" - "If the argument is 0, xsct resets the display to the default temperature (6500K)\n" - "If no arguments are passed, xsct estimates the current display temperature\n" - "If -h or --help is passed xsct will display this usage information\n"); + printf("Xsct (1.5)\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-v, --verbose \t xsct will display debug information\n" + "\t-h, --help \t xsct will display this usage information\n", pname); } #define TEMPERATURE_NORM 6500 @@ -58,7 +60,7 @@ static double DoubleTrim(double x, double a, double b) return buff[ (int)(x > a) + (int)(x > b) ]; } -static int get_sct_for_screen(Display *dpy, int screen) +static int get_sct_for_screen(Display *dpy, int screen, int fdebug) { Window root = RootWindow(dpy, screen); XRRScreenResources *res = XRRGetScreenResourcesCurrent(dpy, root); @@ -90,6 +92,7 @@ static int get_sct_for_screen(Display *dpy, int screen) gammar /= gammam; gammag /= gammam; gammab /= gammam; + if (fdebug > 0) fprintf(stderr, "DEBUG: Gamma: %f, %f, %f\n", gammar, gammag, gammab); gammad = gammab - gammar; if (gammad < 0.0) { @@ -126,7 +129,7 @@ static int get_sct_for_screen(Display *dpy, int screen) return temp; } -static void sct_for_screen(Display *dpy, int screen, int temp) +static void sct_for_screen(Display *dpy, int screen, int temp, int fdebug) { double t = 0.0, g = 0.0, gammar, gammag, gammab; int n, c; @@ -152,6 +155,7 @@ static void sct_for_screen(Display *dpy, int screen, int temp) gammag = DoubleTrim(GAMMA_K0GB + GAMMA_K1GB * g, 0.0, 1.0); gammab = 1.0; } + if (fdebug > 0) fprintf(stderr, "DEBUG: Gamma: %f, %f, %f\n", gammar, gammag, gammab); n = res->ncrtc; for (c = 0; c < n; c++) @@ -181,7 +185,8 @@ static void sct_for_screen(Display *dpy, int screen, int temp) int main(int argc, char **argv) { - int screen, screens, temp; + int i, screen, screens, temp; + int fdebug = 0, fhelp = 0; Display *dpy = XOpenDisplay(NULL); if (!dpy) { perror("XOpenDisplay(NULL) failed"); @@ -190,25 +195,30 @@ int main(int argc, char **argv) } screens = XScreenCount(dpy); - temp = TEMPERATURE_NORM; - if (argc > 1) + temp = -1; + for (i = 1; i < argc; i++) { - if (!strcmp(argv[1],"-h") || !strcmp(argv[1],"--help")) + if ((strcmp(argv[i],"-v") == 0) || (strcmp(argv[i],"--verbose") == 0)) fdebug = 1; + else if ((strcmp(argv[i],"-h") == 0) || (strcmp(argv[i],"--help") == 0)) fhelp = 1; + else temp = atoi(argv[i]); + } + if (fhelp > 0) + { + usage(argv[0]); + } else { + if (temp < 0) { - usage(); + for (screen = 0; screen < screens; screen++) + { + temp = get_sct_for_screen(dpy, screen, fdebug); + printf("Screen %d: temperature ~ %d\n", screen, temp); + } } else { - temp = atoi(argv[1]); - if (temp <= 0) + if (temp == 0) temp = TEMPERATURE_NORM; for (screen = 0; screen < screens; screen++) - sct_for_screen(dpy, screen, temp); - } - } else { - for (screen = 0; screen < screens; screen++) - { - temp = get_sct_for_screen(dpy, screen); - printf("Screen %d: temperature ~ %d\n", screen, temp); + sct_for_screen(dpy, screen, temp, fdebug); } } diff --git a/xsct.1 b/xsct.1 @@ -3,29 +3,30 @@ xsct \- X11 set screen color temperature .SH SYNOPSIS .B xsct -[temperature] - -or - -.B xsct -[-h || --help] - +[options] +.I [temperature] .SH DESCRIPTION .B xsct sets the screen's color temperature. .SH OPTIONS -.IP temperature -If passed a value in the correct range (see above) -.B xsct -will set the current screen temperature to this value -.IP 0 -If the value is 0, xsct sets the color temperature to the default of 6500 -.IP -h,--help +.TP +.B -h, --help Display usage information and exit -.IP none +.TP +.B -v, --verbose +Display debug information +.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 .SH AUTHOR xsct was written by Ted Unangst <tedu@openbsd.org> + +.SH SEE ALSO +redshift(1), xtemp(1)