Setting Color Brightness on Linux/Xorg

Setting color brightness on Linux/Xorg

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.

Possible to change screen brightness with C?

I'd start with selecting from the following list of ubuntu pacakges, the tool that allows you to manage your screen's brightness (hint: it depends on the brand)

nvidia-settings - Tool of configuring the NVIDIA graphics driver
smartdimmer - Change LCD brightness on Geforce cards
armada-backlight - adjust backlight of Compaq Armada laptops (E300, M500, M700)
ddccontrol - a program to control monitor parameters
eeepc-acpi-scripts - Scripts to support suspend and hotkeys on the Asus Eee PC laptop
fnfxd - ACPI and hotkey daemon for Toshiba laptops
gddccontrol - a program to control monitor parameters
spicctrl - Sony Vaio controller program to set LCD backlight brightness
tpb - program to use the IBM ThinkPad(tm) special keys
xfce4-power-manager - power manager for Xfce desktop
xfce4-power-manager-plugins - power manager plugins for Xfce panel
xvattr - Utility to change Xv attributes

Once you have selected it,

sudo apt-get build-dep <pkgname>
apt-get source --compile <pkgname>

should get you on the right track



Related Topics



Leave a reply



Submit