Swaylock and hyprlock Trigger Idle Resume Event, Disrupting Screen Brightness

Hello everyone,

I managed to resolve the issue with swaylock and hyprlock triggering the idle resume event and disrupting screen brightness. Below are the configurations for both swayidle and hypridle that worked for me.

Swayidle Configuration

swayidle config:

timeout 1 '' resume "pidof swaylock || (brightnessctl set $(cat /tmp/bn) && hyprctl dispatch dpms on)"
timeout 280 'pidof swaylock || (brightnessctl g > /tmp/bn && brightnessctl -s set 5)' 
timeout 290 'pidof swaylock || hyprctl dispatch dpms off' 
timeout 300 'pidof swaylock || swaylock --screenshots --clock --indicator --indicator-radius 100 --indicator-thickness 7 --effect-blur 7x5 --effect-vignette 0.5:0.5 --ring-color bb00cc --key-hl-color 880033 --line-color 00000000 --inside-color 00000088 --separator-color 00000000 --fade-in 0.2' 
timeout 1 '' resume "bash /path/to/check_swaylock.sh"
timeout 5 'pidof swaylock && brightnessctl -p -r && brightnessctl -s set 5' 
timeout 10 'pidof swaylock && hyprctl dispatch dpms off' 

check_swaylock.sh:

#!/bin/bash

# Check if swaylock is running
if pidof swaylock >/dev/null; then
    # Get the first process ID of swaylock
    pid=$(pgrep -o swaylock)
    
    # Check the elapsed time since the process started
    elapsed_time=$(ps -p "$pid" -o etimes= | tr -d ' ')
    
    # If the elapsed time is greater than 1 second
    if [ "$elapsed_time" -gt 1 ]; then
        # Restore the screen brightness from /tmp/bn
        brightness=$(cat /tmp/bn)
        brightnessctl set "$brightness"
        
        # Turn on the DPMS (Display Power Management Signaling) to ensure the display is active
        hyprctl dispatch dpms on
    fi
fi

To enable:

exec brightnessctl g > /tmp/bn && swayidle -C /path/to/swayidle-config

To bind the lock screen key:

killall -s SIGUSR1 swayidle

Hypridle Configuration

hypridle.conf:

general {
    lock_cmd = pidof hyprlock || hyprlock
    before_sleep_cmd = loginctl lock-session
    after_sleep_cmd = hyprctl dispatch dpms on
}

listener {
    timeout = 1
    on-timeout = pidof hyprlock || (bn=$(brightnessctl g) && [ "$bn" != "$(cat /tmp/bn)" ] && echo $bn > /tmp/bn)
    on-resume = pidof hyprlock || (brightnessctl set $(cat /tmp/bn) && hyprctl dispatch dpms on)
}

listener {
    timeout = 280
    on-timeout = pidof hyprlock || brightnessctl -s set 5
}

listener {
    timeout = 290
    on-timeout = pidof hyprlock || hyprctl dispatch dpms off
}

listener {
    timeout = 300
    on-timeout = loginctl lock-session
}

listener {
    timeout = 1
    on-resume = pidof hyprlock && (pid=$(pgrep -o hyprlock) && [ "$(ps -p $pid -o etimes= | tr -d ' ')" -gt 1 ] && brightnessctl set $(cat /tmp/bn) && hyprctl dispatch dpms on)
}

listener {
    timeout = 5
    on-timeout = pidof hyprlock && brightnessctl -s set 5
}

listener {
    timeout = 10
    on-timeout = pidof hyprlock && hyprctl dispatch dpms off
}

These configurations ensure that the screen brightness is managed correctly and that the display is not unexpectedly turned on during locking. If anyone else faces a similar issue, I hope this helps.

1 Like