Difference between revisions of "Automatically reduce brightness"

From ThinkWiki
Jump to: navigation, search
(Updated to a new revision)
(Windows)
 
(20 intermediate revisions by 6 users not shown)
Line 1: Line 1:
== The idea ==
+
= The idea =
When watching someone working with an iBook I noticed that the brightness automatically faded to the lowest level after a few seconds of inactivity. I think that this is a simple way to save power. I wrote a c-daemon which uses the XScreenSaver extension to check whether the user is active. If he is not, it lowers the brightness to a specific level. When he is active again, the brightness is reset to the previous level.
+
When watching someone working with an iBook you may notice that the brightness automatically fades to the lowest level after a few seconds of inactivity. This is a simple yet effective way to save power.
 +
 
 +
= Linux =
 +
I ([[User:Pberndt|Pberndt]]) wrote a c-daemon which uses the XScreenSaver extension to check whether the user is active. If he is not, it lowers the brightness to a specific level. When he is active again, the brightness is reset to the previous level.
 +
 
 +
{{NOTE|This Feature is implemented in the "gnome-power-manager" (at least from gnome 2.14) and can be used without this script (Prerequisites are needed anyway). Enable it under Gnome's Power management settings ([[:Category:Debian|Debian]] Etch: Gnome-Menu/Desktop/Preferences/Power Management) -> General-Tab -> "Dim the laptop panel when idle". "when idle" in this case means, when the gnome-screensaver sets the session idle. Change time at Gnome's Screensaver settings ([[:Category:Debian|Debian]] Etch: Gnome-Menu/Desktop/Preferences/Screensaver). If you want to see the actual content of the screen when dimmed, you should disable "Activate screensaver when session is idle".}}
  
 
== Prerequisites ==
 
== Prerequisites ==
A recent kernel with IBM ACPI extensions. (You should have a file called {{path|/proc/acpi/ibm/brightness}})
+
the following is deprecqted, for the current solution see [[thinkpad-acpi]].
 +
A recent kernel with the [[ibm-acpi]] driver (You should have a directory called {{path|/sys/class/backlight/ibm/}} or {{path|/sys/class/backlight/thinkpad_screen/}}).
  
 
== Installation ==
 
== Installation ==
# Download the [http://pberndt.com/Programme/Linux/brightd/_download/brightd.tar.bz2 brightness control daemon]
+
# Download the [http://www.pberndt.com/Programme/Linux/brightd/_download/latest.phpc brightness control daemon]
 
# Unpack it and chdir into the {{path|brightd}} directory
 
# Unpack it and chdir into the {{path|brightd}} directory
 
# Call {{cmduser|make}}
 
# Call {{cmduser|make}}
Line 15: Line 21:
 
See the README for more detailled instructions and command line parameters.
 
See the README for more detailled instructions and command line parameters.
  
== Example installation for Gentoo linux and XFCE4 ==
+
=== Example installation for Gentoo linux and XFCE4 ===
  $ wget -o /dev/null -O brightd.tar.bz2 "http://www.pberndt.com/Programme/Linux/brightd/_download/brightd-0.1.tar.bz2?ct=raw&sub=att"
