💾 Archived View for gmi.bacardi55.io › blog › 2023 › 02 › 18 › new-laptop-part5-power-management captured on 2023-06-14 at 14:03:17. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-03-20)

-=-=-=-=-=-=-

New laptop part 5: power management

Posted on 2023-02-18

Introduction

This blog post is about a few things I put in place for screen locking and automatically suspend. It isn't about battery optimisation.

i3lock

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 `~/.config/i3/scripts/blur-lock':

#!/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 `5x4' to `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].

i3lock

on github

xss-lock

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. --

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 (`~/.config/i3/config'):

exec --no-startup-id xss-lock -- /home/bacardi55/.config/i3/scripts/blur-lock

Rofi script

The power menu allow easy select to hibernate, suspend, lock, logout, reboot or shutdown:

This script comes from [EndeavourOS i3wm configuration].

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"

After installing `xautolock', of course:

sudo pacman -S xautolock

Suspend automatically

To suspend the screen automatically after 15 minutes, edit the `/etc/systemd/logind.conf':

`logind.conf'

[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.conf':

[Sleep]
AllowHibernation=yes
AllowSuspendThenHibernate=yes
HibernateState=disk
HibernateDelaySec=30min

Normally, it should suspend after 15min and move to hibernation 30min later.

Fixing hibernation

I finally managed to fix hibernation on my installation. This was due to dracut configuration missing. EndeavourOS switched to `dracut' from `mkinitcpio'. All I needed to do was to add:

add_dracutmodules+=" resume "

In the `/etc/dracut.conf.d/calamares-luks.conf' file. And then rebuild initramfs:

sudo dracut-rebuild

Thanks a lot [Lorenzo's post] for this! Read his post for more information too.

Lorenzo's post

Conclusion

That's it for this post, nothing crazy here. The main win for me was fixing the hibernation :).

/gemlog/

Send me a gemini mention

send me an email!