banner
Previous Page
PCLinuxOS Magazine
PCLinuxOS
Article List
Disclaimer
Next Page

Control Screen Brightness Without A Power Manager


by Paul Arnote (parnote)

I have to be totally honest. I have this laptop that was given to me. It's a Toshiba Satellite L305-S5957 with a single core Celeron processor, 4GiB RAM, and a 160 GiB hard drive. Of all the laptops I have, it's the only one with a single core processor. Yet, it's probably the one that I use over 90% of the time. All of my other laptops (notably excepting my 32 bit laptops and netbooks that I still have), have dual core processors.



Even though the processor stinks on the Toshiba, I use it most because I like the keyboard, both the feel and layout. It may seem to be a small thing, but the keyboard layout on the Toshiba frees me to work the way I'm most accustomed to working. Sure, I could attach a full size USB keyboard to the other laptops, but that isn't always as convenient as I would like.

At any rate, the Toshiba does have some issues that I just put up with. It's very heat sensitive, won't run my own program that's in the repository (Touchpad Toggle) without rendering my wifi inoperable, and it freezes up -- as in locked up tighter than a drum -- when running Xscreensaver and any power management software. When it locks up, nothing but a hard restart will resurrect the computer. R-E-I-S-U-B won't work (I've tried it many times).

So, I've strayed away from running power management software and Xscreensaver (which is the worst). But by not running power management software, I was left without an easily accessible way to dim my laptop screen (no, the Fn keys don't work, as is frequently the issue with laptops). Or so I thought.


xrandr

Xrandr is a powerhouse of a utility for when it comes to dealing with displays, especially laptop displays. Typically, standalone desktop monitors have separate controls to adjust the screen brightness, so xrandr definitely won't be needed to control screen brightness on a desktop monitor. But not so for laptop displays, and this is where xrandr really shines. Xrandr was installed by default on my PCLinuxOS Xfce installation.

For those of you who shy away from the command line, I have one word: don't. The xrandr utility is easy enough to use. All the commands are entered as a normal user, so you don't even have to su to root.

First, we need to know some information. Enter xrandr --listmonitors on the command line of a terminal session. Your output will look something like this:

$ xrandr --listmonitors
Monitors: 1
0: +LVDS1 1280/330x800/210+0+0 LVDS1

This tells you that xrandr sees only one monitor on the laptop, which it refers to as LVDS1. It also tells you the resolution of the monitor.

You can use another command to give you an even more detailed report, by entering xrandr --current on the command line. Your output will look something like this:

$ xrandr --current
Screen 0: minimum 8 x 8, current 1280 x 800, maximum 32767 x 32767
LVDS1 connected 1280x800+0+0 (normal left inverted right x axis y axis) 330mm x 210mm
   1280x800      60.00*+  60.00* 
   1280x800_60   60.00  
   1024x768      60.00  
   800x600       60.32  
   640x480       59.94  
DP1 disconnected (normal left inverted right x axis y axis)
TV1 disconnected (normal left inverted right x axis y axis)
VGA1 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)

This command tells you not only the current resolution and screen identity, but also the other resolutions that are available, their refresh rates, and a status report on all of the other display connections. Still, we see our primary (and only) screen being identified by xrandr as LVDS1.

So, now that we're armed with that information, it's very easy to control the brightness of our laptop screen. Let me show you the command, and then I'll walk you through it.

xrandr --output LVDS1 --brightness 0.72

The “--output LVDS1” tells xrandr that you want to target the display that it calls LVDS1. Then, “--brightness 0.72” sets the brightness to just under 3/4ths full brightness. The value for the --brightness parameter must be a fractional value between 0.0 and 1.0, with 1.0 being full brightness. Lately, I've changed the --brightness parameter to 0.50, preferring an even darker starting screen.

It doesn't get much easier than that. If you place a space and ampersand (“ &” … without the quotes) at the end of the command, the command will be executed in the background and you will immediately regain control of your command line. This is a habit I've gotten into over the years to force execution of a command to the background, instead of it staying in the foreground and tying up my command line prompt.

This is exactly the command that I have placed into my startup commands in Xfce. As soon as the laptop is booted, the command is executed and my display brightness is set from the time that the desktop appears.


But wait -- there's more

Well, of course there's more. This wouldn't be Linux if there wasn't more than one way to get this -- or any other -- task done.

First, you need to open Synaptic and install the command line utility xbacklight from the PCLinuxOS repository. Below is the help text for xbacklight.

$ xbacklight --help
usage: xbacklight [options]
  where options are:
  -display <display> or -d <display>
  -help
  -set <percentage> or = <percentage>
  -inc <percentage> or + <percentage>
  -dec <percentage> or - <percentage>
  -get
  -time <fade time in milliseconds>
  -steps <number of steps in fade>

The options we're most interested in here are -set, -inc, and -dec. Keep in mind that xbacklight uses whole number percentages, different from xrandr's --brightness option, which uses fractions.

Thus, xbacklight -set 72 performs exactly like xrandr --output LVDS1 --brightness 0.72. In fact, they can most often be used interchangeably.

But xbacklight differs from xrandr with its -inc (increase) and -dec (decrease) options. You can specify to increase or decrease the screen brightness by a set percentage every time the command is issued. A good use for this is to bind this command to a keyboard combination, replacing the typically non-functioning screen brightness keys.

So, xbacklight -inc 2 will increase the brightness by two percent, while xbacklight -dec 2 will decrease the brightness by two percent. I have, however, found the functionality of this to be somewhat dependent on your hardware configuration. Nothing I do can get the xbacklight -inc 2 command to work, but the xbacklight -dec 2 command works exceptionally well. I can't even get the command to increase the screen brightness to work from a naked command line.


Summary

Of course, xrandr is capable of doing a lot more. The purpose of this article wasn't to give complete coverage to everything that xrandr can do. Rather, we used xrandr to meet a specific need. In this case, we used xrandr to control the screen brightness on a laptop, where there are no independent controls for brightness.

I usually have my computer on 24/7. I frequently check my email and do other things on my computer early in the morning, before the kids get up. At that time, I'm sitting in the dark, and the only light in the room is from the screen on my laptop. The last thing I want to do is to stare at a laptop screen that's at full brightness. It can be blinding, in the sense that such a bright screen destroys my night vision that's necessary for seeing in the room beyond my laptop.

With xrandr and xbacklight, you can have full control over the brightness of your laptop screen, without having to run a power management program. This is one thing I really love about Linux. There seems to always be more than one way to get something done.



Previous Page              Top              Next Page