Im personally using Vaio VPCCW21FX (Nvidia Graphic) and Ubuntu Studio 11.10 ..
I tried many solutions and nothing could resolve my problem with LCD brightness!
Finally wrote these two perl files to manually set brightness/Contrast and Gamma functions inside Nvidia driver config file.
This will be helpfull only if you are able to change brightness within Nvidia X Server Settings
Step 1: create this file and name it "Brightness-Up.pl"
(you can use any text editing tool like : gedit,nano,vi,etc.. copy & paste)
### Code by forgottenrip@yahoo.com ###
my $find1 = "0/RedBrightness=";my $find2 = "0/RedGamma=";
open FILE, "<Nvidia-Settings.cfg";
my @lines = <FILE>;
for (@lines) {
if ($_ =~ /$find1/) { chomp $_;$value= substr($_,16,5); }
if ($_ =~ /$find2/) { chomp $_;$value2= substr($_,11,5);}
}
my @Lines;
if ( $value > 0.0) { $value = $value - 0.30 };
if ( $value2 > 1.1) { $value2 = $value2 - 0.08 };
$last_value = $value + 0.30;
$Lines[0] ="0/RedBrightness=".$last_value;
$Lines[1] ="0/GreenBrightness=".$last_value;;
$Lines[2] ="0/BlueBrightness=".$last_value;;
$last_value = $value + 0.30;
$Lines[3] ="0/RedContrast=".$last_value;;
$Lines[4] ="0/GreenContrast=".$last_value;;
$Lines[5] ="0/BlueContrast=".$last_value;;
$last_value = $value2 + 0.08;
$Lines[6] ="0/RedGamma=".$last_value;;
$Lines[7] ="0/GreenGamma=".$last_value;;
$Lines[8] ="0/BlueGamma=".$last_value;;
$filename = "Nvidia-Settings.cfg";
open fh2,'>',$filename or die ("can't open '$filename': $! \n");
foreach ( @Lines )
{ chomp;print "$_\n";print fh2 "$_\n"; };
close fh2;
`nvidia-settings -l --config=Nvidia-Settings.cfg`;
Step 2: then make another file, name it "Brightness-Down.pl" and fill with this code:
### Code by forgottenrip@yahoo.com ###
my $find1 = "0/RedBrightness=";my $find2 = "0/RedGamma=";
open FILE, "<Nvidia-Settings.cfg";
my @lines = <FILE>;
for (@lines) {
if ($_ =~ /$find1/) {chomp $_;$value= substr($_,16,5);}
if ($_ =~ /$find2/) {chomp $_;$value2= substr($_,11,5);}
}
my @Lines;
if ( $value < -0.80) { $value = $value + 0.30 };
if ( $value2 < 0.8) { $value2 = $value2 + 0.08 };
$last_value = $value - 0.30;
$Lines[0] ="0/RedBrightness=".$last_value;
$Lines[1] ="0/GreenBrightness=".$last_value;;
$Lines[2] ="0/BlueBrightness=".$last_value;;
$last_value = $value - 0.30;
$Lines[3] ="0/RedContrast=".$last_value;;
$Lines[4] ="0/GreenContrast=".$last_value;;
$Lines[5] ="0/BlueContrast=".$last_value;;
$last_value = $value2 - 0.08;
$Lines[6] ="0/RedGamma=".$last_value;;
$Lines[7] ="0/GreenGamma=".$last_value;;
$Lines[8] ="0/BlueGamma=".$last_value;;
$filename = "Nvidia-Settings.cfg";
open fh2,'>',$filename or die ("can't open '$filename': $! \n");
foreach ( @Lines )
{ chomp;print "$_\n";print fh2 "$_\n"; };
close fh2;
`nvidia-settings -l --config=Nvidia-Settings.cfg`;
Step 3: You need to create another file which contains Nvidia Settings..
name it "Nvidia-Settings.cfg" its important that you write name exactly same.
fill with:
0/RedBrightness=0.1
0/GreenBrightness=0.1
0/BlueBrightness=0.1
0/RedContrast=0.1
0/GreenContrast=0.1
0/BlueContrast=0.1
0/RedGamma=1.14
0/GreenGamma=1.14
0/BlueGamma=1.14
Thats it! now place these files in unique folder.. you have to bind your Function Keys to these two perl file.you can use Compiz>commands to do that.
Run below command to install the compizconfig-settings-manager
sudo apt-get install compizconfig-settings-manager
or even you can run seperately with these two commands in shell (terminal):
user$ perl Brightness/Brightness-Up.pl
user$ perl Brightness/Brightness-Down.pl
where Brightness is folder I put those files in it.
To get working brightness key. try following
execute sudo gedit /etc/default/grub
Change this line
GRUB_CMLINE_LINUX_DEFAULT="quiet splash"
to something like below
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_osi=Linux acpi_backlight=vendor"
Execute sudo update-grub
and reboot . See if brightness keys are working.
It is still possible ubuntu won't remember your brightness settings. So you have to change brightness each time.
Please let us know the result as many sony users are facing this problem.
Update: This is for setting brightness manually.
Try following for both path shown by ls /sys/class/backlight/*/brightness
and replace accordingly. Most probably the intel one should work.
Get the maximum brightness:
cat /sys/class/backlight/intel_backlight/max_brightness
Try a lower value to set the brightness, say output is 2048 so I will try with half of it
echo 1024| sudo tee /sys/class/backlight/intel_backlight/brightness
If this works, make this happen in each login automatically by doing the following
sudo gedit /etc/rc.local
Enter this line just before exit 0
. It should look like
echo YOUR_VALUE_HERE > /sys/class/backlight/intel_backlight/brightness
exit 0
I have another question. Does your system has hybrid graphics card? whats the output of lspci | grep vga
?
Also you can try with xdotool
Best Answer
Ok, I got to a different solution that should work for other laptops too, not only for VAIOs.
Make sure that xbacklight and inotify-tools are installed, I just ran
sudo apt-get install xbacklight inotify-tools
.Configure the following script and save it as a bash script (for example, save it as backlight_control.sh), and give it executable permissions with
chmod +x backlight_control.sh
.Then add it to your startup applications (can be done in 12.04 by clicking on the menu item on the top-right corner of the screen). The backlight level should be restored to its previous setting, and the controls should start working, after you log into your session. The brightness meter displays the correct value too.
I hope this helps in case someone else is having the same issue. Any comments on its performance or anything else are welcome.