Setting color brightness on Linux/Xorg
Asked Answered
H

4

5

Is there any command (or API) to set X.Org/Linux color brightness?

In other words, I need something as handy as the xgamma command but for changing RGB brightness real-time.

Is this possibile?

Hurlburt answered 26/12, 2009 at 14:14 Comment(0)
C
7

Use the XF86VidMode* family of functions.

#include <X11/Xlib.h>
#include <X11/extensions/xf86vmode.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main() {
    Display *display;
    int screen;
    int major, minor;
    int i;
    XF86VidModeGamma orig;

    display = XOpenDisplay(NULL);
    if (!display) return -1;
    screen = DefaultScreen(display);
    if (!XF86VidModeQueryVersion(display, &major, &minor)
            || major < 2 || major == 2 && minor < 0
            || !XF86VidModeGetGamma(display, screen, &orig)) {
        XCloseDisplay(display);
        return -1;
    }

    for (i = 0; i <= 32; i++) {
        XF86VidModeGamma gamma;
        gamma.red = exp2f(2 - fabs(i - 16) / 4);
        gamma.green = gamma.red;
        gamma.blue = gamma.red;
        if (!XF86VidModeSetGamma(display, screen, &gamma)) break;
        printf("gamma: %f %f %f", gamma.red, gamma.green, gamma.blue);
        if (!XF86VidModeGetGamma(display, screen, &gamma)) break;
        printf(" -> %f %f %f\n", gamma.red, gamma.green, gamma.blue);
        sleep(1);
    }
    XF86VidModeSetGamma(display, screen, &orig);
    XF86VidModeGetGamma(display, screen, &orig);

    XCloseDisplay(display);
    return 0;
}

This brings the gamma from 0.25 to 4.0 and back, and then restores the original gamma.

Or you could just repeatedly call system("xgamma -gamma %f"), with pretty much the same results.

Corbin answered 26/12, 2009 at 17:55 Comment(0)
O
4
xbacklight -set 80

You have to install this software from your repository. Works well on most laptops, at least on ThinkPads :-)

Outright answered 24/9, 2010 at 21:59 Comment(0)
B
3

To control LCD brightness:

echo 4 > /proc/acpi/video/GFX0/LCD/brightness

The range is 1 to 8.

Brainstorm answered 26/12, 2009 at 14:23 Comment(0)
L
1

May Be You need XRandr?

Limy answered 26/12, 2009 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.