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
Using for Loop to Move Files from Subdirectories to Parent Directories
Awk Command to Create Sha2 of Individual Column and Paste into New File
Whats The Easiest Way to Send Messages to My Linux Daemon App
What's The Meaning of This Sed Command? Sed 's%^.*/%%'
Specially Debugging Line by Line
How to Configure Multiple Ssh Access to an Ec2 Instance
A Mess with Different Perl Installs
Curl Error "No Alternative Certificate.."
How to Solve Libusb_Error_Busy on Raspberry Pi (Debian) Running Node.Js
Inserting Uris into Gtk.Clipboard with Vala
How to Find The Byte Position of Specific Line in a File
How to Get Window Id for Xdotool Automatically
Iptables Remove Specific Rules by Comment
Linux: Triggering Shell Command on File Save
Is There Any Reference Implementation of Linux File System Filter Driver
Linux to Define Custom Shell Command
Where in The Linux Source Does Recognition of Specific Usb Devices Happen