Last active
August 29, 2015 14:04
-
-
Save thenewvu/5018291e1bbee3600988 to your computer and use it in GitHub Desktop.
Set display gamma value on Linux using Xlib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <X11/Xlib.h> | |
#include <X11/extensions/xf86vmode.h> | |
/* How to compile: | |
g++ -o set_gamma_linux.o -c set_gamma_linux.cpp | |
g++ -o set_gamma_linux set_gamma_linux.o -L/usr/lib -L/usr/local/lib -lX11 -lXxf86vm | |
*/ | |
void log(const char* message); | |
int main(int argc, char **argv) | |
{ | |
// open default display | |
Display* display = XOpenDisplay(NULL); | |
if(!display) | |
{ | |
log("XOpenDisplay(NULL) failed."); | |
return -1; | |
} | |
log("XOpenDisplay(NULL) ok."); | |
// get default screen | |
int screen = DefaultScreen(display); | |
// init gamma value | |
XF86VidModeGamma gamma; | |
gamma.red = 0.5; | |
gamma.green = 0.5; | |
gamma.blue = 0.5; | |
// set gamma | |
if(!XF86VidModeSetGamma(display, screen, &gamma)) | |
{ | |
log("XF86VidModeSetGamma failed."); | |
return -1; | |
} | |
log("XF86VidModeSetGamma ok."); | |
XCloseDisplay(display); | |
return 0; | |
} | |
void log(const char* message) | |
{ | |
std::cout << message << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment