This page permanently redirects to gemini://gmi.bacardi55.io/blog/2023/02/18/new-laptop-part5-power-management/.

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':

[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

Proxy Information
Original URL
gemini://gmi.bacardi55.io/blog/2023/02/18/new-laptop-part5-power-management
Status Code
Success (20)
Meta
text/gemini; lang=en
Capsule Response Time
308.958057 milliseconds
Gemini-to-HTML Time
1.067092 milliseconds

This content has been proxied by September (ba2dc).