Ubuntu realizes automatic lock screen without turning off the screen

ubuntu Since 12.04, Ubuntu doesn't come with any screen saver, just a black screen when the system is idle.

If we still have work other than memory when the screen is black, there will be freezes without installing a virtual display, but because the screen is black, you can’t actually see it. But if we need to use ubuntu for rendering or calculation, it will be significantly slower.

The following provides a solution for ubuntu to automatically lock the screen without turning off the screen. It should be noted that this solution will not turn off the screen on the basis of automatic lock screen, but the screen will still be black at the moment of locking the screen. Afterwards, the screen will always be on. If you consider power saving, you can turn off the power of the display by yourself without affecting your work.

so let's get started

Solution 1: Set the lock screen time to automatically lock the screen at the time you need to prevent people from forgetting to lock the screen when they leave. When there is a need for work, you can actively lock the screen through win+L, and you can turn off the display if you consider power saving.

1. First, you need to install the extended application of the ubuntu desktop, which will be used later in the command line

sudo apt install gnome-screensaver xdotool -y

2. Create a new sh file with the following content. Note that the language is English and you need to change " is active " to " is active ":

#!/bin/bash

declare -i i=0
declare -i f=0
gnome-screensaver-command -l
xdotool sleep 1 key ctrl sleep 3
while (($f == 0))
do
	if(gnome-screensaver-command -q | grep -q "为活动");
	then
		xdotool sleep 2 key ctrl
	else
		let f=1
	fi
done

exit 0

3. Modify the system shortcut keys, change the old lock screen to ctrl+alt+L, in fact, any hotkey is fine, as long as there is no conflict.

4. Add system shortcut keys, the content is as follows:

Name (random): lockscreen

Command: bash -c "/The specific path of the above sh file.sh"

Shortcut key: Super+L

Solution 2: Set the screen off time to "Never". When there is a need for work, press and hold win+L to make the system use the display off time. This is a flexible application of short press win+L to turn off the screen immediately, and long press win+L to use the system setting scheme.

Guess you like

Origin blog.csdn.net/DeleteElf/article/details/131644282