Remember window locations when docked and undocked
DISCLAIMER: I'm the creator of this tool.
I've created a little tool to rearrange windows on a traybar icon click. You may compile it from source or ask to have a (portable) binary through the issues link.
It is hosted at Github: https://github.com/manutalcual/winredock
I would be glad to hear from you if you have suggestions.
EDIT: 2018/11/22
It is fully automated now.
I'm currently using DisplayFusion Pro for window location (not only). I don't know how this works when you disconnect and connect your monitor - I have three always.
I think, that you must close and reopen your apps to be re-arranged.
Edit: This is feature is available only in Pro version. - Information from comments.
homepage of DisplayFusion