This blog post is about a few things I put in place for screen locking and automatically suspend. It isn’t about battery optimisation.
To lock the screen, I’m using i3lock. As for the lock image, instead of using a “static” image, I’m using a blur image of the current screen. I find it more dynamic.
To create a blur image of the desktop and use with i3lock, I use this script from EndeavourOS i3wm configuration:
The script is
#!/usr/bin/env bash PICTURE=/tmp/i3lock.png SCREENSHOT="scrot -z $PICTURE" BLUR="20x16" $SCREENSHOT convert $PICTURE -blur $BLUR $PICTURE i3lock -i $PICTURE rm $PICTURE
I just changed the
BLUR variable (from
20x16) to blur even more the image. With that, even if I leave the screen on a chat app, it will blurry enough to not be readable at all.
Original script can be found on github.
As the archlinux wiki says:
xss-lock subscribes to the systemd-events suspend, hibernate, lock-session, and unlock-session with appropriate actions (run locker and wait for user to unlock or kill locker). xss-lock also reacts to DPMS events and runs or kills the locker in response. – https://wiki.archlinux.org/title/Power_management#xss-lock
This means that when a
lock-session events will be launched,
xss-lock will trigger a command. In my case, the script above that start i3lock with the blurred image.
To install it:
sudo pacman -S xss-lock
To test it:
xss-lock -- /home/bacardi55/.config/i3/scripts/blur-lock
Then, to start it at the start of the session, I put in my i3 config (
exec --no-startup-id xss-lock -- /home/bacardi55/.config/i3/scripts/blur-lock
The power menu allow easy select to hibernate, suspend, lock, logout, reboot or shutdown:
This script comes from EndeavourOS i3wm configuration.
Lock screen automatically
To lock the screen automatically after 10min, I use
xautolock and start it within my i3 config:
exec --no-startup-id xautolock -time 10 -locker "~/.config/i3/scripts/blur-lock"
xautolock, of course:
sudo pacman -S xautolock
To suspend the screen automatically after 15 minutes, edit the
[Login] HandlePowerKey=suspend-then-hibernate HandleLidSwitch=suspend-then-hibernate HandleLidSwitchExternalPower=suspend-then-hibernate HandleLidSwitchDocked=ignore IdleAction=suspend-then-hibernate IdleActionSec=15min
The above will start
suspend-then-hibernate that will first suspend and then hibernate. To configure it, edit
[Sleep] AllowHibernation=yes AllowSuspendThenHibernate=yes HibernateState=disk HibernateDelaySec=30min
Normally, it should suspend after 15min and move to hibernation 30min later.
I finally managed to fix hibernation on my installation. This was due to dracut configuration missing. EndeavourOS switched to
mkinitcpio. All I needed to do was to add:
add_dracutmodules+=" resume "
/etc/dracut.conf.d/calamares-luks.conf file. And then rebuild initramfs:
Thanks a lot Lorenzo’s post for this! Read his post for more information too.
That’s it for this post, nothing crazy here. The main win for me was fixing the hibernation :).