I use Ubuntu 18.04.3 gnome laptop with a second monitor connected with HDMI. If I close the lid of my laptop it successfully locks (after I reopen it I have to type my password) but the windows opened on my second screen stay in place. I mean they can be seen after the lid is closed. I want them to go away in that situation (the second screen must go black), how do I do that?
If you change the primary display to your Built-In display, it does it automatically. I use a tv as a second monitor and this seemed to work for me. The tv only went blank but did not turn off.
If you don't mind a slightly longer startup time, you can set your laptop to hibernate rather than suspend when you close the lid. If you want to try this, you can follow the directions on this article - https://tipsonubuntu.com/2018/04/28/change-lid-close-action-ubuntu-18-04-lts/. I've copied them below.
First, open the terminal and run:
In the configuration file that opens up, there should be a line that reads:
You want to change that to:
(Remove the "#" and replace "suspend" with "hibernate")
Afterwards, save the configuration file. For the changes to take effect, go back to your terminal window and run:
Your laptop should then hibernate rather than suspend when you close the lid, and it shouldn't be able to output any image while hibernating.