Docking/undocking external display messes up snapped window layouts

Describe the bug

I have four terminal windows snapped top-left, top-right, bottom-left,bottom-right in a separate desktop called Desktop 2, on an external monitor with the lid closed on the MacBook.

When I undock my MacBook (Pro 15 with touchbar) from an external display the windows are all messed up on the MacBook display in a somewhat random manner.

If I fix up the layout on the MacBook, then attach to an external monitor with the lid closed, the layout once again gets messed up on the external display.

What would be nice if possible is for BTT to recognize when an external monitor is being plugged/unplugged and for the layouts to be preserved.

Affected input device :

Displays external/internal

Device information:

  • Type of Mac: MacBook Pro 15 2017 w touchbar
  • macOS version: 10.13.5 (17F77)
  • BetterTouchTool version: 2.518 (857)