在 Linux/Xorg 上设置颜色亮度

发布于 2024-08-16 06:25:52 字数 203 浏览 12 评论 0原文

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

换句话说,我需要像 xgamma 命令一样方便的命令,但用于更改 RGB 亮度实时

这可能吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

允世 2024-08-23 06:25:52

使用 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;
}

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

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

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.

靖瑶 2024-08-23 06:25:52
xbacklight -set 80

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

xbacklight -set 80

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

倥絔 2024-08-23 06:25:52

控制 LCD 亮度:

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

范围为 1 至 8。

To control LCD brightness:

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

The range is 1 to 8.

吾性傲以野 2024-08-23 06:25:52

也许您需要 XRandr?

May Be You need XRandr?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文