diff --git a/backends/scg/scg.c b/backends/scg/scg.c index c74da7b..1b50f29 100644 --- a/backends/scg/scg.c +++ b/backends/scg/scg.c @@ -7,51 +7,51 @@ #include int main(int argc, char **argv) { - Display *dpy = XOpenDisplay(NULL); - - if(dpy == NULL) { - return 12; // exit code 12, if no display is found + Display *dpy = XOpenDisplay(NULL); + + if(dpy == NULL) { + return 12; // exit code 12, if no display is found + } + + int screen = DefaultScreen(dpy); + Window root = RootWindow(dpy, screen); + XRRScreenResources *res = XRRGetScreenResourcesCurrent(dpy, root); + + double gamma_r; + double gamma_g; + double gamma_b; + + /* parsing */ + if (argc == 4) { + gamma_r = atof(argv[1]); + gamma_g = atof(argv[2]); + gamma_b = atof(argv[3]); + }else { + return 1; + } + + int num_crtcs = res->ncrtc; + for (int c = 0; c < res->ncrtc; c++) { + int crtcxid = res->crtcs[c]; + + int size = XRRGetCrtcGammaSize(dpy, crtcxid); + XRRCrtcGamma *crtc_gamma = XRRAllocGamma(size); + + for (int i = 0; i < size; i++) { + double g = 65535.0 * i / size; + crtc_gamma->red[i] = g * gamma_r; + crtc_gamma->green[i] = g * gamma_g; + crtc_gamma->blue[i] = g * gamma_b; } + XRRSetCrtcGamma(dpy, crtcxid, crtc_gamma); + + XFree(crtc_gamma); + } + + XRRFreeScreenResources(res); + XCloseDisplay(dpy); - int screen = DefaultScreen(dpy); - Window root = RootWindow(dpy, screen); - - XRRScreenResources *res = XRRGetScreenResourcesCurrent(dpy, root); - - double gamma_r; - double gamma_g; - double gamma_b; - - /* parsing */ - if (argc == 4) { - gamma_r = atof(argv[1]); - gamma_g = atof(argv[2]); - gamma_b = atof(argv[3]); - }else { - return 1; - } - - int num_crtcs = res->ncrtc; - for (int c = 0; c < res->ncrtc; c++) { - int crtcxid = res->crtcs[c]; - - int size = XRRGetCrtcGammaSize(dpy, crtcxid); - - XRRCrtcGamma *crtc_gamma = XRRAllocGamma(size); - - for (int i = 0; i < size; i++) { - double g = 65535.0 * i / size; - crtc_gamma->red[i] = g * gamma_r; - crtc_gamma->green[i] = g * gamma_g; - crtc_gamma->blue[i] = g * gamma_b; - } - XRRSetCrtcGamma(dpy, crtcxid, crtc_gamma); - - XFree(crtc_gamma); - } - XRRFreeScreenResources(res); - XCloseDisplay(dpy); - return 0; + return 0; } /* diff --git a/blugon.1 b/blugon.1 index da5604c..fb3a3d3 100644 --- a/blugon.1 +++ b/blugon.1 @@ -42,7 +42,7 @@ You can copy the default 'gamma' configuration into your home directory: There are more templates for 'gamma' in "/usr/share/blugon/". Syntax in 'gamma' has to be in one of the following two forms: - $ [hour] [minute] [red] [green] [blue] + $ [hour] [minute] [red] [green] [blue] $ [hour] [minute] [temperature] [red], [green], [blue] between 0 and 1