+
The following is an example which shows how to install brightd manually. The prefered way to install brightd on gentoo is to use the [http://bugs.gentoo.org/show_bug.cgi?id=177214 ebuild from bugzilla].
  $ tar xjf brightd-0.1.tar.bz2
+
  $ wget -o /dev/null -O brightd.tar.bz2 "http://www.pberndt.com/raw/Programme/Linux/brightd/_download/brightd-0.3_pre2.tar.bz2"
  $ cd brightd-0.1/
+
  $ tar xjf brightd.tar.bz2
 +
  $ cd brightd-*/
 
  $ make
 
  $ make
 
  gcc -lX11 -lXss -o brightd brightd.c
 
  gcc -lX11 -lXss -o brightd brightd.c
  $ cp brightd /usr/local/bin/
+
  $ make install
 +
install -Ds brightd //usr/bin/brightd
 +
install -D brightd.1 //usr/share/man/man1/brightd.1
 
  $ cd /etc/xdg/xfce4
 
  $ cd /etc/xdg/xfce4
 
  $ vi xinitrc
 
  $ vi xinitrc
Line 30: Line 39:
 
  $ cat > permissions
 
  $ cat > permissions
 
  start() {
 
  start() {
         ebegin "Setting permissions on /proc"
+
         ebegin "Setting permissions on /sys"
 
   
 
   
         chmod g+w /sys/class/backlight/ibm/brightness
+
         chmod g+w /sys/class/backlight/*/brightness
         chgrp wheel /sys/class/backlight/ibm/brightness
+
         chgrp wheel /sys/class/backlight/*/brightness
 
   
 
   
 
         eend $?
 
         eend $?
Line 41: Line 50:
 
  $ ./permissions start
 
  $ ./permissions start
  
Done. Restart X to see it working.
+
Done. Restart X to see it working. Have a look at the "-x" parameter if you intend to start the daemon from an init-script.
  
== Example installation for Debian Sid ==
+
=== Example installation for Debian Sid ===
 
brightd isn't yet in the official Debian archives ([http://bugs.debian.org/419329 an ITP was filled]), but you can get precompiled binaries for unstable from [[User:Zhenech|Zhenech]]'s page.
 
brightd isn't yet in the official Debian archives ([http://bugs.debian.org/419329 an ITP was filled]), but you can get precompiled binaries for unstable from [[User:Zhenech|Zhenech]]'s page.
  
{{cmduser|wget http://debian.die-welt.net/pool/main/brightd/brightd_0.0.20070226-1_i386.deb}}
+
{{cmduser|wget http://debian.die-welt.net/pool/main/brightd/brightd_0.1-1_i386.deb}}
  
{{cmdroot|dpkg -i brightd_0.0.20070226-1_i386.deb}}
+
{{cmdroot|dpkg -i brightd_0.1-1_i386.deb}}
  
 
Done. Relogin into your X session and brightd will be started. You can change this and other settings by editing {{path|/etc/default/brightd}}.
 
Done. Relogin into your X session and brightd will be started. You can change this and other settings by editing {{path|/etc/default/brightd}}.
 
{{NOTE|Changing permissions is not needed, because the binary is installed suid-root.}}
 
{{NOTE|Changing permissions is not needed, because the binary is installed suid-root.}}
 +
 +
== Possible problems ==
 +
=== brightd does not fade, screensaver deactivated ===
 +
On my Debian Sid box, brightd can run for hours and just do nothing. This happens because it thinks the screensaver is deactivated and screen shouldn't be faded (useful while watching videos).
 +
But in fact the screensaver isn't deactivated. To solve this problem, just execute the following command before starting bright:
 +
 +
{{cmduser|xset s default}}
 +
 +
=== brightd says it is fading, but does not ===
 +
On my Z61m {{path|/sys/class/backlight/ibm/brightness}} is 0 after the laptop boots up. As long it is 0, brightd does nothing, because it thinks, brightness is already as low as possible, so I need to initialize the brightness-level before using brightd:
 +
 +
{{cmdroot|echo 7>/sys/class/backlight/ibm/brightness}}
 +
 +
= Windows =
 +
A fairly simple yet effective implementation of the same idea in Python is available [http://homepage.rub.de/Arkadiusz.Wahlig/thinkpad-python.zip here]. It was written by [[User:Yak|Yak]]. However, it does not work on '''Windows Vista''' anymore.
 +
 +
== Prerequisites ==
 +
Since it is written in Python, you must have a [http://www.python.org/download Python interpreter] installed on your system. Version 2.5 or newer is required.
 +
 +
== Installation ==
 +
# Download the [http://homepage.rub.de/Arkadiusz.Wahlig/thinkpad-python.zip ZIP file] with the script and extract it to a directory of your preference.
 +
# Edit the '''dimmer.pyw''' file (using a text editor) to match your preferences. See below for possible settings.
 +
# Start the '''dimmer.pyw''' script (double click on it) to test it.
 +
# If it works, create a shortcut in the '''Autostart''' folder so the script is automatically run on every boot.
 +
 +
== Configuration ==
 +
You configure the script by editing it. The settings section is right at the top of the script. Here are the default values (version 1.4).
 +
 +
# SETTINGS:
 +
 +
# ac = when on AC adapter, dc = when on battery
 +
 +
# number of (idle) seconds before the screen will dim,
 +
# values > 30 should be used to ensure that the screen
 +
# won't dim while watching a movie, 0 means no dimming
 +
timeout_ac = 600
 +
timeout_dc = 60
 +
 +
# brightness level after dimming (0-7)
 +
brightness_ac = 3
 +
brightness_dc = 0
 +
 +
{{NOTE|If the script is already running, it will notice that the settings have been changed and quit (starting with version 1.3). You have to start the script again to apply the changes.}}
 +
 +
== Demo ==
 +
A video showing the script in action has been uploaded to [http://www.youtube.com/watch?v=n7RLHP_c7gE YouTube].

Latest revision as of 14:53, 30 November 2008

The idea

When watching someone working with an iBook you may notice that the brightness automatically fades to the lowest level after a few seconds of inactivity. This is a simple yet effective way to save power.

Linux

I (Pberndt) wrote a c-daemon which uses the XScreenSaver extension to check whether the user is active. If he is not, it lowers the brightness to a specific level. When he is active again, the brightness is reset to the previous level.

NOTE!
This Feature is implemented in the "gnome-power-manager" (at least from gnome 2.14) and can be used without this script (Prerequisites are needed anyway). Enable it under Gnome's Power management settings (Debian Etch: Gnome-Menu/Desktop/Preferences/Power Management) -> General-Tab -> "Dim the laptop panel when idle". "when idle" in this case means, when the gnome-screensaver sets the session idle. Change time at Gnome's Screensaver settings (Debian Etch: Gnome-Menu/Desktop/Preferences/Screensaver). If you want to see the actual content of the screen when dimmed, you should disable "Activate screensaver when session is idle".

Prerequisites

the following is deprecqted, for the current solution see thinkpad-acpi. A recent kernel with the ibm-acpi driver (You should have a directory called /sys/class/backlight/ibm/ or /sys/class/backlight/thinkpad_screen/).

Installation

  1. Download the brightness control daemon
  2. Unpack it and chdir into the brightd directory
  3. Call $ make
  4. Move the brightd executable into a directory like /usr/local/bin
  5. Put $ brightd -d into your ~/.Xsession (or another distro-specific startup script)
  6. Change the permissions of /sys/class/backlight/ibm/brightness so that your user can write to that file

See the README for more detailled instructions and command line parameters.

Example installation for Gentoo linux and XFCE4

The following is an example which shows how to install brightd manually. The prefered way to install brightd on gentoo is to use the ebuild from bugzilla.

$ wget -o /dev/null -O brightd.tar.bz2 "http://www.pberndt.com/raw/Programme/Linux/brightd/_download/brightd-0.3_pre2.tar.bz2"
$ tar xjf brightd.tar.bz2
$ cd brightd-*/
$ make
gcc -lX11 -lXss -o brightd brightd.c
$ make install
install -Ds brightd //usr/bin/brightd
install -D brightd.1 //usr/share/man/man1/brightd.1
$ cd /etc/xdg/xfce4
$ vi xinitrc
73Gi
/usr/local/bin/brightd -s 5 -w 2 -d
<escape>:x 
$ cd /etc/init.d/
$ cat > permissions
start() {
        ebegin "Setting permissions on /sys"

        chmod g+w /sys/class/backlight/*/brightness
        chgrp wheel /sys/class/backlight/*/brightness

        eend $?
}
$ chmod a+x permissions
$ rc-update add permissions boot
$ ./permissions start

Done. Restart X to see it working. Have a look at the "-x" parameter if you intend to start the daemon from an init-script.

Example installation for Debian Sid

brightd isn't yet in the official Debian archives (an ITP was filled), but you can get precompiled binaries for unstable from Zhenech's page.

$ wget http://debian.die-welt.net/pool/main/brightd/brightd_0.1-1_i386.deb

# dpkg -i brightd_0.1-1_i386.deb

Done. Relogin into your X session and brightd will be started. You can change this and other settings by editing /etc/default/brightd.

NOTE!
Changing permissions is not needed, because the binary is installed suid-root.

Possible problems

brightd does not fade, screensaver deactivated

On my Debian Sid box, brightd can run for hours and just do nothing. This happens because it thinks the screensaver is deactivated and screen shouldn't be faded (useful while watching videos). But in fact the screensaver isn't deactivated. To solve this problem, just execute the following command before starting bright:

$ xset s default

brightd says it is fading, but does not

On my Z61m /sys/class/backlight/ibm/brightness is 0 after the laptop boots up. As long it is 0, brightd does nothing, because it thinks, brightness is already as low as possible, so I need to initialize the brightness-level before using brightd:

# echo 7>/sys/class/backlight/ibm/brightness

Windows

A fairly simple yet effective implementation of the same idea in Python is available here. It was written by Yak. However, it does not work on Windows Vista anymore.

Prerequisites

Since it is written in Python, you must have a Python interpreter installed on your system. Version 2.5 or newer is required.

Installation

  1. Download the ZIP file with the script and extract it to a directory of your preference.
  2. Edit the dimmer.pyw file (using a text editor) to match your preferences. See below for possible settings.
  3. Start the dimmer.pyw script (double click on it) to test it.
  4. If it works, create a shortcut in the Autostart folder so the script is automatically run on every boot.

Configuration

You configure the script by editing it. The settings section is right at the top of the script. Here are the default values (version 1.4).

# SETTINGS:

# ac = when on AC adapter, dc = when on battery

# number of (idle) seconds before the screen will dim,
# values > 30 should be used to ensure that the screen
# won't dim while watching a movie, 0 means no dimming
timeout_ac = 600
timeout_dc = 60

# brightness level after dimming (0-7)
brightness_ac = 3
brightness_dc = 0
NOTE!
If the script is already running, it will notice that the settings have been changed and quit (starting with version 1.3). You have to start the script again to apply the changes.

Demo

A video showing the script in action has been uploaded to YouTube.