在Linux/Xorg上设置颜色亮度
-
21-09-2019 - |
题
解决方案
使用 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")
, ,结果几乎相同。
其他提示
控制LCD亮度:
echo 4 > /proc/acpi/video/GFX0/LCD/brightness
范围是1到8。
xbacklight -set 80
您必须从存储库中安装此软件。至少在ThinkPads上,在大多数笔记本电脑上都可以很好地工作:-)
可能您需要Xrandr吗?
不隶属于 StackOverflow