// 2>/dev/null; cc -o xdark -Wall xdark.c -L/usr/X11R6/lib -lm -lX11 -lXxf86vm && exec ./xdark "$@"; exit // see also: nipl-tools/bin/xdark+ to keep terminal, desktop backgrounds black! #include #include #include #include #include #include /* xdark is like xgamma, it changes the brightness of your display in software. It can make it dark, invert the display colours, etc. apt-get install libxxf86vm-dev (or apt-get install xorg-dev) cc -o xdark -Wall xdark.c -lm -lX11 -lXxf86vm See also: xcalib Sam Watkins, 2008 */ #define gamma_ramp_max_size 4096 Display *display; int n_screens; int screen; int size; double from, to; unsigned short r[gamma_ramp_max_size]; unsigned short g[gamma_ramp_max_size]; unsigned short b[gamma_ramp_max_size]; void get_brightness(double *from, double *to) { XF86VidModeGetGammaRamp(display, screen, size, r, g, b); *from = floor(g[0] / 65535.0 * 100 + .5) / 100; *to = floor(g[size-1] / 65535.0 * 100 + .5) / 100; } void set_brightness(double from, double to) { int i; for(i=0; i3) || (!invert && argc == 2 && argv[1][0] == '-')) { fprintf(stderr, "usage: xdark [-i] [[from-brightness] to-brightness]\n"); fprintf(stderr, " without args, it reads the values\n"); fprintf(stderr, " brightness should be between 0.0 (dark) to 1.0 (bright)\n"); fprintf(stderr, " -i invert\n"); fprintf(stderr, "try:\n"); fprintf(stderr, " xdark 0.5\n"); fprintf(stderr, " xdark\n"); fprintf(stderr, " xdark 1 0\n"); fprintf(stderr, " xdark 0.5 0\n"); fprintf(stderr, " xdark 1\n"); exit(1); } if((display = XOpenDisplay(NULL)) == NULL) { fprintf(stderr, "failed: XOpenDisplay\n"); exit(1); } // screen = DefaultScreen(display); n_screens = ScreenCount(display); // fprintf(stderr, "screen count %d\n", n_screens); for(screen = 0; screen < n_screens; ++screen) { // fprintf(stderr, "screen number %d\n", screen); XF86VidModeGetGammaRampSize(display, screen, &size); if (size > gamma_ramp_max_size) { fprintf(stderr, "gamma ramp size is unexpectedly large: %d\n", size); exit(1); } if (invert) { double tmp; get_brightness(&from, &to); tmp = from; from = to; to = tmp; set_brightness(from, to); } else if (argc == 1) { get_brightness(&from, &to); printf("%0.02f %0.02f\n", from, to); } else { if (argc == 3) { from = atof(argv[1]); to = atof(argv[2]); } else { from = 0; to = atof(argv[1]); } if((from < 0) || (from > 1) || (to < 0) || (to > 1)) { fprintf(stderr, "brightness should be between 0.0 (dark) to 1.0 (bright)\n"); exit(1); } set_brightness(from, to); } } XCloseDisplay(display); exit(0); }