0

I know of the Meta+L (and some other combo) to lock the screen which makes the screen go to sleep pretty quickly.

However, I'd like to put my computer screen to sleep but not lock it.

Is there a way to have a hotkey do that under Gnome Ubuntu 18.04?

Alexis Wilke
  • 2,787

2 Answers2

2

First, in settings - Screen Lock, turn "Screen Lock" off to disable the lock screen from automatically kicking in after a period of inactivity, or when you return from "sleep" state.

To make Super+L blank the screen, first disable its default assignment in "Settings" - "Keyboard shortcuts" (Click the entry, press Backspace to clear the assignment and click "Set" to finish.

Then, under custom shortcuts, create a new shortcut key (click "+" at the bottom). As "Command", specify

sh -c 'sleep 1 && xdg-screensaver activate'

and assign your desired shortcut key.

The "sleep" command is needed to give you time to release the keys. Otherwise, the command is executed, but as you release keys, the screen will be unblanked already.

Update 2023-07-10: the command originally provided, i.e., sh -c 'sleep 1 && xset dpms force off', only works when the traditional display server X11 is in use. Thanks to Martin Laakso for pointing this out,

vanadium
  • 97,564
1

-Credit to vanadium, going to update his answer for Ubuntu 24-

To make Super+L blank the screen, first disable its default assignment in "Settings" - "Keyboard shortcuts" (Click the entry, press Backspace to clear the assignment and click "Set" to finish.

Then, under custom shortcuts, create a new shortcut key (click "+" at the bottom). As "Command", specify

set this as a custom keyboard shortcut:

sh -c 'systemctl suspend && xdg-screensaver activate'

To disable the lock screen on the screen saver run this in terminal:

gsettings set org.gnome.desktop.screensaver lock-enabled false

Josiah
  • 111