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 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:
sudo gedit /etc/systemd/logind.conf
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:
systemctl restart systemd-logind.service
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.