Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I recently installed Ubuntu 11.10 on my Mac Book Pro 7,1. I installed the NVIDIA driver (285). The brightness keys are working (F1 and F2) and I get the box showing the brightness but it does nothing. I can change the brightness in the NVIDIA X Server Settings application. How can I get the brightness working without uninstalling the driver? Thanks in advance.

share|improve this question
    
Same thing happened to me on a MacBook Pro 5,5. –  Cerin Mar 11 '12 at 18:20
add comment

6 Answers 6

I had a similar issue with my laptop, there is an option you need to add to your /etc/X11/xorg.conf

  1. sudo nano /etc/X11/xorg.conf
  2. Find the line Section "Device" and add the following

    Option "RegistryDwords" "EnableBrightnessControl=1"    
    
share|improve this answer
    
This fixed it for me. Thanks. –  Cerin Mar 11 '12 at 19:44
    
This also works with Ubuntu 12.04 –  shaneonabike Sep 25 '13 at 19:21
add comment

NVIDIA brightness bash script

The above perl script didnt work for me so I wrote my own script as a bash script (since I don't know perl). It got a bit long but it creates the settings file by itself and can be used with command line options to adjust brightness or gamma or both at the same time. I use it with the --brightness-up and --brightness-down switches for the brightness keys on my Keyboard. Easy to assign in XFCE4 and surely also in KDE / GNOME.

nvidia-brightness.sh:

#!/bin/sh

# Tested only with nvidia-settings-319.12 and nvidia-drivers-319.17 on Funtoo Linux running XFCE 4.10
#
# Requirements:
# - NVIDIA Drivers (e.g. nvidia-current in Ubuntu)
# - NVIDIA Settings (nvidia-settings in Ubuntu)
# - xrandr (used by default to determine the correct display name)
#
# This script can be used to change the brightness on systems with an NVIDIA graphics card
# that lack the support for changing the brightness (probably needing acpi backlight).
# It uses "nvidia-settings -a" to assign new gamma or brightness values to the display.
#
# "nvidia-brightness.sh" may be run from the command line or can be assigned to the brightness keys on your Keyboard
# e.g. in XFCE4.
#
# Type "nvidia-brightness.sh --help" for valid options.

usage ()
{
cat << ENDMSG
Usage: 
   nvidia-brightness.sh [ options ]
Options:
   [ -gu ] or [ --gamma-up ]         increase gamma by 0.1
   [ -gd ] or [ --gamma-down ]       decrease gamma by 0.1
   [ -bu ] or [ --brightness-up ]    increase brightness by 0.1
   [ -bd ] or [ --brightness-down ]  decrease brightness by 0.1
   [ -i ]  or [ --initialize ]       Must be run once to create the settings file
                                     (~/.nvidia-brightness.cfg).
                                     Brightness settings from ~/.nvidia-settings-rc
                                     will be used if file exists, otherwise 
                                     gamma will be set to 1.0 and brightness to 0.0
                                     (NVIDIA Standard).
   [ -l ]  or [ --load-config ]      Load current settings from ~/.nvidia-brightness.cfg
                                     (e.g. as X11 autostart script)

Examples:
   nvidia-brightness -gd       this will decrease gamma by 0.1
   nvidia-brightness -bu -gd   this will increase brightness by 0.1 and decrease gamma by 0.1
ENDMSG
}

case $1 in 
    -h|--help)
        usage
        exit 0
esac

if [ "$1" != "-i" -a "$1" != "--initialize" ]; then
    if [ ! -f ~/.nvidia-brightness.cfg ]; then 
        echo 'You must run this script with the --initialize option once to create the settings file.'
        echo 'Type "nvidia-brightness.sh --help" for more information.';
        exit 1
    fi
fi

#### INITIALIZE ####
initialize_cfg ()
{
CONNECTED="[`xrandr | grep " connected" | awk '{ print $1 }'`]"
#CONNECTED="`cat ~/.nvidia-settings-rc  | grep RedBrightness | grep -o "\[.*]"`"
#CONNECTED="[DVI-I-1]"
#CONNECTED="[dpy:2]"
#CONNECTED="0"

if [ -f ~/.nvidia-settings-rc ]; then 
    if [ "`grep RedGamma ~/.nvidia-settings-rc`" != "" ]; then
        if [ "`grep RedBrightness ~/.nvidia-settings-rc`" != "" ]; then
            GAMMA_TEMP=`grep RedGamma= ~/.nvidia-settings-rc | sed s/^.*=//`
            BRIGHTNESS_TEMP=`grep RedBrightness= ~/.nvidia-settings-rc | sed s/^.*=//`
            NVIDIA_SETTINGS_OK=1
        fi
    fi
fi


[ "$NVIDIA_SETTINGS_OK" != "1" ] && \
GAMMA_TEMP=1.000000 \
BRIGHTNESS_TEMP=0.000000

echo "\
CONNECTED_DISPLAY=$CONNECTED
GAMMA=$GAMMA_TEMP
BRIGHTNESS=$BRIGHTNESS_TEMP" > ~/.nvidia-brightness.cfg

source ~/.nvidia-brightness.cfg

GAMMACOMMA=`echo $GAMMA | sed s/"\."/"\,"/`
BRIGHTNESSCOMMA=`echo $BRIGHTNESS | sed s/"\."/"\,"/`

nvidia-settings -n -a $CONNECTED_DISPLAY/Gamma=$GAMMACOMMA -a $CONNECTED_DISPLAY/Brightness=$BRIGHTNESSCOMMA 1>/dev/null
}

