// we are

Thinkpad: How to Use the Fn+F7 Hot Key on Xrandr-compliant Graphic Drivers!

Well, I’ll start this blog post with a big thank to my region. Indeed, studies in France are almost free of charges. But, in my region, they even have decided to offer laptops to their master students to attract more students.

I have received mine last year. It is a wonderful (yet, quite heavy) Lenovo Thinkpad R61i. It features a Core Duo (not a core 2 duo), 2 GB of RAM, 120GB on the hard disk drive and an NVIDIA Quadro NVS 140M.

I was really unpleased to discover it was an NVIDA video card, but I’ve come to like it over the last few months, when I discovered 3D support finally appeared using gallium 3D and the latest mesa bits.

Today, after my exams, I went to the project room my school has, plugged my laptop on the 24” screen and typed the usual :

$ xrandr --output VGA-1 --auto
$ xrandr --output LVDS-1 --off

This is way better than using NVIDIA’s utilities (it is portable) but yet, it is so boring to write the same thing on and on…

As I had a couple of hours to spare, I have decided to use the laptop hotkeys to switch between the screens (LVDS –> VGA and VGA–> LVDS).

To fulfill this goal, I have used the acpid daemon and I have made a simple bash script to detect implement the logic of the switch.

How to use the hotkeys Fn+F7 to switch from screen to screen

I have been greatly helped in this task by thinkwiki’s fn-f7 script.

Capture the event using acpid

In order to capture the event, we need to create a file called : /etc/acpi/events/thinkpad-fn-f7.conf

event=ibm/hotkey HKEY 00000080 00001007

This will capture the event Fn+F7 and launch the script /usr/local/sbin/ See Function keys’s ACPI events if you want to use another key sequence to throw up the event.

The bash script

First of all, I would like to warn users using nvidia’s binary blob that they will have to change the bash script in order to use the nvidia-config tool. If you do so, please send it to me so as I can update my blog post. The bash script should work with every FOSS drivers (radeon, intel, nouveau) and, maybe, with FGLRX.

The script is a little more complicated than the acpid configuration but nothing impossible ;).

First, we need to know how our screens our named. To do so, please launch :

$ xrandr

You should notice outputs called LVDS and VGA. LVDS-x is the name of your built-in laptop screen, VGA-x is the name of the VGA output. On my computer, the built-in screen is called LVDS-1 while the VGA output is called VGA-1.

Now we have these important names, we can create this script (/usr/local/sbin/


# External output may be "VGA" or "VGA-0" or "DVI-0" or "TMDS-1"

# Figure out which user and X11 display to work on
# TODO there has to be a better way to do this?
X_USER=$(w -h -s | grep ":[0-9]\W" | head -1 | cut -d ' ' -f1)
export DISPLAY=":0"

# Switch to X user if necessary
if [ "$X_USER" != "$USER" ]; then
    SU="su $X_USER -c"
    SU="sh -c"

INTERNAL_STATE=$(xrandr | grep "$INTERNAL_OUTPUT" | cut -d' ' -f2)
EXTERNAL_STATE=$(xrandr | grep "$EXTERNAL_OUTPUT" | cut -d' ' -f2)

INTERNAL_ACTIVE=$(xrandr | grep $INTERNAL_OUTPUT | cut -d' ' -f3 | grep -v "^(")
EXTERNAL_ACTIVE=$(xrandr | grep $EXTERNAL_OUTPUT | cut -d' ' -f3 | grep -v "^(")

if [ "$INTERNAL_ACTIVE" != "" ] && [ "$EXTERNAL_STATE" == "connected" ]; then
    xrandr --output $EXTERNAL_OUTPUT --auto
    xrandr --output $INTERNAL_OUTPUT --off
    xrandr --output $INTERNAL_OUTPUT --auto
    xrandr --output $EXTERNAL_OUTPUT --off

Just change the values you have found with the ones in the script and you’re done! Restart the acpid daemon (or reboot your computer) and you’re done!

To try it out, just plug your screen onto the thinkpad and press Fn+F7. After some flickering on both screen, your laptop’s screen should have gone black while the external screen now be in its native resolution.

Updated on 2010-01-20: Change the title of the article, add a warning for blob users and added a better conclusion.

This part has been added the 2010-02-11: Well, it turns out that acpid was a bad move. Indeed, I was often to restart the acpid daemon after a resume or even right after a boot (WTF ?). So, instead of using acpid to get the hotkey event, I would recommend you to use your DE’s hotkeys settings.

In my case, this works great with KDE 4.4. The only problem I encounter happens if you suspend your computer, unplug the VGA monitor and resume it. You would get a blank screen and would have to type your password without seeing it.

That’s OK for me