I have a laptop I use at work (with a docking station), in the train and at home (with an external display), on which my environment is ion3.
As I use suspend-to-RAM all the time, I have added some keybindings to automatically reconfigure my screen when I plug/unplug an external display (on the dock as well as direct VGA connection).
The lua code to paste in your .ion3/cfg_ion.lua for the bindings looks like:
function autoscreen_on() local f = io.popen('/home/david/bin/autoscreen -c', 'r') if not f then return end local s = f:read('*a') f:close() ioncore.restart() end function autoscreen_off() local f = io.popen('/home/david/bin/autoscreen -d', 'r') if not f then return end local s = f:read('*a') f:close() ioncore.restart() end defbindings("WMPlex.toplevel", { bdoc("Turn on any external display and tell ion to reconfigure itself"), kpress(META.."F10", "autoscreen_on()"), }) defbindings("WMPlex.toplevel", { bdoc("Turn off any external display and tell ion to reconfigure itself"), kpress(META.."F11", "autoscreen_off()"), })
It makes use of the following python script (named /home/david/bin/autoscreen in the lua code above):
#!/usr/bin/env python import sys import os import re from subprocess import Popen, PIPE import optparse parser = optparse.OptionParser("A simple automatic screen configurator (using xrandr)") parser.add_option('-c', '--connect', action="store_true", dest='connect', default=False, help="configure every connected screens") parser.add_option('-d', '--disconnect', action="store_true", dest='disconnect', default=False, help="unconfigure every connected screens other than LVDS (laptop screen)") parser.add_option('', '--main-display', dest='maindisplay', default="LVDS", help="main display identifier (typically, the laptop LCD screen; defaults to LVDS)") options, args = parser.parse_args() if int(options.connect) + int(options.disconnect) > 1: print "ERROR: only one option -c or -d at a time" parser.print_help() sys.exit(1) xrandr = Popen("xrandr", shell=True, bufsize=0, stdout=PIPE).stdout.read() connected = re.findall(r'([a-zA-Z0-9-]*) connected', xrandr) connected = [c for c in connected if c != options.maindisplay] cmd = "xrandr --output %s %s" if options.connect or options.disconnect: for c in connected: if options.connect: action = "--auto" elif options.disconnect: action = "--off" p = Popen(cmd % (c, action), shell=True) sts = os.waitpid(p.pid, 0)
blog entry of