#### LOAD CONFIGURATION ####
load_cfg ()
{
source ~/.nvidia-brightness.cfg

GAMMACOMMA=`echo $GAMMA | sed s/"\."/"\,"/`
BRIGHTNESSCOMMA=`echo $BRIGHTNESS | sed s/"\."/"\,"/`

nvidia-settings -n -a $CONNECTED_DISPLAY/Gamma=$GAMMACOMMA -a $CONNECTED_DISPLAY/Brightness=$BRIGHTNESSCOMMA 1>/dev/null
}

#### GAMMA CHANGE ####
gamma_up ()
{
source ~/.nvidia-brightness.cfg

GAMMANEW=`echo $GAMMA | awk '{printf "%f", $GAMMA + 0.100000}'`

GAMMACOMMA=`echo $GAMMANEW | sed s/"\."/"\,"/`

nvidia-settings -n -a $CONNECTED_DISPLAY/Gamma=$GAMMACOMMA  1>/dev/null 

sed -i  s/.*GAMMA=.*/GAMMA=$GAMMANEW/g ~/.nvidia-brightness.cfg
}

gamma_down ()
{
source ~/.nvidia-brightness.cfg

GAMMANEW=`echo $GAMMA | awk '{printf "%f", $GAMMA - 0.100000}'`

GAMMACOMMA=`echo $GAMMANEW | sed s/"\."/"\,"/`

nvidia-settings -n -a $CONNECTED_DISPLAY/Gamma=$GAMMACOMMA  1>/dev/null

sed -i  s/.*GAMMA=.*/GAMMA=$GAMMANEW/g ~/.nvidia-brightness.cfg
}

#### BRIGHTNESS CHANGE ####
brightness_up ()
{
source ~/.nvidia-brightness.cfg

BRIGHTNESSNEW=`echo $BRIGHTNESS | awk '{printf "%f", $BRIGHTNESS + 0.100000}'`

BRIGHTNESSCOMMA=`echo $BRIGHTNESSNEW | sed s/"\."/"\,"/`

nvidia-settings -n -a $CONNECTED_DISPLAY/Brightness=$BRIGHTNESSCOMMA 1>/dev/null

sed -i  s/.*BRIGHTNESS=.*/BRIGHTNESS=$BRIGHTNESSNEW/g ~/.nvidia-brightness.cfg
}

brightness_down ()
{
source ~/.nvidia-brightness.cfg

BRIGHTNESSNEW=`echo $BRIGHTNESS | awk '{printf "%f", $BRIGHTNESS - 0.100000}'`

BRIGHTNESSCOMMA=`echo $BRIGHTNESSNEW | sed s/"\."/"\,"/`

nvidia-settings -n -a $CONNECTED_DISPLAY/Brightness=$BRIGHTNESSCOMMA 1>/dev/null

sed -i  s/.*BRIGHTNESS=.*/BRIGHTNESS=$BRIGHTNESSNEW/g ~/.nvidia-brightness.cfg
}

if [ "$3" != "" ]; then
    usage
    exit 1
fi

error_mixed_gamma ()
{
    echo "Error: [ --gamma-up ] and [ --gamma-down ] can't be used together."
}

error_mixed_brightness ()
{
    echo "Error: [ --brightness-up ] and [ --brightness-down ] can't be used together."
}


if [ "$2" != "" ]; then
    [ "$2" != "-bu" -a "$2" != "--brightness-up" -a "$2" != "-bd" -a "$2" != "--brightness-down" \
    -a "$2" != "-gu" -a "$2" != "--gamma-up" -a "$2" != "-gd" -a "$2" != "--gamma-down" ] && usage && exit 1
fi

