display – After disconnecting an external monitor, windows are not resized correctly if the Dock is on the right. How to workaround?

  1. I have Dock attached to the right of the screen.
  2. My Dock is always visible (does not disappear automatically).
  3. When connected, an external monitor is the main screen, so that dock is shown there.

After disconnecting the external monitor, the applications that were occupying all space of the screen, keep occupying all space, but now also size beyond the Dock boundary, so I get part of the application rendered behind the dock.

The only way to work around it is to manually switch to each application and double-click its bar, so that it re-sizes to take full screen again. This is very annoying.

The question is: is this a bug, or am I doing it in a wrong way, or is there a particular setting in MacOS that would automatically resize applications after monitor disconnection to not be rendered behind the Dock?