Problem I like to switch between my external monitor at home and my netbook screen when I'm out. lxrandr came with my LXDE install but it is a pain to use. To compound the problem, if I do something stupid, like run to school pulling the VGA from my suspended computer, it is quite difficult to get the display to switch back to LVDS. (this has happened more than I would like to admit)
Solution Step One: I wrote this bash script with some help
from https://wiki.archlinux.org/index.php/Xrandr and http://en.tldp.org/LDP/abs/html/abs-guide.html#!/bin/bash
# Toggles between laptop and external display devices. Sets laptop screen if external device goes missing.
xStatus=`xrandr`
connectedOutputs=$(echo "$xStatus" | grep " connected" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
disconnectedOutputs=$(echo "$xStatus" | grep " disconnected" | sed -e "s/\([A-Z0-9]\+\) disconnected.*/\1/")
activeOutput=$(echo "$xStatus" | grep -e " connected [^(]" | sed -e "s/\([A-Z0-9]\+\) connected.*/\1/")
connectionCount=$(echo $connectedOutputs | wc -w)
command="xrandr "
if [[ "$connectionCount" -gt 1 ]]; then
for display in $connectedOutputs; do
if [[ $display = $activeOutput ]]; then
command+="--output $display --off "
else
command+="--output $display --auto "
fi
done
else
command+="--output $connectedOutputs --auto "
for display in $disconnectedOutputs; do
command+="--output $display --off "
done
fi
$command If there are two connected displays this will turn the active one off and auto configure the other.
If there is only one connected display, it will activate the connected one and deactivate the disconnected ones (yes, deactivating disconnected devices is necessary).
If both screen are already active this script does nothing.
Step Two: Key-binding. First I used chmod a+x to make my script executable. My Fn-F8 key has a toggle display pic on it. I used xev to find the name of that key. Turned out to be XF86Display. I then added the following to the key-bindings in my openbox/rc.xml (lxde-rc.xml actually).
<keybind key="XF86Display">
<action name="Execute">
<command>/home/ben/Documents/scripts/toggle-display</command>
</action>
</keybind> Now, no matter what happens, hitting Fn-F8 does the right thing. Yay!