case $1 in
    -gu|--gamma-up) 
        [ "$2" == "-gd" ] && error_mixed_gamma && exit 1
        [ "$2" == "--gamma-down" ] && error_mixed_gamma && exit 1
        gamma_up
        ;;
    -gd|--gamma-down) 
        [ "$2" == "-gu" ] && error_mixed_gamma && exit 1
        [ "$2" == "--gamma-up" ] && error_mixed_gamma && exit 1
        gamma_down
        ;;
    -bu|--brightness-up) 
        [ "$2" == "-bd" ] && error_mixed_brightness && exit 1
        [ "$2" == "--brightness-down" ] && error_mixed_brightness && exit 1
        brightness_up
        ;;
    -bd|--brightness-down) 
        [ "$2" == "-bu" ] && error_mixed_brightness && exit 1
        [ "$2" == "--brightness-up" ] && error_mixed_brightness && exit 1
        brightness_down
        ;;
    -h|--help) 
        usage
        exit 0
        ;;
    -i|--initialize)
        if [ "$2" != "" ]; then usage; exit 1; fi   
        initialize_cfg
        exit 0
        ;;
    -l|--load-config)
        if [ "$2" != "" ]; then usage; exit 1; fi   
        load_cfg
        exit 0
        ;;
    *) 
        usage
        exit 1
esac

case $2 in
    -gu|--gamma-up) 
        gamma_up
        ;;
    -gd|--gamma-down) 
        gamma_down
        ;;
    -bu|--brightness-up) 
        brightness_up
        ;;
    -bd|--brightness-down) 
        brightness_down
        ;;
    -h|--help) 
        usage
        exit 0
        ;;
    "")
        ;;
    *) 
        usage
        exit 1
esac

Usage:

Save the file somewhere in your PATH e.g.

/usr/local/bin/nvidia-brightness.sh

Don't forget to

chmod +x /usr/local/bin/nvidia-brightness.sh

Before you can use it you have to type

nvidia-brightness.sh -i

This will create the settings file and can also be used to reset the brightness at any time.

Type

nvidia-settings.sh --help

for more options:

Usage: 
   nvidia-brightness.sh [ options ]
Options:
   [ -gu ] or [ --gamma-up ]         increase gamma by 0.1
   [ -gd ] or [ --gamma-down ]       decrease gamma by 0.1
   [ -bu ] or [ --brightness-up ]    increase brightness by 0.1
   [ -bd ] or [ --brightness-down ]  decrease brightness by 0.1
   [ -i ]  or [ --initialize ]       Must be run once to create the settings file
                                     (~/.nvidia-brightness.cfg).
                                     Brightness settings from ~/.nvidia-settings-rc
                                     will be used if file exists, otherwise 
                                     gamma will be set to 1.0 and brightness to 0.0
                                     (NVIDIA Standard).
   [ -l ]  or [ --load-config ]      Load current settings from ~/.nvidia-brightness.cfg
                                     (e.g. as X11 autostart script)

Examples:
   nvidia-brightness -gd       this will decrease gamma by 0.1
   nvidia-brightness -bu -gd   this will increase brightness by 0.1 and decrease gamma by 0.1
share|improve this answer
    
This looks exactly what I'm looking for but I get an error: ERROR: Error parsing assignment '/Gamma=' (No attribute value specified). –  James Oct 9 '13 at 20:25
add comment

I was able to get my brightness keys working on my Lenovo W530 on Ubuntu 12.04.

These days X automatically configures itself, so creating an xorg.conf file might make your system inflexible. Instead you can add a section to a file in /usr/share/X11/xorg.conf.d/ and X will include that section in the configuration that it automatically generates.

So to get the screen brightness keys working with your Nvidia graphics card, create a file in the xorg.conf.d directory, e.g:

sudo gedit /usr/share/X11/xorg.conf.d/10-nvidia-brightness.conf

Paste the following into the file:

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BoardName      "Quadro K1000M"
    Option         "RegistryDwords" "EnableBrightnessControl=1"
EndSection

Log out and log back in, or reboot, and your brightness keys should now work!

(I blogged this here)

share|improve this answer
    
Works on my Macbook 2008 too! Just wrote the Identifier, Driver and Option lines. Been looking for this for some time now. –  Alejandro Mezcua Apr 28 '13 at 15:31
add comment

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.

share|improve this answer
add comment

There are some computers, such as my Lenovo W520, that don't with the Option "RegistryDwords" "EnableBrightnessControl=1" line. If you are one of those unlucky ones, you can try the nvidiabl driver (link here).

The nvidiabl driver provides a proper way to change the screen brightness. On some laptops the Option "RegistryDwords" "EnableBrightnessControl=1" hack will cause the backlight controller or your GPU to emit a high pitched noise.

Just download and install the latest Deb file from here: https://github.com/downloads/guillaumezin/nvidiabl/nvidiabl-dkms_0.72_all.deb

and run:

echo "nvidiabl" | sudo tee -a /etc/modules

to ensure that the module will be loaded when the computer boots.

share|improve this answer
add comment

You need to enable Brightness Control. Open terminal and type sudo gedit /etc/x11/xorg.conf And then add Option "RegistryDwords" "EnableBrightnessControl=1" inside the ** device section**, make it new line. Then restart your computer and everything should be fine.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.