How can I save/restore window positions when I undock/dock my laptop?

view full story

http://unix.stackexchange.com – I have a laptop with a docking station that has a large monitor connected to it. When the laptop is docked, I use the monitor as my primary display, and the laptop screen as a secondary display. When I undock, the laptop screen becomes my primary display, and all the windows move over to it. When I dock the laptop, the monitor automatically becomes the primary display again, but the windows all stay on the laptop screen. I have to drag each one over to the monitor and resize it. How can I get my windows to automatically resume the positions and sizes they had just before I undocked (assum (HowTos)