5

是否有任何命令(或 API)来设置 X.Org/Linux 颜色亮度?

换句话说,我需要像xgamma命令一样方便的东西,但可以实时更改 RGB 亮度。

这可能吗?

4

4 回答 4

7

使用XF86VidMode*系列函数。

#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;
}

这会将 gamma 从 0.25 带到 4.0 并返回,然后恢复原始 gamma。

或者你可以反复调用system("xgamma -gamma %f"),得到几乎相同的结果。

于 2009-12-26T17:55:56.963 回答
4
xbacklight -set 80

您必须从您的存储库安装此软件。在大多数笔记本电脑上运行良好,至少在 ThinkPad 上运行良好 :-)

于 2010-09-24T21:59:56.260 回答
3

控制 LCD 亮度:

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

范围是 1 到 8。

于 2009-12-26T14:23:39.823 回答
1

可能是您需要 XRandr 吗?

于 2009-12-26T15:24:42.277 回答