简体   繁体   English

如何使用XF86VidModeSetGamma()更改第二台显示器的gamma?

[英]How do I change gamma of my second monitor with XF86VidModeSetGamma()?

I've written a small function to change the gamma value of my monitor, but unfortunately it changes the gamma exactly of the wrong monitor, where I don't need it. 我写了一个小函数来改变我的显示器的伽玛值,但不幸的是它改变了错误显示器的伽玛,我不需要它。

I've tried nearly everything, but I can't find any working solution - it's always the wrong monitor. 我几乎尝试了所有东西,但我找不到任何有效的解决方案 - 它始终是错误的监视器。

How do I tell it correctly of which monitor it should change the gamma? 如何正确地告诉它应该更改伽玛的哪个显示器?

Another strange thing is, ScreenCount() always returns 1. 另一个奇怪的事情是,ScreenCount()总是返回1。

This function should be a workaround for the broken SDL_SetGamma(), which doesn't work on Linux, or at least not with ATi cards. 此函数应该是已损坏的SDL_SetGamma()的变通方法,它在Linux上不起作用,或者至少不在ATi卡上。 I am loading libXxf86vm.so at runtime, so it's an optional feature and doesn't need to be linked into the app. 我在运行时加载libXxf86vm.so ,因此它是一个可选功能,不需要链接到应用程序。

It would be also great if someone could explain me, how I can change the gamma of my second monitor with the xgamma command, because exactly the same is happening with that command. 如果有人能解释我,我怎么能用xgamma命令改变我的第二台监视器的伽玛值,这也xgamma ,因为该命令完全相同。

#include <X11/Xlib.h>

typedef struct {
    float red;          /* Red Gamma value */
    float green;        /* Green Gamma value */
    float blue;         /* Blue Gamma value */
} XF86VidModeGamma;

typedef Bool (*XF86VidModeSetGamma)(Display*, int, XF86VidModeGamma*);

int changegamma(float red, float green, float blue)
{
    void *lib;
    XF86VidModeSetGamma f;
    int screen;
    Display *display;
    XF86VidModeGamma gamma;

    lib = dlopen("libXxf86vm.so", RTLD_LAZY);
    if(!lib) goto error;

    f = (XF86VidModeSetGamma)dlsym(lib, "XF86VidModeSetGamma");
    if(!lib) goto error; 

    gamma.red = red;
    gamma.green = green;
    gamma.blue = blue;

    display = XOpenDisplay(NULL);

    if(!display) goto error; 
    screen = DefaultScreen(display);

    if(!f(display, screen, &gamma)) goto error; 
    XCloseDisplay(display);
    dlclose(lib);

    return 0;
error:;
    if(lib) dlclose(lib);
    return SDL_SetGamma(red, green, blue);
}

the XF86-interface to screens is really quite old and doesn't reflect modern multi-screen setups (using xinerama,...). 屏幕的XF86界面非常古老,并不能反映现代多屏幕设置(使用xinerama,......)。

in any case you should use xrandr to set per-display settings these days. 在任何情况下,你应该使用xrandr来设置这些天的每个显示设置。 the easiest way is probably to just check the source-code of the xrandr utility itself, which can be used to set per-screen gamma from the cmdline. 最简单的方法可能只是检查xrandr实用程序本身的源代码,它可用于设置cmdline中的每屏幕伽玛。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM