1

So sometimes when I connect my laptop to a monitor I like to use both screens at the same time but sometimes I just want to use the monitor. However when I close my laptop screen, my cursor can still go off my monitor screen and to the laptop. I tried messing around with the power management settings such as turning the screen off when lid is closed and connected to an external monitor, but that turns both screens off. Currently, whenever I close my laptop screen I have to go to settings and manually disable it. Is there a way to automate this process? I am currently using Lubuntu 21.04. The other answers I’ve found say to do nothing when the lid closes but I need to disable the screen when the lid’s closed.

Shrey Varma
  • 13
  • 1
  • 4

2 Answers2

1

A simple way (which I use) is to use Fn key on your laptop keyboard, that manages external displays and switch to "external monitor only" before you close the lid.

A complex way (which I do not use) is to create a script.
How to run a script when the lid is closed?
Shortcut to switch displays

ordinary
  • 199
1

Here's how I have solved this problem. I use a keyboard shortcut to turn the laptop screen on and off.

First, run the following command to list your displays:

xrandr

Your laptop screen name should be something like LVDS1. You will need this name later.

Next, set a keyboard shortcut through Settings > Keyboard and click on the plus symbol near the lower right side of the window.

For the name, enter "screen off"

For the command, enter the following command but replace LVDS1 with the name of your laptop screen which may or may not be the same:

xrandr --output LVDS1 --off

Now, click on "Set Shortcut" and press CRTL+ALT+SHIFT+ (the last one is a down arrow if it's hard to see).

Finally, click "Add" to save the shortcut.

image settings window to add a keyboard shortcut with the options filled in as described in the instructions


Now, set a shortcut to turn the screen back on.

Again, click the plus symbol to add another shortcut.

For the name, enter "screen on".

For the command, enter the following command but replace LVDS1 with the name of your laptop screen which may or may not be the same:

 xrandr --output LVDS1 --auto

Now, click on "Set Shortcut" and press CRTL+ALT+SHIFT+ (the last one is an up arrow if it's hard to see).

Finally, click "Add" to save the shortcut.


You will need to log out and log back in to apply these shortcuts.

Also, you can use whatever keys you want. I chose the particular keys because they are unlikely to already be in use. If you set to a combination of keys that are already in use, the shortcut will not work.

mchid
  • 43,546
  • 8
  • 97
  • 150
  • Unfortunately xrandr is not supported by Wayland so you will have to login without Wayland. – mchid Apr 25 '21 at 06:46
  • Why not use existent hard coded single key F1...12 or double key Fn+F1...12 shortcut to manage monitors? Scripting for automation, I get that part. Script that gets triggered by the lid and changes the monitor for you. – ordinary Apr 25 '21 at 14:30
  • @ordinary As a general rule, I like to set all my user defined keyboard shortcuts using CTRL+ALT+SHIFT. As far as I know, there is no application or shortcut that uses all three of these keys for combos. This way, I can easily set my shortcuts to whatever additional key I want without conflicts. In this case, it made sense to use up and down for screen-on and screen-off. – mchid Apr 25 '21 at 15:24
  • I understand your preference. I was talking about laptops existent default special keys with monitor logo, for me, it's the same key as F7. I should have commented under @shreyv post, sorry about that. But your answer seem to work for them, so it's all good. Have a great week. – ordinary Apr 26 '21 at 02:37
  • @ordinary No problem. I see what you're saying though. Laptops are different and they didn't list their make and model. Also, when it comes to the laptop lid switch, this usually depends on ACPI which can also vary. – mchid Apr 26 '21 at 10:54
  • @ordinary On the topic of ACPI, sometimes those keys don't even work right out the box on Ubuntu. There's usually a support package or a workaround to get it working if not but not always. – mchid Apr 26 '21 at 11:05
  • 1
    Not surprising. AFAIK some brands do have poor support for firmware in general, not just for Linux. That which isn't advertised, and you learn to consider with time when buying. Like they say, you get what you pay for. But then you see people listing xyz isn't working. I'm fine with my H/W under Linux e.g. S3 sleep was added the same year after the release. Seen few updates related to `Fn' keys, it's settings in UEFI besides general updates to security, performance, etc. – ordinary Apr 26 '21 at 13:13